Pausing the render loop

I am trying to make a custom render loop to skip rendering when there are no user interactions or animations going. I found this post on the old forum;

using “_activeAnimatables.length” and “cameraRotation” for animations and camera rotation works fine, but “cameraDirection” seems to not work on its own. I can keep rendering runing while changing camera direction once the render enabeling is triggered by either camera rotation or animations, but not on its own using keyboard for instence;

I could not figure how to disable the PG default renderLoop in an elegant way, so I just set up R key to switch to my custom loop;

https://playground.babylonjs.com/#31SIHA

Try moving with just the arrow keys after switching with R key, and it will not trigger unless it is already triggered by a rotation of the mouse.

I guess the keyboard input is not beeing pulled in the same way as the mouse input, or there is something to do with inertia or something. Is there some other camera info I should pull here to get it to check for camera movement. I could set it up with checking key inputs for instance, but checking directly on the camera would be best to avoid a lot of extra setup for different inputs and the overhead of actualy running that extra code every loop.

Let me know if any if this is unclear, or I need to elaborate on something.

1 Like

Hey!

because keyboard is pulled by the scene during rendering, you need to manually check it with:

camera.inputs.attached.keyboard.checkInputs();

The working example: https://playground.babylonjs.com/#31SIHA#1

1 Like

Awesome. Thanks Deltakosh :slight_smile:

1 Like

Cross-linking another useful thread because it helped me: Render only after user interactions :v:

1 Like