Panda3D
|
00001 // Filename: eggJointData.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 EGGJOINTDATA_H 00016 #define EGGJOINTDATA_H 00017 00018 #include "pandatoolbase.h" 00019 #include "eggComponentData.h" 00020 #include "eggGroup.h" 00021 #include "luse.h" 00022 #include "pset.h" 00023 00024 class EggCharacterDb; 00025 00026 //////////////////////////////////////////////////////////////////// 00027 // Class : EggJointData 00028 // Description : This is one node of a hierarchy of EggJointData 00029 // nodes, each of which represents a single joint of the 00030 // character hierarchy across all loaded files: the 00031 // various models, the LOD's of each model, and the 00032 // various animation channel files. 00033 //////////////////////////////////////////////////////////////////// 00034 class EggJointData : public EggComponentData { 00035 public: 00036 EggJointData(EggCharacterCollection *collection, 00037 EggCharacterData *char_data); 00038 00039 INLINE EggJointData *get_parent() const; 00040 INLINE int get_num_children() const; 00041 INLINE EggJointData *get_child(int n) const; 00042 INLINE EggJointData *find_joint(const string &name); 00043 00044 LMatrix4d get_frame(int model_index, int n) const; 00045 LMatrix4d get_net_frame(int model_index, int n, EggCharacterDb &db) const; 00046 LMatrix4d get_net_frame_inv(int model_index, int n, EggCharacterDb &db) const; 00047 00048 INLINE bool has_rest_frame() const; 00049 INLINE bool rest_frames_differ() const; 00050 INLINE const LMatrix4d &get_rest_frame() const; 00051 void force_initial_rest_frame(); 00052 00053 INLINE void reparent_to(EggJointData *new_parent); 00054 void move_vertices_to(EggJointData *new_owner); 00055 int score_reparent_to(EggJointData *new_parent, EggCharacterDb &db); 00056 00057 bool do_rebuild_all(EggCharacterDb &db); 00058 void optimize(); 00059 void expose(EggGroup::DCSType dcs_type = EggGroup::DC_default); 00060 void zero_channels(const string &components); 00061 void quantize_channels(const string &components, double quantum); 00062 void apply_default_pose(int source_model, int frame); 00063 00064 virtual void add_back_pointer(int model_index, EggObject *egg_object); 00065 virtual void write(ostream &out, int indent_level = 0) const; 00066 00067 protected: 00068 void do_begin_reparent(); 00069 bool calc_new_parent_depth(pset<EggJointData *> &chain); 00070 void do_begin_compute_reparent(); 00071 bool do_compute_reparent(int model_index, int n, EggCharacterDb &db); 00072 bool do_joint_rebuild(int model_index, EggCharacterDb &db); 00073 void do_finish_reparent(); 00074 00075 private: 00076 EggJointData *make_new_joint(const string &name); 00077 EggJointData *find_joint_exact(const string &name); 00078 EggJointData *find_joint_matches(const string &name); 00079 00080 bool is_new_ancestor(EggJointData *child) const; 00081 const LMatrix4d &get_new_net_frame(int model_index, int n, EggCharacterDb &db); 00082 const LMatrix4d &get_new_net_frame_inv(int model_index, int n, EggCharacterDb &db); 00083 LMatrix4d get_new_frame(int model_index, int n, EggCharacterDb &db); 00084 00085 bool _has_rest_frame; 00086 bool _rest_frames_differ; 00087 LMatrix4d _rest_frame; 00088 00089 // These are used to cache the above results for optimizing 00090 // do_compute_reparent(). 00091 LMatrix4d _new_net_frame, _new_net_frame_inv; 00092 bool _got_new_net_frame, _got_new_net_frame_inv; 00093 bool _computed_reparent; 00094 bool _computed_ok; 00095 00096 protected: 00097 typedef pvector<EggJointData *> Children; 00098 Children _children; 00099 EggJointData *_parent; 00100 EggJointData *_new_parent; 00101 int _new_parent_depth; 00102 bool _got_new_parent_depth; 00103 00104 00105 public: 00106 static TypeHandle get_class_type() { 00107 return _type_handle; 00108 } 00109 static void init_type() { 00110 EggComponentData::init_type(); 00111 register_type(_type_handle, "EggJointData", 00112 EggComponentData::get_class_type()); 00113 } 00114 virtual TypeHandle get_type() const { 00115 return get_class_type(); 00116 } 00117 virtual TypeHandle force_init_type() {init_type(); return get_class_type();} 00118 00119 private: 00120 static TypeHandle _type_handle; 00121 00122 friend class EggCharacterCollection; 00123 friend class EggCharacterData; 00124 friend class OrderJointsByNewDepth; 00125 }; 00126 00127 #include "eggJointData.I" 00128 00129 #endif