How to render a batch of similar object3D effectively?

Started by kiffa, September 29, 2013, 10:38:32 AM

Previous topic - Next topic

kiffa

For example, many trees which share the same mesh and the same texture, but have different translations and rotations and need be checked collision dividually(which means I can collide with only one of these trees and don't affect others).

Now I'm doing this like:

Object3D tree;
for(int i = 0; i < treeNum; ++i){
  trees[i] = tree.cloneObject();
  trees[i].translate(xxx);
  world.addObject(trees[i]);
}


But when the treeNum going large, the performance will drop down heavily. Each tree has about 20 tris, there are about 10 - 80 trees on screen.

1, Generally, is this(rendering 10 - 80 objects of 20-tiris ) a problem(with other objects of the scene)?

2, Could I render these trees once(like merging them to one large object3D)but check collision dividually?

EgonOlsen

To a degree, it depends on your definition of 'drops down heavily'. I prefer numbers instead, because from 50 to 40 FPS might be a heavy drop for one, but for me, it's not.

Anyway, rendering 10 additional objects usually isn't that much of a problem but 80 might be. You can minimize state changes and save memory by calling shareCompiledData and shareTextureData on your clones.
Merging them all into one means that collision detection happens against all of them unless you are using completely different meshes for both tasks and switch visibility between rendering and collision detection.