00001 // Filename: loaderFileTypeBam.cxx 00002 // Created by: jason (21Jun00) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved 00008 // 00009 // All use of this software is subject to the terms of the Panda 3d 00010 // Software license. You should have received a copy of this license 00011 // along with this source code; you will also find a current copy of 00012 // the license at http://www.panda3d.org/license.txt . 00013 // 00014 // To contact the maintainers of this program write to 00015 // panda3d@yahoogroups.com . 00016 // 00017 //////////////////////////////////////////////////////////////////// 00018 00019 #include "loaderFileTypeBam.h" 00020 #include "config_pgraph.h" 00021 #include "bamFile.h" 00022 00023 #include "dcast.h" 00024 00025 TypeHandle LoaderFileTypeBam::_type_handle; 00026 00027 //////////////////////////////////////////////////////////////////// 00028 // Function: LoaderFileTypeBam::Constructor 00029 // Access: Public 00030 // Description: 00031 //////////////////////////////////////////////////////////////////// 00032 LoaderFileTypeBam:: 00033 LoaderFileTypeBam() { 00034 } 00035 00036 //////////////////////////////////////////////////////////////////// 00037 // Function: LoaderFileTypeBam::get_name 00038 // Access: Public, Virtual 00039 // Description: 00040 //////////////////////////////////////////////////////////////////// 00041 string LoaderFileTypeBam:: 00042 get_name() const { 00043 return "Bam"; 00044 } 00045 00046 //////////////////////////////////////////////////////////////////// 00047 // Function: LoaderFileTypeBam::get_extension 00048 // Access: Public, Virtual 00049 // Description: 00050 //////////////////////////////////////////////////////////////////// 00051 string LoaderFileTypeBam:: 00052 get_extension() const { 00053 return "bam"; 00054 } 00055 00056 //////////////////////////////////////////////////////////////////// 00057 // Function: LoaderFileTypeBam::load_file 00058 // Access: Public, Virtual 00059 // Description: 00060 //////////////////////////////////////////////////////////////////// 00061 PT(PandaNode) LoaderFileTypeBam:: 00062 load_file(const Filename &path, bool report_errors) const { 00063 BamFile bam_file; 00064 if (!bam_file.open_read(path, report_errors)) { 00065 return NULL; 00066 } 00067 00068 PT(PandaNode) result; 00069 00070 TypedWritable *object = bam_file.read_object(); 00071 if (object == TypedWritable::Null) { 00072 if (report_errors) { 00073 loader_cat.error() << "Bam file " << path << " is empty.\n"; 00074 } 00075 00076 } else if (!object->is_of_type(PandaNode::get_class_type())) { 00077 if (report_errors) { 00078 loader_cat.error() 00079 << "Bam file " << path 00080 << " contains a " << object->get_type() << ", not a PandaNode.\n"; 00081 } 00082 00083 } else { 00084 result = DCAST(PandaNode, object); 00085 00086 if (report_errors) { 00087 bam_file.read_object(); 00088 if (!bam_file.is_eof()) { 00089 loader_cat.warning() 00090 << "Ignoring extra objects in " << path << "\n"; 00091 } 00092 } 00093 } 00094 00095 if (!bam_file.resolve()) { 00096 if (report_errors) { 00097 loader_cat.error() 00098 << "Unable to resolve Bam file.\n"; 00099 result = (PandaNode *)NULL; 00100 } 00101 } 00102 00103 return result; 00104 } 00105