18 TypeHandle EggCompositePrimitive::_type_handle;
24 EggCompositePrimitive::
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()) {
101 triangulate_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;
373 void EggCompositePrimitive::
374 prepare_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));
397 void EggCompositePrimitive::
398 prepare_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);
420 bool EggCompositePrimitive::
430 void EggCompositePrimitive::
431 write_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 base class for primitives such as triangle strips and triangle fans, which include several compon...
virtual void unify_attributes(Shading shading)
If the shading property is S_per_vertex, ensures that all vertices have a normal and a color,...
EggVertexPool * get_pool() const
Returns the vertex pool this vertex belongs in.
A base class for nodes in the hierarchy that are not leaf nodes.
get_component
Returns the attributes for the nth component triangle.
void copy_normal(const EggAttributes &other)
Sets this normal to be the same as the other's, include morphs.
PT(EggCompositePrimitive) EggCompositePrimitive
Subdivides the composite primitive into triangles and adds those triangles to the parent group node i...
get_shading
Returns the shading properties apparent on this particular primitive.
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.
get_vertex
Returns a particular index based on its index number.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual Shading get_shading() const
Returns the shading properties apparent on this particular primitive.
bool matches_normal(const EggAttributes &other) const
Returns true if this normal 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 set of attributes that may be applied to vertices as well as polygons, such as surface normal and...
void copy_color(const EggAttributes &other)
Sets this color to be the same as the other's, include morphs.
virtual void apply_last_attribute()
Sets the last vertex of the triangle (or each component) to the primitive normal and/or color,...
virtual bool cleanup()
Cleans up modeling errors in whatever context this makes sense.
Any one-, two-, three-, or four-component vertex, possibly with attributes such as a normal.
std::ostream & indent(std::ostream &out, int indent_level)
A handy function for doing text formatting.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
EggNode * add_child(EggNode *node)
Adds the indicated child to the group and returns it.
void replace(iterator position, EggVertex *vertex)
Replaces the vertex at the indicated position with the indicated vertex.
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.
virtual void apply_first_attribute()
Sets the first 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...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
EggVertex * create_unique_vertex(const EggVertex ©)
Creates a new vertex in the pool that is a copy of the indicated one and returns it.
A collection of vertices.
int compare_to(const EggAttributes &other) const
An ordering operator to compare two vertices for sorting order.
get_num_components
Returns the number of individual component triangles within the composite.