Panda3D
eggUtilities.cxx
1 // Filename: eggUtilities.cxx
2 // Created by: drose (28Jan99)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #include "eggUtilities.h"
16 #include "eggPrimitive.h"
17 #include "eggGroupNode.h"
18 #include "pt_EggTexture.h"
19 #include "dcast.h"
20 
21 
22 ////////////////////////////////////////////////////////////////////
23 // Function: get_textures_by_filename
24 // Description: Extracts from the egg subgraph beginning at the
25 // indicated node a set of all the texture objects
26 // referenced, grouped together by filename. Texture
27 // objects that share a common filename (but possibly
28 // differ in other properties) are returned together in
29 // the same element of the map.
30 ////////////////////////////////////////////////////////////////////
31 void
32 get_textures_by_filename(const EggNode *node, EggTextureFilenames &result) {
33  if (node->is_of_type(EggPrimitive::get_class_type())) {
34  const EggPrimitive *prim = DCAST(EggPrimitive, node);
35 
36  int num_textures = prim->get_num_textures();
37  for (int i = 0; i < num_textures; i++) {
38  PT_EggTexture tex = prim->get_texture(i);
39  result[tex->get_filename()].insert(tex);
40  }
41 
42  } else if (node->is_of_type(EggGroupNode::get_class_type())) {
43  const EggGroupNode *group = DCAST(EggGroupNode, node);
44 
45  EggGroupNode::const_iterator ci;
46  for (ci = group->begin(); ci != group->end(); ++ci) {
47  get_textures_by_filename(*ci, result);
48  }
49  }
50 }
51 
A base class for any of a number of kinds of geometry primitives: polygons, point lights...
Definition: eggPrimitive.h:51
This is our own Panda specialization on the default STL map.
Definition: pmap.h:52
int get_num_textures() const
Returns the number of textures applied to the primitive.
Definition: eggPrimitive.I:218
A base class for nodes in the hierarchy that are not leaf nodes.
Definition: eggGroupNode.h:51
EggTexture * get_texture() const
Returns the first texture on the primitive, if any, or NULL if there are no textures on the primitive...
Definition: eggPrimitive.I:182
A base class for things that may be directly added into the egg hierarchy.
Definition: eggNode.h:38
bool is_of_type(TypeHandle handle) const
Returns true if the current object is or derives from the indicated type.
Definition: typedObject.I:63