Right. So in the before times, if you had three geometries
g0: [position, uv, normal, INSTANCE_A]
g1: [position, uv, normal, INSTANCE_B]
g2: [position, uv, normal, INSTANCE_C]
And you render these in three meshes, three would make 12 calls to bind stuff which was sub optimal. It would go, “oh, here is a new geometry, let me bind all of its buffers”.
Modern three however, should be a lot better about this. Basically, if you call these three meshes one after another, only the INSTANCE_*
attribute should be bound multiple times, the first three will be bound once.
However, i don’t think that this was ever that detrimental to performance. You dont have 10000 meshes, you have one instanced mesh.
You have to keep your A,B,C in memory anyway, unless you are expecting something else to happen with your code. So, creating three geometries, is a valid solution.
The project I am working on is quite big and it would require some time to implement non-onBeforeRender approach.
This is not true.
- Find where
renderer.render(scene,camera)
is happening, it has to be happening somewhere, otherwise you are not even calling theonBeforeRender
- before that call add this:
scene.traverse(o=>{
if(o instanceof Mesh){
if(typeof o.userData.MY_ON_BEFORE_RENDER === 'function'){
o.userData.MY_ON_BEFORE_RENDER(renderer,scene,camera,elephant,taylorSwift...)
}
}
})
Your other code
- this.onBeforeRender = myOnBeforeRender
+ this.userData.MY_ON_BEFORE_RENDER = myOnBeforeRender
EDIT
Right, i forgot, instead of changing the buffers you can try this
this.userData.MY_ON_BEFORE_RENDER = ()=>{
this.geometry = geometries[myIndex.value]
}