Panda3D
character.h
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file character.h
10  * @author drose
11  * @date 2002-03-06
12  */
13 
14 #ifndef CHARACTER_H
15 #define CHARACTER_H
16 
17 #include "pandabase.h"
18 
19 #include "characterJoint.h"
20 #include "characterSlider.h"
21 #include "characterVertexSlider.h"
22 #include "jointVertexTransform.h"
23 #include "partBundleNode.h"
24 #include "vector_PartGroupStar.h"
25 #include "pointerTo.h"
26 #include "geom.h"
27 #include "pStatCollector.h"
28 #include "transformTable.h"
29 #include "transformBlendTable.h"
30 #include "sliderTable.h"
31 
33 
34 /**
35  * An animated character, with skeleton-morph animation and either soft-
36  * skinned or hard-skinned vertices.
37  */
38 class EXPCL_PANDA_CHAR Character : public PartBundleNode {
39 protected:
40  Character(const Character &copy, bool copy_bundles);
41 
42 PUBLISHED:
43  explicit Character(const std::string &name);
44  virtual ~Character();
45 
46 public:
47  virtual PandaNode *make_copy() const;
48  virtual PandaNode *dupe_for_flatten() const;
49 
50  virtual bool cull_callback(CullTraverser *trav, CullTraverserData &data);
51 
52  virtual CPT(TransformState)
53  calc_tight_bounds(LPoint3 &min_point, LPoint3 &max_point,
54  bool &found_any,
55  const TransformState *transform,
56  Thread *current_thread) const;
57 
58 PUBLISHED:
59  virtual PandaNode *combine_with(PandaNode *other);
60 
61  INLINE CharacterJointBundle *get_bundle(int i) const;
62  void merge_bundles(PartBundle *old_bundle, PartBundle *other_bundle);
63  void merge_bundles(PartBundleHandle *old_bundle_handle,
64  PartBundleHandle *other_bundle_handle);
65 
66  void set_lod_animation(const LPoint3 &center,
67  PN_stdfloat far_distance, PN_stdfloat near_distance,
68  PN_stdfloat delay_factor);
69  void clear_lod_animation();
70 
71  CharacterJoint *find_joint(const std::string &name) const;
72  CharacterSlider *find_slider(const std::string &name) const;
73 
74  void write_parts(std::ostream &out) const;
75  void write_part_values(std::ostream &out) const;
76 
77  void update_to_now();
78  void update();
79  void force_update();
80 
81 protected:
82  virtual void r_copy_children(const PandaNode *from, InstanceMap &inst_map,
83  Thread *current_thread);
84  virtual void update_bundle(PartBundleHandle *old_bundle_handle,
85  PartBundle *new_bundle);
86  CPT(TransformState) get_rel_transform(CullTraverser *trav, CullTraverserData &data);
87 
88 private:
89  void do_update();
90  void set_lod_current_delay(double delay);
91 
97 
98  void fill_joint_map(JointMap &joint_map, PartGroup *copy, PartGroup *orig);
99  void r_merge_bundles(Character::JointMap &joint_map,
100  PartGroup *old_group, PartGroup *new_group);
101  void r_copy_char(PandaNode *dest, const PandaNode *source,
102  const Character *from, NodeMap &node_map,
103  const JointMap &joint_map, GeomVertexMap &gvmap,
104  GeomJointMap &gjmap, GeomSliderMap &gsmap);
105  void r_update_geom(PandaNode *node,
106  const JointMap &joint_map, GeomVertexMap &gvmap,
107  GeomJointMap &gjmap, GeomSliderMap &gsmap);
108  PT(Geom) copy_geom(const Geom *source,
109  const JointMap &joint_map, GeomVertexMap &gvmap,
110  GeomJointMap &gjmap, GeomSliderMap &gsmap);
111  void copy_node_pointers(const Character::NodeMap &node_map,
112  PartGroup *dest, const PartGroup *source);
113 
114  CPT(TransformTable) redirect_transform_table(const TransformTable *source,
115  const JointMap &joint_map,
116  GeomJointMap &gjmap);
117  CPT(TransformBlendTable) redirect_transform_blend_table
118  (const TransformBlendTable *source, const JointMap &joint_map,
119  GeomJointMap &gjmap);
120  CPT(SliderTable) redirect_slider_table(const SliderTable *source,
121  GeomSliderMap &gsmap);
122 
123  PT(JointVertexTransform) redirect_joint(const VertexTransform *vt,
124  const JointMap &joint_map,
125  GeomJointMap &gjmap);
126  PT(CharacterVertexSlider) redirect_slider(const VertexSlider *vs, GeomSliderMap &gsmap);
127 
128  void r_clear_joint_characters(PartGroup *part);
129 
130  // into our joints and sliders. typedef vector_PartGroupStar Parts; Parts
131  // _parts;
132 
133  double _last_auto_update;
134 
135  int _view_frame;
136  double _view_distance2;
137 
138  LPoint3 _lod_center;
139  PN_stdfloat _lod_far_distance;
140  PN_stdfloat _lod_near_distance;
141  PN_stdfloat _lod_delay_factor;
142  bool _do_lod_animation;
143 
144  // Statistics
145  PStatCollector _joints_pcollector;
146  PStatCollector _skinning_pcollector;
147  static PStatCollector _animation_pcollector;
148 
149  // This variable is only used temporarily, while reading from the bam file.
150  unsigned int _temp_num_parts;
151 
152 public:
153  static void register_with_read_factory();
154  virtual void write_datagram(BamWriter *manager, Datagram &dg);
155  virtual int complete_pointers(TypedWritable **plist,
156  BamReader *manager);
157 
158 protected:
159  static TypedWritable *make_from_bam(const FactoryParams &params);
160  void fillin(DatagramIterator &scan, BamReader *manager);
161 
162 public:
163  virtual TypeHandle get_type() const {
164  return get_class_type();
165  }
166  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
167  static TypeHandle get_class_type() {
168  return _type_handle;
169  }
170  static void init_type() {
171  PartBundleNode::init_type();
172  register_type(_type_handle, "Character",
173  PartBundleNode::get_class_type());
174  }
175 
176 private:
177  static TypeHandle _type_handle;
178 };
179 
180 #include "character.I"
181 
182 #endif
A basic node of the scene graph or data graph.
Definition: pandaNode.h:64
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is our own Panda specialization on the default STL map.
Definition: pmap.h:49
Indicates a coordinate-system transform on vertices.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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:110
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:325
An animated character, with skeleton-morph animation and either soft- skinned or hard-skinned vertice...
Definition: character.h:38
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:35
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
Definition: register_type.I:22
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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:37
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:63
This is our own Panda specialization on the default STL list.
Definition: plist.h:35
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:3580
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:37
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:190
A container for geometry primitives.
Definition: geom.h:54
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition: factoryParams.h:36
virtual void write_datagram(BamWriter *manager, Datagram &me)
Writes the contents of this object to the datagram for shipping out to a Bam file.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual PandaNode * make_copy() const
Returns a newly-allocated PandaNode that is a shallow copy of this one.
Definition: pandaNode.cxx:487
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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:46
This is the root of a MovingPart hierarchy.
Definition: partBundle.h:46
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A class to retrieve the individual data elements previously stored in a Datagram.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:38
This object performs a depth-first traversal of the scene graph, with optional view-frustum culling,...
Definition: cullTraverser.h:45
This is the base class for PartRoot and MovingPart.
Definition: partGroup.h:43