Panda3D
 All Classes Functions Variables Enumerations
eggCharacterData.h
1 // Filename: eggCharacterData.h
2 // Created by: drose (23Feb01)
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 EGGCHARACTERDATA_H
16 #define EGGCHARACTERDATA_H
17 
18 #include "pandatoolbase.h"
19 
20 #include "eggJointData.h"
21 #include "eggNode.h"
22 #include "eggData.h"
23 #include "pointerTo.h"
24 #include "namable.h"
25 #include "nameUniquifier.h"
26 
27 #include "pmap.h"
28 
30 class EggSliderData;
31 class EggCharacterDb;
32 
33 ////////////////////////////////////////////////////////////////////
34 // Class : EggCharacterData
35 // Description : Represents a single character, as read and collected
36 // from several models and animation files. This
37 // contains a hierarchy of EggJointData nodes
38 // representing the skeleton, as well as a list of
39 // EggSliderData nodes representing the morph channels
40 // for the character.
41 //
42 // This is very similar to the Character class from
43 // Panda, in that it's capable of associating
44 // skeleton-morph animation channels with models and
45 // calculating the vertex position for each frame. To
46 // some degree, it duplicates the functionality of
47 // Character. However, it differs in one fundamental
48 // principle: it is designed to be a non-real-time
49 // operation, working directly on the Egg structures as
50 // they are, instead of first boiling the Egg data into
51 // native Panda Geom tables for real-time animation.
52 // Because of this, it is (a) double-precision instead
53 // of single precision, (b) capable of generating
54 // modified Egg files, and (c) about a hundred times
55 // slower than the Panda Character class.
56 //
57 // The data in this structure is normally filled in by
58 // the EggCharacterCollection class.
59 ////////////////////////////////////////////////////////////////////
60 class EggCharacterData : public Namable {
61 public:
63  virtual ~EggCharacterData();
64 
65  void rename_char(const string &name);
66 
67  void add_model(int model_index, EggNode *model_root, EggData *egg_data);
68  INLINE int get_num_models() const;
69  INLINE int get_model_index(int n) const;
70  INLINE EggNode *get_model_root(int n) const;
71  INLINE EggData *get_egg_data(int n) const;
72  int get_num_frames(int model_index) const;
73  bool check_num_frames(int model_index);
74  double get_frame_rate(int model_index) const;
75 
76  INLINE EggJointData *get_root_joint() const;
77  INLINE EggJointData *find_joint(const string &name) const;
78  INLINE EggJointData *make_new_joint(const string &name, EggJointData *parent);
79  INLINE int get_num_joints() const;
80  INLINE EggJointData *get_joint(int n) const;
81 
82  bool do_reparent();
84 
85  INLINE int get_num_sliders() const;
86  INLINE EggSliderData *get_slider(int n) const;
87  EggSliderData *find_slider(const string &name) const;
88  EggSliderData *make_slider(const string &name);
89 
90  INLINE int get_num_components() const;
91  INLINE EggComponentData *get_component(int n) const;
92 
93  size_t estimate_db_size() const;
94 
95  virtual void write(ostream &out, int indent_level = 0) const;
96 
97 private:
98  class Model {
99  public:
100  int _model_index;
101  PT(EggNode) _model_root;
102  PT(EggData) _egg_data;
103  };
104  typedef pvector<Model> Models;
105  Models _models;
106 
107  EggCharacterCollection *_collection;
108  EggJointData *_root_joint;
109 
111  SlidersByName _sliders_by_name;
112 
114  Sliders _sliders;
115 
117  Joints _joints;
118 
120  Components _components;
121 
122  NameUniquifier _component_names;
123 
124  friend class EggCharacterCollection;
125 };
126 
127 #include "eggCharacterData.I"
128 
129 #endif
130 
131 
EggSliderData * make_slider(const string &name)
Returns the slider matching the indicated name.
bool do_reparent()
Begins the process of restructuring the joint hierarchy according to the previous calls to reparent_t...
int get_num_models() const
Returns the total number of models associated with this character.
bool check_num_frames(int model_index)
Walks through each component and ensures that all have the same number of frames of animation (except...
size_t estimate_db_size() const
Returns the estimated amount of memory, in megabytes, that will be required to perform the do_reparen...
double get_frame_rate(int model_index) const
Returns the stated frame rate of the specified model.
int get_num_joints() const
Returns the total number of joints in the character joint hierarchy.
void rename_char(const string &name)
Renames all of the models in the character data to the indicated name.
EggSliderData * get_slider(int n) const
Returns the nth slider in the character slider list.
This corresponds to a single morph slider control.
Definition: eggSliderData.h:31
This is the primary interface into all the egg data, and the root of the egg file structure...
Definition: eggData.h:41
EggNode * get_model_root(int n) const
Returns the model_root of the nth model associated with this character.
This is the base class of both EggJointData and EggSliderData.
int get_num_components() const
Returns the total number of joints and sliders in the character.
A handy class for converting a list of arbitrary names (strings) so that each name is guaranteed to b...
A base class for all things which can have a name.
Definition: namable.h:29
int get_model_index(int n) const
Returns the model_index of the nth model associated with this character.
This class is used during joint optimization or restructuring to store the table of interim joint com...
EggJointData * get_root_joint() const
Returns the root joint of the character hierarchy.
EggComponentData * get_component(int n) const
Returns the nth joint or slider in the character.
Represents a set of characters, as read and collected from possibly several model and/or animation eg...
EggSliderData * find_slider(const string &name) const
Returns the slider with the indicated name, or NULL if no slider has that name.
void choose_optimal_hierarchy()
Chooses the best possible parent joint for each of the joints in the hierarchy, based on the score co...
Represents a single character, as read and collected from several models and animation files...
This is one node of a hierarchy of EggJointData nodes, each of which represents a single joint of the...
Definition: eggJointData.h:34
A base class for things that may be directly added into the egg hierarchy.
Definition: eggNode.h:38
EggJointData * get_joint(int n) const
Returns the nth joint in the character joint hierarchy.
void add_model(int model_index, EggNode *model_root, EggData *egg_data)
Indicates that the given model_index (with the indicated model_root) is associated with this characte...
int get_num_frames(int model_index) const
Returns the number of frames of animation of the indicated model.
EggJointData * find_joint(const string &name) const
Returns the first joint found with the indicated name, or NULL if no joint has that name...
int get_num_sliders() const
Returns the number of sliders in the character slider list.
EggData * get_egg_data(int n) const
Returns the EggData representing the egg file that defined this particular model. ...
EggJointData * make_new_joint(const string &name, EggJointData *parent)
Creates a new joint as a child of the indicated joint and returns it.