# SceneGraphReducer

from pandac.PandaModules import SceneGraphReducer

Class : SceneGraphReducer
Description : An interface for simplifying ("flattening") scene graphs by eliminating unneeded nodes and collapsing out unneeded state changes and transforms.
This class is designed so that it may be inherited from and specialized, if needed, to fine-tune the flattening behavior, but normally the default behavior is sufficient.

## Inheritance:

SceneGraphReducer:

## Methods of SceneGraphReducer:

applyAttribs
clearGsg
collectVertexData
flatten
getCombineRadius
getGsg
makeNonindexed
premunge
removeColumn
setCombineRadius
setGsg
unify

## Constants in SceneGraphReducer:

TTTransform | (AttribTypes)
TTColor | (AttribTypes)
TTColorScale | (AttribTypes)
TTTexMatrix | (AttribTypes)
TTClipPlane | (AttribTypes)
TTCullFace | (AttribTypes)
TTOther | (AttribTypes)
CSGeomNode | (CombineSiblings)
CSWithinRadius | (CombineSiblings)
CSOther | (CombineSiblings)
CSRecurse | (CombineSiblings)
CVDName | (CollectVertexData)
CVDModel | (CollectVertexData)
CVDTransform | (CollectVertexData)
CVDAvoidDynamic | (CollectVertexData)
CVDOneNodeOnly | (CollectVertexData)
CVDFormat | (CollectVertexData)
CVDUsageHint | (CollectVertexData)
CVDAnimationType | (CollectVertexData)
MNCompositeOnly | (MakeNonindexed)
MNAvoidAnimated | (MakeNonindexed)
MNAvoidDynamic | (MakeNonindexed)

applyAttribs void SceneGraphReducer::apply_attribs(PandaNode *node, int attrib_types = ((~ (TT_clip_plane | TT_cull_face)))); Description: Walks the scene graph, accumulating attribs of the indicated types, applying them to the vertices, and removing them from the scene graph. This has a performance optimization benefit in itself, but is especially useful to pave the way for a call to flatten() and greatly improve the effectiveness of the flattening operation. Multiply instanced geometry is duplicated before the attribs are applied. Of course, this operation does make certain dynamic operations impossible. Description: This flavor of apply_attribs() can be called recursively from within another flatten process (e.g. from PandaNode::apply_attribs_to_vertices()). The parameters were presumably received from a parent SceneGraphReducer object.

clearGsg void SceneGraphReducer::clear_gsg(void); Description: Specifies that no particular GraphicsStateGuardian will be used to guide the optimization. The SceneGraphReducer will instead use config variables such as max-collect-vertices and max-collect-indices.

collectVertexData int SceneGraphReducer::collect_vertex_data(PandaNode *root, int collect_bits = ((~ 0))); Description: Collects all different GeomVertexData blocks that have compatible formats at this node and below into a single, unified block (or at least multiple larger blocks). This is intended to reduce rendering overhead incurred by switching vertex buffers. It can also make a subsequent call to unify() much more effective than it would have been otherwise. The set of bits passed in collect_bits indicates which properties are used to differentiate GeomVertexData blocks. If it is 0, then more blocks will be combined together than if it is nonzero.

flatten int SceneGraphReducer::flatten(PandaNode *root, int combine_siblings_bits); Description: Simplifies the graph by removing unnecessary nodes and nodes. In general, a node (and its parent node) is a candidate for removal if the node has no siblings and the node has no special properties. If combine_siblings_bits is nonzero, some sibling nodes (according to the bits set in combine_siblings_bits) may also be collapsed into a single node. This will further reduce scene graph complexity, sometimes substantially, at the cost of reduced spatial separation. Returns the number of nodes removed from the graph.

getCombineRadius float SceneGraphReducer::get_combine_radius(void) const; Description: Returns the radius that is used in conjunction with CS_within_radius. See set_combine_radius().

getGsg GraphicsStateGuardianBase *SceneGraphReducer::get_gsg(void) const; Description: Returns the particular GraphicsStateGuardian that this object will attempt to optimize to. See set_gsg().

makeNonindexed int SceneGraphReducer::make_nonindexed(PandaNode *root, int nonindexed_bits = ((~ 0))); Description: Converts indexed geometry to nonindexed geometry at the indicated node and below, by duplicating vertices where necessary. The parameter nonindexed_bits is a union of bits defined in SceneGraphReducer::MakeNonindexed, which specifes which types of geometry to avoid making nonindexed.

premunge void SceneGraphReducer::premunge(PandaNode *root, RenderState const *initial_state); Description: Walks the scene graph rooted at this node and below, and uses the indicated GSG to premunge every Geom found to optimize it for eventual rendering on the indicated GSG. If there is no GSG indicated for the SceneGraphReducer, this is a no-op. This operation will also apply to stashed children.

removeColumn int SceneGraphReducer::remove_column(PandaNode *root, InternalName const *column); Description: Removes the indicated data column from any GeomVertexDatas found at the indicated root and below. Returns the number of GeomNodes modified.

setCombineRadius void SceneGraphReducer::set_combine_radius(float combine_radius); Description: Specifies the radius that is used in conjunction with CS_within_radius to decide whether a subgraph's siblings should be combined into a single node or not. If the CS_within_radius bit is included in the combine_siblings_bits parameter passed to flatten, than any nodes whose bounding volume is smaller than the indicated radius will be combined together (as if CS_other were set).

setGsg void SceneGraphReducer::set_gsg(GraphicsStateGuardianBase *gsg); Description: Specifies the particular GraphicsStateGuardian that this object will attempt to optimize to. The GSG may specify parameters such as maximum number of vertices per vertex data, max number of vertices per primitive, and whether triangle strips are preferred. It also affects the types of vertex column data that is created by premunge().

unify void SceneGraphReducer::unify(PandaNode *root, bool preserve_order); Description: Calls unify() on every GeomNode at this level and below. This attempts to reduce the total number of individual Geoms and GeomPrimitives by combining these objects wherever possible. See GeomNode::unify().