Panda3D
somethingToEggConverter.cxx
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file somethingToEggConverter.cxx
10  * @author drose
11  * @date 2001-04-26
12  */
13 
15 
16 #include "eggData.h"
17 #include "eggExternalReference.h"
18 
19 /**
20  *
21  */
22 SomethingToEggConverter::
23 SomethingToEggConverter() {
24  _allow_errors = false;
25  _path_replace = new PathReplace;
26  _path_replace->_path_store = PS_absolute;
27  _animation_convert = AC_none;
28  _start_frame = 0.0;
29  _end_frame = 0.0;
30  _frame_inc = 0.0;
31  _neutral_frame = 0.0;
32  _input_frame_rate = 0.0;
33  _output_frame_rate = 0.0;
34  _control_flags = 0;
35  _merge_externals = false;
36  _egg_data = nullptr;
37  _error = false;
38 }
39 
40 /**
41  *
42  */
43 SomethingToEggConverter::
44 SomethingToEggConverter(const SomethingToEggConverter &copy) :
45  _allow_errors(copy._allow_errors),
46  _path_replace(copy._path_replace),
47  _merge_externals(copy._merge_externals)
48 {
49  _egg_data = nullptr;
50  _error = false;
51 }
52 
53 /**
54  *
55  */
56 SomethingToEggConverter::
57 ~SomethingToEggConverter() {
59 }
60 
61 /**
62  * Sets the egg data that will be filled in when convert_file() is called.
63  * This must be called before convert_file().
64  */
66 set_egg_data(EggData *egg_data) {
67  _egg_data = egg_data;
68 }
69 
70 /**
71  * Returns a space-separated list of extension, in addition to the one
72  * returned by get_extension(), that are recognized by this converter.
73  */
74 std::string SomethingToEggConverter::
76  return std::string();
77 }
78 
79 /**
80  * Returns true if this file type can transparently load compressed files
81  * (with a .pz extension), false otherwise.
82  */
85  return false;
86 }
87 
88 /**
89  * Returns true if this converter can directly convert the model type to
90  * internal Panda memory structures, given the indicated options, or false
91  * otherwise. If this returns true, then convert_to_node() may be called to
92  * perform the conversion, which may be faster than calling convert_file() if
93  * the ultimate goal is a PandaNode anyway.
94  */
96 supports_convert_to_node(const LoaderOptions &options) const {
97  return false;
98 }
99 
100 /**
101  * This may be called after convert_file() has been called and returned true,
102  * indicating a successful conversion. It will return the distance units
103  * represented by the converted egg file, if known, or DU_invalid if not
104  * known.
105  */
108  return DU_invalid;
109 }
110 
111 /**
112  * Reads the input file and directly produces a ready-to-render model file as
113  * a PandaNode. Returns NULL on failure, or if it is not supported. (This
114  * functionality is not supported by all converter types; see
115  * supports_convert_to_node()).
116  */
117 PT(PandaNode) SomethingToEggConverter::
118 convert_to_node(const LoaderOptions &options, const Filename &filename) {
119  return nullptr;
120 }
121 
122 /**
123  * Handles an external reference in the source file. If the merge_externals
124  * flag is true (see set_merge_externals()), this causes the named file to be
125  * read in and converted, and the converted egg geometry is parented to
126  * egg_parent. Otherwise, only a reference to a similarly named egg file is
127  * parented to egg_parent.
128  *
129  * The parameters orig_filename and searchpath are as those passed to
130  * convert_model_path().
131  *
132  * Returns true on success, false on failure.
133  */
136  const Filename &ref_filename) {
137  if (_merge_externals) {
138  SomethingToEggConverter *ext = make_copy();
139  PT(EggData) egg_data = new EggData;
140  egg_data->set_coordinate_system(get_egg_data()->get_coordinate_system());
141  ext->set_egg_data(egg_data);
142 
143  if (!ext->convert_file(ref_filename)) {
144  delete ext;
145  nout << "Unable to read external reference: " << ref_filename << "\n";
146  _error = true;
147  return false;
148  }
149 
150  egg_parent->steal_children(*egg_data);
151  delete ext;
152  return true;
153 
154  } else {
155  // If we're installing external references instead of reading them, we
156  // should make it into an egg filename.
157  Filename filename = ref_filename;
158  filename.set_extension("egg");
159 
160  EggExternalReference *egg_ref = new EggExternalReference("", filename);
161  egg_parent->add_child(egg_ref);
162  }
163 
164  return true;
165 }
void set_extension(const std::string &s)
Replaces the file extension.
Definition: filename.cxx:804
A basic node of the scene graph or data graph.
Definition: pandaNode.h:64
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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...
Specifies parameters that may be passed to the loader.
Definition: loaderOptions.h:23
A base class for nodes in the hierarchy that are not leaf nodes.
Definition: eggGroupNode.h:46
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:37
DistanceUnit
This enumerated type lists all the kinds of units we're likely to come across in model conversion pro...
Definition: distanceUnit.h:23
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:39
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual std::string get_additional_extensions() const
Returns a space-separated list of extension, in addition to the one returned by get_extension(),...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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.
set_coordinate_system
Changes the coordinate system of the EggData.
Definition: eggData.h:73
This encapsulates the user's command-line request to replace existing, incorrect pathnames to models ...
Definition: pathReplace.h:36
Defines a reference to another egg file which should be inserted at this point.
PT(PandaNode) SomethingToEggConverter
Reads the input file and directly produces a ready-to-render model file as a PandaNode.
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),...