Add tests and update navigation controller deactivation logic

This commit is contained in:
2026-04-11 05:16:53 +02:00
parent 5dbd68e0ce
commit 75d8723565
3 changed files with 97 additions and 2 deletions

View File

@@ -3,6 +3,7 @@ import { Vector3 } from "three";
import type { Vec3 } from "../core/vector";
import type {
NavigationControllerDeactivateOptions,
NavigationController,
RuntimeControllerContext
} from "./navigation-controller";
@@ -83,7 +84,11 @@ export class OrbitVisitorNavigationController implements NavigationController {
this.updateCameraTransform();
}
deactivate(ctx: RuntimeControllerContext): void {
deactivate(
ctx: RuntimeControllerContext,
_options: NavigationControllerDeactivateOptions = {}
): void {
void _options;
ctx.domElement.removeEventListener("pointerdown", this.handlePointerDown);
ctx.domElement.removeEventListener("wheel", this.handleWheel);
ctx.domElement.removeEventListener("contextmenu", this.handleContextMenu);

View File

@@ -342,11 +342,17 @@ export class RuntimeHost {
loadScene(runtimeScene: RuntimeSceneDefinition) {
const requestId = ++this.collisionWorldRequestId;
const preservePointerLockDuringLoad =
this.activeController === this.firstPersonController &&
this.desiredNavigationMode === "firstPerson" &&
document.pointerLockElement === this.domElement;
this.sceneReady = false;
this.runtimeScene = runtimeScene;
this.currentWorld = runtimeScene.world;
this.activeController?.deactivate(this.controllerContext);
this.activeController?.deactivate(this.controllerContext, {
releasePointerLock: !preservePointerLockDuringLoad
});
this.activeController = null;
this.firstPersonController.resetSceneState();
this.orbitVisitorController.resetSceneState();