Need clear explanation on clearmodels, flatten

I noticed that in order to optimize performance, some posts recommend using:

clearModelNodes()
flattenMedium()
flattenstrong()

I’ve been looking around the forum to find a clear explanation on the implication of each of these primitives, and their impact on the data structures and performances.

Could such an explanation be given in a concise way? Thank you

Have you checked out their respective descriptions in the API reference? All of these methods are explained there:
panda3d.org/reference/1.8.0 … dePath.php

I went through the following description and sadly it is still not clear of what this means PRACTICALLY :cry: with the aim of optimizing performances. Any simple guidance to clarify all this?

You didn’t look at the full descriptions.

int clearModelNodes ( )
Recursively walks through the scene graph at this level and below, looking for ModelNodes, and calls model_node->set_preserve_transform(PT_drop_node) on each one.
This allows a subsequent call to flatten_strong() to eliminate all of the ModelNodes.
Returns the number of ModelNodes found.

[Basically, when you call loader.loadModel, a ModelNode is added to the top to prevent the model from being merged with others. If you call clearModelNodes, then this ‘barrier’ if you will will be removed.]

int flattenLight ( )
Lightly flattens out the hierarchy below this node by applying transforms, colors, and texture matrices from the nodes onto the vertices, but does not remove any nodes.
This can result in improved rendering performance because there will be fewer transforms in the resulting scene graph, but the number of nodes will remain the same.
In particular, any NodePaths that reference nodes within this hierarchy will not be damaged. However, since this operation will remove transforms from the scene graph, it may be dangerous to apply to nodes where you expect to dynamically modify the transform, or where you expect the geometry to remain in a particular local coordinate system.
The return value is always 0, since flatten_light does not remove any nodes.

int flattenMedium ( )
A more thorough flattening than flatten_light(), this first applies all the transforms, colors, and texture matrices from the nodes onto the vertices, and then removes unneeded grouping nodes–nodes that have exactly one child, for instance, but have no special properties in themselves.
This results in improved performance over flatten_light() because the number of nodes in the scene graph is reduced.
The return value is the number of nodes removed.

int flattenStrong ( )
The strongest possible flattening.
This first applies all of the transforms to the vertices, as in flatten_medium(), but then it will combine sibling nodes together when possible, in addition to removing unnecessary parent-child nodes. This can result in substantially fewer nodes, but any nicely-grouped hierachical bounding volumes may be lost.
It is generally a good idea to apply this kind of flattening only to nodes that will be culled largely as a single unit, like a car. Applying this to an entire scene may result in overall poorer performance because of less-effective culling.

thank you very much rdb!
this helps better understanding which was not obvious.

about optimizing culling

In term of grouping how does this relate to the size of the object, and the textures applied to it?
thank you again

Optimizing the scene is all about reducing the amount of data you send to the graphics card unnecessarily. There are two competing factors:

(1) The number of individual pieces, or “batches” you send. In panda, this is almost the same thing as the number of Geoms. It costs a certain amount of time to send a single Geom to the graphics card, no matter how many vertices the Geom contains.

(2) The total number of vertices the graphics card has to process (and pixels, and so on). There is a certain amount of effort your graphics card has to spend to process all this data. But most graphics cards can process a lot of vertices.

flattenStrong() works by combining many small Geoms into a few larger Geoms, reducing (1), but inadvertently increasing (2). (2) increases because when you have many small Geoms, Panda can discard the small Geoms that fall entirely outside the viewing region. When you combine those Geoms together with other Geoms, though, then Panda has to send all of the Geoms in a single call.

Usually, (1) is the most important limit, which is why flattenStrong() improves your frame rate. But at some point, (2) becomes the limit instead. The precise balance point depends on a lot of things, especially your particular graphics hardware.

David

thank you drwr the picture is getting clearer :laughing: