Panda3D
somethingToEggConverter.h
1 // Filename: somethingToEggConverter.h
2 // Created by: drose (17Apr01)
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 #ifndef SOMETHINGTOEGGCONVERTER_H
16 #define SOMETHINGTOEGGCONVERTER_H
17 
18 #include "pandatoolbase.h"
19 
20 #include "filename.h"
21 #include "config_util.h" // for get_model_path()
22 #include "animationConvert.h"
23 #include "pathReplace.h"
24 #include "pointerTo.h"
25 #include "distanceUnit.h"
26 #include "pandaNode.h"
27 
28 class EggData;
29 class EggGroupNode;
30 class LoaderOptions;
31 
32 ////////////////////////////////////////////////////////////////////
33 // Class : SomethingToEggConverter
34 // Description : This is a base class for a family of converter
35 // classes that manage a conversion from some file type
36 // to egg format.
37 //
38 // Classes of this type can be used to implement xxx2egg
39 // converter programs, as well as LoaderFileTypeXXX
40 // run-time loaders.
41 ////////////////////////////////////////////////////////////////////
43 public:
46  virtual ~SomethingToEggConverter();
47 
48  virtual SomethingToEggConverter *make_copy()=0;
49 
50  INLINE void clear_error();
51  INLINE bool had_error() const;
52 
53  INLINE void set_path_replace(PathReplace *path_replace);
54  INLINE PathReplace *get_path_replace();
55  INLINE const PathReplace *get_path_replace() const;
56 
57  // These methods dealing with animation and frame rate are only
58  // relevant to converter types that understand animation.
59  INLINE void set_animation_convert(AnimationConvert animation_convert);
60  INLINE AnimationConvert get_animation_convert() const;
61 
62  INLINE void set_character_name(const string &character_name);
63  INLINE const string &get_character_name() const;
64 
65  INLINE void set_start_frame(double start_frame);
66  INLINE bool has_start_frame() const;
67  INLINE double get_start_frame() const;
68  INLINE void clear_start_frame();
69 
70  INLINE void set_end_frame(double end_frame);
71  INLINE bool has_end_frame() const;
72  INLINE double get_end_frame() const;
73  INLINE void clear_end_frame();
74 
75  INLINE void set_frame_inc(double frame_inc);
76  INLINE bool has_frame_inc() const;
77  INLINE double get_frame_inc() const;
78  INLINE void clear_frame_inc();
79 
80  INLINE void set_neutral_frame(double neutral_frame);
81  INLINE bool has_neutral_frame() const;
82  INLINE double get_neutral_frame() const;
83  INLINE void clear_neutral_frame();
84 
85  INLINE void set_input_frame_rate(double input_frame_rate);
86  INLINE bool has_input_frame_rate() const;
87  INLINE double get_input_frame_rate() const;
88  INLINE void clear_input_frame_rate();
89 
90  INLINE void set_output_frame_rate(double output_frame_rate);
91  INLINE bool has_output_frame_rate() const;
92  INLINE double get_output_frame_rate() const;
93  INLINE void clear_output_frame_rate();
94 
95  INLINE static double get_default_frame_rate();
96 
97  INLINE void set_merge_externals(bool merge_externals);
98  INLINE bool get_merge_externals() const;
99 
100  void set_egg_data(EggData *egg_data);
101  INLINE void clear_egg_data();
102  INLINE EggData *get_egg_data();
103 
104  virtual string get_name() const=0;
105  virtual string get_extension() const=0;
106  virtual string get_additional_extensions() const;
107  virtual bool supports_compressed() const;
108  virtual bool supports_convert_to_node(const LoaderOptions &options) const;
109 
110  virtual bool convert_file(const Filename &filename)=0;
111  virtual PT(PandaNode) convert_to_node(const LoaderOptions &options, const Filename &filename);
112  virtual DistanceUnit get_input_units();
113 
114  bool handle_external_reference(EggGroupNode *egg_parent,
115  const Filename &ref_filename);
116 
117  INLINE Filename convert_model_path(const Filename &orig_filename);
118 
119  // Set this true to treat errors as warnings and generate output
120  // anyway.
121  bool _allow_errors;
122 
123 protected:
124  PT(PathReplace) _path_replace;
125 
126  AnimationConvert _animation_convert;
127  string _character_name;
128  double _start_frame;
129  double _end_frame;
130  double _frame_inc;
131  double _neutral_frame;
132  double _input_frame_rate; // frames per second
133  double _output_frame_rate; // frames per second
134  enum ControlFlags {
135  CF_start_frame = 0x0001,
136  CF_end_frame = 0x0002,
137  CF_frame_inc = 0x0004,
138  CF_neutral_frame = 0x0008,
139  CF_input_frame_rate = 0x0010,
140  CF_output_frame_rate = 0x0020,
141  };
142  int _control_flags;
143 
144  bool _merge_externals;
145 
146  PT(EggData) _egg_data;
147 
148  bool _error;
149 };
150 
151 #include "somethingToEggConverter.I"
152 
153 #endif
154 
155 
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...
void clear_input_frame_rate()
Removes the value previously set by set_input_frame_rate().
void set_frame_inc(double frame_inc)
Specifies the increment between frames to extract.
void clear_frame_inc()
Removes the value previously set by set_frame_inc().
bool had_error() const
Returns true if an error was detected during the conversion process (unless _allow_errors is true)...
void clear_start_frame()
Removes the value previously set by set_start_frame().
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
void clear_output_frame_rate()
Removes the value previously set by set_output_frame_rate().
bool has_frame_inc() const
Returns true if the frame increment has been explicitly specified via set_frame_inc(), or false if the ending frame should be implicit based on the source.
bool has_start_frame() const
Returns true if the starting frame has been explicitly specified via set_start_frame(), or false if the starting frame should be implicit based on the source.
bool has_neutral_frame() const
Returns true if the neutral frame has been explicitly specified via set_neutral_frame(), or false otherwise.
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.
double get_neutral_frame() const
Returns the value set by a previous call to set_neutral_frame().
void set_neutral_frame(double neutral_frame)
Specifies the frame of animation to represent the neutral pose of the model.
This is the primary interface into all the egg data, and the root of the egg file structure...
Definition: eggData.h:41
const string & get_character_name() const
Returns the name of the character generated.
bool has_input_frame_rate() const
Returns true if the frame rate has been explicitly specified via set_input_frame_rate(), or false otherwise.
void set_character_name(const string &character_name)
Specifies the name of the character generated.
void set_start_frame(double start_frame)
Specifies the starting frame of the animation to convert, in the units specified by set_input_frame_r...
void clear_egg_data()
Sets the EggData to NULL and makes the converter invalid.
void set_end_frame(double end_frame)
Specifies the ending frame of the animation to convert, in the units specified by set_input_frame_rat...
void clear_error()
Resets the error flag to the no-error state.
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:44
double get_input_frame_rate() const
Returns the value set by a previous call to set_input_frame_rate().
AnimationConvert get_animation_convert() const
Returns how source animation will be converted into egg structures.
void set_path_replace(PathReplace *path_replace)
Replaces the PathReplace object (which specifies how to mangle paths from the source to the destinati...
void clear_neutral_frame()
Removes the value previously set by set_neutral_frame().
void set_animation_convert(AnimationConvert animation_convert)
Specifies how source animation will be converted into egg structures.
void set_egg_data(EggData *egg_data)
Sets the egg data that will be filled in when convert_file() is called.
double get_frame_inc() const
Returns the value set by a previous call to set_frame_inc().
double get_start_frame() const
Returns the value set by a previous call to set_start_frame().
PathReplace * get_path_replace()
Returns a pointer to the PathReplace object associated with this converter.
This encapsulates the user's command-line request to replace existing, incorrect pathnames to models ...
Definition: pathReplace.h:40
bool has_end_frame() const
Returns true if the ending frame has been explicitly specified via set_end_frame(), or false if the ending frame should be implicit based on the source.
void set_merge_externals(bool merge_externals)
Sets the merge_externals flag.
double get_output_frame_rate() const
Returns the value set by a previous call to set_output_frame_rate().
void set_output_frame_rate(double output_frame_rate)
Specifies the number of frames per second that the resulting animation should be played at...
bool get_merge_externals() const
Returns the current state of the merge_externals flag.
void clear_end_frame()
Removes the value previously set by set_end_frame().
virtual DistanceUnit get_input_units()
This may be called after convert_file() has been called and returned true, indicating a successful co...
static double get_default_frame_rate()
Returns the default frame rate if nothing is specified for input_frame_rate or output_frame_rate, and the animation package does not have an implicit frame rate.
void set_input_frame_rate(double input_frame_rate)
Specifies the number of frames per second that is represented by the "frame" unit in the animation pa...
This is a base class for a family of converter classes that manage a conversion from some file type t...
bool has_output_frame_rate() const
Returns true if the frame rate has been explicitly specified via set_output_frame_rate(), or false otherwise.
virtual bool supports_compressed() const
Returns true if this file type can transparently load compressed files (with a .pz extension)...
Filename convert_model_path(const Filename &orig_filename)
Converts the indicated model filename to a relative or absolute or whatever filename, according to _path_replace.
double get_end_frame() const
Returns the value set by a previous call to set_end_frame().