From 7125ac91211162e1acf8e1f6380f738b603be555 Mon Sep 17 00:00:00 2001 From: David Rose Date: Fri, 11 Apr 2003 21:19:25 +0000 Subject: [PATCH] remove backstage object before palettizing --- pandatool/src/egg-palettize/eggFile.cxx | 54 ++++++++++++++++--- pandatool/src/egg-palettize/eggFile.h | 3 ++ .../src/egg-palettize/textureReference.cxx | 14 ----- 3 files changed, 49 insertions(+), 22 deletions(-) diff --git a/pandatool/src/egg-palettize/eggFile.cxx b/pandatool/src/egg-palettize/eggFile.cxx index b47b2ad5bc..f60bd17d4c 100644 --- a/pandatool/src/egg-palettize/eggFile.cxx +++ b/pandatool/src/egg-palettize/eggFile.cxx @@ -25,14 +25,15 @@ #include "palettizer.h" #include "filenameUnifier.h" -#include -#include -#include -#include -#include -#include -#include -#include +#include "eggData.h" +#include "eggGroup.h" +#include "eggTextureCollection.h" +#include "datagram.h" +#include "datagramIterator.h" +#include "bamReader.h" +#include "bamWriter.h" +#include "executionEnvironment.h" +#include "dSearchPath.h" TypeHandle EggFile::_type_handle; @@ -449,6 +450,8 @@ read_egg() { } _data = data; + remove_backstage(_data); + return true; } @@ -515,6 +518,41 @@ write_texture_refs(ostream &out, int indent_level) const { } } +//////////////////////////////////////////////////////////////////// +// Function: EggFile::remove_backstage +// Access: Private +// Description: Recursively walks the egg hierarchy and removes any +// "backstage" nodes found from the scene graph +// completely. These aren't part of the egg scene +// anyway, and removing them early helps reduce +// confusion. +//////////////////////////////////////////////////////////////////// +void EggFile:: +remove_backstage(EggGroupNode *node) { + EggGroupNode::iterator ci; + ci = node->begin(); + while (ci != node->end()) { + EggNode *child = (*ci); + bool remove_child = false; + + if (child->is_of_type(EggGroup::get_class_type())) { + EggGroup *egg_group; + DCAST_INTO_V(egg_group, child); + remove_child = egg_group->has_object_type("backstage"); + } + + if (remove_child) { + ci = node->erase(ci); + } else { + if (child->is_of_type(EggGroupNode::get_class_type())) { + // Recurse on children. + remove_backstage(DCAST(EggGroupNode, child)); + } + ++ci; + } + } +} + //////////////////////////////////////////////////////////////////// // Function: EggFile::register_with_read_factory // Access: Public, Static diff --git a/pandatool/src/egg-palettize/eggFile.h b/pandatool/src/egg-palettize/eggFile.h index 205d27f09c..d7b1629cab 100644 --- a/pandatool/src/egg-palettize/eggFile.h +++ b/pandatool/src/egg-palettize/eggFile.h @@ -79,6 +79,9 @@ public: void write_description(ostream &out, int indent_level = 0) const; void write_texture_refs(ostream &out, int indent_level = 0) const; +private: + void remove_backstage(EggGroupNode *node); + private: EggData *_data; Filename _current_directory; diff --git a/pandatool/src/egg-palettize/textureReference.cxx b/pandatool/src/egg-palettize/textureReference.cxx index 2d030d6326..5b068f3daa 100644 --- a/pandatool/src/egg-palettize/textureReference.cxx +++ b/pandatool/src/egg-palettize/textureReference.cxx @@ -445,13 +445,6 @@ get_uv_range(EggGroupNode *group, Palettizer::RemapUV remap) { if (group->is_of_type(EggGroup::get_class_type())) { EggGroup *egg_group; DCAST_INTO_V(egg_group, group); - for (int i = 0; i < egg_group->get_num_object_types(); i++) { - if (cmp_nocase_uh(egg_group->get_object_type(i), "backstage") == 0) { - // If we reach a node with the "backstage" flag set, - // ignore it and everything under it. - return; - } - } if (egg_group->get_dart_type() != EggGroup::DT_none) { // If it's a character, we might change the kind of remapping we @@ -541,13 +534,6 @@ update_uv_range(EggGroupNode *group, Palettizer::RemapUV remap) { if (group->is_of_type(EggGroup::get_class_type())) { EggGroup *egg_group; DCAST_INTO_V(egg_group, group); - for (int i = 0; i < egg_group->get_num_object_types(); i++) { - if (cmp_nocase_uh(egg_group->get_object_type(i), "backstage") == 0) { - // If we reach a node with the "backstage" flag set, - // ignore it and everything under it. - return; - } - } if (egg_group->get_dart_type() != EggGroup::DT_none) { // If it's a character, we might change the kind of remapping we