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 00023 TypeHandle LoaderFileTypePandatool::_type_handle; 00024 00025 //////////////////////////////////////////////////////////////////// 00026 // Function: LoaderFileTypePandatool::Constructor 00027 // Access: Public 00028 // Description: 00029 //////////////////////////////////////////////////////////////////// 00030 LoaderFileTypePandatool:: 00031 LoaderFileTypePandatool(SomethingToEggConverter *converter) : 00032 _converter(converter) 00033 { 00034 converter->set_merge_externals(true); 00035 } 00036 00037 //////////////////////////////////////////////////////////////////// 00038 // Function: LoaderFileTypePandatool::Destructor 00039 // Access: Public, Virtual 00040 // Description: 00041 //////////////////////////////////////////////////////////////////// 00042 LoaderFileTypePandatool:: 00043 ~LoaderFileTypePandatool() { 00044 } 00045 00046 //////////////////////////////////////////////////////////////////// 00047 // Function: LoaderFileTypePandatool::get_name 00048 // Access: Public, Virtual 00049 // Description: 00050 //////////////////////////////////////////////////////////////////// 00051 string LoaderFileTypePandatool:: 00052 get_name() const { 00053 return _converter->get_name(); 00054 } 00055 00056 //////////////////////////////////////////////////////////////////// 00057 // Function: LoaderFileTypePandatool::get_extension 00058 // Access: Public, Virtual 00059 // Description: 00060 //////////////////////////////////////////////////////////////////// 00061 string LoaderFileTypePandatool:: 00062 get_extension() const { 00063 return _converter->get_extension(); 00064 } 00065 00066 //////////////////////////////////////////////////////////////////// 00067 // Function: LoaderFileTypePandatool::get_additional_extensions 00068 // Access: Public, Virtual 00069 // Description: Returns a space-separated list of extension, in 00070 // addition to the one returned by get_extension(), that 00071 // are recognized by this converter. 00072 //////////////////////////////////////////////////////////////////// 00073 string LoaderFileTypePandatool:: 00074 get_additional_extensions() const { 00075 return _converter->get_additional_extensions(); 00076 } 00077 00078 //////////////////////////////////////////////////////////////////// 00079 // Function: LoaderFileTypePandatool::supports_compressed 00080 // Access: Published, Virtual 00081 // Description: Returns true if this file type can transparently load 00082 // compressed files (with a .pz extension), false 00083 // otherwise. 00084 //////////////////////////////////////////////////////////////////// 00085 bool LoaderFileTypePandatool:: 00086 supports_compressed() const { 00087 return _converter->supports_compressed(); 00088 } 00089 00090 //////////////////////////////////////////////////////////////////// 00091 // Function: LoaderFileTypePandatool::resolve_filename 00092 // Access: Public, Virtual 00093 // Description: Searches for the indicated filename on whatever paths 00094 // are appropriate to this file type, and updates it if 00095 // it is found. 00096 //////////////////////////////////////////////////////////////////// 00097 void LoaderFileTypePandatool:: 00098 resolve_filename(Filename &path) const { 00099 path.resolve_filename(get_model_path(), get_extension()); 00100 } 00101 00102 //////////////////////////////////////////////////////////////////// 00103 // Function: LoaderFileTypePandatool::load_file 00104 // Access: Public, Virtual 00105 // Description: 00106 //////////////////////////////////////////////////////////////////// 00107 PT(PandaNode) LoaderFileTypePandatool:: 00108 load_file(const Filename &path, const LoaderOptions &options, 00109 BamCacheRecord *record) const { 00110 PT(PandaNode) result; 00111 00112 PT(EggData) egg_data = new EggData; 00113 _converter->set_egg_data(egg_data); 00114 00115 DSearchPath file_path; 00116 file_path.append_directory(path.get_dirname()); 00117 _converter->get_path_replace()->_path = file_path; 00118 00119 // Convert animation, if the converter supports it. 00120 switch (options.get_flags() & LoaderOptions::LF_convert_anim) { 00121 case LoaderOptions::LF_convert_anim: 00122 _converter->set_animation_convert(AC_both); 00123 break; 00124 00125 case LoaderOptions::LF_convert_skeleton: 00126 _converter->set_animation_convert(AC_model); 00127 break; 00128 00129 case LoaderOptions::LF_convert_channels: 00130 _converter->set_animation_convert(AC_chan); 00131 break; 00132 00133 default: 00134 break; 00135 } 00136 00137 if (_converter->convert_file(path)) { 00138 DistanceUnit input_units = _converter->get_input_units(); 00139 if (input_units != DU_invalid && ptloader_units != DU_invalid && 00140 input_units != ptloader_units) { 00141 // Convert the file to the units specified by the ptloader-units 00142 // Configrc variable. 00143 ptloader_cat.info() 00144 << "Converting from " << format_long_unit(input_units) 00145 << " to " << format_long_unit(ptloader_units) << "\n"; 00146 double scale = convert_units(input_units, ptloader_units); 00147 egg_data->transform(LMatrix4d::scale_mat(scale)); 00148 } 00149 00150 if (!egg_data->has_normals()) { 00151 egg_data->recompute_polygon_normals(); 00152 } 00153 00154 result = load_egg_data(egg_data); 00155 } 00156 _converter->clear_egg_data(); 00157 return result.p(); 00158 }