Panda3D
Public Member Functions | Static Public Member Functions | Protected Member Functions
EggCompositePrimitive Class Reference

The base class for primitives such as triangle strips and triangle fans, which include several component triangles, each of which might have its own color and/or normal. More...

#include "eggCompositePrimitive.h"

Inheritance diagram for EggCompositePrimitive:
EggPrimitive EggNode EggAttributes EggRenderMode EggNamedObject MemoryBase EggObject Namable TypedReferenceCount MemoryBase TypedObject ReferenceCount MemoryBase MemoryBase EggLine EggTriangleFan EggTriangleStrip

List of all members.

Public Member Functions

 EggCompositePrimitive (const string &name="")
 EggCompositePrimitive (const EggCompositePrimitive &copy)
virtual void apply_first_attribute ()
 Sets the first vertex of the triangle (or each component) to the primitive normal and/or color, if the primitive is flat-shaded.
virtual void apply_last_attribute ()
 Sets the last vertex of the triangle (or each component) to the primitive normal and/or color, if the primitive is flat-shaded.
virtual bool cleanup ()
 Cleans up modeling errors in whatever context this makes sense.
virtual TypeHandle force_init_type ()
const EggAttributesget_component (int i) const
 Returns the attributes for the nth component triangle.
EggAttributesget_component (int i)
 Returns the attributes for the nth component triangle.
int get_num_components () const
 Returns the number of individual component triangles within the composite.
virtual Shading get_shading () const
 Returns the shading properties apparent on this particular primitive.
virtual TypeHandle get_type () const
 MAKE_SEQ (get_components, get_num_components, get_component)
EggCompositePrimitiveoperator= (const EggCompositePrimitive &copy)
virtual void post_apply_flat_attribute ()
 Intended as a followup to apply_last_attribute(), this also sets an attribute on the first vertices of the primitive, if they don't already have an attribute set, just so they end up with *something*.
 PT (EggCompositePrimitive) triangulate_in_place()
void set_component (int i, const EggAttributes *attrib)
 Changes the attributes for the nth component triangle.
bool triangulate_into (EggGroupNode *container) const
 Subdivides the composite primitive into triangles and adds those triangles to the indicated container.
virtual void unify_attributes (Shading shading)
 If the shading property is S_per_vertex, ensures that all vertices have a normal and a color, and the overall primitive does not.

Static Public Member Functions

static TypeHandle get_class_type ()
static void init_type ()

Protected Member Functions

virtual bool do_triangulate (EggGroupNode *container) const
 Fills the container up with EggPolygons that represent the component triangles of this triangle strip.
virtual int get_num_lead_vertices () const =0
virtual void prepare_add_vertex (EggVertex *vertex, int i, int n)
 Marks the vertex as belonging to the primitive.
virtual void prepare_remove_vertex (EggVertex *vertex, int i, int n)
 Marks the vertex as removed from the primitive.
void write_body (ostream &out, int indent_level) const
 Writes the attributes and the vertices referenced by the primitive to the indicated output stream in Egg format.

Detailed Description

The base class for primitives such as triangle strips and triangle fans, which include several component triangles, each of which might have its own color and/or normal.

Definition at line 29 of file eggCompositePrimitive.h.


Member Function Documentation

Sets the first vertex of the triangle (or each component) to the primitive normal and/or color, if the primitive is flat-shaded.

This reflects the DirectX convention of storing flat-shaded properties on the first vertex, although it is not usually a convention in Egg.

This may introduce redundant vertices to the vertex pool.

Reimplemented from EggPrimitive.

Reimplemented in EggTriangleFan.

Definition at line 344 of file eggCompositePrimitive.cxx.

References EggPrimitive::do_apply_flat_attribute(), get_component(), and get_num_components().

Sets the last vertex of the triangle (or each component) to the primitive normal and/or color, if the primitive is flat-shaded.

This reflects the OpenGL convention of storing flat-shaded properties on the last vertex, although it is not usually a convention in Egg.

This may introduce redundant vertices to the vertex pool.

Reimplemented from EggPrimitive.

Definition at line 320 of file eggCompositePrimitive.cxx.

References EggPrimitive::do_apply_flat_attribute(), get_component(), and get_num_components().

bool EggCompositePrimitive::cleanup ( ) [virtual]

Cleans up modeling errors in whatever context this makes sense.

For instance, for a polygon, this calls remove_doubled_verts(true). For a point, it calls remove_nonunique_verts(). Returns true if the primitive is valid, or false if it is degenerate.

Reimplemented from EggPrimitive.

Definition at line 398 of file eggCompositePrimitive.cxx.

bool EggCompositePrimitive::do_triangulate ( EggGroupNode container) const [protected, virtual]

Fills the container up with EggPolygons that represent the component triangles of this triangle strip.

It is assumed that the EggCompositePrimitive is not already a child of any other group when this function is called.

Returns true if the triangulation is successful, or false if there was some error (in which case the container may contain some partial triangulation).

Reimplemented in EggTriangleFan, and EggTriangleStrip.

