From 41733f5decda6554b4619e7621e0c4e9de6626fb Mon Sep 17 00:00:00 2001 From: David Rose Date: Fri, 25 Mar 2005 22:45:38 +0000 Subject: [PATCH] better GeomNode management --- panda/src/egg2pg/characterMaker.cxx | 40 ++++++++++++++++++++++------- panda/src/egg2pg/characterMaker.h | 4 ++- 2 files changed, 34 insertions(+), 10 deletions(-) diff --git a/panda/src/egg2pg/characterMaker.cxx b/panda/src/egg2pg/characterMaker.cxx index dd116b3e9d..970e05513b 100644 --- a/panda/src/egg2pg/characterMaker.cxx +++ b/panda/src/egg2pg/characterMaker.cxx @@ -29,6 +29,7 @@ #include "characterJointBundle.h" #include "characterSlider.h" #include "character.h" +#include "geomNode.h" #include "transformState.h" #include "eggSurface.h" #include "eggCurve.h" @@ -151,14 +152,38 @@ egg_to_index(EggNode *egg_node) const { //////////////////////////////////////////////////////////////////// PandaNode *CharacterMaker:: part_to_node(PartGroup *part) const { + PandaNode *node = _character_node; + if (part->is_of_type(CharacterJoint::get_class_type())) { CharacterJoint *joint = DCAST(CharacterJoint, part); if (joint->_geom_node != (PandaNode *)NULL) { - return joint->_geom_node; + node = joint->_geom_node; } } - return _character_node; + if (use_qpgeom) { + // We should always return a GeomNode, so that all polysets + // created at the same level will get added into the same + // GeomNode. Look for a child of this node. If it doesn't have a + // child yet, add a GeomNode and it. Otherwise, if it already has + // a child, return that. + if (node->is_geom_node()) { + return node; + } + for (int i = 0; i < node->get_num_children(); i++) { + PandaNode *child = node->get_child(i); + if (child->is_geom_node()) { + return child; + } + } + PT(GeomNode) geom_node = new GeomNode(""); + node->add_child(geom_node); + return geom_node; + + } else { + // In the original Geom implementation, a node is a node. + return node; + } } @@ -628,19 +653,16 @@ determine_bin_home(EggBin *egg_bin) { egg_group->get_dcs_type() == EggGroup::DC_none) { // If we have rigid geometry that is assigned to a joint without a // flag, which means the joint didn't get created as its own - // node, go ahead and make an implicit flag for the joint. - + // node, go ahead and make an implicit node for the joint. + // The alternative is to return NULL to treat the geometry as // dynamic (and animate it by animating its vertices), but display // lists and vertex buffers will perform better if as much // geometry as possible is rigid. - - egg_group->set_dcs_type(EggGroup::DC_default); - PT(ModelNode) geom_node = new ModelNode(egg_group->get_name()); - geom_node->set_preserve_transform(ModelNode::PT_local); - CharacterJoint *joint; DCAST_INTO_R(joint, egg_to_part(egg_group), home); + egg_group->set_dcs_type(EggGroup::DC_default); + PT(GeomNode) geom_node = new GeomNode(egg_group->get_name()); joint->_geom_node = geom_node.p(); } diff --git a/panda/src/egg2pg/characterMaker.h b/panda/src/egg2pg/characterMaker.h index 296dc5cb28..e7d74c41c4 100644 --- a/panda/src/egg2pg/characterMaker.h +++ b/panda/src/egg2pg/characterMaker.h @@ -23,6 +23,7 @@ #include "computedVerticesMaker.h" #include "vertexTransform.h" +#include "character.h" #include "vector_PartGroupStar.h" #include "typedef.h" #include "pmap.h" @@ -35,6 +36,7 @@ class EggBin; class PartGroup; class CharacterJointBundle; class Character; +class GeomNode; class CharacterSlider; class MovingPartBase; class EggLoader; @@ -88,7 +90,7 @@ private: EggLoader &_loader; EggGroup *_egg_root; - Character *_character_node; + PT(Character) _character_node; CharacterJointBundle *_bundle; ComputedVerticesMaker _comp_verts_maker; PartGroup *_morph_root;