Which Best Method for Mesh Rendering (Updated Every Frame)

Hello guys ,

As i unity developer i just want to ask a quick question

Which method in mesh class Match update function in unity … What it means i want each mesh to have it’s own update method rather use scene.registerBeforeRender() Which controls every update/render happens in the scene

I’ve used those func’s

mesh.onBeforeDrawObservable()

mesh.onAfterRenderObservable()

But Explicitly i don’t know if it’s best choice or not and i have little problem with it … cuz those methods can’t be executed behind camera view (the mesh must be in the view of camera to allow those type of functions to be executed)

so guys what do u think ?
 Thanks in advance

Hey and welcome!!

Well these observables are fine but as you said they are only called if the mesh is in the render queue.

in you case I will suggest to add your own update method to your meshes:

myMesh.update = () => {
...
}

and then inside the scene.registerBeforeRender:

scene.registerBeforeRender(() => {
 scene.meshes.forEach(m => {
  if (m.update) {
    m.update();
  }
 });
});
1 Like

Well said… thx for quick replay,

I have tried to make this solution before ,But Explicitly i was Concern about Foreach loop that will be run in Renderfunction (that’s executed every frame) for all meshes in the scene Whether it contains updateFunction or not
of course we can optimize this by pushing all updatedmesh ( that have updateFunction) in array and handle it rather than scene.meshes

But i would to discuss the subject in general !!
-Do u thought execute all updated mesh in one function that also controls scene rendering
will effect on performance?
-Which is best approach should i follow to control scene like this (scene with updated meshes)

Thanks in advance

Haha I completely get your concern but now that you are on the web you have to know that there is only ONE thread. So calling update there or anywhere else will have no impact at all :slight_smile:
This is not like in Unity where they are lucky enough to have threads

Aha,So do u mean foreach solution similar onBeforeDrawObservable or any solution will run every frame
both will execute in the same thread and so there wont be difference in performance right ?

that is totally correct

1 Like