Could make a standard requestAnimationFrame loop, and then do something like this:
shouldRender = false
shouldRender = gameUpdate(delta) // returns true if we need to render
if (shouldRender) {
scene.render()
}
Then game update returns true if the camera was moved this frame. This would only work if everything is created all at once at the start and the camera is the only object that could move. Moving, creating, or destroying other objects would need to trigger a render as well – or they would end up invisible until the camera moved again.
gameUpdate pseudocode:
shouldRender = false
const inputs = getQueuedInputsFromMouseEtc()
if (inputs) {
moveCamera(inputs)
shouldRender = true // or compare camera.position + rotiation to cached
}
clearInputQueueBecauseWeConsumedItThisFrame()
return shouldRender
Maybe I’m using it the wrong way, but the observable is only called, when the renderloop is running:
If I type into the console (after the scene has loaded) engine.stopRenderLoop() the callback of the observable is not called anymore.
PG: https://playground.babylonjs.com/#KHFLFM#1