From d103f8075184a131cf62014d71c618b2cede1b11 Mon Sep 17 00:00:00 2001 From: Victor Giers Date: Tue, 31 Mar 2026 05:10:46 +0200 Subject: [PATCH] Refactor runtime scene build and viewport host --- src/runtime-three/runtime-scene-build.ts | 14 ++------------ src/viewport-three/viewport-host.ts | 6 +++--- 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/src/runtime-three/runtime-scene-build.ts b/src/runtime-three/runtime-scene-build.ts index 890284ea..f1fcd8cb 100644 --- a/src/runtime-three/runtime-scene-build.ts +++ b/src/runtime-three/runtime-scene-build.ts @@ -1,6 +1,7 @@ import type { Vec3 } from "../core/vector"; import type { BoxBrush, BoxFaceId, FaceUvState } from "../document/brushes"; import type { SceneDocument, WorldSettings } from "../document/scene-document"; +import { cloneWorldSettings } from "../document/world-settings"; import { getPrimaryPlayerStartEntity } from "../entities/entity-instances"; import { getBoxBrushBounds } from "../geometry/box-brush"; import { cloneMaterialDef, type MaterialDef } from "../materials/starter-material-library"; @@ -213,18 +214,7 @@ export function buildRuntimeSceneFromDocument(document: SceneDocument, options: }; return { - world: { - background: { - ...document.world.background - }, - ambientLight: { - ...document.world.ambientLight - }, - sunLight: { - ...document.world.sunLight, - direction: cloneVec3(document.world.sunLight.direction) - } - }, + world: cloneWorldSettings(document.world), brushes, colliders, sceneBounds, diff --git a/src/viewport-three/viewport-host.ts b/src/viewport-three/viewport-host.ts index 986f25ff..c7688657 100644 --- a/src/viewport-three/viewport-host.ts +++ b/src/viewport-three/viewport-host.ts @@ -3,7 +3,6 @@ import { AxesHelper, BoxGeometry, CanvasTexture, - Color, ConeGeometry, CylinderGeometry, DirectionalLight, @@ -71,7 +70,7 @@ interface PlayerStartRenderObjects { export class ViewportHost { private readonly scene = new Scene(); private readonly camera = new PerspectiveCamera(60, 1, 0.1, 1000); - private readonly renderer = new WebGLRenderer({ antialias: true }); + private readonly renderer = new WebGLRenderer({ antialias: true, alpha: true }); private readonly cameraTarget = new Vector3(0, 0, 0); private readonly cameraOffset = new Vector3(); private readonly cameraForward = new Vector3(); @@ -137,6 +136,7 @@ export class ViewportHost { this.scene.add(this.boxCreatePreviewMesh); this.scene.add(this.boxCreatePreviewEdges); this.renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2)); + this.renderer.setClearAlpha(0); } mount(container: HTMLElement) { @@ -161,7 +161,7 @@ export class ViewportHost { } updateWorld(world: WorldSettings) { - this.scene.background = new Color(world.background.colorHex); + this.scene.background = null; this.ambientLight.color.set(world.ambientLight.colorHex); this.ambientLight.intensity = world.ambientLight.intensity; this.sunLight.color.set(world.sunLight.colorHex);