I’m going through the code in the BabylonJS and React tutorial here:
I’m actually using Gatsby as the site generator (or will be), as its a portfolio/demo site and mostly static, and I can use APIs for whatever external data I use. I’m just trying to understand the tutorial code itself.
I really can’t use Playground for this, obviously, but my questions are general API/react based.
First, the 3rd parameter for the Engine object from the Babylonjs API is engineOptions. In the Babylon/react tutorial, in the SceneComponent.jsx code, there is a new Engine declared with engineOptions passed to it.
const { antialias, engineOptions, adaptToDeviceRatio, sceneOptions, onRender, onSceneReady, ...rest } = props;
const engine = new Engine(reactCanvas.current, antialias, engineOptions, adaptToDeviceRatio);
The engineOptions appears to be from props passed to SceneComponent by the index.js, which is the parent: (also copied from the tutorial)
<SceneComponent antialias onSceneReady={onSceneReady} onRender={onRender} id='my-canvas' />
Only here, I don’t see engineProps passed in to the component. The Engine API doesn’t refer to it specifically as boolean, so I’m not sure how this defines any options. The page doesn’t throw any error, and (except an ESLINt warning about missing dependencies) I see the box spinning the way it should be run from my local server.
So the way I’m reading this is, the component is insuring that all the props that may be needed for the the canvas element are passed in, but just not all of them are necessarily declared with a value in the index file, and this itself does not cause an error. Is that correct? My understanding of React is still in development mode, but I feel I have a basic grasp of the principles. How is Engine treating this?
Also, I also want to make sure I understand whats creating the render loop. {this is where I expose my lack of understanding of how the render loop works) Any update to the DOM will trigger the useEffect React hook in the SceneComponent code . Is it the function updating the Y rotation in the index.js file, that keeps triggering DOM updates, that keeps the loop going? (combined with the engine.runRenderLoop in the component code?).
This is hard because there are so many APIs to deal with at once. Babylon, React, not to mention whatever Gatsby is doing(routing, etc). I dont want to just copy and paste, because that will limit my creation and at some point I’m going to get stuck with zero basis for knowing what to target as the problem. I’m going to be creating a variety of interactive Babylon.js pages, so I’m going to be declaring SceneComponent multiple times, and I’ll have to extract all that into component trees I suppose. But first things first. Thanks anyone who has React knowledge or insight on this.