Panda3D
somethingToEggConverter.cxx
1 // Filename: somethingToEggConverter.cxx
2 // Created by: drose (26Apr01)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #include "somethingToEggConverter.h"
16 
17 #include "eggData.h"
18 #include "eggExternalReference.h"
19 
20 ////////////////////////////////////////////////////////////////////
21 // Function: SomethingToEggConverter::Constructor
22 // Access: Public
23 // Description:
24 ////////////////////////////////////////////////////////////////////
25 SomethingToEggConverter::
26 SomethingToEggConverter() {
27  _allow_errors = false;
28  _path_replace = new PathReplace;
29  _path_replace->_path_store = PS_absolute;
30  _animation_convert = AC_none;
31  _start_frame = 0.0;
32  _end_frame = 0.0;
33  _frame_inc = 0.0;
34  _neutral_frame = 0.0;
35  _input_frame_rate = 0.0;
36  _output_frame_rate = 0.0;
37  _control_flags = 0;
38  _merge_externals = false;
39  _egg_data = (EggData *)NULL;
40  _error = false;
41 }
42 
43 ////////////////////////////////////////////////////////////////////
44 // Function: SomethingToEggConverter::Copy Constructor
45 // Access: Public
46 // Description:
47 ////////////////////////////////////////////////////////////////////
48 SomethingToEggConverter::
49 SomethingToEggConverter(const SomethingToEggConverter &copy) :
50  _allow_errors(copy._allow_errors),
51  _path_replace(copy._path_replace),
52  _merge_externals(copy._merge_externals)
53 {
54  _egg_data = (EggData *)NULL;
55  _error = false;
56 }
57 
58 ////////////////////////////////////////////////////////////////////
59 // Function: SomethingToEggConverter::Destructor
60 // Access: Public, Virtual
61 // Description:
62 ////////////////////////////////////////////////////////////////////
63 SomethingToEggConverter::
64 ~SomethingToEggConverter() {
66 }
67 
68 ////////////////////////////////////////////////////////////////////
69 // Function: SomethingToEggConverter::set_egg_data
70 // Access: Public
71 // Description: Sets the egg data that will be filled in when
72 // convert_file() is called. This must be called before
73 // convert_file().
74 ////////////////////////////////////////////////////////////////////
76 set_egg_data(EggData *egg_data) {
77  _egg_data = egg_data;
78 }
79 
80 ////////////////////////////////////////////////////////////////////
81 // Function: SomethingToEggConverter::get_additional_extensions
82 // Access: Public, Virtual
83 // Description: Returns a space-separated list of extension, in
84 // addition to the one returned by get_extension(), that
85 // are recognized by this converter.
86 ////////////////////////////////////////////////////////////////////
89  return string();
90 }
91 
92 ////////////////////////////////////////////////////////////////////
93 // Function: SomethingToEggConverter::supports_compressed
94 // Access: Published, Virtual
95 // Description: Returns true if this file type can transparently load
96 // compressed files (with a .pz extension), false
97 // otherwise.
98 ////////////////////////////////////////////////////////////////////
101  return false;
102 }
103 
104 ////////////////////////////////////////////////////////////////////
105 // Function: SomethingToEggConverter::supports_convert_to_node
106 // Access: Published, Virtual
107 // Description: Returns true if this converter can directly convert
108 // the model type to internal Panda memory structures,
109 // given the indicated options, or false otherwise. If
110 // this returns true, then convert_to_node() may be
111 // called to perform the conversion, which may be faster
112 // than calling convert_file() if the ultimate goal is a
113 // PandaNode anyway.
114 ////////////////////////////////////////////////////////////////////
117  return false;
118 }
119 
120 ////////////////////////////////////////////////////////////////////
121 // Function: SomethingToEggConverter::get_input_units
122 // Access: Public, Virtual
123 // Description: This may be called after convert_file() has been
124 // called and returned true, indicating a successful
125 // conversion. It will return the distance units
126 // represented by the converted egg file, if known, or
127 // DU_invalid if not known.
128 ////////////////////////////////////////////////////////////////////
129 DistanceUnit SomethingToEggConverter::
131  return DU_invalid;
132 }
133 
134 ////////////////////////////////////////////////////////////////////
135 // Function: SomethingToEggConverter::convert_to_node
136 // Access: Public, Virtual
137 // Description: Reads the input file and directly produces a
138 // ready-to-render model file as a PandaNode. Returns
139 // NULL on failure, or if it is not supported. (This
140 // functionality is not supported by all converter
141 // types; see supports_convert_to_node()).
142 ////////////////////////////////////////////////////////////////////
143 PT(PandaNode) SomethingToEggConverter::
144 convert_to_node(const LoaderOptions &options, const Filename &filename) {
145  return NULL;
146 }
147 
148 ////////////////////////////////////////////////////////////////////
149 // Function: SomethingToEggConverter::handle_external_reference
150 // Access: Public
151 // Description: Handles an external reference in the source file. If
152 // the merge_externals flag is true (see
153 // set_merge_externals()), this causes the named file to
154 // be read in and converted, and the converted egg
155 // geometry is parented to egg_parent. Otherwise, only
156 // a reference to a similarly named egg file is parented
157 // to egg_parent.
158 //
159 // The parameters orig_filename and searchpath are as
160 // those passed to convert_model_path().
161 //
162 // Returns true on success, false on failure.
163 ////////////////////////////////////////////////////////////////////
166  const Filename &ref_filename) {
167  if (_merge_externals) {
168  SomethingToEggConverter *ext = make_copy();
169  PT(EggData) egg_data = new EggData;
170  egg_data->set_coordinate_system(get_egg_data()->get_coordinate_system());
171  ext->set_egg_data(egg_data);
172 
173  if (!ext->convert_file(ref_filename)) {
174  delete ext;
175  nout << "Unable to read external reference: " << ref_filename << "\n";
176  _error = true;
177  return false;
178  }
179 
180  egg_parent->steal_children(*egg_data);
181  delete ext;
182  return true;
183 
184  } else {
185  // If we're installing external references instead of reading
186  // them, we should make it into an egg filename.
187  Filename filename = ref_filename;
188  filename.set_extension("egg");
189 
190  EggExternalReference *egg_ref = new EggExternalReference("", filename);
191  egg_parent->add_child(egg_ref);
192  }
193 
194  return true;
195 }
void set_extension(const string &s)
Replaces the file extension.
Definition: filename.cxx:837
A basic node of the scene graph or data graph.
Definition: pandaNode.h:72
virtual bool supports_convert_to_node(const LoaderOptions &options) const
Returns true if this converter can directly convert the model type to internal Panda memory structure...
virtual string get_additional_extensions() const
Returns a space-separated list of extension, in addition to the one returned by get_extension(), that are recognized by this converter.
Specifies parameters that may be passed to the loader.
Definition: loaderOptions.h:26
A base class for nodes in the hierarchy that are not leaf nodes.
Definition: eggGroupNode.h:51
bool handle_external_reference(EggGroupNode *egg_parent, const Filename &ref_filename)
Handles an external reference in the source file.
EggData * get_egg_data()
Returns the EggData structure.
This is the primary interface into all the egg data, and the root of the egg file structure...
Definition: eggData.h:41
void set_coordinate_system(CoordinateSystem coordsys)
Changes the coordinate system of the EggData.
Definition: eggData.cxx:279
void clear_egg_data()
Sets the EggData to NULL and makes the converter invalid.
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:44
void steal_children(EggGroupNode &other)
Moves all the children from the other node to this one.
void set_egg_data(EggData *egg_data)
Sets the egg data that will be filled in when convert_file() is called.
EggNode * add_child(EggNode *node)
Adds the indicated child to the group and returns it.
This encapsulates the user&#39;s command-line request to replace existing, incorrect pathnames to models ...
Definition: pathReplace.h:40
Defines a reference to another egg file which should be inserted at this point.
virtual DistanceUnit get_input_units()
This may be called after convert_file() has been called and returned true, indicating a successful co...
This is a base class for a family of converter classes that manage a conversion from some file type t...
virtual bool supports_compressed() const
Returns true if this file type can transparently load compressed files (with a .pz extension)...