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