Panda3D
 All Classes Functions Variables Enumerations
eggUtilities.cxx
00001 // Filename: eggUtilities.cxx
00002 // Created by:  drose (28Jan99)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #include "eggUtilities.h"
00016 #include "eggPrimitive.h"
00017 #include "eggGroupNode.h"
00018 #include "pt_EggTexture.h"
00019 #include "dcast.h"
00020 
00021 
00022 ////////////////////////////////////////////////////////////////////
00023 //     Function: get_textures_by_filename
00024 //  Description: Extracts from the egg subgraph beginning at the
00025 //               indicated node a set of all the texture objects
00026 //               referenced, grouped together by filename.  Texture
00027 //               objects that share a common filename (but possibly
00028 //               differ in other properties) are returned together in
00029 //               the same element of the map.
00030 ////////////////////////////////////////////////////////////////////
00031 void
00032 get_textures_by_filename(const EggNode *node, EggTextureFilenames &result) {
00033   if (node->is_of_type(EggPrimitive::get_class_type())) {
00034     const EggPrimitive *prim = DCAST(EggPrimitive, node);
00035 
00036     int num_textures = prim->get_num_textures();
00037     for (int i = 0; i < num_textures; i++) {
00038       PT_EggTexture tex = prim->get_texture(i);
00039       result[tex->get_filename()].insert(tex);
00040     }
00041 
00042   } else if (node->is_of_type(EggGroupNode::get_class_type())) {
00043     const EggGroupNode *group = DCAST(EggGroupNode, node);
00044 
00045     EggGroupNode::const_iterator ci;
00046     for (ci = group->begin(); ci != group->end(); ++ci) {
00047       get_textures_by_filename(*ci, result);
00048     }
00049   }
00050 }
00051 
 All Classes Functions Variables Enumerations