15 #include "eggCompositePrimitive.h"
16 #include "eggGroupNode.h"
17 #include "eggVertexPool.h"
19 TypeHandle EggCompositePrimitive::_type_handle;
27 EggCompositePrimitive::
28 ~EggCompositePrimitive() {
31 nassertv(_components.empty());
56 if (basic_shading == S_per_vertex) {
59 if (_components.empty()) {
66 if (!first_component->has_normal()) {
67 first_component =
this;
71 if (!component->has_normal()) {
83 if (!first_component->has_color()) {
84 first_component =
this;
88 if (!component->has_color()) {
116 triangulate_in_place() {
121 parent->remove_child(this);
122 do_triangulate(parent);
153 if (shading == S_unknown) {
154 shading = get_shading();
161 Components::iterator ci;
162 for (ci = _components.begin(); ci != _components.end(); ++ci) {
164 if (component->has_normal()) {
166 copy_normal(*component);
168 component->clear_normal();
170 if (component->has_color()) {
172 copy_color(*component);
174 component->clear_color();
180 set_color(
LColor(1.0f, 1.0f, 1.0f, 1.0f));
184 for (pi = begin(); pi != end(); ++pi) {
187 if (!vertex->has_normal() && has_normal()) {
188 vertex->copy_normal(*
this);
190 if (!vertex->has_color() && has_color()) {
191 vertex->copy_color(*
this);
209 for (pi = begin(); pi != end(); ++pi) {
211 if (orig_vertex->has_normal() || orig_vertex->has_color()) {
212 if (orig_vertex->has_normal() && !has_normal()) {
213 copy_normal(*orig_vertex);
215 if (orig_vertex->has_color() && !has_color()) {
216 copy_color(*orig_vertex);
220 vertex->clear_normal();
221 vertex->clear_color();
233 set_color(
LColor(1.0f, 1.0f, 1.0f, 1.0f));
236 Components::iterator ci;
237 for (ci = _components.begin(); ci != _components.end(); ++ci) {
239 if (!component->has_normal() && has_normal()) {
242 if (!component->has_color() && has_color()) {
255 for (pi = begin(); pi != end(); ++pi) {
258 if (vertex->has_normal()) {
260 copy_normal(*vertex);
262 vertex->clear_normal();
264 if (vertex->has_color()) {
268 vertex->clear_color();
277 Components::iterator ci;
278 for (ci = _components.begin(); ci != _components.end(); ++ci) {
280 if (component->has_normal()) {
282 copy_normal(*component);
284 component->clear_normal();
286 if (component->has_color()) {
288 copy_color(*component);
290 component->clear_color();
296 set_color(
LColor(1.0f, 1.0f, 1.0f, 1.0f));
323 int num_lead_vertices = get_num_lead_vertices();
326 do_apply_flat_attribute(i + num_lead_vertices, component);
349 do_apply_flat_attribute(i, component);
364 int num_lead_vertices = get_num_lead_vertices();
365 for (
int i = 0; i < (int)size(); i++) {
373 if (component->has_normal() && !vertex->has_normal()) {
374 vertex->set_normal(component->get_normal());
375 }
else if (has_normal() && !vertex->has_normal()) {
376 vertex->set_normal(get_normal());
379 if (component->has_color() && !vertex->has_color()) {
380 vertex->set_color(component->
get_color());
381 }
else if (has_color() && !vertex->has_color()) {
399 return (
int)size() >= get_num_lead_vertices() + 1;
414 void EggCompositePrimitive::
415 prepare_add_vertex(
EggVertex *vertex,
int i,
int n) {
416 EggPrimitive::prepare_add_vertex(vertex, i, n);
418 int num_lead_vertices = get_num_lead_vertices();
419 if (n >= num_lead_vertices + 1) {
420 i = max(i - num_lead_vertices, 0);
421 nassertv(i <= (
int)_components.size());
422 _components.insert(_components.begin() + i,
new EggAttributes(*
this));
442 void EggCompositePrimitive::
443 prepare_remove_vertex(
EggVertex *vertex,
int i,
int n) {
444 EggPrimitive::prepare_remove_vertex(vertex, i, n);
446 int num_lead_vertices = get_num_lead_vertices();
447 if (n >= num_lead_vertices + 1) {
448 i = max(i - num_lead_vertices, 0);
449 nassertv(i < (
int)_components.size());
450 delete _components[i];
451 _components.erase(_components.begin() + i);
470 bool EggCompositePrimitive::
483 void EggCompositePrimitive::
484 write_body(ostream &out,
int indent_level)
const {
485 EggPrimitive::write_body(out, indent_level);
490 (attrib->has_color() || attrib->has_normal())) {
491 indent(out, indent_level)
492 <<
"<Component> " << i <<
" {\n";
493 attrib->
write(out, indent_level + 2);
494 indent(out, indent_level) <<
"}\n";
A base class for any of a number of kinds of geometry primitives: polygons, point lights...
bool matches_color(const EggAttributes &other) const
Returns true if this color matches that of the other EggAttributes object, include the morph list...
The base class for primitives such as triangle strips and triangle fans, which include several compon...
LColor get_color() const
Returns the color set on this particular attribute.
virtual Shading get_shading() const
Returns the shading properties apparent on this particular primitive.
void write(ostream &out, int indent_level) const
Writes the attributes to the indicated output stream in Egg format.
A base class for nodes in the hierarchy that are not leaf nodes.
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.
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...
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...
const EggAttributes * get_component(int i) const
Returns the attributes for the nth component triangle.
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...
This is the base class for all three-component vectors and points.
EggNode * add_child(EggNode *node)
Adds the indicated child to the group and returns it.
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.
EggVertexPool * get_pool() const
Returns the vertex pool this vertex belongs in.
virtual void apply_first_attribute()
Sets the first vertex of the triangle (or each component) to the primitive normal and/or color...
EggVertex * get_vertex(int index) const
Returns a particular index based on its index number.
virtual void post_apply_flat_attribute()
Intended as a followup to apply_last_attribute(), this also sets an attribute on the first vertices o...
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 get_num_components() const
Returns the number of individual component triangles within the composite.