Refactor water reflection target size calculation in viewport-host.ts

This commit is contained in:
2026-04-07 06:42:36 +02:00
parent a9ca100c3d
commit 0624f2ae96

View File

@@ -3019,14 +3019,18 @@ export class ViewportHost {
} }
private createWaterReflectionRenderTarget() { private createWaterReflectionRenderTarget() {
const width = Math.max(128, Math.round((this.container?.clientWidth ?? this.renderer.domElement.width || 512) * 0.5)); const canvasWidth = this.container?.clientWidth ?? this.renderer.domElement.width;
const height = Math.max(128, Math.round((this.container?.clientHeight ?? this.renderer.domElement.height || 512) * 0.5)); const canvasHeight = this.container?.clientHeight ?? this.renderer.domElement.height;
const width = Math.max(128, Math.round(Math.max(canvasWidth, 512) * 0.5));
const height = Math.max(128, Math.round(Math.max(canvasHeight, 512) * 0.5));
return new WebGLRenderTarget(width, height); return new WebGLRenderTarget(width, height);
} }
private resizeWaterReflectionTargets() { private resizeWaterReflectionTargets() {
const width = Math.max(128, Math.round((this.container?.clientWidth ?? this.renderer.domElement.width || 512) * 0.5)); const canvasWidth = this.container?.clientWidth ?? this.renderer.domElement.width;
const height = Math.max(128, Math.round((this.container?.clientHeight ?? this.renderer.domElement.height || 512) * 0.5)); const canvasHeight = this.container?.clientHeight ?? this.renderer.domElement.height;
const width = Math.max(128, Math.round(Math.max(canvasWidth, 512) * 0.5));
const height = Math.max(128, Math.round(Math.max(canvasHeight, 512) * 0.5));
for (const binding of this.viewportWaterSurfaceBindings) { for (const binding of this.viewportWaterSurfaceBindings) {
binding.reflectionRenderTarget?.setSize(width, height); binding.reflectionRenderTarget?.setSize(width, height);