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.
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
122 void clear_control_effects();
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
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
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition bamWriter.h:63
An animated character, with skeleton-morph animation and either soft- skinned or hard-skinned vertice...
Definition character.h:38
This template class calls PipelineCycler::read() in the constructor and PipelineCycler::release_read(...
This template class calls PipelineCycler::read_unlocked(), and then provides a transparent read-only ...
This class is similar to CycleDataWriter, except it allows writing to a particular stage of the pipel...
This template class calls PipelineCycler::write() in the constructor and PipelineCycler::release_writ...
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
An instance of this class is passed to the Factory when requesting it to do its business and construc...
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
This is the base class for a single animatable piece that may be bound to one channel (or more,...
This is a particular kind of MovingPart that accepts a matrix each frame.
This is a particular kind of MovingPart that accepts a scalar each frame.
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
virtual void output(std::ostream &out) const
Writes a one-line description of the bundle.
This is the base class for PartRoot and MovingPart.
Definition partGroup.h:43
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
Base class for objects that can be written to and read from Bam files.
virtual void finalize(BamReader *manager)
Called by the BamReader to perform any final actions needed for setting up the object after all objec...
This is our own Panda specialization on the default STL map.
Definition pmap.h:49
This is our own Panda specialization on the default STL vector.
Definition pvector.h:42
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(),...
This class maintains different copies of a page of data between stages of the graphics pipeline (or a...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.