Panda3D
Loading...
Searching...
No Matches
partBundle.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 partBundle.h
10 * @author drose
11 * @date 1999-02-22
12 */
13
14#ifndef PARTBUNDLE_H
15#define PARTBUNDLE_H
16
17#include "pandabase.h"
18
19#include "partGroup.h"
20#include "animControl.h"
21#include "partSubset.h"
22#include "animPreloadTable.h"
23#include "pointerTo.h"
24#include "thread.h"
25#include "cycleData.h"
27#include "cycleDataReader.h"
28#include "cycleDataWriter.h"
29#include "luse.h"
30#include "pvector.h"
31#include "transformState.h"
32#include "weakPointerTo.h"
33#include "copyOnWritePointer.h"
34
35class Loader;
36class AnimBundle;
37class PartBundleNode;
38class PartBundleNode;
39class TransformState;
41
42/**
43 * This is the root of a MovingPart hierarchy. It defines the hierarchy of
44 * moving parts that make up an animatable object.
45 */
46class EXPCL_PANDA_CHAN PartBundle : public PartGroup {
47public:
48
49 // This is passed down through the MovingParts during the do_update() call
50 // to specify the channels that are in effect.
51 typedef pmap<AnimControl *, PN_stdfloat> ChannelBlend;
52
53protected:
54 // The copy constructor is protected; use make_copy() or copy_subgraph().
55 PartBundle(const PartBundle &copy);
56
57PUBLISHED:
58 explicit PartBundle(const std::string &name = "");
59 virtual PartGroup *make_copy() const;
60
61 INLINE CPT(AnimPreloadTable) get_anim_preload() const;
62 INLINE PT(AnimPreloadTable) modify_anim_preload();
63 INLINE void set_anim_preload(AnimPreloadTable *table);
64 INLINE void clear_anim_preload();
65 void merge_anim_preloads(const PartBundle *other);
66
67 // This is the parameter to set_blend_type() and specifies the kind of
68 // blending operation to be performed when multiple controls are in effect
69 // simultaneously (see set_control_effect()) or between sequential frames of
70 // the animation.
71 enum BlendType {
72 // BT_linear does a componentwise average of all blended matrices, which
73 // is a linear blend. The result of this is that if a particular vertex
74 // would have been at point P in one animation and point Q in another one,
75 // it will end up on the line in between them in the resulting blend
76 // animation. However, this tends to stretch and squash limbs in strange
77 // and disturbing ways.
78 BT_linear,
79
80 // BT_normalized_linear is a compromise on BT_linear. The matrix is
81 // blended linearly without the scale and shear components, and the
82 // blended scale and shear components are applied separately. This keeps
83 // all of the character's body parts in the correct size and shape.
84 // However, if the hierarchy is disconnected, body parts can fly off.
85 // It's essential the skeleton hierarchy be completely connected to use
86 // this blend mode successully.
87 BT_normalized_linear,
88
89 // BT_componentwise linearly blends all components separately, including
90 // H, P, and R, and recomposes the matrix.
91 BT_componentwise,
92
93 // BT_componentwise_quat linearly blends all components separately, except
94 // for rotation which is blended as a quaternion.
95 BT_componentwise_quat,
96 };
97
98 INLINE void set_blend_type(BlendType bt);
99 INLINE BlendType get_blend_type() const;
100
101 void set_anim_blend_flag(bool anim_blend_flag);
102 INLINE bool get_anim_blend_flag() const;
103
104 INLINE void set_frame_blend_flag(bool frame_blend_flag);
105 INLINE bool get_frame_blend_flag() const;
106
107 INLINE void set_root_xform(const LMatrix4 &root_xform);
108 INLINE void xform(const LMatrix4 &mat);
109 INLINE const LMatrix4 &get_root_xform() const;
110 PT(PartBundle) apply_transform(const TransformState *transform);
111
112 INLINE int get_num_nodes() const;
113 INLINE PartBundleNode *get_node(int n) const;
114 MAKE_SEQ(get_nodes, get_num_nodes, get_node);
115
116 MAKE_PROPERTY(blend_type, get_blend_type, set_blend_type);
117 MAKE_PROPERTY(anim_blend_flag, get_anim_blend_flag, set_anim_blend_flag);
118 MAKE_PROPERTY(frame_blend_flag, get_frame_blend_flag, set_frame_blend_flag);
119 MAKE_PROPERTY(root_xform, get_root_xform, set_root_xform);
120 MAKE_SEQ_PROPERTY(nodes, get_num_nodes, get_node);
121
123 INLINE void set_control_effect(AnimControl *control, PN_stdfloat effect);
124 INLINE PN_stdfloat get_control_effect(AnimControl *control) const;
125
126 virtual void output(std::ostream &out) const;
127 virtual void write(std::ostream &out, int indent_level) const;
128
129 PT(AnimControl) bind_anim(AnimBundle *anim,
130 int hierarchy_match_flags = 0,
131 const PartSubset &subset = PartSubset());
132 PT(AnimControl) load_bind_anim(Loader *loader,
133 const Filename &filename,
134 int hierarchy_match_flags,
135 const PartSubset &subset,
136 bool allow_async);
137 void wait_pending();
138
139 bool freeze_joint(const std::string &joint_name, const TransformState *transform);
140 bool freeze_joint(const std::string &joint_name, const LVecBase3 &pos, const LVecBase3 &hpr, const LVecBase3 &scale);
141 bool freeze_joint(const std::string &joint_name, PN_stdfloat value);
142 bool control_joint(const std::string &joint_name, PandaNode *node);
143 bool release_joint(const std::string &joint_name);
144
145 bool update();
146 bool force_update();
147
148public:
149 // The following functions aren't really part of the public interface;
150 // they're just public so we don't have to declare a bunch of friends.
151 virtual void control_activated(AnimControl *control);
152 void control_removed(AnimControl *control);
153 INLINE void set_update_delay(double delay);
154
155 bool do_bind_anim(AnimControl *control, AnimBundle *anim,
156 int hierarchy_match_flags, const PartSubset &subset);
157
158protected:
159 virtual void add_node(PartBundleNode *node);
160 virtual void remove_node(PartBundleNode *node);
161
162private:
163 class CData;
164
165 void do_set_control_effect(AnimControl *control, PN_stdfloat effect, CData *cdata);
166 PN_stdfloat do_get_control_effect(AnimControl *control, const CData *cdata) const;
167 void recompute_net_blend(CData *cdata);
168 void clear_and_stop_intersecting(AnimControl *control, CData *cdata);
169
170 COWPT(AnimPreloadTable) _anim_preload;
171
172 typedef pvector<PartBundleNode *> Nodes;
173 Nodes _nodes;
174
175 typedef pmap<WCPT(TransformState), WPT(PartBundle), std::owner_less<WCPT(TransformState)> > AppliedTransforms;
176 AppliedTransforms _applied_transforms;
177
178 double _update_delay;
179
180 // This is the data that must be cycled between pipeline stages.
181 class CData : public CycleData {
182 public:
183 CData();
184 CData(const CData &copy);
185
186 virtual CycleData *make_copy() const;
187 virtual void write_datagram(BamWriter *manager, Datagram &dg) const;
188 virtual void fillin(DatagramIterator &scan, BamReader *manager);
189 virtual TypeHandle get_parent_type() const {
190 return PartBundle::get_class_type();
191 }
192
193 BlendType _blend_type;
194 bool _anim_blend_flag;
195 bool _frame_blend_flag;
196 LMatrix4 _root_xform;
197 AnimControl *_last_control_set;
198 ChannelBlend _blend;
199 PN_stdfloat _net_blend;
200 bool _anim_changed;
201 double _last_update;
202 };
203
204 PipelineCycler<CData> _cycler;
205 typedef CycleDataLockedReader<CData> CDLockedReader;
206 typedef CycleDataReader<CData> CDReader;
207 typedef CycleDataWriter<CData> CDWriter;
208 typedef CycleDataStageWriter<CData> CDStageWriter;
209
210public:
211 static void register_with_read_factory();
212 virtual void finalize(BamReader *manager);
213 virtual void write_datagram(BamWriter *manager, Datagram &dg);
214 virtual int complete_pointers(TypedWritable **p_list,
215 BamReader *manager);
216
217protected:
218 static TypedWritable *make_from_bam(const FactoryParams &params);
219 void fillin(DatagramIterator &scan, BamReader *manager);
220
221public:
222
223 virtual TypeHandle get_type() const {
224 return get_class_type();
225 }
226 virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
227 static TypeHandle get_class_type() {
228 return _type_handle;
229 }
230 static void init_type() {
231 PartGroup::init_type();
232 register_type(_type_handle, "PartBundle",
233 PartGroup::get_class_type());
234 }
235
236private:
237 static TypeHandle _type_handle;
238
239 friend class PartBundleNode;
240 friend class Character;
241 friend class MovingPartBase;
242 friend class MovingPartMatrix;
243 friend class MovingPartScalar;
244};
245
246inline std::ostream &operator <<(std::ostream &out, const PartBundle &bundle) {
247 bundle.output(out);
248 return out;
249}
250
251EXPCL_PANDA_CHAN std::ostream &operator <<(std::ostream &out, PartBundle::BlendType blend_type);
252EXPCL_PANDA_CHAN std::istream &operator >>(std::istream &in, PartBundle::BlendType &blend_type);
253
254#include "partBundle.I"
255
256#endif
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is the root of an AnimChannel hierarchy.
Definition animBundle.h:29
Controls the timing of a character animation.
Definition animControl.h:38
This table records data about a list of animations for a particular model, such as number of frames a...
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition bamReader.h:110
A single page of data maintained by a PipelineCycler.
Definition cycleData.h:50
A class to retrieve the individual data elements previously stored in a Datagram.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition datagram.h:38
The name of a file, such as a texture file or an Egg file.
Definition filename.h:44
A convenient class for loading models from disk, in bam or egg format (or any of a number of other fo...
Definition loader.h:42
void output(std::ostream &out) const
Outputs the Namable.
Definition namable.I:61
A basic node of the scene graph or data graph.
Definition pandaNode.h:65
This is a node that contains a pointer to an PartBundle.
This is the root of a MovingPart hierarchy.
Definition partBundle.h:46
set_anim_blend_flag
Defines the way the character responds to multiple calls to set_control_effect()).
Definition partBundle.h:117
virtual void output(std::ostream &out) const
Writes a one-line description of the bundle.
virtual void control_activated(AnimControl *control)
Called by the AnimControl whenever it starts an animation.
get_node
Returns the nth PartBundleNode associated with this PartBundle.
Definition partBundle.h:114
void set_update_delay(double delay)
Specifies the minimum amount of time, in seconds, that should elapse between any two consecutive upda...
Definition partBundle.I:208
bool update()
Updates all the parts in the bundle to reflect the data for the current frame (as set in each of the ...
bool release_joint(const std::string &joint_name)
Releases the named joint from the effects of a previous call to freeze_joint() or control_joint().
get_frame_blend_flag
Returns whether the character interpolates (blends) between two sequential animation frames,...
Definition partBundle.h:118
void set_anim_preload(AnimPreloadTable *table)
Replaces the AnimPreloadTable associated with the PartBundle.
Definition partBundle.I:37
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
void wait_pending()
Blocks the current thread until all currently-pending AnimControls, with a nonzero control effect,...
get_blend_type
Returns the algorithm that is used when blending multiple frames or multiple animations together,...
Definition partBundle.h:116
bool control_joint(const std::string &joint_name, PandaNode *node)
Specifies that the joint with the indicated name should be animated with the transform on the indicat...
PN_stdfloat get_control_effect(AnimControl *control) const
Returns the amount by which the character is affected by the indicated AnimControl and its associated...
Definition partBundle.I:197
void xform(const LMatrix4 &mat)
Applies the indicated transform to the root of the animated hierarchy.
Definition partBundle.I:136
get_root_xform
Returns the transform matrix which is implicitly applied at the root of the animated hierarchy.
Definition partBundle.h:119
void clear_control_effects()
Sets the control effect of all AnimControls to zero (but does not "stop" the AnimControls).
void merge_anim_preloads(const PartBundle *other)
Copies the contents of the other PartBundle's preload table into this one.
set_frame_blend_flag
Specifies whether the character interpolates (blends) between two sequential frames of an active anim...
Definition partBundle.h:118
void set_control_effect(AnimControl *control, PN_stdfloat effect)
Sets the amount by which the character is affected by the indicated AnimControl (and its associated a...
Definition partBundle.I:185
void control_removed(AnimControl *control)
Called by the AnimControl when it destructs.
void clear_anim_preload()
Removes any AnimPreloadTable associated with the PartBundle.
Definition partBundle.I:45
set_root_xform
Specifies the transform matrix which is implicitly applied at the root of the animated hierarchy.
Definition partBundle.h:119
get_num_nodes
Returns the number of PartBundleNodes that contain a pointer to this PartBundle.
Definition partBundle.h:114
bool force_update()
Updates all the parts in the bundle to reflect the data for the current frame, whether we believe it ...
get_anim_blend_flag
Returns whether the character allows multiple different animations to be bound simultaneously.
Definition partBundle.h:117
bool freeze_joint(const std::string &joint_name, const TransformState *transform)
Specifies that the joint with the indicated name should be frozen with the specified transform.
bool do_bind_anim(AnimControl *control, AnimBundle *anim, int hierarchy_match_flags, const PartSubset &subset)
The internal implementation of bind_anim(), this receives a pointer to an uninitialized AnimControl a...
set_blend_type
Defines the algorithm that is used when blending multiple frames or multiple animations together,...
Definition partBundle.h:116
virtual PartGroup * make_copy() const
Allocates and returns a new copy of the node.
virtual void write(std::ostream &out, int indent_level) const
Writes a brief description of the group and all of its descendants.
virtual PartGroup * make_copy() const
Allocates and returns a new copy of the node.
Definition partGroup.cxx:67
virtual void write_datagram(BamWriter *manager, Datagram &me)
Function to write the important information in the particular object to a Datagram.
static void register_with_read_factory()
Factory method to generate a PartGroup object.
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...
This class is used to define a subset of part names to apply to the PartBundle::bind_anim() operation...
Definition partSubset.h:25
Indicates a coordinate-system transform on vertices.
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
virtual void finalize(BamReader *manager)
Called by the BamReader to perform any final actions needed for setting up the object after all objec...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.