Panda3D
partGroup.h
1 // Filename: partGroup.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 PARTGROUP_H
16 #define PARTGROUP_H
17 
18 #include "pandabase.h"
19 
20 #include "typedWritableReferenceCount.h"
21 #include "pointerTo.h"
22 #include "namable.h"
23 #include "typedef.h"
24 #include "thread.h"
25 #include "plist.h"
26 #include "luse.h"
27 
28 class AnimControl;
29 class AnimGroup;
30 class PartBundle;
31 class PartSubset;
32 class BamReader;
33 class FactoryParams;
34 class BitArray;
35 class CycleData;
36 class TransformState;
37 class PandaNode;
38 class AnimChannelBase;
39 
40 ////////////////////////////////////////////////////////////////////
41 // Class : PartGroup
42 // Description : This is the base class for PartRoot and
43 // MovingPart. It defines a hierarchy of MovingParts.
44 ////////////////////////////////////////////////////////////////////
45 class EXPCL_PANDA_CHAN PartGroup : public TypedWritableReferenceCount, public Namable {
46 PUBLISHED:
47  // This enum defines bits which may be passed into check_hierarchy()
48  // and PartBundle::bind_anim() to allow an inexact match of channel
49  // hierarchies. This specifies conditions that we don't care about
50  // enforcing.
51  enum HierarchyMatchFlags {
52  HMF_ok_part_extra = 0x01,
53  HMF_ok_anim_extra = 0x02,
54  HMF_ok_wrong_root_name = 0x04,
55  };
56 
57 protected:
58  // The default constructor is protected: don't try to create a
59  // PartGroup without a parent. To create a PartGroup hierarchy, you
60  // must first create a PartBundle, and use that as the parent of any
61  // subsequent children.
62  INLINE PartGroup(const string &name = "");
63  INLINE PartGroup(const PartGroup &copy);
64 
65 PUBLISHED:
66  // This is the normal PartGroup constructor.
67  PartGroup(PartGroup *parent, const string &name);
68  virtual ~PartGroup();
69  virtual bool is_character_joint() const;
70 
71  virtual PartGroup *make_copy() const;
72  PartGroup *copy_subgraph() const;
73 
74  int get_num_children() const;
75  PartGroup *get_child(int n) const;
76  MAKE_SEQ(get_children, get_num_children, get_child);
77 
78  PartGroup *get_child_named(const string &name) const;
79  PartGroup *find_child(const string &name) const;
80  void sort_descendants();
81 
82  bool apply_freeze(const TransformState *transform);
83  virtual bool apply_freeze_matrix(const LVecBase3 &pos, const LVecBase3 &hpr, const LVecBase3 &scale);
84  virtual bool apply_freeze_scalar(PN_stdfloat value);
85  virtual bool apply_control(PandaNode *node);
86  virtual bool clear_forced_channel();
87  virtual AnimChannelBase *get_forced_channel() const;
88 
89  virtual void write(ostream &out, int indent_level) const;
90  virtual void write_with_value(ostream &out, int indent_level) const;
91 
92 public:
93  virtual TypeHandle get_value_type() const;
94 
95  bool check_hierarchy(const AnimGroup *anim,
96  const PartGroup *parent,
97  int hierarchy_match_flags = 0) const;
98 
99  virtual bool do_update(PartBundle *root, const CycleData *root_cdata,
100  PartGroup *parent, bool parent_changed,
101  bool anim_changed, Thread *current_thread);
102  virtual void do_xform(const LMatrix4 &mat, const LMatrix4 &inv_mat);
103  virtual void determine_effective_channels(const CycleData *root_cdata);
104 
105 protected:
106  void write_descendants(ostream &out, int indent_level) const;
107  void write_descendants_with_value(ostream &out, int indent_level) const;
108 
109  virtual void pick_channel_index(plist<int> &holes, int &next) const;
110  virtual void bind_hierarchy(AnimGroup *anim, int channel_index,
111  int &joint_index, bool is_included,
112  BitArray &bound_joints,
113  const PartSubset &subset);
114  virtual void find_bound_joints(int &joint_index, bool is_included,
115  BitArray &bound_joints,
116  const PartSubset &subset);
117 
119  Children _children;
120 
121 public:
122  static void register_with_read_factory();
123  virtual void write_datagram(BamWriter* manager, Datagram &me);
124  virtual int complete_pointers(TypedWritable **p_list,
125  BamReader *manager);
126 
127  static TypedWritable *make_PartGroup(const FactoryParams &params);
128 
129 protected:
130  void fillin(DatagramIterator& scan, BamReader* manager);
131 
132 public:
133  virtual TypeHandle get_type() const {
134  return get_class_type();
135  }
136  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
137  static TypeHandle get_class_type() {
138  return _type_handle;
139  }
140 
141 public:
142  static void init_type() {
143  TypedWritableReferenceCount::init_type();
144  register_type(_type_handle, "PartGroup",
145  TypedWritableReferenceCount::get_class_type());
146  }
147 
148 private:
149  static TypeHandle _type_handle;
150 
151  friend class Character;
152  friend class CharacterJointBundle;
153  friend class PartBundle;
154 };
155 
156 #include "partGroup.I"
157 
158 #endif
159 
160 
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
The collection of all the joints and sliders in the character.
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
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
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:73
virtual void fillin(DatagramIterator &scan, BamReader *manager)
This internal function is intended to be called by each class&#39;s make_from_bam() method to read in all...
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
A dynamic array with an unlimited number of bits.
Definition: bitArray.h:42
Parent class for all animation channels.
A base class for all things which can have a name.
Definition: namable.h:29
This is the base class for AnimChannel and AnimBundle.
Definition: animGroup.h:36
virtual int complete_pointers(TypedWritable **p_list, BamReader *manager)
Receives an array of pointers, one for each time manager->read_pointer() was called in fillin()...
This is a 4-by-4 transform matrix.
Definition: lmatrix.h:451
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition: factoryParams.h:40
A base class for things which need to inherit from both TypedWritable and from ReferenceCount.
This class is used to define a subset of part names to apply to the PartBundle::bind_anim() operation...
Definition: partSubset.h:28
A thread; that is, a lightweight process.
Definition: thread.h:51
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
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:43
This is the base class for PartRoot and MovingPart.
Definition: partGroup.h:45