Refactor runtime scene build and viewport host

This commit is contained in:
2026-03-31 05:10:46 +02:00
parent b7fedf3413
commit d103f80751
2 changed files with 5 additions and 15 deletions

View File

@@ -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,

View File

@@ -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);