Panda3D
|
00001 // Filename: character.h 00002 // Created by: drose (06Mar02) 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 CHARACTER_H 00016 #define CHARACTER_H 00017 00018 #include "pandabase.h" 00019 00020 #include "characterJoint.h" 00021 #include "characterSlider.h" 00022 #include "characterVertexSlider.h" 00023 #include "jointVertexTransform.h" 00024 #include "partBundleNode.h" 00025 #include "vector_PartGroupStar.h" 00026 #include "pointerTo.h" 00027 #include "geom.h" 00028 #include "pStatCollector.h" 00029 #include "transformTable.h" 00030 #include "transformBlendTable.h" 00031 #include "sliderTable.h" 00032 00033 class CharacterJointBundle; 00034 class ComputedVertices; 00035 00036 //////////////////////////////////////////////////////////////////// 00037 // Class : Character 00038 // Description : An animated character, with skeleton-morph animation 00039 // and either soft-skinned or hard-skinned vertices. 00040 //////////////////////////////////////////////////////////////////// 00041 class EXPCL_PANDA_CHAR Character : public PartBundleNode { 00042 protected: 00043 Character(const Character ©, bool copy_bundles); 00044 00045 PUBLISHED: 00046 Character(const string &name); 00047 virtual ~Character(); 00048 00049 public: 00050 virtual PandaNode *make_copy() const; 00051 virtual PandaNode *dupe_for_flatten() const; 00052 00053 virtual bool cull_callback(CullTraverser *trav, CullTraverserData &data); 00054 00055 virtual CPT(TransformState) 00056 calc_tight_bounds(LPoint3 &min_point, LPoint3 &max_point, 00057 bool &found_any, 00058 const TransformState *transform, 00059 Thread *current_thread) const; 00060 00061 PUBLISHED: 00062 virtual PandaNode *combine_with(PandaNode *other); 00063 00064 INLINE CharacterJointBundle *get_bundle(int i) const; 00065 void merge_bundles(PartBundle *old_bundle, PartBundle *other_bundle); 00066 void merge_bundles(PartBundleHandle *old_bundle_handle, 00067 PartBundleHandle *other_bundle_handle); 00068 00069 void set_lod_animation(const LPoint3 ¢er, 00070 PN_stdfloat far_distance, PN_stdfloat near_distance, 00071 PN_stdfloat delay_factor); 00072 void clear_lod_animation(); 00073 00074 CharacterJoint *find_joint(const string &name) const; 00075 CharacterSlider *find_slider(const string &name) const; 00076 00077 void write_parts(ostream &out) const; 00078 void write_part_values(ostream &out) const; 00079 00080 void update_to_now(); 00081 void update(); 00082 void force_update(); 00083 00084 protected: 00085 virtual void r_copy_children(const PandaNode *from, InstanceMap &inst_map, 00086 Thread *current_thread); 00087 virtual void update_bundle(PartBundleHandle *old_bundle_handle, 00088 PartBundle *new_bundle); 00089 CPT(TransformState) get_rel_transform(CullTraverser *trav, CullTraverserData &data); 00090 00091 private: 00092 void do_update(); 00093 void set_lod_current_delay(double delay); 00094 00095 typedef pmap<const PandaNode *, PandaNode *> NodeMap; 00096 typedef pmap<const PartGroup *, PartGroup *> JointMap; 00097 typedef pmap<const GeomVertexData *, GeomVertexData *> GeomVertexMap; 00098 typedef pmap<const VertexTransform *, PT(JointVertexTransform) > GeomJointMap; 00099 typedef pmap<const VertexSlider *, PT(CharacterVertexSlider) > GeomSliderMap; 00100 00101 void fill_joint_map(JointMap &joint_map, PartGroup *copy, PartGroup *orig); 00102 void r_merge_bundles(Character::JointMap &joint_map, 00103 PartGroup *old_group, PartGroup *new_group); 00104 void r_copy_char(PandaNode *dest, const PandaNode *source, 00105 const Character *from, NodeMap &node_map, 00106 const JointMap &joint_map, GeomVertexMap &gvmap, 00107 GeomJointMap &gjmap, GeomSliderMap &gsmap); 00108 void r_update_geom(PandaNode *node, 00109 const JointMap &joint_map, GeomVertexMap &gvmap, 00110 GeomJointMap &gjmap, GeomSliderMap &gsmap); 00111 PT(Geom) copy_geom(const Geom *source, 00112 const JointMap &joint_map, GeomVertexMap &gvmap, 00113 GeomJointMap &gjmap, GeomSliderMap &gsmap); 00114 void copy_node_pointers(const Character::NodeMap &node_map, 00115 PartGroup *dest, const PartGroup *source); 00116 00117 CPT(TransformTable) redirect_transform_table(const TransformTable *source, 00118 const JointMap &joint_map, 00119 GeomJointMap &gjmap); 00120 CPT(TransformBlendTable) redirect_transform_blend_table 00121 (const TransformBlendTable *source, const JointMap &joint_map, 00122 GeomJointMap &gjmap); 00123 CPT(SliderTable) redirect_slider_table(const SliderTable *source, 00124 GeomSliderMap &gsmap); 00125 00126 PT(JointVertexTransform) redirect_joint(const VertexTransform *vt, 00127 const JointMap &joint_map, 00128 GeomJointMap &gjmap); 00129 PT(CharacterVertexSlider) redirect_slider(const VertexSlider *vs, GeomSliderMap &gsmap); 00130 00131 void r_clear_joint_characters(PartGroup *part); 00132 00133 // into our joints and sliders. 00134 //typedef vector_PartGroupStar Parts; 00135 //Parts _parts; 00136 00137 double _last_auto_update; 00138 00139 int _view_frame; 00140 double _view_distance2; 00141 00142 LPoint3 _lod_center; 00143 PN_stdfloat _lod_far_distance; 00144 PN_stdfloat _lod_near_distance; 00145 PN_stdfloat _lod_delay_factor; 00146 bool _do_lod_animation; 00147 00148 // Statistics 00149 PStatCollector _joints_pcollector; 00150 PStatCollector _skinning_pcollector; 00151 static PStatCollector _animation_pcollector; 00152 00153 // This variable is only used temporarily, while reading from the 00154 // bam file. 00155 unsigned int _temp_num_parts; 00156 00157 public: 00158 static void register_with_read_factory(); 00159 virtual void write_datagram(BamWriter *manager, Datagram &dg); 00160 virtual int complete_pointers(TypedWritable **plist, 00161 BamReader *manager); 00162 00163 protected: 00164 static TypedWritable *make_from_bam(const FactoryParams ¶ms); 00165 void fillin(DatagramIterator &scan, BamReader *manager); 00166 00167 public: 00168 virtual TypeHandle get_type() const { 00169 return get_class_type(); 00170 } 00171 virtual TypeHandle force_init_type() {init_type(); return get_class_type();} 00172 static TypeHandle get_class_type() { 00173 return _type_handle; 00174 } 00175 static void init_type() { 00176 PartBundleNode::init_type(); 00177 register_type(_type_handle, "Character", 00178 PartBundleNode::get_class_type()); 00179 } 00180 00181 private: 00182 static TypeHandle _type_handle; 00183 }; 00184 00185 #include "character.I" 00186 00187 #endif 00188