Panda3D
|
00001 // Filename: somethingToEggConverter.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 "somethingToEggConverter.h" 00016 00017 #include "eggData.h" 00018 #include "eggExternalReference.h" 00019 00020 //////////////////////////////////////////////////////////////////// 00021 // Function: SomethingToEggConverter::Constructor 00022 // Access: Public 00023 // Description: 00024 //////////////////////////////////////////////////////////////////// 00025 SomethingToEggConverter:: 00026 SomethingToEggConverter() { 00027 _allow_errors = false; 00028 _path_replace = new PathReplace; 00029 _path_replace->_path_store = PS_absolute; 00030 _animation_convert = AC_none; 00031 _start_frame = 0.0; 00032 _end_frame = 0.0; 00033 _frame_inc = 0.0; 00034 _neutral_frame = 0.0; 00035 _input_frame_rate = 0.0; 00036 _output_frame_rate = 0.0; 00037 _control_flags = 0; 00038 _merge_externals = false; 00039 _egg_data = (EggData *)NULL; 00040 _error = false; 00041 } 00042 00043 //////////////////////////////////////////////////////////////////// 00044 // Function: SomethingToEggConverter::Copy Constructor 00045 // Access: Public 00046 // Description: 00047 //////////////////////////////////////////////////////////////////// 00048 SomethingToEggConverter:: 00049 SomethingToEggConverter(const SomethingToEggConverter ©) : 00050 _allow_errors(copy._allow_errors), 00051 _path_replace(copy._path_replace), 00052 _merge_externals(copy._merge_externals) 00053 { 00054 _egg_data = (EggData *)NULL; 00055 _error = false; 00056 } 00057 00058 //////////////////////////////////////////////////////////////////// 00059 // Function: SomethingToEggConverter::Destructor 00060 // Access: Public, Virtual 00061 // Description: 00062 //////////////////////////////////////////////////////////////////// 00063 SomethingToEggConverter:: 00064 ~SomethingToEggConverter() { 00065 clear_egg_data(); 00066 } 00067 00068 //////////////////////////////////////////////////////////////////// 00069 // Function: SomethingToEggConverter::set_egg_data 00070 // Access: Public 00071 // Description: Sets the egg data that will be filled in when 00072 // convert_file() is called. This must be called before 00073 // convert_file(). 00074 //////////////////////////////////////////////////////////////////// 00075 void SomethingToEggConverter:: 00076 set_egg_data(EggData *egg_data) { 00077 _egg_data = egg_data; 00078 } 00079 00080 //////////////////////////////////////////////////////////////////// 00081 // Function: SomethingToEggConverter::get_additional_extensions 00082 // Access: Public, Virtual 00083 // Description: Returns a space-separated list of extension, in 00084 // addition to the one returned by get_extension(), that 00085 // are recognized by this converter. 00086 //////////////////////////////////////////////////////////////////// 00087 string SomethingToEggConverter:: 00088 get_additional_extensions() const { 00089 return string(); 00090 } 00091 00092 //////////////////////////////////////////////////////////////////// 00093 // Function: SomethingToEggConverter::supports_compressed 00094 // Access: Published, Virtual 00095 // Description: Returns true if this file type can transparently load 00096 // compressed files (with a .pz extension), false 00097 // otherwise. 00098 //////////////////////////////////////////////////////////////////// 00099 bool SomethingToEggConverter:: 00100 supports_compressed() const { 00101 return false; 00102 } 00103 00104 //////////////////////////////////////////////////////////////////// 00105 // Function: SomethingToEggConverter::get_input_units 00106 // Access: Public, Virtual 00107 // Description: This may be called after convert_file() has been 00108 // called and returned true, indicating a successful 00109 // conversion. It will return the distance units 00110 // represented by the converted egg file, if known, or 00111 // DU_invalid if not known. 00112 //////////////////////////////////////////////////////////////////// 00113 DistanceUnit SomethingToEggConverter:: 00114 get_input_units() { 00115 return DU_invalid; 00116 } 00117 00118 //////////////////////////////////////////////////////////////////// 00119 // Function: SomethingToEggConverter::handle_external_reference 00120 // Access: Public 00121 // Description: Handles an external reference in the source file. If 00122 // the merge_externals flag is true (see 00123 // set_merge_externals()), this causes the named file to 00124 // be read in and converted, and the converted egg 00125 // geometry is parented to egg_parent. Otherwise, only 00126 // a reference to a similarly named egg file is parented 00127 // to egg_parent. 00128 // 00129 // The parameters orig_filename and searchpath are as 00130 // those passed to convert_model_path(). 00131 // 00132 // Returns true on success, false on failure. 00133 //////////////////////////////////////////////////////////////////// 00134 bool SomethingToEggConverter:: 00135 handle_external_reference(EggGroupNode *egg_parent, 00136 const Filename &ref_filename) { 00137 if (_merge_externals) { 00138 SomethingToEggConverter *ext = make_copy(); 00139 PT(EggData) egg_data = new EggData; 00140 egg_data->set_coordinate_system(get_egg_data()->get_coordinate_system()); 00141 ext->set_egg_data(egg_data); 00142 00143 if (!ext->convert_file(ref_filename)) { 00144 delete ext; 00145 nout << "Unable to read external reference: " << ref_filename << "\n"; 00146 _error = true; 00147 return false; 00148 } 00149 00150 egg_parent->steal_children(*egg_data); 00151 delete ext; 00152 return true; 00153 00154 } else { 00155 // If we're installing external references instead of reading 00156 // them, we should make it into an egg filename. 00157 Filename filename = ref_filename; 00158 filename.set_extension("egg"); 00159 00160 EggExternalReference *egg_ref = new EggExternalReference("", filename); 00161 egg_parent->add_child(egg_ref); 00162 } 00163 00164 return true; 00165 }