Author Topic: How to render a batch of similar object3D effectively?  (Read 1128 times)

Offline kiffa

  • long
  • ***
  • Posts: 199
    • View Profile
How to render a batch of similar object3D effectively?
« on: September 29, 2013, 10:38:32 am »
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:
Code: [Select]

Object3D tree;
for(int i = 0; i < treeNum; ++i){
  trees[i] = tree.cloneObject();

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?
« Last Edit: September 29, 2013, 10:48:58 am by kiffa »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12111
    • View Profile
Re: How to render a batch of similar object3D effectively?
« Reply #1 on: September 29, 2013, 04:55:37 pm »
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.