00001 // Filename: eggCharacterData.h 00002 // Created by: drose (23Feb01) 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 EGGCHARACTERDATA_H 00016 #define EGGCHARACTERDATA_H 00017 00018 #include "pandatoolbase.h" 00019 00020 #include "eggJointData.h" 00021 #include "eggNode.h" 00022 #include "eggData.h" 00023 #include "pointerTo.h" 00024 #include "namable.h" 00025 #include "nameUniquifier.h" 00026 00027 #include "pmap.h" 00028 00029 class EggCharacterCollection; 00030 class EggSliderData; 00031 class EggCharacterDb; 00032 00033 //////////////////////////////////////////////////////////////////// 00034 // Class : EggCharacterData 00035 // Description : Represents a single character, as read and collected 00036 // from several models and animation files. This 00037 // contains a hierarchy of EggJointData nodes 00038 // representing the skeleton, as well as a list of 00039 // EggSliderData nodes representing the morph channels 00040 // for the character. 00041 // 00042 // This is very similar to the Character class from 00043 // Panda, in that it's capable of associating 00044 // skeleton-morph animation channels with models and 00045 // calculating the vertex position for each frame. To 00046 // some degree, it duplicates the functionality of 00047 // Character. However, it differs in one fundamental 00048 // principle: it is designed to be a non-real-time 00049 // operation, working directly on the Egg structures as 00050 // they are, instead of first boiling the Egg data into 00051 // native Panda Geom tables for real-time animation. 00052 // Because of this, it is (a) double-precision instead 00053 // of single precision, (b) capable of generating 00054 // modified Egg files, and (c) about a hundred times 00055 // slower than the Panda Character class. 00056 // 00057 // The data in this structure is normally filled in by 00058 // the EggCharacterCollection class. 00059 //////////////////////////////////////////////////////////////////// 00060 class EggCharacterData : public Namable { 00061 public: 00062 EggCharacterData(EggCharacterCollection *collection); 00063 virtual ~EggCharacterData(); 00064 00065 void rename_char(const string &name); 00066 00067 void add_model(int model_index, EggNode *model_root, EggData *egg_data); 00068 INLINE int get_num_models() const; 00069 INLINE int get_model_index(int n) const; 00070 INLINE EggNode *get_model_root(int n) const; 00071 INLINE EggData *get_egg_data(int n) const; 00072 int get_num_frames(int model_index) const; 00073 bool check_num_frames(int model_index); 00074 double get_frame_rate(int model_index) const; 00075 00076 INLINE EggJointData *get_root_joint() const; 00077 INLINE EggJointData *find_joint(const string &name) const; 00078 INLINE EggJointData *make_new_joint(const string &name, EggJointData *parent); 00079 INLINE int get_num_joints() const; 00080 INLINE EggJointData *get_joint(int n) const; 00081 00082 bool do_reparent(); 00083 void choose_optimal_hierarchy(); 00084 00085 INLINE int get_num_sliders() const; 00086 INLINE EggSliderData *get_slider(int n) const; 00087 EggSliderData *find_slider(const string &name) const; 00088 EggSliderData *make_slider(const string &name); 00089 00090 INLINE int get_num_components() const; 00091 INLINE EggComponentData *get_component(int n) const; 00092 00093 size_t estimate_db_size() const; 00094 00095 virtual void write(ostream &out, int indent_level = 0) const; 00096 00097 private: 00098 class Model { 00099 public: 00100 int _model_index; 00101 PT(EggNode) _model_root; 00102 PT(EggData) _egg_data; 00103 }; 00104 typedef pvector<Model> Models; 00105 Models _models; 00106 00107 EggCharacterCollection *_collection; 00108 EggJointData *_root_joint; 00109 00110 typedef pmap<string, EggSliderData *> SlidersByName; 00111 SlidersByName _sliders_by_name; 00112 00113 typedef pvector<EggSliderData *> Sliders; 00114 Sliders _sliders; 00115 00116 typedef pvector<EggJointData *> Joints; 00117 Joints _joints; 00118 00119 typedef pvector<EggComponentData *> Components; 00120 Components _components; 00121 00122 NameUniquifier _component_names; 00123 00124 friend class EggCharacterCollection; 00125 }; 00126 00127 #include "eggCharacterData.I" 00128 00129 #endif 00130 00131