Panda3D
Loading...
Searching...
No Matches
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
15#include "datagram.h"
16#include "datagramIterator.h"
17#include "bamReader.h"
18#include "bamWriter.h"
19
20TypeHandle 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 */
26CharacterJointBundle::
27CharacterJointBundle(const std::string &name) : PartBundle(name) {
28}
29
30/**
31 *
32 */
33CharacterJointBundle::
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 */
41PartGroup *CharacterJointBundle::
42make_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 */
51void CharacterJointBundle::
52add_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 */
65void CharacterJointBundle::
66remove_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 */
79void CharacterJointBundle::
80r_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 */
102{
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 */
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition bamReader.h:110
void register_finalize(TypedWritable *whom)
Should be called by an object reading itself from the Bam file to indicate that this particular objec...
static WritableFactory * get_factory()
Returns the global WritableFactory for generating TypedWritable objects.
Definition bamReader.I:177
The collection of all the joints and sliders in the character.
static TypedWritable * make_CharacterJointBundle(const FactoryParams &params)
Factory method to generate a CharacterJointBundle object.
static void register_with_read_factory()
Factory method to generate a CharacterJointBundle object.
This represents one joint of the character's animation, containing an animating transform matrix.
An animated character, with skeleton-morph animation and either soft- skinned or hard-skinned vertice...
Definition character.h:38
A class to retrieve the individual data elements previously stored in a Datagram.
An instance of this class is passed to the Factory when requesting it to do its business and construc...
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
This is a node that contains a pointer to an PartBundle.
This is the root of a MovingPart hierarchy.
Definition partBundle.h:46
get_node
Returns the nth PartBundleNode associated with this PartBundle.
Definition partBundle.h:114
get_num_nodes
Returns the number of PartBundleNodes that contain a pointer to this PartBundle.
Definition partBundle.h:114
This is the base class for PartRoot and MovingPart.
Definition partGroup.h:43
virtual bool is_character_joint() const
Returns true if this part is a CharacterJoint, false otherwise.
Definition partGroup.cxx:58
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
bool is_of_type(TypeHandle handle) const
Returns true if the current object is or derives from the indicated type.
Definition typedObject.I:28
Base class for objects that can be written to and read from Bam files.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.