Panda3D
eggCharacterCollection.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 eggCharacterCollection.h
10  * @author drose
11  * @date 2001-02-26
12  */
13 
14 #ifndef EGGCHARACTERCOLLECTION_H
15 #define EGGCHARACTERCOLLECTION_H
16 
17 #include "pandatoolbase.h"
18 
19 #include "eggCharacterData.h"
20 
21 #include "eggData.h"
22 #include "eggNode.h"
23 #include "pointerTo.h"
24 
25 class EggTable;
26 class EggAttributes;
27 
28 /**
29  * Represents a set of characters, as read and collected from possibly several
30  * model and/or animation egg files.
31  */
33 public:
35  virtual ~EggCharacterCollection();
36 
37  int add_egg(EggData *egg);
38 
39  INLINE int get_num_eggs() const;
40  INLINE EggData *get_egg(int i) const;
41  INLINE int get_first_model_index(int egg_index) const;
42  INLINE int get_num_models(int egg_index) const;
43 
44  INLINE int get_num_characters() const;
45  INLINE EggCharacterData *get_character(int i) const;
46  EggCharacterData *get_character_by_name(const std::string &character_name) const;
47 
48  INLINE EggCharacterData *get_character_by_model_index(int model_index) const;
49 
50  void rename_char(int i, const std::string &name);
51 
52  virtual void write(std::ostream &out, int indent_level = 0) const;
53  void check_errors(std::ostream &out, bool force_initial_rest_frame);
54 
56  virtual EggJointData *make_joint_data(EggCharacterData *char_data);
57  virtual EggSliderData *make_slider_data(EggCharacterData *char_data);
58 
59 public:
60  EggCharacterData *make_character(const std::string &character_name);
61 
62  class EggInfo {
63  public:
64  PT(EggData) _egg;
65  typedef pvector< PT(EggNode) > Models;
66  Models _models;
67  int _first_model_index;
68  };
69 
70  typedef pvector<EggInfo> Eggs;
71  Eggs _eggs;
72 
74  Characters _characters;
75  Characters _characters_by_model_index;
76 
77 private:
78  bool scan_hierarchy(EggNode *egg_node);
79  void scan_for_top_joints(EggNode *egg_node, EggNode *model_root,
80  const std::string &character_name);
81  void scan_for_top_tables(EggTable *bundle, EggNode *model_root,
82  const std::string &character_name);
83  void scan_for_morphs(EggNode *egg_node, int model_index,
84  EggCharacterData *char_data);
85  void scan_for_sliders(EggNode *egg_node, int model_index,
86  EggCharacterData *char_data);
87 
88  void add_morph_back_pointers(EggAttributes *attrib, EggObject *egg_object,
89  int model_index, EggCharacterData *char_data);
90  void add_morph_back_pointers_vertex(EggVertex *vertex, EggObject *egg_object,
91  int model_index, EggCharacterData *char_data);
92 
93  // The _top_egg_nodes member is only used temporarily, when adding each pre-
94  // existing egg file to the structure for the first time.
96  class ModelDescription {
97  public:
98  INLINE ModelDescription();
99  EggNodeList _top_nodes;
100  EggObject *_root_node;
101  };
102 
103  typedef pmap<EggNode *, ModelDescription> TopEggNodes;
104  typedef pmap<std::string, TopEggNodes> TopEggNodesByName;
105  TopEggNodesByName _top_egg_nodes;
106 
107  int _next_model_index;
108 
109  void match_egg_nodes(EggCharacterData *char_Data, EggJointData *joint_data,
110  EggNodeList &egg_nodes, int egg_index, int model_index);
111  void found_egg_match(EggCharacterData *char_data, EggJointData *joint_data,
112  EggNode *egg_node, int egg_index, int model_index);
113 };
114 
115 #include "eggCharacterCollection.I"
116 
117 #endif
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual EggCharacterData * make_character_data()
Allocates and returns a new EggCharacterData structure.
void rename_char(int i, const std::string &name)
Renames the ith character to the indicated name.
This is our own Panda specialization on the default STL map.
Definition: pmap.h:49
int get_num_models(int egg_index) const
Returns the number of different models found in the indicated egg file.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
EggCharacterData * make_character(const std::string &character_name)
Allocates and returns a new EggCharacterData object representing the named character,...
This corresponds to a single morph slider control.
Definition: eggSliderData.h:28
int add_egg(EggData *egg)
Adds a new egg file to the list of models and animation files for this particular character.
This is the primary interface into all the egg data, and the root of the egg file structure.
Definition: eggData.h:37
EggCharacterData * get_character_by_name(const std::string &character_name) const
Returns the Character with the indicated name, if it exists in the collection, or NULL if it does not...
This is our own Panda specialization on the default STL vector.
Definition: pvector.h:42
EggData * get_egg(int i) const
Returns the ith egg file.
The set of attributes that may be applied to vertices as well as polygons, such as surface normal and...
Definition: eggAttributes.h:33
int get_num_characters() const
Returns the number of separate Characters that have been discovered in the various egg files added to...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Any one-, two-, three-, or four-component vertex, possibly with attributes such as a normal.
Definition: eggVertex.h:39
EggCharacterData * get_character(int i) const
Returns the ith character in the collection.
Represents a set of characters, as read and collected from possibly several model and/or animation eg...
int get_first_model_index(int egg_index) const
Returns the first model index associated with the indicated egg file.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Represents a single character, as read and collected from several models and animation files.
This corresponds to a.
Definition: eggTable.h:27
EggCharacterData * get_character_by_model_index(int model_index) const
Returns the character associated with the indicated model index.
This is one node of a hierarchy of EggJointData nodes, each of which represents a single joint of the...
Definition: eggJointData.h:31
virtual EggSliderData * make_slider_data(EggCharacterData *char_data)
Allocates and returns a new EggSliderData structure for the given character.
A base class for things that may be directly added into the egg hierarchy.
Definition: eggNode.h:35
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
int get_num_eggs() const
Returns the number of egg files that have successfully been added to the Character table.
The highest-level base class in the egg directory.
Definition: eggObject.h:29
virtual EggJointData * make_joint_data(EggCharacterData *char_data)
Allocates and returns a new EggJointData structure for the given character.
void check_errors(std::ostream &out, bool force_initial_rest_frame)
Can be called after the collection has been completely filled up with egg files to output any message...