# EggGroupNode¶

class EggGroupNode

Bases: EggNode

A base class for nodes in the hierarchy that are not leaf nodes. (See also EggGroup, which is specifically the “<Group>” node in egg.)

An EggGroupNode is an STL-style container of pointers to EggNodes, like a vector. Functions push_back()/pop_back() and insert()/erase() are provided to manipulate the list. The list may also be operated on (read-only) via iterators and begin()/end().

Inheritance diagram

enum TriangulateFlags
enumerator T_polygon = 1
enumerator T_convex = 2
enumerator T_composite = 4
enumerator T_recurse = 8
enumerator T_flat_shaded = 16
explicit EggGroupNode(std::string const &name = "")
EggGroupNode(EggGroupNode const &copy)
EggNode *add_child(EggNode *node)

Adds the indicated child to the group and returns it. If the child node is already a child of some other node, removes it first.

void apply_first_attribute(bool recurse)

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 create redundant vertices in the vertex pool, so it may be a good idea to follow this up with remove_unused_vertices().

void apply_last_attribute(bool recurse)

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 create redundant vertices in the vertex pool, so it may be a good idea to follow this up with remove_unused_vertices().

void clear(void)
void clear_connected_shading(void)

Resets the connected_shading information on all primitives at this node and below, so that it may be accurately rederived by the next call to get_connected_shading().

It may be a good idea to call remove_unused_vertices() as well, to establish the correct connectivity between common vertices.

bool empty(void) const
EggNode *find_child(std::string const &name) const

Returns the child of this node whose name is the indicated string, or NULL if there is no child of this node by that name. Does not search recursively.

void force_filenames(Filename const &directory)

Similar to resolve_filenames(), but each non-absolute filename encountered is arbitrarily taken to be in the indicated directory, whether or not the so- named filename exists.

PyObject *get_children(void) const
static TypeHandle get_class_type(void)
void get_connected_shading(void)

Queries the connected_shading information on all primitives at this node and below, to ensure that it has been completely filled in before we start mucking around with vertices.

EggNode *get_first_child(void)

This is an alternate way to traverse the list of children. It is mainly provided for scripting code, which can’t use the iterators defined above (they don’t export through interrogate very well). These are, of course, non-thread-safe.

Returns the first child in the group’s list of children, or NULL if the list of children is empty. Can be used with get_next_child() to return the complete list of children without using the iterator class; however, this is non-thread-safe, and so is not recommended except for languages other than C++ which cannot use the iterators.

EggNode *get_next_child(void)

Returns the next child in the group’s list of children since the last call to get_first_child() or get_next_child(), or NULL if the last child has been returned. Can be used with get_first_child() to return the complete list of children without using the iterator class; however, this is non- thread-safe, and so is not recommended except for languages other than C++ which cannot use the iterators.

It is an error to call this without previously calling get_first_child().

bool has_absolute_pathnames(void) const

Returns true if any nodes at this level and below include a reference to a file via an absolute pathname, or false if all references are relative.

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 is_right(LVector2d const &v1, LVector2d const &v2)

Returns true if the 2-d v1 is to the right of v2.

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.

void make_point_primitives(void)

Creates PointLight primitives to reference any otherwise unreferences vertices discovered in this group or below.

void mesh_triangles(int flags)

Combine triangles together into triangle strips, at this group and below.

void post_apply_flat_attribute(bool recurse)

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 recompute_polygon_normals(CoordinateSystem cs = ::CS_default)

Recomputes all the polygon normals for polygon geometry at this group node and below so that they accurately reflect the vertex positions. Normals are removed from the vertices and defined only on polygons, giving the geometry a faceted appearance.

This function also removes degenerate polygons that do not have enough vertices to define a normal. It does not affect normals for other kinds of primitives like Nurbs or Points.

This function does not remove or adjust vertices in the vertex pool; it only adds new vertices with the normals removed. Thus, it is a good idea to call remove_unused_vertices() after calling this.

bool recompute_tangent_binormal(GlobPattern const &uv_name)
bool recompute_tangent_binormal(vector_string const &names)

This function recomputes the tangent and binormal for the named texture coordinate set for all vertices at this level and below. Use the empty string for the default texture coordinate set.

