00001 // Filename: characterJointBundle.cxx 00002 // Created by: drose (23Feb99) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 #include "characterJointBundle.h" 00016 #include "datagram.h" 00017 #include "datagramIterator.h" 00018 #include "bamReader.h" 00019 #include "bamWriter.h" 00020 00021 TypeHandle CharacterJointBundle::_type_handle; 00022 00023 //////////////////////////////////////////////////////////////////// 00024 // Function: CharacterJointBundle::Constructor 00025 // Access: Public 00026 // Description: Normally, there is no need to create a 00027 // CharacterJointBundle directly. The Character node 00028 // will automatically create one for itself. 00029 //////////////////////////////////////////////////////////////////// 00030 CharacterJointBundle:: 00031 CharacterJointBundle(const string &name) : PartBundle(name) { 00032 } 00033 00034 //////////////////////////////////////////////////////////////////// 00035 // Function: CharacterJointBundle::Destructor 00036 // Access: Public, Virtual 00037 // Description: 00038 //////////////////////////////////////////////////////////////////// 00039 CharacterJointBundle:: 00040 ~CharacterJointBundle() { 00041 } 00042 00043 //////////////////////////////////////////////////////////////////// 00044 // Function: CharacterJointBundle::make_copy 00045 // Access: Protected, Virtual 00046 // Description: Allocates and returns a new copy of the node. 00047 // Children are not copied, but see copy_subgraph(). 00048 //////////////////////////////////////////////////////////////////// 00049 PartGroup *CharacterJointBundle:: 00050 make_copy() const { 00051 return new CharacterJointBundle(*this); 00052 } 00053 00054 //////////////////////////////////////////////////////////////////// 00055 // Function: CharacterJointBundle::add_node 00056 // Access: Protected, Virtual 00057 // Description: Adds the PartBundleNode pointer to the set of nodes 00058 // associated with the PartBundle. Normally called only 00059 // by the PartBundleNode itself, for instance when the 00060 // bundle is flattened with another node. 00061 //////////////////////////////////////////////////////////////////// 00062 void CharacterJointBundle:: 00063 add_node(PartBundleNode *node) { 00064 PartBundle::add_node(node); 00065 if (node->is_of_type(Character::get_class_type())) { 00066 Character *character = DCAST(Character, node); 00067 r_set_character(this, character); 00068 } 00069 } 00070 00071 //////////////////////////////////////////////////////////////////// 00072 // Function: CharacterJointBundle::remove_node 00073 // Access: Protected, Virtual 00074 // Description: Removes the PartBundleNode pointer from the set of 00075 // nodes associated with the PartBundle. Normally 00076 // called only by the PartBundleNode itself, for 00077 // instance when the bundle is flattened with another 00078 // node. 00079 //////////////////////////////////////////////////////////////////// 00080 void CharacterJointBundle:: 00081 remove_node(PartBundleNode *node) { 00082 PartBundle::remove_node(node); 00083 00084 // If there is still a Character on the list, assign that one to all 00085 // of the joints. 00086 if (get_num_nodes() > 0) { 00087 r_set_character(this, get_node(get_num_nodes() - 1)); 00088 } 00089 } 00090 00091 //////////////////////////////////////////////////////////////////// 00092 // Function: CharacterJointBundle::r_set_character 00093 // Access: Private 00094 // Description: Recursively sets the Character on each joint in the 00095 // hierarchy. 00096 //////////////////////////////////////////////////////////////////// 00097 void CharacterJointBundle:: 00098 r_set_character(PartGroup *group, Character *character) { 00099 if (group == (PartGroup *)NULL) { 00100 // This might happen if we are in the middle of reading the 00101 // Character's hierarchy from the bam file. 00102 return; 00103 } 00104 00105 if (group->is_of_type(CharacterJoint::get_class_type())) { 00106 DCAST(CharacterJoint, group)->set_character(character); 00107 } 00108 00109 Children::const_iterator ci; 00110 for (ci = group->_children.begin(); ci != group->_children.end(); ++ci) { 00111 r_set_character((*ci), character); 00112 } 00113 } 00114 00115 //////////////////////////////////////////////////////////////////// 00116 // Function: CharacterJointBundle::make_CharacterJointBundle 00117 // Access: Protected 00118 // Description: Factory method to generate a CharacterJointBundle object 00119 //////////////////////////////////////////////////////////////////// 00120 TypedWritable* CharacterJointBundle:: 00121 make_CharacterJointBundle(const FactoryParams ¶ms) 00122 { 00123 CharacterJointBundle *me = new CharacterJointBundle; 00124 DatagramIterator scan; 00125 BamReader *manager; 00126 00127 parse_params(params, scan, manager); 00128 me->fillin(scan, manager); 00129 manager->register_finalize(me); 00130 return me; 00131 } 00132 00133 //////////////////////////////////////////////////////////////////// 00134 // Function: CharacterJointBundle::register_with_factory 00135 // Access: Public, Static 00136 // Description: Factory method to generate a CharacterJointBundle object 00137 //////////////////////////////////////////////////////////////////// 00138 void CharacterJointBundle:: 00139 register_with_read_factory() 00140 { 00141 BamReader::get_factory()->register_factory(get_class_type(), make_CharacterJointBundle); 00142 } 00143