Definition at line 471 of file eggCompositePrimitive.cxx.

References EggGroupNode::add_child().

Referenced by triangulate_into().

const EggAttributes * EggCompositePrimitive::get_component ( int  i) const [inline]

Returns the attributes for the nth component triangle.

Definition at line 76 of file eggCompositePrimitive.I.

Returns the number of individual component triangles within the composite.

Each one of these might have a different set of attributes.

Definition at line 53 of file eggCompositePrimitive.I.

Referenced by EggTriangleFan::apply_first_attribute(), apply_first_attribute(), apply_last_attribute(), get_shading(), EggGroupNode::rebuild_vertex_pools(), and write_body().

EggPrimitive::Shading EggCompositePrimitive::get_shading ( ) const [virtual]

Returns the shading properties apparent on this particular primitive.

This returns S_per_vertex if the vertices have colors or normals (and they are not all the same values), or for a simple primitive, S_overall otherwise. A composite primitive may also return S_per_face if the individual component primitives have colors or normals that are not all the same values.

To get the most accurate results, you should call clear_shading() on all connected primitives (or on all primitives in the egg file), followed by get_shading() on each primitive. You may find it easiest to call these methods on the EggData root node (they are defined on EggGroupNode).

Reimplemented from EggPrimitive.

Definition at line 54 of file eggCompositePrimitive.cxx.

References get_component(), get_num_components(), EggAttributes::matches_color(), and EggAttributes::matches_normal().

Intended as a followup to apply_last_attribute(), this also sets an attribute on the first vertices of the primitive, if they don't already have an attribute set, just so they end up with *something*.

Reimplemented from EggPrimitive.

Definition at line 362 of file eggCompositePrimitive.cxx.

References EggAttributes::get_color(), get_component(), and EggPrimitive::get_vertex().

void EggCompositePrimitive::prepare_add_vertex ( EggVertex vertex,
int  i,
int  n 
) [protected, virtual]

Marks the vertex as belonging to the primitive.

This is an internal function called by the STL-like functions push_back() and insert(), in preparation for actually adding the vertex.

i indicates the new position of the vertex in the list; n indicates the new number of vertices after the operation has completed.

Reimplemented from EggPrimitive.

Definition at line 415 of file eggCompositePrimitive.cxx.

void EggCompositePrimitive::prepare_remove_vertex ( EggVertex vertex,
int  i,
int  n 
) [protected, virtual]

Marks the vertex as removed from the primitive.

This is an internal function called by the STL-like functions pop_back() and erase(), in preparation for actually doing the removal.

i indicates the former position of the vertex in the list; n indicates the current number of vertices before the operation has completed.

It is an error to attempt to remove a vertex that is not already a vertex of this primitive.

Reimplemented from EggPrimitive.

Definition at line 443 of file eggCompositePrimitive.cxx.

void EggCompositePrimitive::set_component ( int  i,
const EggAttributes attrib 
) [inline]

Changes the attributes for the nth component triangle.

Definition at line 88 of file eggCompositePrimitive.I.

Referenced by EggGroupNode::rebuild_vertex_pools().

bool EggCompositePrimitive::triangulate_into ( EggGroupNode container) const [inline]

Subdivides the composite primitive into triangles and adds those triangles to the indicated container.

Does not remove the primitive from its existing parent or modify it in any way.

Returns true if the triangulation is successful, or false if there was some error (in which case the container may contain some partial triangulation).

Definition at line 106 of file eggCompositePrimitive.I.

References do_triangulate().

void EggCompositePrimitive::unify_attributes ( EggPrimitive::Shading  shading) [virtual]

If the shading property is S_per_vertex, ensures that all vertices have a normal and a color, and the overall primitive does not.

If the shading property is S_per_face, and this is a composite primitive, ensures that all components have a normal and a color, and the vertices and overall primitive do not. (If this is a simple primitive, S_per_face works the same as S_overall, below).

If the shading property is S_overall, ensures that no vertices or components have a normal or a color, and the overall primitive does (if any exists at all).

After this call, either the primitive will have normals or its vertices will, but not both. Ditto for colors.

This may create redundant vertices in the vertex pool.

Reimplemented from EggPrimitive.

Definition at line 152 of file eggCompositePrimitive.cxx.

References EggAttributes::copy_color(), EggVertex::copy_grefs_from(), EggAttributes::copy_normal(), EggVertexPool::create_unique_vertex(), and EggVertex::get_pool().

void EggCompositePrimitive::write_body ( ostream &  out,
int  indent_level 
) const [protected]

Writes the attributes and the vertices referenced by the primitive to the indicated output stream in Egg format.

Reimplemented from EggPrimitive.

Definition at line 484 of file eggCompositePrimitive.cxx.

References EggAttributes::compare_to(), get_component(), get_num_components(), and EggAttributes::write().

Referenced by EggLine::write(), EggTriangleStrip::write(), and EggTriangleFan::write().


The documentation for this class was generated from the following files:
 All Classes Functions Variables Enumerations