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