From 54c51cba47ac6c5ac5bbeef5779cd33f07bfbf55 Mon Sep 17 00:00:00 2001 From: David Rose Date: Mon, 20 Oct 2008 23:31:19 +0000 Subject: [PATCH] enhancements from Erik Pojar --- pandatool/src/bam/bamToEgg.cxx | 103 +++++++++++++++++++++++++++++++++ pandatool/src/bam/bamToEgg.h | 9 +++ 2 files changed, 112 insertions(+) diff --git a/pandatool/src/bam/bamToEgg.cxx b/pandatool/src/bam/bamToEgg.cxx index 469c8b4090..e3943b5487 100644 --- a/pandatool/src/bam/bamToEgg.cxx +++ b/pandatool/src/bam/bamToEgg.cxx @@ -25,6 +25,9 @@ #include "textureAttrib.h" #include "cullFaceAttrib.h" #include "lodNode.h" +#include "switchNode.h" +#include "sequenceNode.h" +#include "collisionNode.h" #include "geomNode.h" #include "geom.h" #include "geomTriangles.h" @@ -150,6 +153,15 @@ convert_node(const WorkingNodePath &node_path, EggGroupNode *egg_parent, } else if (node->is_of_type(LODNode::get_class_type())) { convert_lod_node(DCAST(LODNode, node), node_path, egg_parent, has_decal); + } else if (node->is_of_type(SequenceNode::get_class_type())) { + convert_sequence_node(DCAST(SequenceNode, node), node_path, egg_parent, has_decal); + + } else if (node->is_of_type(SwitchNode::get_class_type())) { + convert_switch_node(DCAST(SwitchNode, node), node_path, egg_parent, has_decal); + + } else if (node->is_of_type(CollisionNode::get_class_type())) { + convert_collision_node(DCAST(CollisionNode, node), node_path, egg_parent, has_decal); + } else { // Just a generic node. EggGroup *egg_group = new EggGroup(node->get_name()); @@ -208,6 +220,97 @@ convert_lod_node(LODNode *node, const WorkingNodePath &node_path, } } +//////////////////////////////////////////////////////////////////// +// Function: BamToEgg::convert_sequence_node +// Access: Private +// Description: Converts the indicated SequenceNode to the corresponding +// Egg constructs. +//////////////////////////////////////////////////////////////////// +void BamToEgg:: +convert_sequence_node(SequenceNode *node, const WorkingNodePath &node_path, + EggGroupNode *egg_parent, bool has_decal) { + // A sequence node gets converted to an ordinary EggGroup, we only apply + // the appropriate switch attributes to turn it into a sequence + EggGroup *egg_group = new EggGroup(node->get_name()); + egg_parent->add_child(egg_group); + apply_node_properties(egg_group, node); + + // turn it into a sequence with the right frame-rate + egg_group->set_switch_flag(true); + egg_group->set_switch_fps(node->get_frame_rate()); + + int num_children = node->get_num_children(); + + for (int i = 0; i < num_children; i++) { + PandaNode *child = node->get_child(i); + + // Convert just this one node to an EggGroup. + PT(EggGroup) next_group = new EggGroup; + convert_node(WorkingNodePath(node_path, child), next_group, has_decal); + + egg_group->add_child(next_group.p()); + } + +} + +//////////////////////////////////////////////////////////////////// +// Function: BamToEgg::convert_switch_node +// Access: Private +// Description: Converts the indicated SwitchNode to the corresponding +// Egg constructs. +//////////////////////////////////////////////////////////////////// +void BamToEgg:: +convert_switch_node(SwitchNode *node, const WorkingNodePath &node_path, + EggGroupNode *egg_parent, bool has_decal) { + // A sequence node gets converted to an ordinary EggGroup, we only apply + // the appropriate switch attributes to turn it into a sequence + EggGroup *egg_group = new EggGroup(node->get_name()); + egg_parent->add_child(egg_group); + apply_node_properties(egg_group, node); + + // turn it into a switch.. + egg_group->set_switch_flag(true); + + recurse_nodes(node_path, egg_group, has_decal); +} + +//////////////////////////////////////////////////////////////////// +// Function: BamToEgg::convert_collision_node +// Access: Private +// Description: Converts the indicated CollisionNode to the corresponding +// Egg constructs. +//////////////////////////////////////////////////////////////////// +void BamToEgg:: +convert_collision_node(CollisionNode *node, const WorkingNodePath &node_path, + EggGroupNode *egg_parent, bool has_decal) { + // A sequence node gets converted to an ordinary EggGroup, we only apply + // the appropriate switch attributes to turn it into a sequence + EggGroup *egg_group = new EggGroup(node->get_name()); + egg_parent->add_child(egg_group); + apply_node_properties(egg_group, node); + + // turn it into a collision node + egg_group->set_cs_type(EggGroup::CST_polyset); + egg_group->set_collide_flags(EggGroup::CF_descend); + + /* + int num_solids = node->get_num_solids(); + + // traverse solids + for (int i = 0; i < num_solids; i++) { + PandaNode *child = node->get_solid(i); + + // Convert just this one node to an EggGroup. + PT(EggGroup) next_group = new EggGroup; + convert_node(WorkingNodePath(node_path, child), next_group, has_decal); + + egg_group->add_child(next_group.p()); + }*/ + + // recurse over children - hm. do I need to do this? + recurse_nodes(node_path, egg_group, has_decal); +} + //////////////////////////////////////////////////////////////////// // Function: BamToEgg::convert_geom_node // Access: Private diff --git a/pandatool/src/bam/bamToEgg.h b/pandatool/src/bam/bamToEgg.h index a925ed8b33..378f1409bc 100644 --- a/pandatool/src/bam/bamToEgg.h +++ b/pandatool/src/bam/bamToEgg.h @@ -28,6 +28,9 @@ class EggGroupNode; class EggVertexPool; class EggTexture; class LODNode; +class SequenceNode; +class SwitchNode; +class CollisionNode; class GeomNode; class GeomTri; class GeomVertexData; @@ -53,6 +56,12 @@ private: bool has_decal); void convert_lod_node(LODNode *node, const WorkingNodePath &node_path, EggGroupNode *egg_parent, bool has_decal); + void convert_sequence_node(SequenceNode *node, const WorkingNodePath &node_path, + EggGroupNode *egg_parent, bool has_decal); + void convert_switch_node(SwitchNode *node, const WorkingNodePath &node_path, + EggGroupNode *egg_parent, bool has_decal); + void convert_collision_node(CollisionNode *node, const WorkingNodePath &node_path, + EggGroupNode *egg_parent, bool has_decal); void convert_geom_node(GeomNode *node, const WorkingNodePath &node_path, EggGroupNode *egg_parent, bool has_decal); void convert_triangles(const GeomVertexData *vertex_data,