Panda3D

eggCharacterCollection.h

00001 // Filename: eggCharacterCollection.h
00002 // Created by:  drose (26Feb01)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #ifndef EGGCHARACTERCOLLECTION_H
00016 #define EGGCHARACTERCOLLECTION_H
00017 
00018 #include "pandatoolbase.h"
00019 
00020 #include "eggCharacterData.h"
00021 
00022 #include "eggData.h"
00023 #include "eggNode.h"
00024 #include "pointerTo.h"
00025 
00026 class EggTable;
00027 class EggAttributes;
00028 
00029 ////////////////////////////////////////////////////////////////////
00030 //       Class : EggCharacterCollection
00031 // Description : Represents a set of characters, as read and collected
00032 //               from possibly several model and/or animation egg
00033 //               files.
00034 ////////////////////////////////////////////////////////////////////
00035 class EggCharacterCollection {
00036 public:
00037   EggCharacterCollection();
00038   virtual ~EggCharacterCollection();
00039 
00040   int add_egg(EggData *egg);
00041 
00042   INLINE int get_num_eggs() const;
00043   INLINE EggData *get_egg(int i) const;
00044   INLINE int get_first_model_index(int egg_index) const;
00045   INLINE int get_num_models(int egg_index) const;
00046 
00047   INLINE int get_num_characters() const;
00048   INLINE EggCharacterData *get_character(int i) const;
00049   EggCharacterData *get_character_by_name(const string &character_name) const;
00050 
00051   INLINE EggCharacterData *get_character_by_model_index(int model_index) const;
00052 
00053   void rename_char(int i, const string &name);
00054 
00055   virtual void write(ostream &out, int indent_level = 0) const;
00056   void check_errors(ostream &out, bool force_initial_rest_frame);
00057 
00058   virtual EggCharacterData *make_character_data();
00059   virtual EggJointData *make_joint_data(EggCharacterData *char_data);
00060   virtual EggSliderData *make_slider_data(EggCharacterData *char_data);
00061 
00062 public:
00063   EggCharacterData *make_character(const string &character_name);
00064 
00065   class EggInfo {
00066   public:
00067     PT(EggData) _egg;
00068     typedef pvector< PT(EggNode) > Models;
00069     Models _models;
00070     int _first_model_index;
00071   };
00072 
00073   typedef pvector<EggInfo> Eggs;
00074   Eggs _eggs;
00075 
00076   typedef pvector<EggCharacterData *> Characters;
00077   Characters _characters;
00078   Characters _characters_by_model_index;
00079 
00080 private:
00081   bool scan_hierarchy(EggNode *egg_node);
00082   void scan_for_top_joints(EggNode *egg_node, EggNode *model_root,
00083                            const string &character_name);
00084   void scan_for_top_tables(EggTable *bundle, EggNode *model_root,
00085                            const string &character_name);
00086   void scan_for_morphs(EggNode *egg_node, int model_index,
00087                        EggCharacterData *char_data);
00088   void scan_for_sliders(EggNode *egg_node, int model_index,
00089                         EggCharacterData *char_data);
00090 
00091   void add_morph_back_pointers(EggAttributes *attrib, EggObject *egg_object,
00092                                int model_index, EggCharacterData *char_data);
00093   void add_morph_back_pointers_vertex(EggVertex *vertex, EggObject *egg_object,
00094                                       int model_index, EggCharacterData *char_data);
00095 
00096   // The _top_egg_nodes member is only used temporarily, when adding
00097   // each pre-existing egg file to the structure for the first time.
00098   typedef pvector<EggNode *> EggNodeList;
00099   class ModelDescription {
00100   public:
00101     INLINE ModelDescription();
00102     EggNodeList _top_nodes;
00103     EggObject *_root_node;
00104   };
00105 
00106   typedef pmap<EggNode *, ModelDescription> TopEggNodes;
00107   typedef pmap<string, TopEggNodes> TopEggNodesByName;
00108   TopEggNodesByName _top_egg_nodes;
00109 
00110   int _next_model_index;
00111 
00112   void match_egg_nodes(EggCharacterData *char_Data, EggJointData *joint_data,
00113                        EggNodeList &egg_nodes, int egg_index, int model_index);
00114   void found_egg_match(EggCharacterData *char_data, EggJointData *joint_data,
00115                        EggNode *egg_node, int egg_index, int model_index);
00116 };
00117 
00118 #include "eggCharacterCollection.I"
00119 
00120 #endif
00121 
00122 
 All Classes Functions Variables Enumerations