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