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) {
161 Components::iterator ci;
162 for (ci = _components.begin(); ci != _components.end(); ++ci) {
164 if (component->has_normal()) {
168 component->clear_normal();
170 if (component->has_color()) {
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()) {
190 if (!vertex->has_color() && has_color()) {
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()) {
215 if (orig_vertex->has_color() && !has_color()) {
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()) {
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()) {
284 component->clear_normal();
286 if (component->has_color()) {
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";
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.
const EggAttributes * get_component(int i) const
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.
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...
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...
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...
int get_num_components() const
Returns the number of individual component triangles within the composite.
This is the base class for all three-component vectors and points.
void write(ostream &out, int indent_level) const
Writes the attributes to the indicated output stream in Egg format.
EggNode * add_child(EggNode *node)
Adds the indicated child to the group and returns it.
virtual Shading get_shading() const
Returns the shading properties apparent on this particular primitive.
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...
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.
EggVertex * get_vertex(int index) const
Returns a particular index based on its index number.
int compare_to(const EggAttributes &other) const
An ordering operator to compare two vertices for sorting order.