Panda3D
|
00001 // Filename: loaderFileTypePandatool.cxx 00002 // Created by: drose (26Apr01) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 #include "loaderFileTypePandatool.h" 00016 #include "config_ptloader.h" 00017 #include "somethingToEggConverter.h" 00018 #include "config_util.h" 00019 #include "load_egg_file.h" 00020 #include "eggData.h" 00021 #include "loaderOptions.h" 00022 #include "bamCacheRecord.h" 00023 00024 TypeHandle LoaderFileTypePandatool::_type_handle; 00025 00026 //////////////////////////////////////////////////////////////////// 00027 // Function: LoaderFileTypePandatool::Constructor 00028 // Access: Public 00029 // Description: 00030 //////////////////////////////////////////////////////////////////// 00031 LoaderFileTypePandatool:: 00032 LoaderFileTypePandatool(SomethingToEggConverter *converter) : 00033 _converter(converter) 00034 { 00035 converter->set_merge_externals(true); 00036 } 00037 00038 //////////////////////////////////////////////////////////////////// 00039 // Function: LoaderFileTypePandatool::Destructor 00040 // Access: Public, Virtual 00041 // Description: 00042 //////////////////////////////////////////////////////////////////// 00043 LoaderFileTypePandatool:: 00044 ~LoaderFileTypePandatool() { 00045 } 00046 00047 //////////////////////////////////////////////////////////////////// 00048 // Function: LoaderFileTypePandatool::get_name 00049 // Access: Public, Virtual 00050 // Description: 00051 //////////////////////////////////////////////////////////////////// 00052 string LoaderFileTypePandatool:: 00053 get_name() const { 00054 return _converter->get_name(); 00055 } 00056 00057 //////////////////////////////////////////////////////////////////// 00058 // Function: LoaderFileTypePandatool::get_extension 00059 // Access: Public, Virtual 00060 // Description: 00061 //////////////////////////////////////////////////////////////////// 00062 string LoaderFileTypePandatool:: 00063 get_extension() const { 00064 return _converter->get_extension(); 00065 } 00066 00067 //////////////////////////////////////////////////////////////////// 00068 // Function: LoaderFileTypePandatool::get_additional_extensions 00069 // Access: Public, Virtual 00070 // Description: Returns a space-separated list of extension, in 00071 // addition to the one returned by get_extension(), that 00072 // are recognized by this converter. 00073 //////////////////////////////////////////////////////////////////// 00074 string LoaderFileTypePandatool:: 00075 get_additional_extensions() const { 00076 return _converter->get_additional_extensions(); 00077 } 00078 00079 //////////////////////////////////////////////////////////////////// 00080 // Function: LoaderFileTypePandatool::supports_compressed 00081 // Access: Published, Virtual 00082 // Description: Returns true if this file type can transparently load 00083 // compressed files (with a .pz extension), false 00084 // otherwise. 00085 //////////////////////////////////////////////////////////////////// 00086 bool LoaderFileTypePandatool:: 00087 supports_compressed() const { 00088 return _converter->supports_compressed(); 00089 } 00090 00091 //////////////////////////////////////////////////////////////////// 00092 // Function: LoaderFileTypePandatool::resolve_filename 00093 // Access: Public, Virtual 00094 // Description: Searches for the indicated filename on whatever paths 00095 // are appropriate to this file type, and updates it if 00096 // it is found. 00097 //////////////////////////////////////////////////////////////////// 00098 void LoaderFileTypePandatool:: 00099 resolve_filename(Filename &path) const { 00100 path.resolve_filename(get_model_path(), get_extension()); 00101 } 00102 00103 //////////////////////////////////////////////////////////////////// 00104 // Function: LoaderFileTypePandatool::load_file 00105 // Access: Public, Virtual 00106 // Description: 00107 //////////////////////////////////////////////////////////////////// 00108 PT(PandaNode) LoaderFileTypePandatool:: 00109 load_file(const Filename &path, const LoaderOptions &options, 00110 BamCacheRecord *record) const { 00111 if (record != (BamCacheRecord *)NULL) { 00112 record->add_dependent_file(path); 00113 } 00114 00115 PT(PandaNode) result; 00116 00117 PT(EggData) egg_data = new EggData; 00118 _converter->set_egg_data(egg_data); 00119 00120 DSearchPath file_path; 00121 file_path.append_directory(path.get_dirname()); 00122 _converter->get_path_replace()->_path = file_path; 00123 00124 // Convert animation, if the converter supports it. 00125 switch (options.get_flags() & LoaderOptions::LF_convert_anim) { 00126 case LoaderOptions::LF_convert_anim: 00127 _converter->set_animation_convert(AC_both); 00128 break; 00129 00130 case LoaderOptions::LF_convert_skeleton: 00131 _converter->set_animation_convert(AC_model); 00132 break; 00133 00134 case LoaderOptions::LF_convert_channels: 00135 _converter->set_animation_convert(AC_chan); 00136 break; 00137 00138 default: 00139 break; 00140 } 00141 00142 if (_converter->convert_file(path)) { 00143 DistanceUnit input_units = _converter->get_input_units(); 00144 if (input_units != DU_invalid && ptloader_units != DU_invalid && 00145 input_units != ptloader_units) { 00146 // Convert the file to the units specified by the ptloader-units 00147 // Configrc variable. 00148 ptloader_cat.info() 00149 << "Converting from " << format_long_unit(input_units) 00150 << " to " << format_long_unit(ptloader_units) << "\n"; 00151 double scale = convert_units(input_units, ptloader_units); 00152 egg_data->transform(LMatrix4d::scale_mat(scale)); 00153 } 00154 00155 if (!egg_data->has_primitives()) { 00156 egg_data->make_point_primitives(); 00157 } else if (!egg_data->has_normals()) { 00158 egg_data->recompute_polygon_normals(); 00159 } 00160 00161 result = load_egg_data(egg_data); 00162 } 00163 _converter->clear_egg_data(); 00164 return result.p(); 00165 }