Help for flattenStrong

Hello, I’ve a problem using flattenStrong: I obtain the same performances with or without its invocation. It’s a simple application which creates a lot of cubes and then tries to flat them; where is my error? Here’s the code with resources. Very thanks!

from panda3d.core import TextureStage
from panda3d.core import loadPrcFileData
loadPrcFileData( '', 'want-pstats 1' )
loadPrcFileData( '', 'show-frame-rate-meter #t' )
import direct.directbase.DirectStart, itertools
base.disableMouse()
camera.setPosHpr( ( 20, -30, 50 ), ( 0, -48, 0) )
rootNode = render.attachNewNode( 'rootNode' )
for i, j in itertools.product( range( 40 ), range( 40 ) ):
  model = loader.loadModel( 'cube' )
  model.setPosHprScale( ( i, j, 0 ), ( 0, 0, 0 ), .4 )
  model.setTexture( TextureStage( 'ts' ), loader.loadTexture( 'img.jpg' ) )
  model.reparentTo( rootNode )
rootNode.flattenStrong()
run()

Before the flattenStrong you should try:

rootNode.clearModelNodes()

Thank you, I tried, but it doesn’t help so much: I observe 50 ms without clearModelNodes and 40 ms with that.

You are applying a unique TextureStage to each piece, which prevents them from being combined together. Instead of creating a TextureStage(‘ts’) within the loop, create it once, outside the loop, and use the same TextureStage object for each piece.

David

Ok, these two hints (TextureStage and clearModelNodes) solve my problem: thank you!