Panda3D
 All Classes Functions Variables Enumerations
characterJointBundle.cxx
1 // Filename: characterJointBundle.cxx
2 // Created by: drose (23Feb99)
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 #include "characterJointBundle.h"
16 #include "datagram.h"
17 #include "datagramIterator.h"
18 #include "bamReader.h"
19 #include "bamWriter.h"
20 
21 TypeHandle CharacterJointBundle::_type_handle;
22 
23 ////////////////////////////////////////////////////////////////////
24 // Function: CharacterJointBundle::Constructor
25 // Access: Public
26 // Description: Normally, there is no need to create a
27 // CharacterJointBundle directly. The Character node
28 // will automatically create one for itself.
29 ////////////////////////////////////////////////////////////////////
30 CharacterJointBundle::
31 CharacterJointBundle(const string &name) : PartBundle(name) {
32 }
33 
34 ////////////////////////////////////////////////////////////////////
35 // Function: CharacterJointBundle::Destructor
36 // Access: Public, Virtual
37 // Description:
38 ////////////////////////////////////////////////////////////////////
39 CharacterJointBundle::
40 ~CharacterJointBundle() {
41 }
42 
43 ////////////////////////////////////////////////////////////////////
44 // Function: CharacterJointBundle::make_copy
45 // Access: Protected, Virtual
46 // Description: Allocates and returns a new copy of the node.
47 // Children are not copied, but see copy_subgraph().
48 ////////////////////////////////////////////////////////////////////
49 PartGroup *CharacterJointBundle::
50 make_copy() const {
51  return new CharacterJointBundle(*this);
52 }
53 
54 ////////////////////////////////////////////////////////////////////
55 // Function: CharacterJointBundle::add_node
56 // Access: Protected, Virtual
57 // Description: Adds the PartBundleNode pointer to the set of nodes
58 // associated with the PartBundle. Normally called only
59 // by the PartBundleNode itself, for instance when the
60 // bundle is flattened with another node.
61 ////////////////////////////////////////////////////////////////////
62 void CharacterJointBundle::
63 add_node(PartBundleNode *node) {
64  PartBundle::add_node(node);
65  if (node->is_of_type(Character::get_class_type())) {
66  Character *character = DCAST(Character, node);
67  r_set_character(this, character);
68  }
69 }
70 
71 ////////////////////////////////////////////////////////////////////
72 // Function: CharacterJointBundle::remove_node
73 // Access: Protected, Virtual
74 // Description: Removes the PartBundleNode pointer from the set of
75 // nodes associated with the PartBundle. Normally
76 // called only by the PartBundleNode itself, for
77 // instance when the bundle is flattened with another
78 // node.
79 ////////////////////////////////////////////////////////////////////
80 void CharacterJointBundle::
81 remove_node(PartBundleNode *node) {
82  PartBundle::remove_node(node);
83 
84  // If there is still a Character on the list, assign that one to all
85  // of the joints.
86  if (get_num_nodes() > 0) {
87  r_set_character(this, get_node(get_num_nodes() - 1));
88  }
89 }
90 
91 ////////////////////////////////////////////////////////////////////
92 // Function: CharacterJointBundle::r_set_character
93 // Access: Private
94 // Description: Recursively sets the Character on each joint in the
95 // hierarchy.
96 ////////////////////////////////////////////////////////////////////
97 void CharacterJointBundle::
98 r_set_character(PartGroup *group, Character *character) {
99  if (group == (PartGroup *)NULL) {
100  // This might happen if we are in the middle of reading the
101  // Character's hierarchy from the bam file.
102  return;
103  }
104 
105  if (group->is_of_type(CharacterJoint::get_class_type())) {
106  DCAST(CharacterJoint, group)->set_character(character);
107  }
108 
109  Children::const_iterator ci;
110  for (ci = group->_children.begin(); ci != group->_children.end(); ++ci) {
111  r_set_character((*ci), character);
112  }
113 }
114 
115 ////////////////////////////////////////////////////////////////////
116 // Function: CharacterJointBundle::make_CharacterJointBundle
117 // Access: Protected
118 // Description: Factory method to generate a CharacterJointBundle object
119 ////////////////////////////////////////////////////////////////////
122 {
124  DatagramIterator scan;
125  BamReader *manager;
126 
127  parse_params(params, scan, manager);
128  me->fillin(scan, manager);
129  manager->register_finalize(me);
130  return me;
131 }
132 
133 ////////////////////////////////////////////////////////////////////
134 // Function: CharacterJointBundle::register_with_factory
135 // Access: Public, Static
136 // Description: Factory method to generate a CharacterJointBundle object
137 ////////////////////////////////////////////////////////////////////
140 {
142 }
143 
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
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:37
bool is_of_type(TypeHandle handle) const
Returns true if the current object is or derives from the indicated type.
Definition: typedObject.I:63
static TypedWritable * make_CharacterJointBundle(const FactoryParams &params)
Factory method to generate a CharacterJointBundle object.
Character * get_node(int n) const
Returns the nth Character associated with this PartBundle.
This is a node that contains a pointer to an PartBundle.
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition: factoryParams.h:40
void register_finalize(TypedWritable *whom)
Should be called by an object reading itself from the Bam file to indicate that this particular objec...
Definition: bamReader.cxx:880
static void register_with_read_factory()
Factory method to generate a CharacterJointBundle object.
void register_factory(TypeHandle handle, CreateFunc *func)
Registers a new kind of thing the Factory will be able to create.
Definition: factory.I:90
static WritableFactory * get_factory()
Returns the global WritableFactory for generating TypedWritable objects.
Definition: bamReader.I:213
This is the root of a MovingPart hierarchy.
Definition: partBundle.h:49
This represents one joint of the character's animation, containing an animating transform matrix...
int get_num_nodes() const
Returns the number of PartBundleNodes that contain a pointer to this PartBundle.
Definition: partBundle.I:198
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
This is the base class for PartRoot and MovingPart.
Definition: partGroup.h:45