Browse Source

remove backstage object before palettizing

David Rose 23 years ago
parent
commit
7125ac9121

+ 46 - 8
pandatool/src/egg-palettize/eggFile.cxx

@@ -25,14 +25,15 @@
 #include "palettizer.h"
 #include "palettizer.h"
 #include "filenameUnifier.h"
 #include "filenameUnifier.h"
 
 
-#include <eggData.h>
-#include <eggTextureCollection.h>
-#include <datagram.h>
-#include <datagramIterator.h>
-#include <bamReader.h>
-#include <bamWriter.h>
-#include <executionEnvironment.h>
-#include <dSearchPath.h>
+#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;
 TypeHandle EggFile::_type_handle;
 
 
@@ -449,6 +450,8 @@ read_egg() {
   }
   }
 
 
   _data = data;
   _data = data;
+  remove_backstage(_data);
+
   return true;
   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
 //     Function: EggFile::register_with_read_factory
 //       Access: Public, Static
 //       Access: Public, Static

+ 3 - 0
pandatool/src/egg-palettize/eggFile.h

@@ -79,6 +79,9 @@ public:
   void write_description(ostream &out, int indent_level = 0) const;
   void write_description(ostream &out, int indent_level = 0) const;
   void write_texture_refs(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:
 private:
   EggData *_data;
   EggData *_data;
   Filename _current_directory;
   Filename _current_directory;

+ 0 - 14
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())) {
   if (group->is_of_type(EggGroup::get_class_type())) {
     EggGroup *egg_group;
     EggGroup *egg_group;
     DCAST_INTO_V(egg_group, 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 <Group> node with the "backstage" flag set,
-        // ignore it and everything under it.
-        return;
-      }
-    }
 
 
     if (egg_group->get_dart_type() != EggGroup::DT_none) {
     if (egg_group->get_dart_type() != EggGroup::DT_none) {
       // If it's a character, we might change the kind of remapping we
       // 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())) {
   if (group->is_of_type(EggGroup::get_class_type())) {
     EggGroup *egg_group;
     EggGroup *egg_group;
     DCAST_INTO_V(egg_group, 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 <Group> node with the "backstage" flag set,
-        // ignore it and everything under it.
-        return;
-      }
-    }
 
 
     if (egg_group->get_dart_type() != EggGroup::DT_none) {
     if (egg_group->get_dart_type() != EggGroup::DT_none) {
       // If it's a character, we might change the kind of remapping we
       // If it's a character, we might change the kind of remapping we