Panda3D

characterJointBundle.cxx
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 characterJointBundle.cxx
10 * @author drose
11 * @date 1999-02-23
12 */
13
14 #include "characterJointBundle.h"
15 #include "datagram.h"
16 #include "datagramIterator.h"
17 #include "bamReader.h"
18 #include "bamWriter.h"
19
20 TypeHandle CharacterJointBundle::_type_handle;
21
22 /**
23 * Normally, there is no need to create a CharacterJointBundle directly. The
24 * Character node will automatically create one for itself.
25 */
26 CharacterJointBundle::
27 CharacterJointBundle(const std::string &name) : PartBundle(name) {
28 }
29
30 /**
31 *
32 */
33 CharacterJointBundle::
34 ~CharacterJointBundle() {
35 }
36
37 /**
38 * Allocates and returns a new copy of the node. Children are not copied, but
39 * see copy_subgraph().
40 */
41 PartGroup *CharacterJointBundle::
42 make_copy() const {
43 return new CharacterJointBundle(*this);
44 }
45
46 /**
47 * Adds the PartBundleNode pointer to the set of nodes associated with the
48 * PartBundle. Normally called only by the PartBundleNode itself, for
49 * instance when the bundle is flattened with another node.
50 */
51 void CharacterJointBundle::
52 add_node(PartBundleNode *node) {
53 PartBundle::add_node(node);
54 if (node->is_of_type(Character::get_class_type())) {
55 Character *character = DCAST(Character, node);
56 r_set_character(this, character);
57 }
58 }
59
60 /**
61 * Removes the PartBundleNode pointer from the set of nodes associated with
62 * the PartBundle. Normally called only by the PartBundleNode itself, for
63 * instance when the bundle is flattened with another node.
64 */
65 void CharacterJointBundle::
66 remove_node(PartBundleNode *node) {
67 PartBundle::remove_node(node);
68
69 // If there is still a Character on the list, assign that one to all of the
70 // joints.
71 if (get_num_nodes() > 0) {
72 r_set_character(this, get_node(get_num_nodes() - 1));
73 }
74 }
75
76 /**
77 * Recursively sets the Character on each joint in the hierarchy.
78 */
79 void CharacterJointBundle::
80 r_set_character(PartGroup *group, Character *character) {
81 if (group == nullptr) {
82 // This might happen if we are in the middle of reading the Character's
83 // hierarchy from the bam file.
84 return;
85 }
86
87 if (group->is_character_joint()) {
88 ((CharacterJoint *)group)->set_character(character);
89 }
90
91 Children::const_iterator ci;
92 for (ci = group->_children.begin(); ci != group->_children.end(); ++ci) {
93 r_set_character((*ci), character);
94 }
95 }
96
97 /**
98 * Factory method to generate a CharacterJointBundle object
99 */
100 TypedWritable* CharacterJointBundle::
101 make_CharacterJointBundle(const FactoryParams &params)
102 {
103 CharacterJointBundle *me = new CharacterJointBundle;
104 DatagramIterator scan;
105 BamReader *manager;
106
107 parse_params(params, scan, manager);
108 me->fillin(scan, manager);
109 manager->register_finalize(me);
110 return me;
111 }
112
113 /**
114 * Factory method to generate a CharacterJointBundle object
115 */
116 void CharacterJointBundle::
117 register_with_read_factory()
118 {
119 BamReader::get_factory()->register_factory(get_class_type(), make_CharacterJointBundle);
120 }
bamReader.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
parse_params
void parse_params(const FactoryParams &params, DatagramIterator &scan, BamReader *&manager)
Takes in a FactoryParams, passed from a WritableFactory into any TypedWritable's make function,...
Definition: bamReader.I:275
bamWriter.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
characterJointBundle.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
BamReader
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:110
BamReader::register_finalize
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:808
BamReader::get_factory
static WritableFactory * get_factory()
Returns the global WritableFactory for generating TypedWritable objects.
Definition: bamReader.I:177
CharacterJointBundle
The collection of all the joints and sliders in the character.
Definition: characterJointBundle.h:28
CharacterJointBundle::make_CharacterJointBundle
static TypedWritable * make_CharacterJointBundle(const FactoryParams &params)
Factory method to generate a CharacterJointBundle object.
Definition: characterJointBundle.cxx:101
CharacterJointBundle::register_with_read_factory
static void register_with_read_factory()
Factory method to generate a CharacterJointBundle object.
Definition: characterJointBundle.cxx:117
CharacterJoint
This represents one joint of the character's animation, containing an animating transform matrix.
Definition: characterJoint.h:32
Character
An animated character, with skeleton-morph animation and either soft- skinned or hard-skinned vertice...
Definition: character.h:38
DatagramIterator
A class to retrieve the individual data elements previously stored in a Datagram.
Definition: datagramIterator.h:27
FactoryParams
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition: factoryParams.h:36
Factory::register_factory
void register_factory(TypeHandle handle, CreateFunc *func, void *user_data=nullptr)
Registers a new kind of thing the Factory will be able to create.
Definition: factory.I:73
PartBundleNode
This is a node that contains a pointer to an PartBundle.
Definition: partBundleNode.h:35
PartBundle
This is the root of a MovingPart hierarchy.
Definition: partBundle.h:46
PartBundle::get_node
get_node
Returns the nth PartBundleNode associated with this PartBundle.
Definition: partBundle.h:114
PartBundle::get_num_nodes
get_num_nodes
Returns the number of PartBundleNodes that contain a pointer to this PartBundle.
Definition: partBundle.h:114
PartGroup
This is the base class for PartRoot and MovingPart.
Definition: partGroup.h:43
PartGroup::is_character_joint
virtual bool is_character_joint() const
Returns true if this part is a CharacterJoint, false otherwise.
Definition: partGroup.cxx:58
TypeHandle
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
TypedObject::is_of_type
bool is_of_type(TypeHandle handle) const
Returns true if the current object is or derives from the indicated type.
Definition: typedObject.I:28
TypedWritable
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:35
datagramIterator.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
datagram.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.