EggPrimitive

class EggPrimitive

Bases: EggNode, EggAttributes, EggRenderMode

A base class for any of a number of kinds of geometry primitives: polygons, point lights, nurbs patches, parametrics curves, etc. Things with a set of vertices and some rendering properties like color.

An EggPrimitive is an STL-style container of pointers to EggVertex’s. In fact, it IS a vector, and can be manipulated in all the ways that vectors can. However, it is necessary that all vertices belong to the same vertex pool.

Inheritance diagram

Inheritance diagram of EggPrimitive

enum Shading
enumerator S_unknown = 0

The order here is important. The later choices are more specific than the earlier ones.

enumerator S_overall = 1
enumerator S_per_face = 2
enumerator S_per_vertex = 3
void add_texture(EggTexture *texture)

Applies the indicated texture to the primitive.

Note that, in the case of multiple textures being applied to a single primitive, the order in which the textures are applied does not affect the rendering order; use EggTexture::set_sort() to specify that.

EggVertex *add_vertex(EggVertex *vertex)

Adds the indicated vertex to the end of the primitive’s list of vertices, and returns it.

virtual void apply_first_attribute(void)

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.

virtual void apply_last_attribute(void)

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.

virtual bool cleanup(void)

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.

void clear(void)

Removes all of the vertices from the primitive.

void clear_connected_shading(void)

Resets the connected_shading member in this primitive, so that get_connected_shading() will recompute a new value.

void clear_material(void)

Removes any material from the primitive.

void clear_texture(void)

Removes any texturing from the primitive.

void copy_attributes(EggAttributes const &other)
void copy_attributes(EggPrimitive const &other)

Copies the rendering attributes from the indicated primitive.

void copy_vertices(EggPrimitive const &other)

Replaces the current primitive’s list of vertices with a copy of the list of vertices on the other primitive.

virtual EggRenderMode *determine_alpha_mode(void)

Walks back up the hierarchy, looking for an EggGroup or EggPrimitive or some such object at this level or above this primitive that has an alpha_mode other than AM_unspecified. Returns a valid EggRenderMode pointer if one is found, or NULL otherwise.

virtual EggRenderMode *determine_bin(void)

Walks back up the hierarchy, looking for an EggGroup or EggPrimitive or some such object at this level or above this primitive that has a bin specified. Returns a valid EggRenderMode pointer if one is found, or NULL otherwise.

virtual EggRenderMode *determine_depth_offset(void)

Walks back up the hierarchy, looking for an EggGroup or EggPrimitive or some such object at this level or above this primitive that has a depth_offset specified. Returns a valid EggRenderMode pointer if one is found, or NULL otherwise.

virtual EggRenderMode *determine_depth_test_mode(void)

Walks back up the hierarchy, looking for an EggGroup or EggPrimitive or some such object at this level or above this node that has a depth_test_mode other than DTM_unspecified. Returns a valid EggRenderMode pointer if one is found, or NULL otherwise.

virtual EggRenderMode *determine_depth_write_mode(void)

Walks back up the hierarchy, looking for an EggGroup or EggPrimitive or some such object at this level or above this node that has a depth_write_mode other than DWM_unspecified. Returns a valid EggRenderMode pointer if one is found, or NULL otherwise.

virtual EggRenderMode *determine_draw_order(void)

Walks back up the hierarchy, looking for an EggGroup or EggPrimitive or some such object at this level or above this primitive that has a draw_order specified. Returns a valid EggRenderMode pointer if one is found, or NULL otherwise.

virtual EggRenderMode *determine_visibility_mode(void)

Walks back up the hierarchy, looking for an EggGroup or EggPrimitive or some such object at this level or above this node that has a visibility_mode other than VM_unspecified. Returns a valid EggRenderMode pointer if one is found, or NULL otherwise.

bool get_bface_flag(void) const

Retrieves the backfacing flag of the polygon. See set_bface_flag().

static TypeHandle get_class_type(void)
Shading get_connected_shading(void) const

Determines what sort of shading properties this primitive’s connected neighbors have.

To get the most accurate results, you should first call clear_connected_shading() on all connected primitives (or on all primitives in the egg file). It might also be a good idea to call remove_unused_vertices() to ensure proper connectivity.

You may find it easiest to call these other methods on the EggData root node (they are defined on EggGroupNode).

EggMaterial *get_material(void) const

Returns a pointer to the applied material, or NULL if there is no material applied.

int get_num_textures(void) const

