From d4482780b5ae47ecb3bd91a3ea1c18d4371be5b3 Mon Sep 17 00:00:00 2001 From: David Rose Date: Wed, 20 Mar 2002 14:01:49 +0000 Subject: [PATCH] pgraph static char joints to bams --- panda/src/char/characterJoint.cxx | 94 ++++++++++------- panda/src/char/characterJoint.h | 2 + panda/src/char/qpcharacter.cxx | 146 +++++++++++--------------- panda/src/char/qpcharacter.h | 14 ++- panda/src/egg2pg/qpcharacterMaker.cxx | 2 +- panda/src/putil/bam.h | 3 +- 6 files changed, 127 insertions(+), 134 deletions(-) diff --git a/panda/src/char/characterJoint.cxx b/panda/src/char/characterJoint.cxx index a084b7d655..71fa5eaef1 100644 --- a/panda/src/char/characterJoint.cxx +++ b/panda/src/char/characterJoint.cxx @@ -383,6 +383,7 @@ void CharacterJoint:: write_datagram(BamWriter *manager, Datagram &me) { ArcList::iterator ai; + NodeList::iterator ni; // First, make sure all of our arcs are still valid, before we try // to write them out. Remove any invalid arcs. @@ -414,18 +415,35 @@ write_datagram(BamWriter *manager, Datagram &me) } MovingPartMatrix::write_datagram(manager, me); - me.add_uint16(_net_transform_arcs.size()); - for(ai = _net_transform_arcs.begin(); ai != _net_transform_arcs.end(); ai++) { + me.add_uint16(_net_transform_arcs.size()); + for(ai = _net_transform_arcs.begin(); + ai != _net_transform_arcs.end(); + ai++) { manager->write_pointer(me, (*ai)); } me.add_uint16(_local_transform_arcs.size()); - for(ai = _local_transform_arcs.begin(); ai != _local_transform_arcs.end(); ai++) - { + for(ai = _local_transform_arcs.begin(); + ai != _local_transform_arcs.end(); + ai++) { manager->write_pointer(me, (*ai)); } + me.add_uint16(_net_transform_nodes.size()); + for(ni = _net_transform_nodes.begin(); + ni != _net_transform_nodes.end(); + ni++) { + manager->write_pointer(me, (*ni)); + } + + me.add_uint16(_local_transform_nodes.size()); + for(ni = _local_transform_nodes.begin(); + ni != _local_transform_nodes.end(); + ni++) { + manager->write_pointer(me, (*ni)); + } + _initial_net_transform_inverse.write_datagram(me); } @@ -438,22 +456,36 @@ write_datagram(BamWriter *manager, Datagram &me) // place //////////////////////////////////////////////////////////////////// void CharacterJoint:: -fillin(DatagramIterator& scan, BamReader* manager) -{ +fillin(DatagramIterator &scan, BamReader *manager) { int i; MovingPartMatrix::fillin(scan, manager); _num_net_arcs = scan.get_uint16(); - for(i = 0; i < _num_net_arcs; i++) - { + for(i = 0; i < _num_net_arcs; i++) { manager->read_pointer(scan); } _num_local_arcs = scan.get_uint16(); - for(i = 0; i < _num_local_arcs; i++) - { + for(i = 0; i < _num_local_arcs; i++) { manager->read_pointer(scan); } + if (manager->get_file_minor_ver() < 7) { + // No _node lists before version 3.7. + _num_net_nodes = 0; + _num_local_nodes = 0; + } else { + _num_net_nodes = scan.get_uint16(); + for(i = 0; i < _num_net_nodes; i++) { + manager->read_pointer(scan); + } + + _num_local_nodes = scan.get_uint16(); + for(i = 0; i < _num_local_nodes; i++) { + manager->read_pointer(scan); + } + cerr << "read " << _num_net_nodes << " net transforms\n"; + } + _initial_net_transform_inverse.read_datagram(scan); } @@ -467,38 +499,26 @@ fillin(DatagramIterator& scan, BamReader* manager) int CharacterJoint:: complete_pointers(TypedWritable **p_list, BamReader* manager) { + int pi = MovingPartMatrix::complete_pointers(p_list, manager); + int i; - int start = MovingPartMatrix::complete_pointers(p_list, manager); - int mid = start+_num_net_arcs; - int end = start+_num_net_arcs+_num_local_arcs; - - for(i = start; i < mid; i++) - { - if (p_list[i] == TypedWritable::Null) - { - char_cat->warning() << get_name() - << " Ignoring null Net NodeRelation" << endl; - } - else - { - add_net_transform(DCAST(NodeRelation, p_list[i])); - } + for (i = 0; i < _num_net_arcs; i++) { + add_net_transform(DCAST(NodeRelation, p_list[pi++])); } - for(i = mid; i < end; i++) - { - if (p_list[i] == TypedWritable::Null) - { - char_cat->warning() << get_name() - << " Ignoring null Local NodeRelation" << endl; - } - else - { - add_local_transform(DCAST(NodeRelation, p_list[i])); - } + for (i = 0; i < _num_local_arcs; i++) { + add_local_transform(DCAST(NodeRelation, p_list[pi++])); } - return end; + for (i = 0; i < _num_net_nodes; i++) { + add_net_transform(DCAST(PandaNode, p_list[pi++])); + } + + for (i = 0; i < _num_local_nodes; i++) { + add_local_transform(DCAST(PandaNode, p_list[pi++])); + } + + return pi; } //////////////////////////////////////////////////////////////////// diff --git a/panda/src/char/characterJoint.h b/panda/src/char/characterJoint.h index d115435a3c..a85e25df44 100644 --- a/panda/src/char/characterJoint.h +++ b/panda/src/char/characterJoint.h @@ -87,6 +87,7 @@ protected: private: int _num_net_arcs, _num_local_arcs; + int _num_net_nodes, _num_local_nodes; public: // The _geom_node member just holds a temporary pointer to a node @@ -118,6 +119,7 @@ private: static TypeHandle _type_handle; friend class Character; + friend class qpCharacter; }; #endif diff --git a/panda/src/char/qpcharacter.cxx b/panda/src/char/qpcharacter.cxx index 75e56f63d7..334678bc56 100644 --- a/panda/src/char/qpcharacter.cxx +++ b/panda/src/char/qpcharacter.cxx @@ -21,13 +21,12 @@ #include "computedVertices.h" #include "config_char.h" -#include "geomNode.h" +#include "qpgeomNode.h" #include "datagram.h" #include "datagramIterator.h" #include "bamReader.h" #include "bamWriter.h" #include "pStatTimer.h" -#include "geomNode.h" #include "animControl.h" #include "clockObject.h" #include "pStatTimer.h" @@ -211,92 +210,76 @@ copy_joints(PartGroup *copy, PartGroup *orig) { } } -/* //////////////////////////////////////////////////////////////////// -// Function: qpCharacter::r_copy_subgraph -// Access: Private, Virtual -// Description: This is a virtual function inherited from Node. It's -// called when a copy_subgraph() operation reaches the -// qpCharacter node. In the case of a qpCharacter, it's -// overridden to do the all right things to copy the -// dynamic geometry to the new qpCharacter. +// Function: qpCharacter::r_copy_children +// Access: Protected, Virtual +// Description: This is called by r_copy_subgraph(); the copy has +// already been made of this particular node (and this +// is the copy); this function's job is to copy all of +// the children from the original. // // Note that it includes the parameter inst_map, which // is a map type, and is not (and cannot be) exported -// from PANDA.DLL. Thus, any derivative of Node that is -// not also a member of PANDA.DLL *cannot* access this -// map. +// from PANDA.DLL. Thus, any derivative of PandaNode +// that is not also a member of PANDA.DLL *cannot* +// access this map, and probably should not even +// override this function. //////////////////////////////////////////////////////////////////// -Node *qpCharacter:: -r_copy_subgraph(TypeHandle graph_type, Node::InstanceMap &) const { - Node *copy = make_copy(); - nassertr(copy != (Node *)NULL, NULL); - if (copy->get_type() != get_type()) { - graph_cat.warning() - << "Don't know how to copy nodes of type " << get_type() << "\n"; - } - +void qpCharacter:: +r_copy_children(const PandaNode *from, PandaNode::InstanceMap &inst_map) { // We assume there will be no instancing going on below the // qpCharacter node. If there is, too bad; it will get flattened out. - // Now we preempt the node's r_copy_subgraph() operation with our - // own function that keeps track of the old vs. new arcs and also + // We preempt the node's r_copy_children() operation with our own + // function that keeps track of the old vs. new nodes and also // updates any Geoms we find with our new dynamic vertices. - qpCharacter *char_copy; - DCAST_INTO_R(char_copy, copy, NULL); - ArcMap arc_map; - char_copy->r_copy_char(char_copy, this, graph_type, this, arc_map); - char_copy->copy_arc_pointers(this, arc_map); - - return copy; + const qpCharacter *from_char; + DCAST_INTO_V(from_char, from); + NodeMap node_map; + r_copy_char(this, from_char, from_char, node_map); + copy_node_pointers(from_char, node_map); } -*/ -/* //////////////////////////////////////////////////////////////////// // Function: qpCharacter::r_copy_char // Access: Private -// Description: Recursively walks the scene graph hierarchy below the +// Description: Recursively walks the scene graph hiernodehy below the // qpCharacter node, duplicating it while noting the -// orig:copy arc mappings, and also updates any +// orig:copy node mappings, and also updates any // GeomNodes found. //////////////////////////////////////////////////////////////////// void qpCharacter:: -r_copy_char(Node *dest, const Node *source, TypeHandle graph_type, - const qpCharacter *from, qpCharacter::ArcMap &arc_map) { - if (source->is_of_type(GeomNode::get_class_type())) { - const GeomNode *source_gnode; - GeomNode *dest_gnode; +r_copy_char(PandaNode *dest, const PandaNode *source, + const qpCharacter *from, qpCharacter::NodeMap &node_map) { + if (source->is_geom_node()) { + const qpGeomNode *source_gnode; + qpGeomNode *dest_gnode; DCAST_INTO_V(source_gnode, source); DCAST_INTO_V(dest_gnode, dest); - dest_gnode->clear(); + dest_gnode->remove_all_geoms(); int num_geoms = source_gnode->get_num_geoms(); for (int i = 0; i < num_geoms; i++) { - dDrawable *d = source_gnode->get_geom(i); - if (d->is_of_type(Geom::get_class_type())) { - dest_gnode->add_geom(copy_geom(DCAST(Geom, d), from)); - } else { - dest_gnode->add_geom(d); - } + Geom *geom = source_gnode->get_geom(i); + const RenderState *state = source_gnode->get_geom_state(i); + dest_gnode->add_geom(copy_geom(geom, from), state); } } - int num_children = source->get_num_children(graph_type); + int num_children = source->get_num_children(); for (int i = 0; i < num_children; i++) { - NodeRelation *source_arc = source->get_child(graph_type, i); - const Node *source_child = source_arc->get_child(); - nassertv(source_child != (Node *)NULL); + const PandaNode *source_child = source->get_child(i); + int source_sort = source->get_child_sort(i); - Node *dest_child; + PandaNode *dest_child; if (source_child->is_of_type(qpCharacter::get_class_type())) { // We make a special case for nodes of type qpCharacter. If we // encounter one of these, we have a qpCharacter under a // qpCharacter, and the nested qpCharacter's copy should be called // instead of ours. - dest_child = source_child->copy_subgraph(graph_type); + dest_child = source_child->copy_subgraph(); } else { // Otherwise, we assume that make_copy() will make a suitable @@ -304,21 +287,13 @@ r_copy_char(Node *dest, const Node *source, TypeHandle graph_type, // have parented to a qpCharacter and expect copy_subgraph() to // work correctly. Too bad. dest_child = source_child->make_copy(); - r_copy_char(dest_child, source_child, graph_type, from, arc_map); + r_copy_char(dest_child, source_child, from, node_map); } - - NodeRelation *dest_arc = - NodeRelation::create_typed_arc(graph_type, dest, dest_child); - nassertv(dest_arc != (NodeRelation *)NULL); - nassertv(dest_arc->is_exact_type(graph_type)); - - dest_arc->copy_transitions_from(source_arc); - arc_map[source_arc] = dest_arc; + dest->add_child(dest_child, source_sort); + node_map[source_child] = dest_child; } } -*/ -/* //////////////////////////////////////////////////////////////////// // Function: qpCharacter::copy_geom // Access: Private @@ -373,18 +348,16 @@ copy_geom(Geom *source, const qpCharacter *from) { return dest; } -*/ -/* //////////////////////////////////////////////////////////////////// -// Function: qpCharacter::copy_arc_pointers +// Function: qpCharacter::copy_node_pointers // Access: Public -// Description: Creates _net_transform_arcs and _local_transform_arcs +// Description: Creates _net_transform_nodes and _local_transform_nodes // as appropriate in each of the qpCharacter's joints, as // copied from the other qpCharacter. //////////////////////////////////////////////////////////////////// void qpCharacter:: -copy_arc_pointers(const qpCharacter *from, const qpCharacter::ArcMap &arc_map) { +copy_node_pointers(const qpCharacter *from, const qpCharacter::NodeMap &node_map) { nassertv(_parts.size() == from->_parts.size()); for (int i = 0; i < (int)_parts.size(); i++) { if (_parts[i]->is_of_type(CharacterJoint::get_class_type())) { @@ -394,44 +367,43 @@ copy_arc_pointers(const qpCharacter *from, const qpCharacter::ArcMap &arc_map) { DCAST_INTO_V(source_joint, from->_parts[i]); DCAST_INTO_V(dest_joint, _parts[i]); - CharacterJoint::ArcList::const_iterator ai; - for (ai = source_joint->_net_transform_arcs.begin(); - ai != source_joint->_net_transform_arcs.end(); + CharacterJoint::NodeList::const_iterator ai; + for (ai = source_joint->_net_transform_nodes.begin(); + ai != source_joint->_net_transform_nodes.end(); ++ai) { - NodeRelation *source_arc = (*ai); + PandaNode *source_node = (*ai); - ArcMap::const_iterator mi; - mi = arc_map.find(source_arc); - if (mi != arc_map.end()) { - NodeRelation *dest_arc = (*mi).second; + NodeMap::const_iterator mi; + mi = node_map.find(source_node); + if (mi != node_map.end()) { + PandaNode *dest_node = (*mi).second; // Here's an internal joint that the source qpCharacter was // animating directly. We'll animate our corresponding // joint the same way. - dest_joint->add_net_transform(dest_arc); + dest_joint->add_net_transform(dest_node); } } - for (ai = source_joint->_local_transform_arcs.begin(); - ai != source_joint->_local_transform_arcs.end(); + for (ai = source_joint->_local_transform_nodes.begin(); + ai != source_joint->_local_transform_nodes.end(); ++ai) { - NodeRelation *source_arc = (*ai); + PandaNode *source_node = (*ai); - ArcMap::const_iterator mi; - mi = arc_map.find(source_arc); - if (mi != arc_map.end()) { - NodeRelation *dest_arc = (*mi).second; + NodeMap::const_iterator mi; + mi = node_map.find(source_node); + if (mi != node_map.end()) { + PandaNode *dest_node = (*mi).second; // Here's an internal joint that the source qpCharacter was // animating directly. We'll animate our corresponding // joint the same way. - dest_joint->add_local_transform(dest_arc); + dest_joint->add_local_transform(dest_node); } } } } } -*/ //////////////////////////////////////////////////////////////////// diff --git a/panda/src/char/qpcharacter.h b/panda/src/char/qpcharacter.h index c66773c7f5..520369ff66 100644 --- a/panda/src/char/qpcharacter.h +++ b/panda/src/char/qpcharacter.h @@ -66,15 +66,13 @@ PUBLISHED: private: void copy_joints(PartGroup *copy, PartGroup *orig); - /* - typedef pmap ArcMap; - virtual Node *r_copy_subgraph(TypeHandle graph_type, - InstanceMap &inst_map) const; - void r_copy_char(Node *dest, const Node *source, TypeHandle graph_type, - const qpCharacter *from, ArcMap &arc_map); + typedef pmap NodeMap; + + virtual void r_copy_children(const PandaNode *from, InstanceMap &inst_map); + void r_copy_char(PandaNode *dest, const PandaNode *source, + const qpCharacter *from, NodeMap &node_map); PT(Geom) copy_geom(Geom *source, const qpCharacter *from); - void copy_arc_pointers(const qpCharacter *from, const ArcMap &arc_map); - */ + void copy_node_pointers(const qpCharacter *from, const NodeMap &node_map); // These are the actual dynamic vertex pools for this qpCharacter's // ComputedVertices--the vertices that it will recompute each frame diff --git a/panda/src/egg2pg/qpcharacterMaker.cxx b/panda/src/egg2pg/qpcharacterMaker.cxx index be050c113d..46300dc1a3 100644 --- a/panda/src/egg2pg/qpcharacterMaker.cxx +++ b/panda/src/egg2pg/qpcharacterMaker.cxx @@ -217,7 +217,7 @@ parent_joint_nodes(PartGroup *part) { PandaNode *joint_node = joint->_qpgeom_node; if (joint_node != NULL) { _character_node->add_child(joint_node); - // joint->add_net_transform(joint_node); + joint->add_net_transform(joint_node); joint_node->set_transform(TransformState::make_mat(joint->_net_transform)); } } diff --git a/panda/src/putil/bam.h b/panda/src/putil/bam.h index 6ffb42913c..d7b1712d9b 100644 --- a/panda/src/putil/bam.h +++ b/panda/src/putil/bam.h @@ -32,7 +32,7 @@ static const unsigned short _bam_major_ver = 3; // Bumped to major version 2 on 7/6/00 due to major changes in Character. // Bumped to major version 3 on 12/8/00 to change float64's to float32's. -static const unsigned short _bam_minor_ver = 6; +static const unsigned short _bam_minor_ver = 7; // Bumped to minor version 1 on 12/15/00 to add FFT-style channel // compression. // Bumped to minor version 2 on 2/15/01 to add ModelNode::_preserve_transform. @@ -40,6 +40,7 @@ static const unsigned short _bam_minor_ver = 6; // Bumped to minor version 4 on 12/11/01 to transpose quaternions. // Bumped to minor version 5 on 12/13/01 to remove obsolete fields from Texture. // Bumped to minor version 6 on 5/16/02 to add ImageBuffer::_filename. +// Bumped to minor version 7 on 5/19/02 to add CharacterJoint::_net_transform_nodes, etc. #endif