From ee83c31f74215f92f8d7e99ba2ed10136a7aacaf Mon Sep 17 00:00:00 2001 From: Victor Giers Date: Tue, 7 Apr 2026 10:52:46 +0200 Subject: [PATCH] Add render enablement control in ViewportHost --- src/viewport-three/viewport-host.ts | 31 ++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/src/viewport-three/viewport-host.ts b/src/viewport-three/viewport-host.ts index cf487ed5..1c35733f 100644 --- a/src/viewport-three/viewport-host.ts +++ b/src/viewport-three/viewport-host.ts @@ -347,6 +347,7 @@ export class ViewportHost { ); private resizeObserver: ResizeObserver | null = null; private animationFrame = 0; + private renderEnabled = false; private container: HTMLElement | null = null; private brushSelectionChangeHandler: ((selection: EditorSelection) => void) | null = null; private whiteboxHoverLabelChangeHandler: ((label: string | null) => void) | null = null; @@ -447,7 +448,30 @@ export class ViewportHost { }); this.resizeObserver.observe(container); - this.render(); + if (this.renderEnabled) { + this.render(); + } + } + + setRenderEnabled(enabled: boolean) { + if (this.renderEnabled === enabled) { + return; + } + + this.renderEnabled = enabled; + + if (!enabled) { + if (this.animationFrame !== 0) { + cancelAnimationFrame(this.animationFrame); + this.animationFrame = 0; + } + this.previousFrameTime = 0; + return; + } + + if (this.container !== null && this.animationFrame === 0) { + this.render(); + } } updateWorld(world: WorldSettings) { @@ -4427,6 +4451,11 @@ export class ViewportHost { } private render = () => { + if (!this.renderEnabled) { + this.animationFrame = 0; + return; + } + this.animationFrame = window.requestAnimationFrame(this.render); this.updateTransformGizmoPose(); const now = performance.now();