Panda3D
 All Classes Functions Variables Enumerations
eggGroupNode.h
1 // Filename: eggGroupNode.h
2 // Created by: drose (16Jan99)
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 #ifndef EGGGROUPNODE_H
16 #define EGGGROUPNODE_H
17 
18 #include "pandabase.h"
19 
20 #include "eggNode.h"
21 #include "eggVertexPool.h"
22 
23 #include "coordinateSystem.h"
24 #include "typedObject.h"
25 #include "pointerTo.h"
26 #include "luse.h"
27 #include "globPattern.h"
28 #include "plist.h"
29 
32 class EggPolygon;
33 class EggVertex;
34 class EggVertexPool;
35 class DSearchPath;
36 class BamCacheRecord;
37 
38 ////////////////////////////////////////////////////////////////////
39 // Class : EggGroupNode
40 // Description : A base class for nodes in the hierarchy that are not
41 // leaf nodes. (See also EggGroup, which is
42 // specifically the "<Group>" node in egg.)
43 //
44 // An EggGroupNode is an STL-style container of pointers
45 // to EggNodes, like a vector. Functions
46 // push_back()/pop_back() and insert()/erase() are
47 // provided to manipulate the list. The list may also
48 // be operated on (read-only) via iterators and
49 // begin()/end().
50 ////////////////////////////////////////////////////////////////////
51 class EXPCL_PANDAEGG EggGroupNode : public EggNode {
52 
53  // This is a bit of private interface stuff that must be here as a
54  // forward reference. This allows us to define the EggGroupNode as
55  // an STL container.
56 
57 private:
58  // We define the list of children as a list and not a vector, so we
59  // can avoid the bad iterator-invalidating properties of vectors as
60  // we insert/delete elements.
62 
63  // Here begins the actual public interface to EggGroupNode.
64 
65 PUBLISHED:
66  EggGroupNode(const string &name = "") : EggNode(name) { }
67  EggGroupNode(const EggGroupNode &copy);
68  EggGroupNode &operator = (const EggGroupNode &copy);
69  virtual ~EggGroupNode();
70 
71  virtual void write(ostream &out, int indent_level) const;
72 
73  // The EggGroupNode itself appears to be an STL container of
74  // pointers to EggNodes. The set of children is read-only, however,
75  // except through the limited add_child/remove_child or insert/erase
76  // interface. The following implements this.
77 public:
78 #if defined(WIN32_VC) || defined(WIN64_VC)
79  typedef const PT(EggNode) *pointer;
80  typedef const PT(EggNode) *const_pointer;
81 #else
82  typedef Children::const_pointer pointer;
83  typedef Children::const_pointer const_pointer;
84 #endif
85  typedef Children::const_reference reference;
86  typedef Children::const_reference const_reference;
87  typedef Children::const_iterator iterator;
88  typedef Children::const_iterator const_iterator;
89  typedef Children::const_reverse_iterator reverse_iterator;
90  typedef Children::const_reverse_iterator const_reverse_iterator;
91  typedef Children::size_type size_type;
92  typedef Children::difference_type difference_type;
93 
94  iterator begin() const;
95  iterator end() const;
96  reverse_iterator rbegin() const;
97  reverse_iterator rend() const;
98 
99  iterator insert(iterator position, PT(EggNode) x);
100  iterator erase(iterator position);
101  iterator erase(iterator first, iterator last);
102  void replace(iterator position, PT(EggNode) x);
103 
104 PUBLISHED:
105  bool empty() const;
106  size_type size() const;
107  void clear();
108 
109  // This is an alternate way to traverse the list of children. It is
110  // mainly provided for scripting code, which can't use the iterators
111  // defined above (they don't export through interrogate very well).
112  // These are, of course, non-thread-safe.
113  EggNode *get_first_child();
114  EggNode *get_next_child();
115 
116  EXTENSION(PyObject *get_children() const);
117 
118  EggNode *add_child(EggNode *node);
119  PT(EggNode) remove_child(EggNode *node);
120  void steal_children(EggGroupNode &other);
121 
122  EggNode *find_child(const string &name) const;
123 
124  bool has_absolute_pathnames() const;
125  void resolve_filenames(const DSearchPath &searchpath);
126  void force_filenames(const Filename &directory);
127  void reverse_vertex_ordering();
128 
129  void recompute_vertex_normals(double threshold, CoordinateSystem cs = CS_default);
130  void recompute_polygon_normals(CoordinateSystem cs = CS_default);
131  void strip_normals();
132 
133  bool recompute_tangent_binormal(const GlobPattern &uv_name);
134  bool recompute_tangent_binormal(const vector_string &names);
135  bool recompute_tangent_binormal_auto();
136 
137  enum TriangulateFlags {
138  T_polygon = 0x001,
139  T_convex = 0x002,
140  T_composite = 0x004,
141  T_recurse = 0x008,
142  T_flat_shaded = 0x010,
143  };
144 
145  int triangulate_polygons(int flags);
146  void mesh_triangles(int flags);
147  void make_point_primitives();
148 
149  int rename_nodes(vector_string strip_prefix, bool recurse);
150 
151  int remove_unused_vertices(bool recurse);
152  int remove_invalid_primitives(bool recurse);
153  void clear_connected_shading();
154  void get_connected_shading();
155  void unify_attributes(bool use_connected_shading, bool allow_per_primitive,
156  bool recurse);
157  void apply_last_attribute(bool recurse);
158  void apply_first_attribute(bool recurse);
159  void post_apply_flat_attribute(bool recurse);
160  virtual bool has_primitives() const;
161  virtual bool joint_has_primitives() const;
162  virtual bool has_normals() const;
163 
164 public:
165  void rebuild_vertex_pools(EggVertexPools &vertex_pools,
166  unsigned int max_vertices,
167  bool recurse);
168 
169 protected:
170  virtual void update_under(int depth_offset);
171 
172  virtual void r_transform(const LMatrix4d &mat, const LMatrix4d &inv,
173  CoordinateSystem to_cs);
174  virtual void r_transform_vertices(const LMatrix4d &mat);
175  virtual void r_mark_coordsys(CoordinateSystem cs);
176  virtual void r_flatten_transforms();
177  virtual void r_apply_texmats(EggTextureCollection &textures);
178 
179 
180  CoordinateSystem find_coordsys_entry();
181  int find_textures(EggTextureCollection *collection);
182  int find_materials(EggMaterialCollection *collection);
183  bool r_load_externals(const DSearchPath &searchpath,
184  CoordinateSystem coordsys,
185  BamCacheRecord *record);
186 
187 PUBLISHED:
188  INLINE static bool is_right(const LVector2d &v1, const LVector2d &v2);
189 
190 private:
191  Children _children;
192  const_iterator _gnc_iterator;
193 
194  // Don't try to use these private functions. User code should add
195  // and remove children via add_child()/remove_child(), or via the
196  // STL-like push_back()/pop_back() or insert()/erase(), above.
197  void prepare_add_child(EggNode *node);
198  void prepare_remove_child(EggNode *node);
199 
200  // This bit is in support of recompute_vertex_normals().
201  class NVertexReference {
202  public:
203  EggPolygon *_polygon;
204  LNormald _normal;
205  size_t _vertex;
206  };
209 
210  void r_collect_vertex_normals(NVertexCollection &collection,
211  double threshold, CoordinateSystem cs);
212  void do_compute_vertex_normals(const NVertexGroup &group);
213 
214  // This bit is in support of recompute_tangent_binormal().
215  class TBNVertexReference {
216  public:
217  EggPolygon *_polygon;
218  size_t _vertex;
219  LVector3d _sdir;
220  LVector3d _tdir;
221  };
222  class TBNVertexValue {
223  public:
224  INLINE bool operator < (const TBNVertexValue &other) const;
225  LVertexd _pos;
226  LNormald _normal;
227  string _uv_name;
228  LTexCoordd _uv;
229  bool _facing;
230  };
233 
234  void r_collect_tangent_binormal(const GlobPattern &uv_name,
235  TBNVertexCollection &collection);
236  void do_compute_tangent_binormal(const TBNVertexValue &value,
237  const TBNVertexGroup &group);
238 
239 public:
240  static TypeHandle get_class_type() {
241  return _type_handle;
242  }
243  static void init_type() {
244  EggNode::init_type();
245  register_type(_type_handle, "EggGroupNode",
246  EggNode::get_class_type());
247  }
248  virtual TypeHandle get_type() const {
249  return get_class_type();
250  }
251  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
252 
253 private:
254  static TypeHandle _type_handle;
255 
256  friend class EggTextureCollection;
257  friend class EggMaterialCollection;
258 };
259 
260 #include "eggGroupNode.I"
261 
262 #endif
263 
This is our own Panda specialization on the default STL map.
Definition: pmap.h:52
This is a 4-by-4 transform matrix.
Definition: lmatrix.h:4716
This is a two-component vector offset.
Definition: lvector2.h:416
A base class for nodes in the hierarchy that are not leaf nodes.
Definition: eggGroupNode.h:51
This is a collection of materials by MRef name.
This is a two-component point in space.
Definition: lpoint2.h:411
This is a collection of textures by TRef name.
This is our own Panda specialization on the default STL vector.
Definition: pvector.h:39
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:44
An instance of this class is written to the front of a Bam or Txo file to make the file a cached inst...
Any one-, two-, three-, or four-component vertex, possibly with attributes such as a normal...
Definition: eggVertex.h:41
A single polygon.
Definition: eggPolygon.h:26
This is a three-component vector distance (as opposed to a three-component point, which represents a ...
Definition: lvector3.h:746
This is a three-component point in space (as opposed to a three-component vector, which represents a ...
Definition: lpoint3.h:531
A base class for things that may be directly added into the egg hierarchy.
Definition: eggNode.h:38
This class stores a list of directories that can be searched, in order, to locate a particular file...
Definition: dSearchPath.h:32
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
A collection of vertices.
Definition: eggVertexPool.h:46
This class can be used to test for string matches against standard Unix-shell filename globbing conve...
Definition: globPattern.h:37