Returns the number of textures applied to the primitive.

std::size_t get_num_vertices(void) const

These are shorthands if you don’t want to use the iterators.

These are shorthands if you don’t want to use the iterators.

These are shorthands if you don’t want to use the iterators.

EggVertexPool *get_pool(void) const

Returns the vertex pool associated with the vertices of the primitive, or NULL if the primitive has no vertices.

virtual Shading get_shading(void) const

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).

std::string get_sort_name(void) const

Returns the name of the primitive for the purposes of sorting primitives into different groups, if there is one.

Presently, this is defined as the primitive name itself, unless it begins with a digit.

EggTexture *get_texture(void) const
EggTexture *get_texture(int n) const

Returns the first texture on the primitive, if any, or NULL if there are no textures on the primitive.

Deprecated: This method is used in support of single-texturing only.

New code should be written to use the multitexture variants instead.

Returns the nth texture that has been applied to the primitive.

EggVertex *get_vertex(std::size_t index) const

Returns a particular index based on its index number.

bool has_material(void) const

Returns true if the primitive is materiald (and get_material() will return a real pointer), false otherwise (and get_material() will return NULL).

virtual bool has_normals(void) const

Returns true if any of the primitives (e.g. polygons) defined within this group or below have either face or vertex normals defined, false otherwise.

virtual bool has_primitives(void) const

Returns true if there are any primitives (e.g. polygons) defined within this group or below, false otherwise.

bool has_texture(void) const
bool has_texture(EggTexture *texture) const

Returns true if the primitive has any textures specified, false otherwise.

Deprecated: This method is used in support of single-texturing only.

New code should be written to use the multitexture variants instead.

Returns true if the primitive has the particular indicated texture, false otherwise.

bool has_vertex_color(void) const

Returns true if any vertex on the primitive has a specific color set, false otherwise.

If you call unify_attributes() first, this will also return false even if all the vertices were set to the same value (since unify_attributes() removes redundant vertex properties).

bool has_vertex_normal(void) const

Returns true if any vertex on the primitive has a specific normal set, false otherwise.

If you call unify_attributes() first, this will also return false even if all the vertices were set to the same value (since unify_attributes() removes redundant vertex properties).

void insert_vertex(std::size_t index, EggVertex *vertex)

Inserts a vertex at the given position.

virtual bool joint_has_primitives(void) const

Returns true if there are any primitives (e.g. polygons) defined within this group or below, but the search does not include nested joints.

virtual EggPrimitive *make_copy(void) const = 0
virtual void post_apply_flat_attribute(void)

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.

void remove_doubled_verts(bool closed)

Certain kinds of primitives, particularly polygons, don’t like to have the same vertex repeated consecutively. Unfortunately, some modeling programs (like MultiGen) make this an easy mistake to make.

It’s handy to have a function to remove these redundant vertices. If closed is true, it also checks that the first and last vertices are not the same.

This function identifies repeated vertices by position only; it does not consider any other properties, such as color or UV, significant in differentiating vertices.

void remove_nonunique_verts(void)

Removes any multiple appearances of the same vertex from the primitive. This primarily makes sense for a point primitive, which is really a collection of points and which doesn’t make sense to include the same point twice, in any order.

EggVertex *remove_vertex(EggVertex *vertex)
void remove_vertex(std::size_t index)

Removes the indicated vertex from the primitive and returns it. If the vertex was not already in the primitive, does nothing and returns NULL.

Removes the indicated vertex from the primitive.

virtual void reverse_vertex_ordering(void)

Reverses the ordering of the vertices in this primitive, if appropriate, in order to change the direction the polygon appears to be facing. Does not adjust the surface normal, if any.

void set_bface_flag(bool flag)

Sets the backfacing flag of the polygon. If this is true, the polygon will be rendered so that both faces are visible; if it is false, only the front face of the polygon will be visible.

void set_material(EggMaterial *material)

Applies the indicated material to the primitive.

void set_texture(EggTexture *texture)

Replaces the current list of textures with the indicated texture.

Deprecated: This method is used in support of single-texturing only.

Please use the multitexture variant add_texture instead.

void set_vertex(std::size_t index, EggVertex *vertex)

Replaces a particular vertex based on its index number in the list of vertices. This is just a convenience function for people who don’t want to mess with the iterators.

void test_vref_integrity(void) const
virtual void unify_attributes(EggPrimitive::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.

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.

virtual void write(std::ostream &out, int indent_level) const = 0