Panda3D
 All Classes Functions Variables Enumerations
partBundle.h
1 // Filename: partBundle.h
2 // Created by: drose (22Feb99)
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 PARTBUNDLE_H
16 #define PARTBUNDLE_H
17 
18 #include "pandabase.h"
19 
20 #include "partGroup.h"
21 #include "animControl.h"
22 #include "partSubset.h"
23 #include "animPreloadTable.h"
24 #include "pointerTo.h"
25 #include "thread.h"
26 #include "cycleData.h"
27 #include "cycleDataLockedReader.h"
28 #include "cycleDataReader.h"
29 #include "cycleDataWriter.h"
30 #include "luse.h"
31 #include "pvector.h"
32 #include "transformState.h"
33 #include "weakPointerTo.h"
34 #include "copyOnWritePointer.h"
35 
36 class Loader;
37 class AnimBundle;
38 class PartBundleNode;
39 class PartBundleNode;
40 class TransformState;
41 class AnimPreloadTable;
42 
43 ////////////////////////////////////////////////////////////////////
44 // Class : PartBundle
45 // Description : This is the root of a MovingPart hierarchy. It
46 // defines the hierarchy of moving parts that make up an
47 // animatable object.
48 ////////////////////////////////////////////////////////////////////
49 class EXPCL_PANDA_CHAN PartBundle : public PartGroup {
50 public:
51 
52  // This is passed down through the MovingParts during the
53  // do_update() call to specify the channels that are in effect.
55 
56 protected:
57  // The copy constructor is protected; use make_copy() or copy_subgraph().
58  PartBundle(const PartBundle &copy);
59 
60 PUBLISHED:
61  PartBundle(const string &name = "");
62  virtual PartGroup *make_copy() const;
63 
64  INLINE CPT(AnimPreloadTable) get_anim_preload() const;
65  INLINE PT(AnimPreloadTable) modify_anim_preload();
66  INLINE void set_anim_preload(AnimPreloadTable *table);
67  INLINE void clear_anim_preload();
68  void merge_anim_preloads(const PartBundle *other);
69 
70  // This is the parameter to set_blend_type() and specifies the kind
71  // of blending operation to be performed when multiple controls are
72  // in effect simultaneously (see set_control_effect()) or between
73  // sequential frames of the animation.
74  enum BlendType {
75  // BT_linear does a componentwise average of all blended matrices,
76  // which is a linear blend. The result of this is that if a
77  // particular vertex would have been at point P in one animation
78  // and point Q in another one, it will end up on the line in
79  // between them in the resulting blend animation. However, this
80  // tends to stretch and squash limbs in strange and disturbing
81  // ways.
82  BT_linear,
83 
84  // BT_normalized_linear is a compromise on BT_linear. The matrix
85  // is blended linearly without the scale and shear components, and
86  // the blended scale and shear components are applied separately.
87  // This keeps all of the character's body parts in the correct
88  // size and shape. However, if the hierarchy is disconnected,
89  // body parts can fly off. It's essential the skeleton hierarchy
90  // be completely connected to use this blend mode successully.
91  BT_normalized_linear,
92 
93  // BT_componentwise linearly blends all components separately,
94  // including H, P, and R, and recomposes the matrix.
95  BT_componentwise,
96 
97  // BT_componentwise_quat linearly blends all components
98  // separately, except for rotation which is blended as a
99  // quaternion.
100  BT_componentwise_quat,
101  };
102 
103  INLINE void set_blend_type(BlendType bt);
104  INLINE BlendType get_blend_type() const;
105 
106  void set_anim_blend_flag(bool anim_blend_flag);
107  INLINE bool get_anim_blend_flag() const;
108 
109  INLINE void set_frame_blend_flag(bool frame_blend_flag);
110  INLINE bool get_frame_blend_flag() const;
111 
112  INLINE void set_root_xform(const LMatrix4 &root_xform);
113  INLINE void xform(const LMatrix4 &mat);
114  INLINE const LMatrix4 &get_root_xform() const;
115  PT(PartBundle) apply_transform(const TransformState *transform);
116 
117  INLINE int get_num_nodes() const;
118  INLINE PartBundleNode *get_node(int n) const;
119  MAKE_SEQ(get_nodes, get_num_nodes, get_node);
120 
121  void clear_control_effects();
122  INLINE void set_control_effect(AnimControl *control, PN_stdfloat effect);
123  INLINE PN_stdfloat get_control_effect(AnimControl *control) const;
124 
125  virtual void output(ostream &out) const;
126  virtual void write(ostream &out, int indent_level) const;
127 
128  PT(AnimControl) bind_anim(AnimBundle *anim,
129  int hierarchy_match_flags = 0,
130  const PartSubset &subset = PartSubset());
131  PT(AnimControl) load_bind_anim(Loader *loader,
132  const Filename &filename,
133  int hierarchy_match_flags,
134  const PartSubset &subset,
135  bool allow_async);
136  void wait_pending();
137 
138  bool freeze_joint(const string &joint_name, const TransformState *transform);
139  bool freeze_joint(const string &joint_name, const LVecBase3 &pos, const LVecBase3 &hpr, const LVecBase3 &scale);
140  bool freeze_joint(const string &joint_name, PN_stdfloat value);
141  bool control_joint(const string &joint_name, PandaNode *node);
142  bool release_joint(const string &joint_name);
143 
144  bool update();
145  bool force_update();
146 
147 public:
148  // The following functions aren't really part of the public
149  // interface; they're just public so we don't have to declare a
150  // bunch of friends.
151  virtual void control_activated(AnimControl *control);
152  INLINE void set_update_delay(double delay);
153 
154  bool do_bind_anim(AnimControl *control, AnimBundle *anim,
155  int hierarchy_match_flags, const PartSubset &subset);
156 
157 protected:
158  virtual void add_node(PartBundleNode *node);
159  virtual void remove_node(PartBundleNode *node);
160 
161 private:
162  class CData;
163 
164  void do_set_control_effect(AnimControl *control, PN_stdfloat effect, CData *cdata);
165  PN_stdfloat do_get_control_effect(AnimControl *control, const CData *cdata) const;
166  void recompute_net_blend(CData *cdata);
167  void clear_and_stop_intersecting(AnimControl *control, CData *cdata);
168 
169  COWPT(AnimPreloadTable) _anim_preload;
170 
172  Nodes _nodes;
173 
175  AppliedTransforms _applied_transforms;
176 
177  double _update_delay;
178 
179  // This is the data that must be cycled between pipeline stages.
180  class CData : public CycleData {
181  public:
182  CData();
183  CData(const CData &copy);
184 
185  virtual CycleData *make_copy() const;
186  virtual void write_datagram(BamWriter *manager, Datagram &dg) const;
187  virtual void fillin(DatagramIterator &scan, BamReader *manager);
188  virtual TypeHandle get_parent_type() const {
189  return PartBundle::get_class_type();
190  }
191 
192  BlendType _blend_type;
193  bool _anim_blend_flag;
194  bool _frame_blend_flag;
195  LMatrix4 _root_xform;
196  AnimControl *_last_control_set;
197  ChannelBlend _blend;
198  PN_stdfloat _net_blend;
199  bool _anim_changed;
200  double _last_update;
201  };
202 
203  PipelineCycler<CData> _cycler;
207 
208 public:
209  static void register_with_read_factory();
210  virtual void finalize(BamReader *manager);
211  virtual void write_datagram(BamWriter *manager, Datagram &dg);
212  virtual int complete_pointers(TypedWritable **p_list,
213  BamReader *manager);
214 
215 protected:
216  static TypedWritable *make_from_bam(const FactoryParams &params);
217  void fillin(DatagramIterator &scan, BamReader *manager);
218 
219 public:
220 
221  virtual TypeHandle get_type() const {
222  return get_class_type();
223  }
224  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
225  static TypeHandle get_class_type() {
226  return _type_handle;
227  }
228  static void init_type() {
229  PartGroup::init_type();
230  register_type(_type_handle, "PartBundle",
231  PartGroup::get_class_type());
232  }
233 
234 private:
235  static TypeHandle _type_handle;
236 
237  friend class PartBundleNode;
238  friend class Character;
239  friend class MovingPartBase;
240  friend class MovingPartMatrix;
241  friend class MovingPartScalar;
242 };
243 
244 inline ostream &operator <<(ostream &out, const PartBundle &bundle) {
245  bundle.output(out);
246  return out;
247 }
248 
249 ostream &operator <<(ostream &out, PartBundle::BlendType blend_type);
250 istream &operator >>(istream &in, PartBundle::BlendType &blend_type);
251 
252 #include "partBundle.I"
253 
254 #endif
A basic node of the scene graph or data graph.
Definition: pandaNode.h:72
This is the base class for all three-component vectors and points.
Definition: lvecBase3.h:105
This table records data about a list of animations for a particular model, such as number of frames a...
virtual void finalize(BamReader *manager)
Called by the BamReader to perform any final actions needed for setting up the object after all objec...
virtual PartGroup * make_copy() const
Allocates and returns a new copy of the node.
Definition: partGroup.cxx:76
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:122
An animated character, with skeleton-morph animation and either soft-skinned or hard-skinned vertices...
Definition: character.h:41
This is the root of an AnimChannel hierarchy.
Definition: animBundle.h:31
A single page of data maintained by a PipelineCycler.
Definition: cycleData.h:50
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:37
A convenient class for loading models from disk, in bam or egg format (or any of a number of other fo...
Definition: loader.h:47
This is the base class for a single animatable piece that may be bound to one channel (or more...
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:73
virtual void write(ostream &out, int indent_level) const
Writes a brief description of the group and all of its descendants.
Definition: partGroup.cxx:304
This template class calls PipelineCycler::read_unlocked(), and then provides a transparent read-only ...
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:44
This is a 4-by-4 transform matrix.
Definition: lmatrix.h:451
This is a node that contains a pointer to an PartBundle.
This template class calls PipelineCycler::read() in the constructor and PipelineCycler::release_read(...
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 output(ostream &out) const
Writes a one-line description of the bundle.
Definition: partBundle.cxx:235
This template class calls PipelineCycler::write() in the constructor and PipelineCycler::release_writ...
This class is used to define a subset of part names to apply to the PartBundle::bind_anim() operation...
Definition: partSubset.h:28
static void register_with_read_factory()
Factory method to generate a PartGroup object.
Definition: partGroup.cxx:790
This is a particular kind of MovingPart that accepts a scalar each frame.
void output(ostream &out) const
Outputs the Namable.
Definition: namable.I:97
This is a particular kind of MovingPart that accepts a matrix each frame.
This is the root of a MovingPart hierarchy.
Definition: partBundle.h:49
Controls the timing of a character animation.
Definition: animControl.h:41
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
virtual void write_datagram(BamWriter *manager, Datagram &me)
Function to write the important information in the particular object to a Datagram.
Definition: partGroup.cxx:714
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:43
virtual int complete_pointers(TypedWritable **p_list, BamReader *manager)
Takes in a vector of pointers to TypedWritable objects that correspond to all the requests for pointe...
Definition: partGroup.cxx:757
This is the base class for PartRoot and MovingPart.
Definition: partGroup.h:45