It is necessary for each vertex to already have a normal (or at least a polygon normal), as well as a texture coordinate in the named texture coordinate set, before calling this function. You might precede this with recompute_vertex_normals() to ensure that the normals exist.

Like recompute_vertex_normals(), this function does not remove or adjust vertices in the vertex pool; it only adds new vertices with the new tangents and binormals computed. Thus, it is a good idea to call remove_unused_vertices() after calling this.

This function recomputes the tangent and binormal for the named texture coordinate sets. Returns true if anything was done.

bool recompute_tangent_binormal_auto(void)

This function recomputes the tangent and binormal for any texture coordinate set that affects a normal map. Returns true if anything was done.

void recompute_vertex_normals(double threshold, CoordinateSystem cs = ::CS_default)

Recomputes all the vertex normals for polygon geometry at this group node and below so that they accurately reflect the vertex positions. A shared edge between two polygons (even in different groups) is considered smooth if the angle between the two edges is less than threshold degrees.

This function also removes degenerate polygons that do not have enough vertices to define a normal. It does not affect normals for other kinds of primitives like Nurbs or Points.

This function does not remove or adjust vertices in the vertex pool; it only adds new vertices with the correct normals. Thus, it is a good idea to call remove_unused_vertices() after calling this.

PointerTo<EggNode> remove_child(EggNode *node)

Removes the indicated child node from the group and returns it. If the child was not already in the group, does nothing and returns NULL.

int remove_invalid_primitives(bool recurse)

Removes primitives at this level and below which appear to be degenerate; e.g. polygons with fewer than 3 vertices, etc. Returns the number of primitives removed.

int remove_unused_vertices(bool recurse)

Removes all vertices from VertexPools within this group or below that are not referenced by at least one primitive. Also collapses together equivalent vertices, and renumbers all vertices after the operation so their indices are consecutive, beginning at zero. Returns the total number of vertices removed.

Note that this operates on the VertexPools within this group level, without respect to primitives that reference these vertices (unlike other functions like strip_normals()). It is therefore most useful to call this on the EggData root, rather than on a subgroup within the hierarchy, since a VertexPool may appear anywhere in the hierarchy.

int rename_nodes(vector_string strip_prefix, bool recurse)

Rename by stripping out the prefix

void resolve_filenames(DSearchPath const &searchpath)

Walks the tree and attempts to resolve any filenames encountered. This looks up filenames along the specified search path; it does not automatically search the model_path for missing files.

void reverse_vertex_ordering(void)

Reverses the vertex ordering of all polygons defined at this node and below. Does not change the surface normals, if any.

size_type size(void) const
void steal_children(EggGroupNode &other)

Moves all the children from the other node to this one. This is especially useful because the group node copy assignment operator does not copy children.

void strip_normals(void)

Removes all normals from primitives, and the vertices they reference, at this node and below.

This function does not remove or adjust vertices in the vertex pool; it only adds new vertices with the normal removed. Thus, it is a good idea to call remove_unused_vertices() after calling this.

int triangulate_polygons(int flags)

Replace all higher-order polygons at this point in the scene graph and below with triangles. Returns the total number of new triangles produced, less degenerate polygons removed.

If flags contains T_polygon and T_convex, both concave and convex polygons will be subdivided into triangles; with only T_polygon, only concave polygons will be subdivided, and convex polygons will be largely unchanged.

void unify_attributes(bool use_connected_shading, bool allow_per_primitive, bool recurse)

Applies per-vertex normal and color to all vertices, if they are in fact per-vertex (and different for each vertex), or moves them to the primitive if they are all the same.

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

If use_connected_shading is true, each polygon is considered in conjunction with all connected polygons; otherwise, each polygon is considered individually.

If allow_per_primitive is false, S_per_face or S_overall will treated like S_per_vertex: normals and colors will always be assigned to the vertices. In this case, there will never be per-primitive colors or normals after this call returns. On the other hand, if allow_per_primitive is true, then S_per_face means that normals and colors should be assigned to the primitives, and removed from the vertices, as described above.

This may create redundant vertices in the vertex pool, so it may be a good idea to follow this up with remove_unused_vertices().