Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

panda/src/egg/eggGroupNode.h

Go to the documentation of this file.
00001 // Filename: eggGroupNode.h
00002 // Created by:  drose (16Jan99)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
00008 //
00009 // All use of this software is subject to the terms of the Panda 3d
00010 // Software license.  You should have received a copy of this license
00011 // along with this source code; you will also find a current copy of
00012 // the license at http://www.panda3d.org/license.txt .
00013 //
00014 // To contact the maintainers of this program write to
00015 // panda3d@yahoogroups.com .
00016 //
00017 ////////////////////////////////////////////////////////////////////
00018 
00019 #ifndef EGGGROUPNODE_H
00020 #define EGGGROUPNODE_H
00021 
00022 #include "pandabase.h"
00023 
00024 #include "eggNode.h"
00025 
00026 #include "coordinateSystem.h"
00027 #include "typedObject.h"
00028 #include "pointerTo.h"
00029 #include "luse.h"
00030 
00031 #include "plist.h"
00032 
00033 class EggTextureCollection;
00034 class EggMaterialCollection;
00035 class EggPolygon;
00036 class EggVertex;
00037 class DSearchPath;
00038 
00039 ////////////////////////////////////////////////////////////////////
00040 //       Class : EggGroupNode
00041 // Description : A base class for nodes in the hierarchy that are not
00042 //               leaf nodes.  (See also EggGroup, which is
00043 //               specifically the "<Group>" node in egg.)
00044 //
00045 //               An EggGroupNode is an STL-style container of pointers
00046 //               to EggNodes, like a vector.  Functions
00047 //               push_back()/pop_back() and insert()/erase() are
00048 //               provided to manipulate the list.  The list may also
00049 //               be operated on (read-only) via iterators and
00050 //               begin()/end().
00051 ////////////////////////////////////////////////////////////////////
00052 class EXPCL_PANDAEGG EggGroupNode : public EggNode {
00053 
00054   // This is a bit of private interface stuff that must be here as a
00055   // forward reference.  This allows us to define the EggGroupNode as
00056   // an STL container.
00057 
00058 private:
00059   // We define the list of children as a list and not a vector, so we
00060   // can avoid the bad iterator-invalidating properties of vectors as
00061   // we insert/delete elements.
00062   typedef plist< PT(EggNode) > Children;
00063 
00064   // Here begins the actual public interface to EggGroupNode.
00065 
00066 public:
00067   EggGroupNode(const string &name = "") : EggNode(name) { }
00068   EggGroupNode(const EggGroupNode &copy);
00069   EggGroupNode &operator = (const EggGroupNode &copy);
00070   virtual ~EggGroupNode();
00071 
00072   virtual void write(ostream &out, int indent_level) const;
00073 
00074   // The EggGroupNode itself appears to be an STL container of
00075   // pointers to EggNodes.  The set of children is read-only, however,
00076   // except through the limited add_child/remove_child or insert/erase
00077   // interface.  The following implements this.
00078 
00079 #ifdef WIN32_VC
00080   typedef const PT(EggNode) *pointer;
00081   typedef const PT(EggNode) *const_pointer;
00082 #else
00083   typedef Children::const_pointer pointer;
00084   typedef Children::const_pointer const_pointer;
00085 #endif
00086   typedef Children::const_reference reference;
00087   typedef Children::const_reference const_reference;
00088   typedef Children::const_iterator iterator;
00089   typedef Children::const_iterator const_iterator;
00090   typedef Children::const_reverse_iterator reverse_iterator;
00091   typedef Children::const_reverse_iterator const_reverse_iterator;
00092   typedef Children::size_type size_type;
00093   typedef Children::difference_type difference_type;
00094 
00095   iterator begin() const;
00096   iterator end() const;
00097   reverse_iterator rbegin() const;
00098   reverse_iterator rend() const;
00099   bool empty() const;
00100   size_type size() const;
00101 
00102   iterator insert(iterator position, PT(EggNode) x);
00103   iterator erase(iterator position);
00104   iterator erase(iterator first, iterator last);
00105   void replace(iterator position, PT(EggNode) x);
00106   void clear();
00107 
00108   PT(EggNode) add_child(PT(EggNode) node);
00109   PT(EggNode) remove_child(PT(EggNode) node);
00110   void steal_children(EggGroupNode &other);
00111 
00112   void resolve_filenames(const DSearchPath &searchpath);
00113   void reverse_vertex_ordering();
00114 
00115   void recompute_vertex_normals(double threshold, CoordinateSystem cs = CS_default);
00116   void recompute_polygon_normals(CoordinateSystem cs = CS_default);
00117   void strip_normals();
00118 
00119   int triangulate_polygons(bool convex_also);
00120 
00121   int remove_unused_vertices();
00122   int remove_invalid_primitives();
00123 
00124 protected:
00125   virtual void update_under(int depth_offset);
00126 
00127   virtual void r_transform(const LMatrix4d &mat, const LMatrix4d &inv,
00128                            CoordinateSystem to_cs);
00129   virtual void r_transform_vertices(const LMatrix4d &mat);
00130   virtual void r_mark_coordsys(CoordinateSystem cs);
00131   virtual void r_flatten_transforms();
00132   virtual void r_apply_texmats(EggTextureCollection &textures);
00133 
00134 
00135   CoordinateSystem find_coordsys_entry();
00136   int find_textures(EggTextureCollection *collection);
00137   int find_materials(EggMaterialCollection *collection);
00138   bool r_load_externals(const DSearchPath &searchpath, 
00139                         CoordinateSystem coordsys);
00140 
00141 private:
00142   Children _children;
00143 
00144   // Don't try to use these private functions.  User code should add
00145   // and remove children via add_child()/remove_child(), or via the
00146   // STL-like push_back()/pop_back() or insert()/erase(), above.
00147   void prepare_add_child(EggNode *node);
00148   void prepare_remove_child(EggNode *node);
00149 
00150   // This bit is in support of recompute_vertex_normals().
00151   class NVertexReference {
00152   public:
00153     EggPolygon *_polygon;
00154     Normald _normal;
00155     size_t _vertex;
00156   };
00157   typedef pvector<NVertexReference> NVertexGroup;
00158   typedef pmap<Vertexd, NVertexGroup> NVertexCollection;
00159 
00160   void r_collect_vertex_normals(NVertexCollection &collection,
00161                                 double threshold, CoordinateSystem cs);
00162   void do_compute_vertex_normals(const NVertexGroup &group);
00163 
00164 public:
00165   static TypeHandle get_class_type() {
00166     return _type_handle;
00167   }
00168   static void init_type() {
00169     EggNode::init_type();
00170     register_type(_type_handle, "EggGroupNode",
00171                   EggNode::get_class_type());
00172   }
00173   virtual TypeHandle get_type() const {
00174     return get_class_type();
00175   }
00176   virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00177 
00178 private:
00179   static TypeHandle _type_handle;
00180 
00181   friend class EggTextureCollection;
00182   friend class EggMaterialCollection;
00183 };
00184 
00185 #include "eggGroupNode.I"
00186 
00187 #endif
00188 

Generated on Fri May 2 00:37:39 2003 for Panda by doxygen1.3