Panda3D
character.h
1 // Filename: character.h
2 // Created by: drose (06Mar02)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef CHARACTER_H
16 #define CHARACTER_H
17 
18 #include "pandabase.h"
19 
20 #include "characterJoint.h"
21 #include "characterSlider.h"
22 #include "characterVertexSlider.h"
23 #include "jointVertexTransform.h"
24 #include "partBundleNode.h"
25 #include "vector_PartGroupStar.h"
26 #include "pointerTo.h"
27 #include "geom.h"
28 #include "pStatCollector.h"
29 #include "transformTable.h"
30 #include "transformBlendTable.h"
31 #include "sliderTable.h"
32 
34 class ComputedVertices;
35 
36 ////////////////////////////////////////////////////////////////////
37 // Class : Character
38 // Description : An animated character, with skeleton-morph animation
39 // and either soft-skinned or hard-skinned vertices.
40 ////////////////////////////////////////////////////////////////////
41 class EXPCL_PANDA_CHAR Character : public PartBundleNode {
42 protected:
43  Character(const Character &copy, bool copy_bundles);
44 
45 PUBLISHED:
46  Character(const string &name);
47  virtual ~Character();
48 
49 public:
50  virtual PandaNode *make_copy() const;
51  virtual PandaNode *dupe_for_flatten() const;
52 
53  virtual bool cull_callback(CullTraverser *trav, CullTraverserData &data);
54 
55  virtual CPT(TransformState)
56  calc_tight_bounds(LPoint3 &min_point, LPoint3 &max_point,
57  bool &found_any,
58  const TransformState *transform,
59  Thread *current_thread) const;
60 
61 PUBLISHED:
62  virtual PandaNode *combine_with(PandaNode *other);
63 
64  INLINE CharacterJointBundle *get_bundle(int i) const;
65  void merge_bundles(PartBundle *old_bundle, PartBundle *other_bundle);
66  void merge_bundles(PartBundleHandle *old_bundle_handle,
67  PartBundleHandle *other_bundle_handle);
68 
69  void set_lod_animation(const LPoint3 &center,
70  PN_stdfloat far_distance, PN_stdfloat near_distance,
71  PN_stdfloat delay_factor);
72  void clear_lod_animation();
73 
74  CharacterJoint *find_joint(const string &name) const;
75  CharacterSlider *find_slider(const string &name) const;
76 
77  void write_parts(ostream &out) const;
78  void write_part_values(ostream &out) const;
79 
80  void update_to_now();
81  void update();
82  void force_update();
83 
84 protected:
85  virtual void r_copy_children(const PandaNode *from, InstanceMap &inst_map,
86  Thread *current_thread);
87  virtual void update_bundle(PartBundleHandle *old_bundle_handle,
88  PartBundle *new_bundle);
89  CPT(TransformState) get_rel_transform(CullTraverser *trav, CullTraverserData &data);
90 
91 private:
92  void do_update();
93  void set_lod_current_delay(double delay);
94 
100 
101  void fill_joint_map(JointMap &joint_map, PartGroup *copy, PartGroup *orig);
102  void r_merge_bundles(Character::JointMap &joint_map,
103  PartGroup *old_group, PartGroup *new_group);
104  void r_copy_char(PandaNode *dest, const PandaNode *source,
105  const Character *from, NodeMap &node_map,
106  const JointMap &joint_map, GeomVertexMap &gvmap,
107  GeomJointMap &gjmap, GeomSliderMap &gsmap);
108  void r_update_geom(PandaNode *node,
109  const JointMap &joint_map, GeomVertexMap &gvmap,
110  GeomJointMap &gjmap, GeomSliderMap &gsmap);
111  PT(Geom) copy_geom(const Geom *source,
112  const JointMap &joint_map, GeomVertexMap &gvmap,
113  GeomJointMap &gjmap, GeomSliderMap &gsmap);
114  void copy_node_pointers(const Character::NodeMap &node_map,
115  PartGroup *dest, const PartGroup *source);
116 
117  CPT(TransformTable) redirect_transform_table(const TransformTable *source,
118  const JointMap &joint_map,
119  GeomJointMap &gjmap);
120  CPT(TransformBlendTable) redirect_transform_blend_table
121  (const TransformBlendTable *source, const JointMap &joint_map,
122  GeomJointMap &gjmap);
123  CPT(SliderTable) redirect_slider_table(const SliderTable *source,
124  GeomSliderMap &gsmap);
125 
126  PT(JointVertexTransform) redirect_joint(const VertexTransform *vt,
127  const JointMap &joint_map,
128  GeomJointMap &gjmap);
129  PT(CharacterVertexSlider) redirect_slider(const VertexSlider *vs, GeomSliderMap &gsmap);
130 
131  void r_clear_joint_characters(PartGroup *part);
132 
133  // into our joints and sliders.
134  //typedef vector_PartGroupStar Parts;
135  //Parts _parts;
136 
137  double _last_auto_update;
138 
139  int _view_frame;
140  double _view_distance2;
141 
142  LPoint3 _lod_center;
143  PN_stdfloat _lod_far_distance;
144  PN_stdfloat _lod_near_distance;
145  PN_stdfloat _lod_delay_factor;
146  bool _do_lod_animation;
147 
148  // Statistics
149  PStatCollector _joints_pcollector;
150  PStatCollector _skinning_pcollector;
151  static PStatCollector _animation_pcollector;
152 
153  // This variable is only used temporarily, while reading from the
154  // bam file.
155  unsigned int _temp_num_parts;
156 
157 public:
158  static void register_with_read_factory();
159  virtual void write_datagram(BamWriter *manager, Datagram &dg);
160  virtual int complete_pointers(TypedWritable **plist,
161  BamReader *manager);
162 
163 protected:
164  static TypedWritable *make_from_bam(const FactoryParams &params);
165  void fillin(DatagramIterator &scan, BamReader *manager);
166 
167 public:
168  virtual TypeHandle get_type() const {
169  return get_class_type();
170  }
171  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
172  static TypeHandle get_class_type() {
173  return _type_handle;
174  }
175  static void init_type() {
176  PartBundleNode::init_type();
177  register_type(_type_handle, "Character",
178  PartBundleNode::get_class_type());
179  }
180 
181 private:
182  static TypeHandle _type_handle;
183 };
184 
185 #include "character.I"
186 
187 #endif
188 
A basic node of the scene graph or data graph.
Definition: pandaNode.h:72
This is our own Panda specialization on the default STL map.
Definition: pmap.h:52
The collection of all the joints and sliders in the character.
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:122
virtual PandaNode * combine_with(PandaNode *other)
Collapses this PandaNode with the other PandaNode, if possible, and returns a pointer to the combined...
Definition: pandaNode.cxx:397
An animated character, with skeleton-morph animation and either soft-skinned or hard-skinned vertices...
Definition: character.h:41
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:37
This collects together the pieces of data that are accumulated for each node while walking the scene ...
This is a specialization on VertexSlider that returns the slider value associated with a particular C...
This is an abstract base class that retains some slider value, which is a linear value that typically...
Definition: vertexSlider.h:41
This is a three-component point in space (as opposed to a three-component vector, which represents a ...
Definition: lpoint3.h:99
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:73
This is our own Panda specialization on the default STL list.
Definition: plist.h:38
This is a morph slider within the character.
static void register_with_read_factory()
Tells the BamReader how to create objects of type PandaNode.
Definition: pandaNode.cxx:4153
This is a trivial class returned by PartBundleNode::get_bundle().
A lightweight class that represents a single element that may be timed and/or counted via stats...
Stores the total set of VertexSliders that the vertices in a particular GeomVertexData object might d...
Definition: sliderTable.h:42
This is an abstract base class that holds a pointer to some transform, computed in some arbitrary way...
This is a node that contains a pointer to an PartBundle.
virtual PandaNode * dupe_for_flatten() const
This is similar to make_copy(), but it makes a copy for the specific purpose of flatten.
Definition: pandaNode.cxx:222
A container for geometry primitives.
Definition: geom.h:58
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition: factoryParams.h:40
virtual void write_datagram(BamWriter *manager, Datagram &me)
Writes the contents of this object to the datagram for shipping out to a Bam file.
virtual PandaNode * make_copy() const
Returns a newly-allocated PandaNode that is a shallow copy of this one.
Definition: pandaNode.cxx:604
This is a specialization on VertexTransform that returns the transform necessary to move vertices as ...
Stores the total set of VertexTransforms that the vertices in a particular GeomVertexData object migh...
A thread; that is, a lightweight process.
Definition: thread.h:51
This is the root of a MovingPart hierarchy.
Definition: partBundle.h:49
This represents one joint of the character's animation, containing an animating transform matrix...
virtual int complete_pointers(TypedWritable **p_list, BamReader *manager)
Receives an array of pointers, one for each time manager->read_pointer() was called in fillin()...
This structure collects together the different combinations of transforms and blend amounts used by a...
A class to retrieve the individual data elements previously stored in a Datagram. ...
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:43
This object performs a depth-first traversal of the scene graph, with optional view-frustum culling...
Definition: cullTraverser.h:48
This is the base class for PartRoot and MovingPart.
Definition: partGroup.h:45