Panda3D

Loading...
Searching...
No Matches
eggPrimitive.I
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 eggPrimitive.I
10 * @author drose
11 * @date 1999-01-16
12 */
13
14/**
15 *
16 */
17INLINE EggPrimitive::
18EggPrimitive(const std::string &name): EggNode(name) {
19 _bface = false;
20 _connected_shading = S_unknown;
21}
22
23/**
24 *
25 */
26INLINE EggPrimitive::
27EggPrimitive(const EggPrimitive &copy) :
28 EggNode(copy),
29 EggAttributes(copy),
30 EggRenderMode(copy),
31 _textures(copy._textures),
32 _material(copy._material),
33 _bface(copy._bface)
34{
35 copy_vertices(copy);
36 _connected_shading = S_unknown;
37}
38
39/**
40 *
41 */
42INLINE EggPrimitive &EggPrimitive::
43operator = (const EggPrimitive &copy) {
44 EggNode::operator = (copy);
45 EggAttributes::operator = (copy);
46 EggRenderMode::operator = (copy);
47 copy_vertices(copy);
48 _textures = copy._textures;
49 _material = copy._material;
50 _bface = copy._bface;
51 _connected_shading = S_unknown;
52 return *this;
53}
54
55/**
56 *
57 */
58INLINE EggPrimitive::
59~EggPrimitive() {
60 clear();
61}
62
63/**
64 * Returns the name of the primitive for the purposes of sorting primitives
65 * into different groups, if there is one.
66 *
67 * Presently, this is defined as the primitive name itself, unless it begins
68 * with a digit.
69 */
70INLINE std::string EggPrimitive::
71 get_sort_name() const {
72 const std::string &name = get_name();
73 if (!name.empty() && !isdigit(name[0])) {
74 return name;
75 }
76 return std::string();
77}
78
79/**
80 * Resets the connected_shading member in this primitive, so that
81 * get_connected_shading() will recompute a new value.
82 */
83INLINE void EggPrimitive::
84 clear_connected_shading() {
85 _connected_shading = S_unknown;
86}
87
88/**
89 * Determines what sort of shading properties this primitive's connected
90 * neighbors have.
91 *
92 * To get the most accurate results, you should first call
93 * clear_connected_shading() on all connected primitives (or on all primitives
94 * in the egg file). It might also be a good idea to call
95 * remove_unused_vertices() to ensure proper connectivity.
96 *
97 * You may find it easiest to call these other methods on the EggData root
98 * node (they are defined on EggGroupNode).
99 */
100INLINE EggPrimitive::Shading EggPrimitive::
101 get_connected_shading() const {
102 if (_connected_shading == S_unknown) {
103 ((EggPrimitive *)this)->set_connected_shading(S_unknown, this);
104 }
105
106 return _connected_shading;
107}
108
109/**
110 * Replaces the current list of textures with the indicated texture.
111 *
112 * @deprecated This method is used in support of single-texturing only.
113 * Please use the multitexture variant add_texture instead.
114 */
115INLINE void EggPrimitive::
116 set_texture(EggTexture *texture) {
117 clear_texture();
118 add_texture(texture);
119}
120
121/**
122 * Returns true if the primitive has any textures specified, false otherwise.
123 *
124 * @deprecated This method is used in support of single-texturing only.
125 * New code should be written to use the multitexture variants instead.
126 */
127INLINE bool EggPrimitive::
128 has_texture() const {
129 return get_num_textures() > 0;
130}
131
132/**
133 * Returns true if the primitive has the particular indicated texture, false
134 * otherwise.
135 */
136INLINE bool EggPrimitive::
137 has_texture(EggTexture *texture) const {
138 PT_EggTexture t = texture;
139 return (std::find(_textures.begin(), _textures.end(), t) != _textures.end());
140}
141
142/**
143 * Returns the first texture on the primitive, if any, or NULL if there are no
144 * textures on the primitive.
145 *
146 * @deprecated This method is used in support of single-texturing only.
147 * New code should be written to use the multitexture variants instead.
148 */
149INLINE EggTexture *EggPrimitive::
150 get_texture() const {
151 return has_texture() ? get_texture(0) : nullptr;
152}
153
154/**
155 * Applies the indicated texture to the primitive.
156 *
157 * Note that, in the case of multiple textures being applied to a single
158 * primitive, the order in which the textures are applied does not affect the
159 * rendering order; use EggTexture::set_sort() to specify that.
160 */
161INLINE void EggPrimitive::
162 add_texture(EggTexture *texture) {
163 _textures.push_back(texture);
164}
165
166/**
167 * Removes any texturing from the primitive.
168 */
169INLINE void EggPrimitive::
170 clear_texture() {
171 _textures.clear();
172}
173
174/**
175 * Returns the number of textures applied to the primitive.
176 */
177INLINE int EggPrimitive::
178 get_num_textures() const {
179 return _textures.size();
180}
181
182/**
183 * Returns the nth texture that has been applied to the primitive.
184 */
185INLINE EggTexture *EggPrimitive::
186 get_texture(int n) const {
187 nassertr(n >= 0 && n < (int)_textures.size(), nullptr);
188 return _textures[n];
189}
190
191
192/**
193 * Applies the indicated material to the primitive.
194 */
195INLINE void EggPrimitive::
196 set_material(EggMaterial *material) {
197 _material = material;
198}
199
200/**
201 * Removes any material from the primitive.
202 */
203INLINE void EggPrimitive::
204 clear_material() {
205 _material = nullptr;
206}
207
208/**
209 * Returns a pointer to the applied material, or NULL if there is no material
210 * applied.
211 */
212INLINE EggMaterial *EggPrimitive::
213 get_material() const {
214 return _material;
215}
216
217
218/**
219 * Returns true if the primitive is materiald (and get_material() will return
220 * a real pointer), false otherwise (and get_material() will return NULL).
221 */
222INLINE bool EggPrimitive::
223 has_material() const {
224 return _material != nullptr;
225}
226
227
228/**
229 * Sets the backfacing flag of the polygon. If this is true, the polygon will
230 * be rendered so that both faces are visible; if it is false, only the front
231 * face of the polygon will be visible.
232 */
233INLINE void EggPrimitive::
234 set_bface_flag(bool flag) {
235 _bface = flag;
236}
237
238
239/**
240 * Retrieves the backfacing flag of the polygon. See set_bface_flag().
241 */
242INLINE bool EggPrimitive::
243 get_bface_flag() const {
244 return _bface;
245}
246
247
248/**
249 *
250 */
251INLINE EggPrimitive::iterator EggPrimitive::
252begin() const {
253 return _vertices.begin();
254}
255
256/**
257 *
258 */
259INLINE EggPrimitive::iterator EggPrimitive::
260end() const {
261 return _vertices.end();
262}
263
264/**
265 *
266 */
267INLINE EggPrimitive::reverse_iterator EggPrimitive::
268rbegin() const {
269 return _vertices.rbegin();
270}
271
272/**
273 *
274 */
275INLINE EggPrimitive::reverse_iterator EggPrimitive::
276rend() const {
277 return _vertices.rend();
278}
279
280/**
281 *
282 */
283INLINE bool EggPrimitive::
284empty() const {
285 return _vertices.empty();
286}
287
288/**
289 *
290 */
291INLINE EggPrimitive::size_type EggPrimitive::
292size() const {
293 return _vertices.size();
294}
295
296/**
297 * This is read-only: you can't assign directly to an indexed vertex. See
298 * set_vertex() instead.
299 */
300INLINE EggVertex *EggPrimitive::
301 operator [] (int index) const {
302 nassertr(index >= 0 && index < (int)size(), nullptr);
303 return *(begin() + index);
304}
305
306/**
307 *
308 */
309INLINE EggPrimitive::iterator EggPrimitive::
310insert(iterator position, EggVertex *x) {
311 prepare_add_vertex(x, position - _vertices.begin(), _vertices.size() + 1);
312 iterator i = _vertices.insert((Vertices::iterator &)position, x);
313 x->test_pref_integrity();
314 test_vref_integrity();
315 return i;
316}
317
318/**
319 *
320 */
321INLINE EggPrimitive::iterator EggPrimitive::
322erase(iterator position) {
323 prepare_remove_vertex(*position, position - _vertices.begin(), _vertices.size());
324 iterator i = _vertices.erase((Vertices::iterator &)position);
325 test_vref_integrity();
326 return i;
327}
328
329/**
330 * Replaces the vertex at the indicated position with the indicated vertex.
331 * It is an error to call this with an invalid position iterator (e.g.
332 * end()).
333 */
334INLINE void EggPrimitive::
335 replace(iterator position, EggVertex *x) {
336 nassertv(position != end());
337
338 // We pass -1 for i and n so that EggCompositePrimitive won't try to adjust
339 // its _components list.
340 prepare_remove_vertex(*position, -1, -1);
341 prepare_add_vertex(x, -1, -1);
342 *(Vertices::iterator &)position = x;
343
344 x->test_pref_integrity();
345 test_vref_integrity();
346}
347
348/**
349 * Removes all of the vertices from the primitive.
350 */
351INLINE void EggPrimitive::
352 clear() {
353 erase(begin(), end());
354}
355
356/**
357 *
358 */
359INLINE size_t EggPrimitive::
360get_num_vertices() const {
361 return size();
362}
363
364/**
365 * Replaces a particular vertex based on its index number in the list of
366 * vertices. This is just a convenience function for people who don't want to
367 * mess with the iterators.
368 */
369INLINE void EggPrimitive::
370 set_vertex(size_t index, EggVertex *vertex) {
371 nassertv(index < size());
372 replace(begin() + index, vertex);
373}
374
375/**
376 * Inserts a vertex at the given position.
377 */
378INLINE void EggPrimitive::
379 insert_vertex(size_t index, EggVertex *vertex) {
380 if (index > _vertices.size()) {
381 index = _vertices.size();
382 }
383 _vertices.insert(_vertices.begin() + index, vertex);
384}
385
386/**
387 * Returns a particular index based on its index number.
388 */
389INLINE EggVertex *EggPrimitive::
390 get_vertex(size_t index) const {
391 nassertr(index < size(), nullptr);
392 return *(begin() + index);
393}
394
395/**
396 * Returns the vertex pool associated with the vertices of the primitive, or
397 * NULL if the primitive has no vertices.
398 */
399INLINE EggVertexPool *EggPrimitive::
400 get_pool() const {
401 return empty() ? nullptr : _vertices.front()->get_pool();
402}
EggAttributes
The set of attributes that may be applied to vertices as well as polygons, such as surface normal and...
Definition eggAttributes.h:33
EggMaterial
Definition eggMaterial.h:26
EggNode
A base class for things that may be directly added into the egg hierarchy.
Definition eggNode.h:36
EggPrimitive
A base class for any of a number of kinds of geometry primitives: polygons, point lights,...
Definition eggPrimitive.h:49
EggPrimitive::set_bface_flag
set_bface_flag
Sets the backfacing flag of the polygon.
Definition eggPrimitive.h:116
EggPrimitive::clear_texture
void clear_texture()
Removes any texturing from the primitive.
Definition eggPrimitive.I:170
EggPrimitive::get_material
get_material
Returns a pointer to the applied material, or NULL if there is no material applied.
Definition eggPrimitive.h:115
EggPrimitive::get_pool
get_pool
Returns the vertex pool associated with the vertices of the primitive, or NULL if the primitive has n...
Definition eggPrimitive.h:191
EggPrimitive::set_texture
void set_texture(EggTexture *texture)
Replaces the current list of textures with the indicated texture.
Definition eggPrimitive.I:116
EggPrimitive::copy_vertices
void copy_vertices(const EggPrimitive &other)
Replaces the current primitive's list of vertices with a copy of the list of vertices on the other pr...
Definition eggPrimitive.cxx:704
EggPrimitive::set_material
set_material
Applies the indicated material to the primitive.
Definition eggPrimitive.h:115
EggPrimitive::clear_material
clear_material
Removes any material from the primitive.
Definition eggPrimitive.h:115
EggPrimitive::has_texture
bool has_texture() const
Returns true if the primitive has any textures specified, false otherwise.
Definition eggPrimitive.I:128
EggPrimitive::get_vertex
get_vertex
Returns a particular index based on its index number.
Definition eggPrimitive.h:186
EggPrimitive::get_connected_shading
get_connected_shading
Determines what sort of shading properties this primitive's connected neighbors have.
Definition eggPrimitive.h:112
EggPrimitive::set_vertex
set_vertex
Replaces a particular vertex based on its index number in the list of vertices.
Definition eggPrimitive.h:190
EggPrimitive::get_bface_flag
get_bface_flag
Retrieves the backfacing flag of the polygon.
Definition eggPrimitive.h:116
EggPrimitive::replace
void replace(iterator position, EggVertex *vertex)
Replaces the vertex at the indicated position with the indicated vertex.
Definition eggPrimitive.I:335
EggPrimitive::get_num_textures
get_num_textures
Returns the number of textures applied to the primitive.
Definition eggPrimitive.h:100
EggPrimitive::get_sort_name
get_sort_name
Returns the name of the primitive for the purposes of sorting primitives into different groups,...
Definition eggPrimitive.h:110
EggPrimitive::clear
void clear()
Removes all of the vertices from the primitive.
Definition eggPrimitive.I:352
EggPrimitive::clear_connected_shading
void clear_connected_shading()
Resets the connected_shading member in this primitive, so that get_connected_shading() will recompute...
Definition eggPrimitive.I:84
EggPrimitive::insert_vertex
insert_vertex
Inserts a vertex at the given position.
Definition eggPrimitive.h:190
EggPrimitive::operator[]
EggVertex * operator[](int index) const
This is read-only: you can't assign directly to an indexed vertex.
Definition eggPrimitive.I:301
EggPrimitive::get_texture
get_texture
Returns the first texture on the primitive, if any, or NULL if there are no textures on the primitive...
Definition eggPrimitive.h:100
EggPrimitive::add_texture
void add_texture(EggTexture *texture)
Applies the indicated texture to the primitive.
Definition eggPrimitive.I:162
EggPrimitive::has_material
has_material
Returns true if the primitive is materiald (and get_material() will return a real pointer),...
Definition eggPrimitive.h:115
EggRenderMode
This class stores miscellaneous rendering properties that is associated with geometry,...
Definition eggRenderMode.h:31
EggTexture
Defines a texture map that may be applied to geometry.
Definition eggTexture.h:30
EggVertexPool
A collection of vertices.
Definition eggVertexPool.h:41
EggVertex
Any one-, two-, three-, or four-component vertex, possibly with attributes such as a normal.
Definition eggVertex.h:39
iterator