24EggCompositePrimitive::
25~EggCompositePrimitive() {
28 nassertv(_components.empty());
47 if (basic_shading == S_per_vertex) {
50 if (_components.empty()) {
57 if (!first_component->has_normal()) {
58 first_component =
this;
62 if (!component->has_normal()) {
74 if (!first_component->has_color()) {
75 first_component =
this;
79 if (!component->has_color()) {
101triangulate_in_place() {
103 nassertr(parent !=
nullptr,
this);
106 parent->remove_child(
this);
107 do_triangulate(parent);
132 if (shading == S_unknown) {
140 Components::iterator ci;
141 for (ci = _components.begin(); ci != _components.end(); ++ci) {
143 if (component->has_normal()) {
147 component->clear_normal();
149 if (component->has_color()) {
153 component->clear_color();
159 set_color(LColor(1.0f, 1.0f, 1.0f, 1.0f));
163 for (pi = begin(); pi != end(); ++pi) {
166 if (!vertex->has_normal() && has_normal()) {
167 vertex->copy_normal(*
this);
169 if (!vertex->has_color() && has_color()) {
170 vertex->copy_color(*
this);
174 nassertv(vertex_pool !=
nullptr);
188 for (pi = begin(); pi != end(); ++pi) {
190 if (orig_vertex->has_normal() || orig_vertex->has_color()) {
191 if (orig_vertex->has_normal() && !has_normal()) {
194 if (orig_vertex->has_color() && !has_color()) {
199 vertex->clear_normal();
200 vertex->clear_color();
203 nassertv(vertex_pool !=
nullptr);
212 set_color(LColor(1.0f, 1.0f, 1.0f, 1.0f));
215 Components::iterator ci;
216 for (ci = _components.begin(); ci != _components.end(); ++ci) {
218 if (!component->has_normal() && has_normal()) {
221 if (!component->has_color() && has_color()) {
234 for (pi = begin(); pi != end(); ++pi) {
237 if (vertex->has_normal()) {
241 vertex->clear_normal();
243 if (vertex->has_color()) {
247 vertex->clear_color();
251 nassertv(vertex_pool !=
nullptr);
256 Components::iterator ci;
257 for (ci = _components.begin(); ci != _components.end(); ++ci) {
259 if (component->has_normal()) {
263 component->clear_normal();
265 if (component->has_color()) {
269 component->clear_color();
275 set_color(LColor(1.0f, 1.0f, 1.0f, 1.0f));
297 int num_lead_vertices = get_num_lead_vertices();
300 do_apply_flat_attribute(i + num_lead_vertices, component);
318 do_apply_flat_attribute(i, component);
330 int num_lead_vertices = get_num_lead_vertices();
331 for (
int i = 0; i < (int)size(); i++) {
339 if (component->has_normal() && !vertex->has_normal()) {
340 vertex->set_normal(component->get_normal());
341 }
else if (has_normal() && !vertex->has_normal()) {
342 vertex->set_normal(get_normal());
345 if (component->has_color() && !vertex->has_color()) {
346 vertex->set_color(component->
get_color());
347 }
else if (has_color() && !vertex->has_color()) {
362 return (
int)size() >= get_num_lead_vertices() + 1;
373void EggCompositePrimitive::
374prepare_add_vertex(
EggVertex *vertex,
int i,
int n) {
375 EggPrimitive::prepare_add_vertex(vertex, i, n);
377 int num_lead_vertices = get_num_lead_vertices();
378 if (n >= num_lead_vertices + 1) {
379 i = std::max(i - num_lead_vertices, 0);
380 nassertv(i <= (
int)_components.size());
381 _components.insert(_components.begin() + i,
new EggAttributes(*
this));
397void EggCompositePrimitive::
398prepare_remove_vertex(
EggVertex *vertex,
int i,
int n) {
399 EggPrimitive::prepare_remove_vertex(vertex, i, n);
401 int num_lead_vertices = get_num_lead_vertices();
402 if (n >= num_lead_vertices + 1) {
403 i = std::max(i - num_lead_vertices, 0);
404 nassertv(i < (
int)_components.size());
405 delete _components[i];
406 _components.erase(_components.begin() + i);
420bool EggCompositePrimitive::
430void EggCompositePrimitive::
431write_body(std::ostream &out,
int indent_level)
const {
432 EggPrimitive::write_body(out, indent_level);
437 (attrib->has_color() || attrib->has_normal())) {
439 <<
"<Component> " << i <<
" {\n";
440 attrib->
write(out, indent_level + 2);
441 indent(out, indent_level) <<
"}\n";
The set of attributes that may be applied to vertices as well as polygons, such as surface normal and...
bool matches_normal(const EggAttributes &other) const
Returns true if this normal matches that of the other EggAttributes object, include the morph list.
void copy_normal(const EggAttributes &other)
Sets this normal to be the same as the other's, include morphs.
int compare_to(const EggAttributes &other) const
An ordering operator to compare two vertices for sorting order.
void copy_color(const EggAttributes &other)
Sets this color to be the same as the other's, include morphs.
LColor get_color() const
Returns the color set on this particular attribute.
bool matches_color(const EggAttributes &other) const
Returns true if this color matches that of the other EggAttributes object, include the morph list.
void write(std::ostream &out, int indent_level) const
Writes the attributes to the indicated output stream in Egg format.
The base class for primitives such as triangle strips and triangle fans, which include several compon...
virtual void apply_last_attribute()
Sets the last vertex of the triangle (or each component) to the primitive normal and/or color,...
virtual void post_apply_flat_attribute()
Intended as a followup to apply_last_attribute(), this also sets an attribute on the first vertices o...
get_num_components
Returns the number of individual component triangles within the composite.
get_component
Returns the attributes for the nth component triangle.
virtual void unify_attributes(Shading shading)
If the shading property is S_per_vertex, ensures that all vertices have a normal and a color,...
virtual void apply_first_attribute()
Sets the first vertex of the triangle (or each component) to the primitive normal and/or color,...
virtual Shading get_shading() const
Returns the shading properties apparent on this particular primitive.
virtual bool cleanup()
Cleans up modeling errors in whatever context this makes sense.
A base class for nodes in the hierarchy that are not leaf nodes.
EggNode * add_child(EggNode *node)
Adds the indicated child to the group and returns it.
get_shading
Returns the shading properties apparent on this particular primitive.
get_vertex
Returns a particular index based on its index number.
void replace(iterator position, EggVertex *vertex)
Replaces the vertex at the indicated position with the indicated vertex.
A collection of vertices.
EggVertex * create_unique_vertex(const EggVertex ©)
Creates a new vertex in the pool that is a copy of the indicated one and returns it.
Any one-, two-, three-, or four-component vertex, possibly with attributes such as a normal.
EggVertexPool * get_pool() const
Returns the vertex pool this vertex belongs in.
void copy_grefs_from(const EggVertex &other)
Copies all the group references from the other vertex onto this one.
TypeHandle is the identifier used to differentiate C++ class types.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
std::ostream & indent(std::ostream &out, int indent_level)
A handy function for doing text formatting.