brianzinn / react-babylonjs

React for Babylon 3D engine
https://brianzinn.github.io/react-babylonjs/
812 stars 102 forks source link

Non-Declarative version does double render #204

Closed GlebVST closed 2 years ago

GlebVST commented 2 years ago

Hi,

While profiling an app that's using this lib (pretty dated on version though) with non-declarative approach described here in the docs have figured out there is double rendering going on due to a call to scene.render() inside the loop onSceneMount!

Was scratching my head why the FPS doesn't go higher than 33%!

I though maybe newer versions has this fixed but looking at corresponding example shows the same double rendering:

2022-02-22 05 16 16 PM

Maybe fix the example and put some alert in the docs?

Best regards, Gleb

brianzinn commented 2 years ago

TIL that there can be multiple render loop functions. Thanks for bringing this up. I updated ironically yesterday on master a new Engine component. It's not on NPM yet, but it allows much finer control. Additionally, since the original version you reference there are hooks for onBeforeRender and onAfterRender that run in the existing render loop. Here is the babylon code that schooled me as well - I had mistakenly thought there was a single runRenderLoop, but it's a list: https://github.com/BabylonJS/Babylon.js/blob/ac1eb10bf5198373a33c1a0015581037c313e95a/src/Engines/thinEngine.ts#L1564

brianzinn commented 2 years ago

@GlebVST - Looks like when adding your own render loop that it should be preceded by

// calling this with no parameter will clear the active render loops
engine.stopRenderLoop();

https://github.com/BabylonJS/Babylon.js/blob/ac1eb10bf5198373a33c1a0015581037c313e95a/src/Engines/thinEngine.ts#L1443

brianzinn commented 2 years ago

I will update the examples - please re-open if you have additional questions or comments. (closing for inactivity)