further enhancements from Erik Pojar

This commit is contained in:
David Rose 2008-10-21 18:31:45 +00:00
parent 3a2959d09d
commit c5daffceaf
2 changed files with 54 additions and 17 deletions

View File

@ -28,6 +28,10 @@
#include "switchNode.h" #include "switchNode.h"
#include "sequenceNode.h" #include "sequenceNode.h"
#include "collisionNode.h" #include "collisionNode.h"
#include "collisionPolygon.h"
#include "collisionPlane.h"
#include "collisionSphere.h"
#include "collisionInvSphere.h"
#include "geomNode.h" #include "geomNode.h"
#include "geom.h" #include "geom.h"
#include "geomTriangles.h" #include "geomTriangles.h"
@ -271,7 +275,17 @@ convert_switch_node(SwitchNode *node, const WorkingNodePath &node_path,
// turn it into a switch.. // turn it into a switch..
egg_group->set_switch_flag(true); egg_group->set_switch_flag(true);
recurse_nodes(node_path, egg_group, has_decal); 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());
}
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -287,25 +301,47 @@ convert_collision_node(CollisionNode *node, const WorkingNodePath &node_path,
// the appropriate switch attributes to turn it into a sequence // the appropriate switch attributes to turn it into a sequence
EggGroup *egg_group = new EggGroup(node->get_name()); EggGroup *egg_group = new EggGroup(node->get_name());
egg_parent->add_child(egg_group); egg_parent->add_child(egg_group);
apply_node_properties(egg_group, node); apply_node_properties(egg_group, node, false);
// turn it into a collision node // turn it into a collision node
egg_group->set_cs_type(EggGroup::CST_polyset); egg_group->set_cs_type(EggGroup::CST_polyset);
egg_group->set_collide_flags(EggGroup::CF_descend); egg_group->set_collide_flags(EggGroup::CF_descend);
/*
int num_solids = node->get_num_solids(); int num_solids = node->get_num_solids();
if (num_solids > 0) {
// create vertex pool for collisions
EggVertexPool *cvpool = new EggVertexPool("vpool-collision");
egg_group->add_child(cvpool);
// traverse solids // traverse solids
for (int i = 0; i < num_solids; i++) { for (int i = 0; i < num_solids; i++) {
PandaNode *child = node->get_solid(i); CPT(CollisionSolid) child = node->get_solid(i);
if (child->is_of_type(CollisionPolygon::get_class_type())) {
EggPolygon *egg_poly = new EggPolygon;
egg_group->add_child(egg_poly);
// Convert just this one node to an EggGroup. CPT(CollisionPolygon) poly = DCAST(CollisionPolygon, child);
PT(EggGroup) next_group = new EggGroup; int num_points = poly->get_num_points();
convert_node(WorkingNodePath(node_path, child), next_group, has_decal); for (int j = 0; j < num_points; j++) {
EggVertex egg_vert;
egg_vert.set_pos(LCAST(double, poly->get_point(j)));
egg_vert.set_normal(LCAST(double, poly->get_normal()));
egg_group->add_child(next_group.p()); EggVertex *new_egg_vert = cvpool->create_unique_vertex(egg_vert);
}*/ egg_poly->add_vertex(new_egg_vert);
}
} else if (child->is_of_type(CollisionPlane::get_class_type())) {
nout << "Encountered unhandled collsion type: CollisionPlane" << "\n";
} else if (child->is_of_type(CollisionSphere::get_class_type())) {
nout << "Encountered unhandled collsion type: CollisionSphere" << "\n";
} else if (child->is_of_type(CollisionInvSphere::get_class_type())) {
nout << "Encountered unhandled collsion type: CollisionInvSphere" << "\n";
} else {
nout << "Encountered unknown CollisionSolid" << "\n";
}
}
}
// recurse over children - hm. do I need to do this? // recurse over children - hm. do I need to do this?
recurse_nodes(node_path, egg_group, has_decal); recurse_nodes(node_path, egg_group, has_decal);
@ -504,12 +540,13 @@ recurse_nodes(const WorkingNodePath &node_path, EggGroupNode *egg_parent,
// were applied, false otherwise. // were applied, false otherwise.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
bool BamToEgg:: bool BamToEgg::
apply_node_properties(EggGroup *egg_group, PandaNode *node) { apply_node_properties(EggGroup *egg_group, PandaNode *node, bool allow_backstage) {
bool any_applied = false; bool any_applied = false;
if (node->is_overall_hidden()) { if (node->is_overall_hidden() && allow_backstage) {
// This node is hidden. We'll go ahead and convert it, but we'll // This node is hidden. We'll go ahead and convert it, but we'll
// put in the "backstage" flag to mean it's not real geometry. // put in the "backstage" flag to mean it's not real geometry.
// unless the caller wants to keep it (by setting allow_backstage to false)
egg_group->add_object_type("backstage"); egg_group->add_object_type("backstage");
} }

View File

@ -71,7 +71,7 @@ private:
void recurse_nodes(const WorkingNodePath &node_path, EggGroupNode *egg_parent, void recurse_nodes(const WorkingNodePath &node_path, EggGroupNode *egg_parent,
bool has_decal); bool has_decal);
bool apply_node_properties(EggGroup *egg_group, PandaNode *node); bool apply_node_properties(EggGroup *egg_group, PandaNode *node, bool allow_backstage = true);
EggTexture *get_egg_texture(Texture *tex); EggTexture *get_egg_texture(Texture *tex);