I’m currently working on creating a camera (“Museum”) mode where, when the mode is toggled with a button click, the one ArcRotateCamera in the scene slowly, continuously rotates around its centerpoint. I have the button toggling the Redux state correctly, my handler is correctly printing the state, and the rotation motion is functioning as expected once turned on, but I can’t get it to turn off.
I’m using registerBeforeRender successfully whenever the Museum mode is toggled on, but unable to use unregisterBeforeRender when Museum mode is toggled off. Am I misunderstanding how to use it? (Note that I’ve tried to use unregisterBeforeRender in a conditional part of my registerBeforeRender function, a style which I’ve seen a couple places online, and I’ve tried to have registerBeforeRender and unregisterBeforeRender get called separately depending on my mode boolean:
let previousState: StateProps = {
museumModeOn: false
};
function stateChangeHandler(
state: StateProps,
manager: C.StateManager,
dispatcher: DispatcherProps,
scene: BABYLON.Scene
): void {
if (previousState.museumModeOn !== state.museumModeOn) {
// Register a function that rotates the ArcRotateCamera on each render when museumModeOn gets toggled to true
scene.registerBeforeRender(function museumRotateCamera() {
if (state.museumModeOn) {
if (state.camera != null) {
state.camera.useAutoRotationBehavior = true;
}
}
// Unregister the function when museumModeOn gets toggled off
else {
if (state.camera != null) {
scene.unregisterBeforeRender(museumRotateCamera);
}
}
});
}
}
Hey there, thanks for the response! Can I ask how your suggestion is different than what I’m currently doing in the StateChangeHander, here? Maybe I’m missing something?
Thanks so much for pointing that I can do this while bypassing the registerBeforeRender() function. So clear in retrospect but exactly what I needed. Cheers