00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef PARTBUNDLE_H
00016 #define PARTBUNDLE_H
00017
00018 #include "pandabase.h"
00019
00020 #include "partGroup.h"
00021 #include "animControl.h"
00022 #include "partSubset.h"
00023 #include "animPreloadTable.h"
00024 #include "pointerTo.h"
00025 #include "thread.h"
00026 #include "cycleData.h"
00027 #include "cycleDataLockedReader.h"
00028 #include "cycleDataReader.h"
00029 #include "cycleDataWriter.h"
00030 #include "luse.h"
00031 #include "pvector.h"
00032 #include "transformState.h"
00033 #include "weakPointerTo.h"
00034 #include "copyOnWritePointer.h"
00035
00036 class Loader;
00037 class AnimBundle;
00038 class PartBundleNode;
00039 class PartBundleNode;
00040 class TransformState;
00041 class AnimPreloadTable;
00042
00043
00044
00045
00046
00047
00048
00049 class EXPCL_PANDA_CHAN PartBundle : public PartGroup {
00050 public:
00051
00052
00053
00054 typedef pmap<AnimControl *, PN_stdfloat> ChannelBlend;
00055
00056 protected:
00057
00058 PartBundle(const PartBundle ©);
00059
00060 PUBLISHED:
00061 PartBundle(const string &name = "");
00062 virtual PartGroup *make_copy() const;
00063
00064 INLINE CPT(AnimPreloadTable) get_anim_preload() const;
00065 INLINE PT(AnimPreloadTable) modify_anim_preload();
00066 INLINE void set_anim_preload(AnimPreloadTable *table);
00067 INLINE void clear_anim_preload();
00068 void merge_anim_preloads(const PartBundle *other);
00069
00070
00071
00072
00073
00074 enum BlendType {
00075
00076
00077
00078
00079
00080
00081
00082 BT_linear,
00083
00084
00085
00086
00087
00088
00089
00090
00091 BT_normalized_linear,
00092
00093
00094
00095 BT_componentwise,
00096
00097
00098
00099
00100 BT_componentwise_quat,
00101 };
00102
00103 INLINE void set_blend_type(BlendType bt);
00104 INLINE BlendType get_blend_type() const;
00105
00106 void set_anim_blend_flag(bool anim_blend_flag);
00107 INLINE bool get_anim_blend_flag() const;
00108
00109 INLINE void set_frame_blend_flag(bool frame_blend_flag);
00110 INLINE bool get_frame_blend_flag() const;
00111
00112 INLINE void set_root_xform(const LMatrix4 &root_xform);
00113 INLINE void xform(const LMatrix4 &mat);
00114 INLINE const LMatrix4 &get_root_xform() const;
00115 PT(PartBundle) apply_transform(const TransformState *transform);
00116
00117 INLINE int get_num_nodes() const;
00118 INLINE PartBundleNode *get_node(int n) const;
00119 MAKE_SEQ(get_nodes, get_num_nodes, get_node);
00120
00121 void clear_control_effects();
00122 INLINE void set_control_effect(AnimControl *control, PN_stdfloat effect);
00123 INLINE PN_stdfloat get_control_effect(AnimControl *control) const;
00124
00125 virtual void output(ostream &out) const;
00126 virtual void write(ostream &out, int indent_level) const;
00127
00128 PT(AnimControl) bind_anim(AnimBundle *anim,
00129 int hierarchy_match_flags = 0,
00130 const PartSubset &subset = PartSubset());
00131 PT(AnimControl) load_bind_anim(Loader *loader,
00132 const Filename &filename,
00133 int hierarchy_match_flags,
00134 const PartSubset &subset,
00135 bool allow_async);
00136 void wait_pending();
00137
00138 bool freeze_joint(const string &joint_name, const TransformState *transform);
00139 bool freeze_joint(const string &joint_name, const LVecBase3 &pos, const LVecBase3 &hpr, const LVecBase3 &scale);
00140 bool freeze_joint(const string &joint_name, PN_stdfloat value);
00141 bool control_joint(const string &joint_name, PandaNode *node);
00142 bool release_joint(const string &joint_name);
00143
00144 bool update();
00145 bool force_update();
00146
00147 public:
00148
00149
00150
00151 virtual void control_activated(AnimControl *control);
00152 INLINE void set_update_delay(double delay);
00153
00154 bool do_bind_anim(AnimControl *control, AnimBundle *anim,
00155 int hierarchy_match_flags, const PartSubset &subset);
00156
00157 protected:
00158 virtual void add_node(PartBundleNode *node);
00159 virtual void remove_node(PartBundleNode *node);
00160
00161 private:
00162 class CData;
00163
00164 void do_set_control_effect(AnimControl *control, PN_stdfloat effect, CData *cdata);
00165 PN_stdfloat do_get_control_effect(AnimControl *control, const CData *cdata) const;
00166 void recompute_net_blend(CData *cdata);
00167 void clear_and_stop_intersecting(AnimControl *control, CData *cdata);
00168
00169 COWPT(AnimPreloadTable) _anim_preload;
00170
00171 typedef pvector<PartBundleNode *> Nodes;
00172 Nodes _nodes;
00173
00174 typedef pmap<WCPT(TransformState), WPT(PartBundle) > AppliedTransforms;
00175 AppliedTransforms _applied_transforms;
00176
00177 double _update_delay;
00178
00179
00180 class CData : public CycleData {
00181 public:
00182 CData();
00183 CData(const CData ©);
00184
00185 virtual CycleData *make_copy() const;
00186 virtual void write_datagram(BamWriter *manager, Datagram &dg) const;
00187 virtual void fillin(DatagramIterator &scan, BamReader *manager);
00188 virtual TypeHandle get_parent_type() const {
00189 return PartBundle::get_class_type();
00190 }
00191
00192 BlendType _blend_type;
00193 bool _anim_blend_flag;
00194 bool _frame_blend_flag;
00195 LMatrix4 _root_xform;
00196 AnimControl *_last_control_set;
00197 ChannelBlend _blend;
00198 PN_stdfloat _net_blend;
00199 bool _anim_changed;
00200 double _last_update;
00201 };
00202
00203 PipelineCycler<CData> _cycler;
00204 typedef CycleDataLockedReader<CData> CDLockedReader;
00205 typedef CycleDataReader<CData> CDReader;
00206 typedef CycleDataWriter<CData> CDWriter;
00207
00208 public:
00209 static void register_with_read_factory();
00210 virtual void finalize(BamReader *manager);
00211 virtual void write_datagram(BamWriter *manager, Datagram &dg);
00212 virtual int complete_pointers(TypedWritable **p_list,
00213 BamReader *manager);
00214
00215 protected:
00216 static TypedWritable *make_from_bam(const FactoryParams ¶ms);
00217 void fillin(DatagramIterator &scan, BamReader *manager);
00218
00219 public:
00220
00221 virtual TypeHandle get_type() const {
00222 return get_class_type();
00223 }
00224 virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00225 static TypeHandle get_class_type() {
00226 return _type_handle;
00227 }
00228 static void init_type() {
00229 PartGroup::init_type();
00230 register_type(_type_handle, "PartBundle",
00231 PartGroup::get_class_type());
00232 }
00233
00234 private:
00235 static TypeHandle _type_handle;
00236
00237 friend class PartBundleNode;
00238 friend class Character;
00239 friend class MovingPartBase;
00240 friend class MovingPartMatrix;
00241 friend class MovingPartScalar;
00242 };
00243
00244 inline ostream &operator <<(ostream &out, const PartBundle &bundle) {
00245 bundle.output(out);
00246 return out;
00247 }
00248
00249 ostream &operator <<(ostream &out, PartBundle::BlendType blend_type);
00250 istream &operator >>(istream &in, PartBundle::BlendType &blend_type);
00251
00252 #include "partBundle.I"
00253
00254 #endif