00001 // Filename: somethingToEggConverter.cxx 00002 // Created by: drose (26Apr01) 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 "somethingToEggConverter.h" 00020 00021 #include "eggData.h" 00022 #include "eggExternalReference.h" 00023 00024 //////////////////////////////////////////////////////////////////// 00025 // Function: SomethingToEggConverter::Constructor 00026 // Access: Public 00027 // Description: 00028 //////////////////////////////////////////////////////////////////// 00029 SomethingToEggConverter:: 00030 SomethingToEggConverter() { 00031 _allow_errors = false; 00032 _path_replace = new PathReplace; 00033 _path_replace->_path_store = PS_absolute; 00034 _animation_convert = AC_none; 00035 _start_frame = 0.0; 00036 _end_frame = 0.0; 00037 _frame_inc = 0.0; 00038 _neutral_frame = 0.0; 00039 _input_frame_rate = 0.0; 00040 _output_frame_rate = 0.0; 00041 _control_flags = 0; 00042 _merge_externals = false; 00043 _egg_data = (EggData *)NULL; 00044 _owns_egg_data = false; 00045 _error = false; 00046 } 00047 00048 //////////////////////////////////////////////////////////////////// 00049 // Function: SomethingToEggConverter::Copy Constructor 00050 // Access: Public 00051 // Description: 00052 //////////////////////////////////////////////////////////////////// 00053 SomethingToEggConverter:: 00054 SomethingToEggConverter(const SomethingToEggConverter ©) : 00055 _allow_errors(copy._allow_errors), 00056 _path_replace(copy._path_replace), 00057 _merge_externals(copy._merge_externals) 00058 { 00059 _egg_data = (EggData *)NULL; 00060 _owns_egg_data = false; 00061 _error = false; 00062 } 00063 00064 //////////////////////////////////////////////////////////////////// 00065 // Function: SomethingToEggConverter::Destructor 00066 // Access: Public, Virtual 00067 // Description: 00068 //////////////////////////////////////////////////////////////////// 00069 SomethingToEggConverter:: 00070 ~SomethingToEggConverter() { 00071 clear_egg_data(); 00072 } 00073 00074 //////////////////////////////////////////////////////////////////// 00075 // Function: SomethingToEggConverter::set_egg_data 00076 // Access: Public 00077 // Description: Sets the egg data that will be filled in when 00078 // convert_file() is called. This must be called before 00079 // convert_file(). If owns_egg_data is true, the 00080 // egg_data will be deleted when the converter 00081 // destructs. (We don't use the reference counting on 00082 // EggData, to allow static EggDatas to be passed in.) 00083 //////////////////////////////////////////////////////////////////// 00084 void SomethingToEggConverter:: 00085 set_egg_data(EggData *egg_data, bool owns_egg_data) { 00086 if (_owns_egg_data) { 00087 delete _egg_data; 00088 } 00089 _egg_data = egg_data; 00090 _owns_egg_data = owns_egg_data; 00091 } 00092 00093 //////////////////////////////////////////////////////////////////// 00094 // Function: SomethingToEggConverter::handle_external_reference 00095 // Access: Public 00096 // Description: Handles an external reference in the source file. If 00097 // the merge_externals flag is true (see 00098 // set_merge_externals()), this causes the named file to 00099 // be read in and converted, and the converted egg 00100 // geometry is parented to egg_parent. Otherwise, only 00101 // a reference to a similarly named egg file is parented 00102 // to egg_parent. 00103 // 00104 // The parameters orig_filename and searchpath are as 00105 // those passed to convert_model_path(). 00106 // 00107 // Returns true on success, false on failure. 00108 //////////////////////////////////////////////////////////////////// 00109 bool SomethingToEggConverter:: 00110 handle_external_reference(EggGroupNode *egg_parent, 00111 const Filename &ref_filename) { 00112 if (_merge_externals) { 00113 SomethingToEggConverter *ext = make_copy(); 00114 EggData egg_data; 00115 egg_data.set_coordinate_system(get_egg_data().get_coordinate_system()); 00116 ext->set_egg_data(&egg_data, false); 00117 00118 if (!ext->convert_file(ref_filename)) { 00119 delete ext; 00120 nout << "Unable to read external reference: " << ref_filename << "\n"; 00121 if (!_allow_errors) { 00122 _error = true; 00123 } 00124 return false; 00125 } 00126 00127 egg_parent->steal_children(egg_data); 00128 delete ext; 00129 return true; 00130 00131 } else { 00132 // If we're installing external references instead of reading 00133 // them, we should make it into an egg filename. 00134 Filename filename = ref_filename; 00135 filename.set_extension("egg"); 00136 00137 EggExternalReference *egg_ref = new EggExternalReference("", filename); 00138 egg_parent->add_child(egg_ref); 00139 } 00140 00141 return true; 00142 }