Panda3D
|
00001 // Filename: partGroup.h 00002 // Created by: drose (22Feb99) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 #ifndef PARTGROUP_H 00016 #define PARTGROUP_H 00017 00018 #include "pandabase.h" 00019 00020 #include "typedWritableReferenceCount.h" 00021 #include "pointerTo.h" 00022 #include "namable.h" 00023 #include "typedef.h" 00024 #include "thread.h" 00025 #include "plist.h" 00026 #include "luse.h" 00027 00028 class AnimControl; 00029 class AnimGroup; 00030 class PartBundle; 00031 class PartSubset; 00032 class BamReader; 00033 class FactoryParams; 00034 class BitArray; 00035 class CycleData; 00036 class TransformState; 00037 class PandaNode; 00038 class AnimChannelBase; 00039 00040 //////////////////////////////////////////////////////////////////// 00041 // Class : PartGroup 00042 // Description : This is the base class for PartRoot and 00043 // MovingPart. It defines a hierarchy of MovingParts. 00044 //////////////////////////////////////////////////////////////////// 00045 class EXPCL_PANDA_CHAN PartGroup : public TypedWritableReferenceCount, public Namable { 00046 public: 00047 // This enum defines bits which may be passed into check_hierarchy() 00048 // and PartBundle::bind_anim() to allow an inexact match of channel 00049 // hierarchies. This specifies conditions that we don't care about 00050 // enforcing. 00051 enum HierarchyMatchFlags { 00052 HMF_ok_part_extra = 0x01, 00053 HMF_ok_anim_extra = 0x02, 00054 HMF_ok_wrong_root_name = 0x04, 00055 }; 00056 00057 protected: 00058 // The default constructor is protected: don't try to create a 00059 // PartGroup without a parent. To create a PartGroup hierarchy, you 00060 // must first create a PartBundle, and use that as the parent of any 00061 // subsequent children. 00062 INLINE PartGroup(const string &name = ""); 00063 INLINE PartGroup(const PartGroup ©); 00064 00065 PUBLISHED: 00066 // This is the normal PartGroup constructor. 00067 PartGroup(PartGroup *parent, const string &name); 00068 virtual ~PartGroup(); 00069 virtual bool is_character_joint() const; 00070 00071 virtual PartGroup *make_copy() const; 00072 PartGroup *copy_subgraph() const; 00073 00074 int get_num_children() const; 00075 PartGroup *get_child(int n) const; 00076 MAKE_SEQ(get_children, get_num_children, get_child); 00077 00078 PartGroup *get_child_named(const string &name) const; 00079 PartGroup *find_child(const string &name) const; 00080 void sort_descendants(); 00081 00082 bool apply_freeze(const TransformState *transform); 00083 virtual bool apply_freeze_matrix(const LVecBase3 &pos, const LVecBase3 &hpr, const LVecBase3 &scale); 00084 virtual bool apply_freeze_scalar(PN_stdfloat value); 00085 virtual bool apply_control(PandaNode *node); 00086 virtual bool clear_forced_channel(); 00087 virtual AnimChannelBase *get_forced_channel() const; 00088 00089 virtual void write(ostream &out, int indent_level) const; 00090 virtual void write_with_value(ostream &out, int indent_level) const; 00091 00092 public: 00093 virtual TypeHandle get_value_type() const; 00094 00095 bool check_hierarchy(const AnimGroup *anim, 00096 const PartGroup *parent, 00097 int hierarchy_match_flags = 0) const; 00098 00099 virtual bool do_update(PartBundle *root, const CycleData *root_cdata, 00100 PartGroup *parent, bool parent_changed, 00101 bool anim_changed, Thread *current_thread); 00102 virtual void do_xform(const LMatrix4 &mat, const LMatrix4 &inv_mat); 00103 virtual void determine_effective_channels(const CycleData *root_cdata); 00104 00105 protected: 00106 void write_descendants(ostream &out, int indent_level) const; 00107 void write_descendants_with_value(ostream &out, int indent_level) const; 00108 00109 virtual void pick_channel_index(plist<int> &holes, int &next) const; 00110 virtual void bind_hierarchy(AnimGroup *anim, int channel_index, 00111 int &joint_index, bool is_included, 00112 BitArray &bound_joints, 00113 const PartSubset &subset); 00114 virtual void find_bound_joints(int &joint_index, bool is_included, 00115 BitArray &bound_joints, 00116 const PartSubset &subset); 00117 00118 typedef pvector< PT(PartGroup) > Children; 00119 Children _children; 00120 00121 public: 00122 static void register_with_read_factory(); 00123 virtual void write_datagram(BamWriter* manager, Datagram &me); 00124 virtual int complete_pointers(TypedWritable **p_list, 00125 BamReader *manager); 00126 00127 static TypedWritable *make_PartGroup(const FactoryParams ¶ms); 00128 00129 protected: 00130 void fillin(DatagramIterator& scan, BamReader* manager); 00131 00132 public: 00133 virtual TypeHandle get_type() const { 00134 return get_class_type(); 00135 } 00136 virtual TypeHandle force_init_type() {init_type(); return get_class_type();} 00137 static TypeHandle get_class_type() { 00138 return _type_handle; 00139 } 00140 00141 public: 00142 static void init_type() { 00143 TypedWritableReferenceCount::init_type(); 00144 register_type(_type_handle, "PartGroup", 00145 TypedWritableReferenceCount::get_class_type()); 00146 } 00147 00148 private: 00149 static TypeHandle _type_handle; 00150 00151 friend class Character; 00152 friend class CharacterJointBundle; 00153 friend class PartBundle; 00154 }; 00155 00156 #include "partGroup.I" 00157 00158 #endif 00159 00160