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
eggData.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
EggCharacterData::make_slider
EggSliderData * make_slider(const std::string &name)
Returns the slider matching the indicated name.
Definition: eggCharacterData.cxx:356
EggCharacterData::get_slider
EggSliderData * get_slider(int n) const
Returns the nth slider in the character slider list.
Definition: eggCharacterData.I:127
pvector< Model >
EggCharacterData::get_component
EggComponentData * get_component(int n) const
Returns the nth joint or slider in the character.
Definition: eggCharacterData.I:147
EggCharacterData::get_num_sliders
int get_num_sliders() const
Returns the number of sliders in the character slider list.
Definition: eggCharacterData.I:119
pmap< std::string, EggSliderData * >
EggCharacterData::find_slider
EggSliderData * find_slider(const std::string &name) const
Returns the slider with the indicated name, or NULL if no slider has that name.
Definition: eggCharacterData.cxx:341
EggCharacterData
Represents a single character, as read and collected from several models and animation files.
Definition: eggCharacterData.h:52
EggCharacterData::find_joint
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.
Definition: eggCharacterData.I:80
EggCharacterData::get_num_components
int get_num_components() const
Returns the total number of joints and sliders in the character.
Definition: eggCharacterData.I:136
EggCharacterData::add_model
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...
Definition: eggCharacterData.cxx:85
EggCharacterData::choose_optimal_hierarchy
void choose_optimal_hierarchy()
Chooses the best possible parent joint for each of the joints in the hierarchy, based on the score co...
Definition: eggCharacterData.cxx:294
EggCharacterData::get_model_root
EggNode * get_model_root(int n) const
Returns the model_root of the nth model associated with this character.
Definition: eggCharacterData.I:49
nameUniquifier.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
eggJointData.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
EggCharacterData::estimate_db_size
size_t estimate_db_size() const
Returns the estimated amount of memory, in megabytes, that will be required to perform the do_reparen...
Definition: eggCharacterData.cxx:378
EggCharacterData::get_joint
EggJointData * get_joint(int n) const
Returns the nth joint in the character joint hierarchy.
Definition: eggCharacterData.I:110
EggCharacterData::get_frame_rate
double get_frame_rate(int model_index) const
Returns the stated frame rate of the specified model.
Definition: eggCharacterData.cxx:123
pmap.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
EggData
This is the primary interface into all the egg data, and the root of the egg file structure.
Definition: eggData.h:37
EggJointData
This is one node of a hierarchy of EggJointData nodes, each of which represents a single joint of the...
Definition: eggJointData.h:31
namable.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
eggNode.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
EggComponentData
This is the base class of both EggJointData and EggSliderData.
Definition: eggComponentData.h:34
EggCharacterData::get_num_frames
int get_num_frames(int model_index) const
Returns the number of frames of animation of the indicated model.
Definition: eggCharacterData.cxx:100
EggCharacterData::rename_char
void rename_char(const std::string &name)
Renames all of the models in the character data to the indicated name.
Definition: eggCharacterData.cxx:66
EggSliderData
This corresponds to a single morph slider control.
Definition: eggSliderData.h:28
EggCharacterData::get_model_index
int get_model_index(int n) const
Returns the model_index of the nth model associated with this character.
Definition: eggCharacterData.I:37
EggCharacterData::check_num_frames
bool check_num_frames(int model_index)
Walks through each component and ensures that all have the same number of frames of animation (except...
Definition: eggCharacterData.cxx:144
EggCharacterData::get_num_joints
int get_num_joints() const
Returns the total number of joints in the character joint hierarchy.
Definition: eggCharacterData.I:101
EggCharacterData::get_egg_data
EggData * get_egg_data(int n) const
Returns the EggData representing the egg file that defined this particular model.
Definition: eggCharacterData.I:59
EggCharacterData::get_root_joint
EggJointData * get_root_joint() const
Returns the root joint of the character hierarchy.
Definition: eggCharacterData.I:71
EggCharacterData::do_reparent
bool do_reparent()
Begins the process of restructuring the joint hierarchy according to the previous calls to reparent_t...
Definition: eggCharacterData.cxx:183
Namable
A base class for all things which can have a name.
Definition: namable.h:26
EggCharacterCollection
Represents a set of characters, as read and collected from possibly several model and/or animation eg...
Definition: eggCharacterCollection.h:32
pandatoolbase.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
eggCharacterData.I
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
EggCharacterData::get_num_models
int get_num_models() const
Returns the total number of models associated with this character.
Definition: eggCharacterData.I:22
EggCharacterData::make_new_joint
EggJointData * make_new_joint(const std::string &name, EggJointData *parent)
Creates a new joint as a child of the indicated joint and returns it.
Definition: eggCharacterData.I:90
EggNode
A base class for things that may be directly added into the egg hierarchy.
Definition: eggNode.h:35
pointerTo.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
EggCharacterDb
This class is used during joint optimization or restructuring to store the table of interim joint com...
Definition: eggCharacterDb.h:41
NameUniquifier
A handy class for converting a list of arbitrary names (strings) so that each name is guaranteed to b...
Definition: nameUniquifier.h:28