@umituz/web-virtual 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +63 -2
- package/package.json +78 -4
- package/src/components/EntityInspector.tsx +224 -0
- package/src/components/EntityPins.tsx +67 -0
- package/src/components/VirtualWorld.tsx +229 -0
- package/src/components/WorldControls.tsx +143 -0
- package/src/components/index.ts +4 -0
- package/src/core/environment.test.ts +55 -0
- package/src/core/environment.ts +120 -0
- package/src/core/events.ts +50 -0
- package/src/core/index.ts +4 -0
- package/src/core/registry.ts +80 -0
- package/src/core/types.ts +170 -0
- package/src/engine/camera.ts +111 -0
- package/src/engine/index.ts +6 -0
- package/src/engine/lighting.ts +81 -0
- package/src/engine/materials.ts +215 -0
- package/src/engine/performance.ts +79 -0
- package/src/engine/raycaster.ts +51 -0
- package/src/engine/renderer.ts +227 -0
- package/src/entities/architecture/OfficeArchitectureBuilder.ts +172 -0
- package/src/entities/furniture/DeskBuilder.ts +280 -0
- package/src/entities/index.ts +4 -0
- package/src/entities/people/AvatarBuilder.ts +116 -0
- package/src/entities/props/PlantBuilder.ts +58 -0
- package/src/index.ts +6 -0
- package/src/presets/factoryPreset.ts +168 -0
- package/src/presets/farmPreset.ts +158 -0
- package/src/presets/hospitalPreset.ts +117 -0
- package/src/presets/index.ts +5 -0
- package/src/presets/officePreset.ts +415 -0
- package/src/presets/schoolPreset.ts +111 -0
- package/src/styles/virtual.css +190 -0
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
import * as THREE from 'three'
|
|
2
|
+
import type { WorldDefinition, WorldEntity, PinDisplayMode, EntitySelectedEvent } from '../core/types'
|
|
3
|
+
import { MaterialPalette } from './materials'
|
|
4
|
+
import { WorldLighting } from './lighting'
|
|
5
|
+
import { WorldCamera, type CameraPresetName } from './camera'
|
|
6
|
+
import { WorldRaycaster } from './raycaster'
|
|
7
|
+
import { PerformanceManager, DirectDOMProjector } from './performance'
|
|
8
|
+
|
|
9
|
+
export interface WorldEngineOptions {
|
|
10
|
+
canvas: HTMLCanvasElement
|
|
11
|
+
world: WorldDefinition
|
|
12
|
+
pinElements?: Map<string, HTMLElement>
|
|
13
|
+
onSelectEntity?: (event: EntitySelectedEvent) => void
|
|
14
|
+
onHoverEntity?: (entity: WorldEntity | null) => void
|
|
15
|
+
onFpsUpdate?: (fps: number) => void
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export class WorldEngine {
|
|
19
|
+
public scene: THREE.Scene
|
|
20
|
+
public renderer: THREE.WebGLRenderer
|
|
21
|
+
public materials: MaterialPalette
|
|
22
|
+
public lighting: WorldLighting
|
|
23
|
+
public cameraSystem: WorldCamera
|
|
24
|
+
public raycaster: WorldRaycaster
|
|
25
|
+
public perfManager: PerformanceManager
|
|
26
|
+
public projector: DirectDOMProjector
|
|
27
|
+
|
|
28
|
+
public interactiveObjects: THREE.Object3D[] = []
|
|
29
|
+
public animators: Array<(delta: number, elapsed: number) => void> = []
|
|
30
|
+
|
|
31
|
+
private isDisposed = false
|
|
32
|
+
private animationFrameId: number | null = null
|
|
33
|
+
private clock = new THREE.Clock()
|
|
34
|
+
private hoveredEntityId: string | null = null
|
|
35
|
+
|
|
36
|
+
constructor(private options: WorldEngineOptions) {
|
|
37
|
+
const { canvas, world } = options
|
|
38
|
+
|
|
39
|
+
this.scene = new THREE.Scene()
|
|
40
|
+
this.scene.background = new THREE.Color(world.theme.backgroundColor || '#0f172a')
|
|
41
|
+
|
|
42
|
+
this.renderer = new THREE.WebGLRenderer({
|
|
43
|
+
canvas,
|
|
44
|
+
antialias: true,
|
|
45
|
+
powerPreference: 'high-performance',
|
|
46
|
+
alpha: false,
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
const width = canvas.parentElement?.clientWidth || window.innerWidth
|
|
50
|
+
const height = canvas.parentElement?.clientHeight || window.innerHeight
|
|
51
|
+
|
|
52
|
+
this.renderer.setSize(width, height)
|
|
53
|
+
this.renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2))
|
|
54
|
+
this.renderer.shadowMap.enabled = world.lighting.shadows !== false
|
|
55
|
+
this.renderer.shadowMap.type = THREE.PCFSoftShadowMap
|
|
56
|
+
this.renderer.toneMapping = THREE.ACESFilmicToneMapping
|
|
57
|
+
this.renderer.toneMappingExposure = 1.05
|
|
58
|
+
|
|
59
|
+
this.materials = new MaterialPalette()
|
|
60
|
+
this.lighting = new WorldLighting(this.scene, world.lighting)
|
|
61
|
+
this.cameraSystem = new WorldCamera(canvas, width / height, world.camera)
|
|
62
|
+
this.raycaster = new WorldRaycaster()
|
|
63
|
+
this.perfManager = new PerformanceManager()
|
|
64
|
+
this.projector = new DirectDOMProjector()
|
|
65
|
+
|
|
66
|
+
this.initEventListeners(canvas)
|
|
67
|
+
this.startLoop()
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
private initEventListeners(canvas: HTMLCanvasElement): void {
|
|
71
|
+
const handlePointerDown = (e: MouseEvent) => {
|
|
72
|
+
if (e.button !== 0) return // Left click only
|
|
73
|
+
const rect = canvas.getBoundingClientRect()
|
|
74
|
+
const hit = this.raycaster.intersect(
|
|
75
|
+
e.clientX,
|
|
76
|
+
e.clientY,
|
|
77
|
+
rect,
|
|
78
|
+
this.cameraSystem.camera,
|
|
79
|
+
this.interactiveObjects,
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
if (hit) {
|
|
83
|
+
const entity = this.options.world.entities.find((en) => en.id === hit.entityId)
|
|
84
|
+
if (entity && this.options.onSelectEntity) {
|
|
85
|
+
this.options.onSelectEntity({
|
|
86
|
+
entity,
|
|
87
|
+
position: entity.position,
|
|
88
|
+
screenPosition: { x: e.clientX, y: e.clientY },
|
|
89
|
+
})
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const handlePointerMove = (e: MouseEvent) => {
|
|
95
|
+
const rect = canvas.getBoundingClientRect()
|
|
96
|
+
const hit = this.raycaster.intersect(
|
|
97
|
+
e.clientX,
|
|
98
|
+
e.clientY,
|
|
99
|
+
rect,
|
|
100
|
+
this.cameraSystem.camera,
|
|
101
|
+
this.interactiveObjects,
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
const hitId = hit ? hit.entityId : null
|
|
105
|
+
if (hitId !== this.hoveredEntityId) {
|
|
106
|
+
this.hoveredEntityId = hitId
|
|
107
|
+
canvas.style.cursor = hitId ? 'pointer' : 'default'
|
|
108
|
+
|
|
109
|
+
if (this.options.onHoverEntity) {
|
|
110
|
+
const entity = hitId
|
|
111
|
+
? this.options.world.entities.find((en) => en.id === hitId) || null
|
|
112
|
+
: null
|
|
113
|
+
this.options.onHoverEntity(entity)
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
canvas.addEventListener('click', handlePointerDown)
|
|
119
|
+
canvas.addEventListener('mousemove', handlePointerMove)
|
|
120
|
+
|
|
121
|
+
// Store unbind callbacks on instance
|
|
122
|
+
this.unbindEvents = () => {
|
|
123
|
+
canvas.removeEventListener('click', handlePointerDown)
|
|
124
|
+
canvas.removeEventListener('mousemove', handlePointerMove)
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
private unbindEvents: () => void = () => {}
|
|
129
|
+
|
|
130
|
+
public resize(width: number, height: number): void {
|
|
131
|
+
if (this.isDisposed || width <= 0 || height <= 0) return
|
|
132
|
+
this.cameraSystem.updateAspect(width / height)
|
|
133
|
+
this.renderer.setSize(width, height)
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
public setNightMode(isNight: boolean): void {
|
|
137
|
+
this.lighting.setNightMode(isNight)
|
|
138
|
+
const bgColor = isNight
|
|
139
|
+
? this.options.world.theme.nightBackgroundColor || '#020617'
|
|
140
|
+
: this.options.world.theme.backgroundColor || '#0f172a'
|
|
141
|
+
this.scene.background = new THREE.Color(bgColor)
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
public setCameraPreset(preset: CameraPresetName): void {
|
|
145
|
+
this.cameraSystem.setPreset(preset)
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
public focusOnEntity(entityId: string): void {
|
|
149
|
+
const entity = this.options.world.entities.find((en) => en.id === entityId)
|
|
150
|
+
if (entity) {
|
|
151
|
+
this.cameraSystem.focusOn(entity.position, 7)
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
public resetCamera(): void {
|
|
156
|
+
this.cameraSystem.reset()
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
private startLoop(): void {
|
|
160
|
+
const loop = () => {
|
|
161
|
+
if (this.isDisposed) return
|
|
162
|
+
|
|
163
|
+
const delta = this.clock.getDelta()
|
|
164
|
+
const elapsed = this.clock.getElapsedTime()
|
|
165
|
+
|
|
166
|
+
// Update camera smooth transitions & controls damping
|
|
167
|
+
this.cameraSystem.update()
|
|
168
|
+
|
|
169
|
+
// Update animations (avatar subtle breathing, active working pulses)
|
|
170
|
+
for (const animator of this.animators) {
|
|
171
|
+
animator(delta, elapsed)
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// Render Three.js scene
|
|
175
|
+
this.renderer.render(this.scene, this.cameraSystem.camera)
|
|
176
|
+
|
|
177
|
+
// Direct GPU CSS translate3d projection for 60fps labels without React re-render
|
|
178
|
+
if (this.options.pinElements && this.options.pinElements.size > 0) {
|
|
179
|
+
const rect = this.renderer.domElement.getBoundingClientRect()
|
|
180
|
+
this.projector.projectEntities(
|
|
181
|
+
this.options.world.entities,
|
|
182
|
+
this.cameraSystem.camera,
|
|
183
|
+
rect.width,
|
|
184
|
+
rect.height,
|
|
185
|
+
this.options.pinElements,
|
|
186
|
+
)
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// Performance monitoring
|
|
190
|
+
const fps = this.perfManager.update()
|
|
191
|
+
if (this.options.onFpsUpdate && Math.random() < 0.05) {
|
|
192
|
+
this.options.onFpsUpdate(fps)
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
this.animationFrameId = requestAnimationFrame(loop)
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
this.animationFrameId = requestAnimationFrame(loop)
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
public dispose(): void {
|
|
202
|
+
this.isDisposed = true
|
|
203
|
+
if (this.animationFrameId !== null) {
|
|
204
|
+
cancelAnimationFrame(this.animationFrameId)
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
this.unbindEvents()
|
|
208
|
+
this.cameraSystem.dispose()
|
|
209
|
+
this.lighting.dispose()
|
|
210
|
+
this.materials.dispose()
|
|
211
|
+
|
|
212
|
+
// Clear meshes and scene
|
|
213
|
+
this.scene.traverse((obj) => {
|
|
214
|
+
if (obj instanceof THREE.Mesh) {
|
|
215
|
+
obj.geometry.dispose()
|
|
216
|
+
if (Array.isArray(obj.material)) {
|
|
217
|
+
obj.material.forEach((m) => m.dispose())
|
|
218
|
+
} else if (obj.material) {
|
|
219
|
+
obj.material.dispose()
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
})
|
|
223
|
+
this.scene.clear()
|
|
224
|
+
|
|
225
|
+
this.renderer.dispose()
|
|
226
|
+
}
|
|
227
|
+
}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import * as THREE from 'three'
|
|
2
|
+
import type { MaterialPalette } from '../../engine/materials'
|
|
3
|
+
import type { WorldTheme } from '../../core/types'
|
|
4
|
+
|
|
5
|
+
export interface ArchitectureOptions {
|
|
6
|
+
width: number
|
|
7
|
+
depth: number
|
|
8
|
+
theme?: WorldTheme
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function buildOfficeArchitecture(
|
|
12
|
+
materials: MaterialPalette,
|
|
13
|
+
options: ArchitectureOptions,
|
|
14
|
+
): THREE.Group {
|
|
15
|
+
const root = new THREE.Group()
|
|
16
|
+
root.name = 'office-architecture'
|
|
17
|
+
|
|
18
|
+
const tileMat = materials.getTileFloor(options.theme?.floorColor || '#e2e8f0')
|
|
19
|
+
const woodMat = materials.getWoodParquet(options.theme?.woodFloorColor || '#b48a58')
|
|
20
|
+
const frameMat = materials.getFrameMaterial(options.theme?.wallFrameColor || '#0f172a')
|
|
21
|
+
const glassMat = materials.getGlassMaterial(
|
|
22
|
+
options.theme?.glassColor || '#93c5fd',
|
|
23
|
+
options.theme?.glassOpacity ?? 0.28,
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
const W = options.width || 36
|
|
27
|
+
const D = options.depth || 20
|
|
28
|
+
|
|
29
|
+
// 1. Flooring
|
|
30
|
+
// Left 65% = Open office tiles
|
|
31
|
+
const openW = W * 0.65
|
|
32
|
+
const floorOpen = new THREE.Mesh(new THREE.PlaneGeometry(openW, D), tileMat)
|
|
33
|
+
floorOpen.rotation.x = -Math.PI / 2
|
|
34
|
+
floorOpen.position.set(-W / 2 + openW / 2, 0, 0)
|
|
35
|
+
floorOpen.receiveShadow = true
|
|
36
|
+
root.add(floorOpen)
|
|
37
|
+
|
|
38
|
+
// Right 35% = Executive & Meeting Wood Parquet
|
|
39
|
+
const execW = W * 0.35
|
|
40
|
+
const floorExec = new THREE.Mesh(new THREE.PlaneGeometry(execW, D), woodMat)
|
|
41
|
+
floorExec.rotation.x = -Math.PI / 2
|
|
42
|
+
floorExec.position.set(W / 2 - execW / 2, 0.002, 0) // slightly offset to prevent z-fighting
|
|
43
|
+
floorExec.receiveShadow = true
|
|
44
|
+
root.add(floorExec)
|
|
45
|
+
|
|
46
|
+
// Subtle floor grid on open area
|
|
47
|
+
const gridHelper = new THREE.GridHelper(openW, Math.round(openW / 2), 0x94a3b8, 0xcbd5e1)
|
|
48
|
+
gridHelper.position.set(-W / 2 + openW / 2, 0.004, 0)
|
|
49
|
+
root.add(gridHelper)
|
|
50
|
+
|
|
51
|
+
// 2. Outer Perimeter Glass Walls & Dark Structural Columns
|
|
52
|
+
const H = 3.6
|
|
53
|
+
|
|
54
|
+
// Helper for framed glass panel
|
|
55
|
+
const createGlassWall = (width: number, height: number): THREE.Group => {
|
|
56
|
+
const wallGroup = new THREE.Group()
|
|
57
|
+
|
|
58
|
+
// Glass sheet
|
|
59
|
+
const glass = new THREE.Mesh(new THREE.PlaneGeometry(width, height), glassMat)
|
|
60
|
+
glass.position.set(0, height / 2, 0)
|
|
61
|
+
wallGroup.add(glass)
|
|
62
|
+
|
|
63
|
+
// Bottom rail
|
|
64
|
+
const botRail = new THREE.Mesh(new THREE.BoxGeometry(width, 0.08, 0.06), frameMat)
|
|
65
|
+
botRail.position.set(0, 0.04, 0)
|
|
66
|
+
botRail.castShadow = true
|
|
67
|
+
wallGroup.add(botRail)
|
|
68
|
+
|
|
69
|
+
// Top rail
|
|
70
|
+
const topRail = new THREE.Mesh(new THREE.BoxGeometry(width, 0.08, 0.06), frameMat)
|
|
71
|
+
topRail.position.set(0, height - 0.04, 0)
|
|
72
|
+
topRail.castShadow = true
|
|
73
|
+
wallGroup.add(topRail)
|
|
74
|
+
|
|
75
|
+
// Vertical Mullions every 3 meters
|
|
76
|
+
const mullionCount = Math.max(1, Math.floor(width / 3))
|
|
77
|
+
const step = width / (mullionCount + 1)
|
|
78
|
+
for (let i = 1; i <= mullionCount; i++) {
|
|
79
|
+
const mul = new THREE.Mesh(new THREE.BoxGeometry(0.06, height, 0.08), frameMat)
|
|
80
|
+
mul.position.set(-width / 2 + i * step, height / 2, 0)
|
|
81
|
+
mul.castShadow = true
|
|
82
|
+
wallGroup.add(mul)
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return wallGroup
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// North Perimeter Wall
|
|
89
|
+
const northWall = createGlassWall(W, H)
|
|
90
|
+
northWall.position.set(0, 0, -D / 2)
|
|
91
|
+
root.add(northWall)
|
|
92
|
+
|
|
93
|
+
// South Perimeter Wall (Lower front wall for unobstructed view, 1.2m)
|
|
94
|
+
const southWall = createGlassWall(W, 1.2)
|
|
95
|
+
southWall.position.set(0, 0, D / 2)
|
|
96
|
+
root.add(southWall)
|
|
97
|
+
|
|
98
|
+
// West Perimeter Wall
|
|
99
|
+
const westWall = createGlassWall(D, H)
|
|
100
|
+
westWall.rotation.y = Math.PI / 2
|
|
101
|
+
westWall.position.set(-W / 2, 0, 0)
|
|
102
|
+
root.add(westWall)
|
|
103
|
+
|
|
104
|
+
// East Perimeter Wall
|
|
105
|
+
const eastWall = createGlassWall(D, H)
|
|
106
|
+
eastWall.rotation.y = -Math.PI / 2
|
|
107
|
+
eastWall.position.set(W / 2, 0, 0)
|
|
108
|
+
root.add(eastWall)
|
|
109
|
+
|
|
110
|
+
// 3. Central Dividing Glass Partition (between Open Office & Executive Wood Wing)
|
|
111
|
+
const dividerX = -W / 2 + openW
|
|
112
|
+
const divWall = createGlassWall(D, H)
|
|
113
|
+
divWall.rotation.y = Math.PI / 2
|
|
114
|
+
divWall.position.set(dividerX, 0, 0)
|
|
115
|
+
root.add(divWall)
|
|
116
|
+
|
|
117
|
+
// 4. Executive Suite Separation Wall (splitting Meeting Room and CEO Suite)
|
|
118
|
+
const execSplit = createGlassWall(execW, H)
|
|
119
|
+
execSplit.position.set(W / 2 - execW / 2, 0, -1)
|
|
120
|
+
root.add(execSplit)
|
|
121
|
+
|
|
122
|
+
// 5. Cubicle Partitions for Open Office (Modern frosted glass / fabric dividers)
|
|
123
|
+
const cubicleDividerMat = materials.getGlassMaterial('#bfdbfe', 0.45)
|
|
124
|
+
const createCubicleDivider = (len: number): THREE.Group => {
|
|
125
|
+
const cubGroup = new THREE.Group()
|
|
126
|
+
const sheet = new THREE.Mesh(new THREE.BoxGeometry(len, 1.25, 0.04), cubicleDividerMat)
|
|
127
|
+
sheet.position.set(0, 0.625, 0)
|
|
128
|
+
sheet.castShadow = true
|
|
129
|
+
cubGroup.add(sheet)
|
|
130
|
+
|
|
131
|
+
const topCap = new THREE.Mesh(new THREE.BoxGeometry(len, 0.04, 0.05), frameMat)
|
|
132
|
+
topCap.position.set(0, 1.25, 0)
|
|
133
|
+
cubGroup.add(topCap)
|
|
134
|
+
return cubGroup
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// Row 1 divider
|
|
138
|
+
const c1 = createCubicleDivider(12)
|
|
139
|
+
c1.position.set(-W / 2 + 8, 0, -5.2)
|
|
140
|
+
root.add(c1)
|
|
141
|
+
|
|
142
|
+
// Row 2 divider
|
|
143
|
+
const c2 = createCubicleDivider(12)
|
|
144
|
+
c2.position.set(-W / 2 + 8, 0, -0.2)
|
|
145
|
+
root.add(c2)
|
|
146
|
+
|
|
147
|
+
// Row 3 divider
|
|
148
|
+
const c3 = createCubicleDivider(12)
|
|
149
|
+
c3.position.set(-W / 2 + 8, 0, 4.8)
|
|
150
|
+
root.add(c3)
|
|
151
|
+
|
|
152
|
+
// 6. Presentation Digital Whiteboard / Monitor in Conference Room
|
|
153
|
+
const boardGroup = new THREE.Group()
|
|
154
|
+
boardGroup.position.set(W / 2 - 0.1, 1.8, 4.5)
|
|
155
|
+
boardGroup.rotation.y = -Math.PI / 2
|
|
156
|
+
|
|
157
|
+
const boardFrame = new THREE.Mesh(
|
|
158
|
+
new THREE.BoxGeometry(3.6, 1.8, 0.06),
|
|
159
|
+
materials.getFrameMaterial('#0f172a'),
|
|
160
|
+
)
|
|
161
|
+
boardGroup.add(boardFrame)
|
|
162
|
+
|
|
163
|
+
const boardScreen = new THREE.Mesh(
|
|
164
|
+
new THREE.PlaneGeometry(3.5, 1.7),
|
|
165
|
+
materials.getMonitorScreenMaterial(true, '#1e3a8a'),
|
|
166
|
+
)
|
|
167
|
+
boardScreen.position.set(0, 0, 0.032)
|
|
168
|
+
boardGroup.add(boardScreen)
|
|
169
|
+
root.add(boardGroup)
|
|
170
|
+
|
|
171
|
+
return root
|
|
172
|
+
}
|
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
import * as THREE from 'three'
|
|
2
|
+
import type { MaterialPalette } from '../../engine/materials'
|
|
3
|
+
|
|
4
|
+
export function createModernWorkstation(
|
|
5
|
+
materials: MaterialPalette,
|
|
6
|
+
options: {
|
|
7
|
+
entityId?: string
|
|
8
|
+
topColor?: string
|
|
9
|
+
dualMonitor?: boolean
|
|
10
|
+
hasLaptop?: boolean
|
|
11
|
+
} = {},
|
|
12
|
+
): THREE.Group {
|
|
13
|
+
const group = new THREE.Group()
|
|
14
|
+
if (options.entityId) {
|
|
15
|
+
group.userData = { entityId: options.entityId }
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const desktopMat = materials.getDeskTopMaterial(options.topColor || '#f8fafc')
|
|
19
|
+
const legMat = materials.getMetalLegMaterial()
|
|
20
|
+
const bezelMat = materials.getMonitorBezelMaterial()
|
|
21
|
+
const screenMat = materials.getMonitorScreenMaterial(true, '#38bdf8')
|
|
22
|
+
const chairMat = materials.getLeatherMaterial('#334155')
|
|
23
|
+
|
|
24
|
+
// 1. Desktop surface (1.6m x 0.8m x 0.04m)
|
|
25
|
+
const topGeo = new THREE.BoxGeometry(1.6, 0.04, 0.8)
|
|
26
|
+
const topMesh = new THREE.Mesh(topGeo, desktopMat)
|
|
27
|
+
topMesh.position.set(0, 0.74, 0)
|
|
28
|
+
topMesh.castShadow = true
|
|
29
|
+
topMesh.receiveShadow = true
|
|
30
|
+
if (options.entityId) topMesh.userData = { entityId: options.entityId }
|
|
31
|
+
group.add(topMesh)
|
|
32
|
+
|
|
33
|
+
// 2. Desk Legs (T-frame metal legs)
|
|
34
|
+
const legGeo = new THREE.BoxGeometry(0.06, 0.72, 0.7)
|
|
35
|
+
const leftLeg = new THREE.Mesh(legGeo, legMat)
|
|
36
|
+
leftLeg.position.set(-0.7, 0.36, 0)
|
|
37
|
+
leftLeg.castShadow = true
|
|
38
|
+
group.add(leftLeg)
|
|
39
|
+
|
|
40
|
+
const rightLeg = new THREE.Mesh(legGeo, legMat)
|
|
41
|
+
rightLeg.position.set(0.7, 0.36, 0)
|
|
42
|
+
rightLeg.castShadow = true
|
|
43
|
+
group.add(rightLeg)
|
|
44
|
+
|
|
45
|
+
// 3. Ergonomic Chair
|
|
46
|
+
const chairGroup = new THREE.Group()
|
|
47
|
+
chairGroup.position.set(0, 0, 0.5)
|
|
48
|
+
|
|
49
|
+
// Seat
|
|
50
|
+
const seatGeo = new THREE.BoxGeometry(0.48, 0.08, 0.46)
|
|
51
|
+
const seat = new THREE.Mesh(seatGeo, chairMat)
|
|
52
|
+
seat.position.set(0, 0.46, 0)
|
|
53
|
+
seat.castShadow = true
|
|
54
|
+
chairGroup.add(seat)
|
|
55
|
+
|
|
56
|
+
// Backrest
|
|
57
|
+
const backGeo = new THREE.BoxGeometry(0.46, 0.52, 0.06)
|
|
58
|
+
const back = new THREE.Mesh(backGeo, chairMat)
|
|
59
|
+
back.position.set(0, 0.74, 0.2)
|
|
60
|
+
back.rotation.x = -0.1
|
|
61
|
+
back.castShadow = true
|
|
62
|
+
chairGroup.add(back)
|
|
63
|
+
|
|
64
|
+
// Base stand & wheels
|
|
65
|
+
const standGeo = new THREE.CylinderGeometry(0.03, 0.03, 0.42, 8)
|
|
66
|
+
const stand = new THREE.Mesh(standGeo, legMat)
|
|
67
|
+
stand.position.set(0, 0.21, 0)
|
|
68
|
+
chairGroup.add(stand)
|
|
69
|
+
|
|
70
|
+
group.add(chairGroup)
|
|
71
|
+
|
|
72
|
+
// 4. Primary Monitor
|
|
73
|
+
const monitorGroup = new THREE.Group()
|
|
74
|
+
monitorGroup.position.set(options.dualMonitor ? -0.28 : 0, 0.76, -0.22)
|
|
75
|
+
|
|
76
|
+
// Stand
|
|
77
|
+
const mStandGeo = new THREE.BoxGeometry(0.04, 0.28, 0.04)
|
|
78
|
+
const mStand = new THREE.Mesh(mStandGeo, legMat)
|
|
79
|
+
mStand.position.set(0, 0.14, 0)
|
|
80
|
+
monitorGroup.add(mStand)
|
|
81
|
+
|
|
82
|
+
const mBaseGeo = new THREE.CylinderGeometry(0.12, 0.12, 0.015, 16)
|
|
83
|
+
const mBase = new THREE.Mesh(mBaseGeo, legMat)
|
|
84
|
+
mBase.position.set(0, 0.01, 0)
|
|
85
|
+
monitorGroup.add(mBase)
|
|
86
|
+
|
|
87
|
+
// Screen frame
|
|
88
|
+
const frameGeo = new THREE.BoxGeometry(0.68, 0.4, 0.03)
|
|
89
|
+
const frame = new THREE.Mesh(frameGeo, bezelMat)
|
|
90
|
+
frame.position.set(0, 0.32, 0)
|
|
91
|
+
frame.castShadow = true
|
|
92
|
+
if (options.entityId) frame.userData = { entityId: options.entityId }
|
|
93
|
+
monitorGroup.add(frame)
|
|
94
|
+
|
|
95
|
+
// Screen display
|
|
96
|
+
const dispGeo = new THREE.PlaneGeometry(0.64, 0.36)
|
|
97
|
+
const disp = new THREE.Mesh(dispGeo, screenMat)
|
|
98
|
+
disp.position.set(0, 0.32, 0.016)
|
|
99
|
+
if (options.entityId) disp.userData = { entityId: options.entityId }
|
|
100
|
+
monitorGroup.add(disp)
|
|
101
|
+
|
|
102
|
+
group.add(monitorGroup)
|
|
103
|
+
|
|
104
|
+
// 5. Secondary Monitor (Dual Monitor Setup)
|
|
105
|
+
if (options.dualMonitor) {
|
|
106
|
+
const monitor2 = monitorGroup.clone()
|
|
107
|
+
monitor2.position.set(0.35, 0.76, -0.2)
|
|
108
|
+
monitor2.rotation.y = -Math.PI / 8
|
|
109
|
+
group.add(monitor2)
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// 6. Laptop (if enabled)
|
|
113
|
+
if (options.hasLaptop) {
|
|
114
|
+
const laptopGroup = new THREE.Group()
|
|
115
|
+
laptopGroup.position.set(0.45, 0.76, -0.05)
|
|
116
|
+
laptopGroup.rotation.y = -Math.PI / 6
|
|
117
|
+
|
|
118
|
+
const baseG = new THREE.BoxGeometry(0.3, 0.015, 0.2)
|
|
119
|
+
const baseM = new THREE.Mesh(baseG, bezelMat)
|
|
120
|
+
baseM.position.set(0, 0.007, 0)
|
|
121
|
+
laptopGroup.add(baseM)
|
|
122
|
+
|
|
123
|
+
const screenG = new THREE.BoxGeometry(0.3, 0.2, 0.01)
|
|
124
|
+
const scrM = new THREE.Mesh(screenG, bezelMat)
|
|
125
|
+
scrM.position.set(0, 0.1, -0.1)
|
|
126
|
+
scrM.rotation.x = -Math.PI / 12
|
|
127
|
+
laptopGroup.add(scrM)
|
|
128
|
+
|
|
129
|
+
group.add(laptopGroup)
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// 7. Keyboard & Mouse
|
|
133
|
+
const kbGeo = new THREE.BoxGeometry(0.42, 0.01, 0.14)
|
|
134
|
+
const kb = new THREE.Mesh(kbGeo, bezelMat)
|
|
135
|
+
kb.position.set(0, 0.765, 0.08)
|
|
136
|
+
group.add(kb)
|
|
137
|
+
|
|
138
|
+
const mouseGeo = new THREE.BoxGeometry(0.06, 0.015, 0.1)
|
|
139
|
+
const mouse = new THREE.Mesh(mouseGeo, bezelMat)
|
|
140
|
+
mouse.position.set(0.3, 0.765, 0.08)
|
|
141
|
+
group.add(mouse)
|
|
142
|
+
|
|
143
|
+
// 8. Ceramic Coffee Mug
|
|
144
|
+
const mugGeo = new THREE.CylinderGeometry(0.04, 0.035, 0.08, 12)
|
|
145
|
+
const mugMat = materials.getWallMaterial('#ffffff')
|
|
146
|
+
const mug = new THREE.Mesh(mugGeo, mugMat)
|
|
147
|
+
mug.position.set(-0.55, 0.8, -0.1)
|
|
148
|
+
group.add(mug)
|
|
149
|
+
|
|
150
|
+
return group
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export function createExecutiveDesk(
|
|
154
|
+
materials: MaterialPalette,
|
|
155
|
+
options: { entityId?: string } = {},
|
|
156
|
+
): THREE.Group {
|
|
157
|
+
const group = new THREE.Group()
|
|
158
|
+
if (options.entityId) group.userData = { entityId: options.entityId }
|
|
159
|
+
|
|
160
|
+
const woodMat = materials.getExecutiveWoodMaterial()
|
|
161
|
+
const chairMat = materials.getLeatherMaterial('#0f172a')
|
|
162
|
+
const bezelMat = materials.getMonitorBezelMaterial()
|
|
163
|
+
const screenMat = materials.getMonitorScreenMaterial(true, '#38bdf8')
|
|
164
|
+
|
|
165
|
+
// Main Executive Table (2.2m x 0.9m)
|
|
166
|
+
const mainGeo = new THREE.BoxGeometry(2.2, 0.08, 0.9)
|
|
167
|
+
const mainTop = new THREE.Mesh(mainGeo, woodMat)
|
|
168
|
+
mainTop.position.set(0, 0.74, 0)
|
|
169
|
+
mainTop.castShadow = true
|
|
170
|
+
if (options.entityId) mainTop.userData = { entityId: options.entityId }
|
|
171
|
+
group.add(mainTop)
|
|
172
|
+
|
|
173
|
+
// Solid Pedestal Bases
|
|
174
|
+
const baseLGeo = new THREE.BoxGeometry(0.3, 0.7, 0.8)
|
|
175
|
+
const baseL = new THREE.Mesh(baseLGeo, woodMat)
|
|
176
|
+
baseL.position.set(-0.85, 0.35, 0)
|
|
177
|
+
baseL.castShadow = true
|
|
178
|
+
group.add(baseL)
|
|
179
|
+
|
|
180
|
+
const baseR = baseL.clone()
|
|
181
|
+
baseR.position.set(0.85, 0.35, 0)
|
|
182
|
+
group.add(baseR)
|
|
183
|
+
|
|
184
|
+
// High-back Executive Leather Chair
|
|
185
|
+
const chair = new THREE.Group()
|
|
186
|
+
chair.position.set(0, 0, 0.65)
|
|
187
|
+
const seatGeo = new THREE.BoxGeometry(0.58, 0.1, 0.54)
|
|
188
|
+
const seat = new THREE.Mesh(seatGeo, chairMat)
|
|
189
|
+
seat.position.set(0, 0.48, 0)
|
|
190
|
+
chair.add(seat)
|
|
191
|
+
|
|
192
|
+
const backGeo = new THREE.BoxGeometry(0.56, 0.8, 0.08)
|
|
193
|
+
const back = new THREE.Mesh(backGeo, chairMat)
|
|
194
|
+
back.position.set(0, 0.88, 0.22)
|
|
195
|
+
back.rotation.x = -0.1
|
|
196
|
+
chair.add(back)
|
|
197
|
+
|
|
198
|
+
group.add(chair)
|
|
199
|
+
|
|
200
|
+
// Executive Curved Ultrawide Display
|
|
201
|
+
const screenGeo = new THREE.BoxGeometry(1.1, 0.45, 0.04)
|
|
202
|
+
const screen = new THREE.Mesh(screenGeo, bezelMat)
|
|
203
|
+
screen.position.set(0, 1.08, -0.2)
|
|
204
|
+
screen.castShadow = true
|
|
205
|
+
group.add(screen)
|
|
206
|
+
|
|
207
|
+
const dispGeo = new THREE.PlaneGeometry(1.06, 0.41)
|
|
208
|
+
const disp = new THREE.Mesh(dispGeo, screenMat)
|
|
209
|
+
disp.position.set(0, 1.08, -0.178)
|
|
210
|
+
group.add(disp)
|
|
211
|
+
|
|
212
|
+
return group
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
export function createConferenceTable(materials: MaterialPalette): THREE.Group {
|
|
216
|
+
const group = new THREE.Group()
|
|
217
|
+
|
|
218
|
+
const woodMat = materials.getExecutiveWoodMaterial()
|
|
219
|
+
const legMat = materials.getMetalLegMaterial()
|
|
220
|
+
const chairMat = materials.getLeatherMaterial('#334155')
|
|
221
|
+
|
|
222
|
+
// Large Conference Table (4.5m x 1.6m)
|
|
223
|
+
const tableGeo = new THREE.BoxGeometry(4.5, 0.08, 1.6)
|
|
224
|
+
const table = new THREE.Mesh(tableGeo, woodMat)
|
|
225
|
+
table.position.set(0, 0.74, 0)
|
|
226
|
+
table.castShadow = true
|
|
227
|
+
table.receiveShadow = true
|
|
228
|
+
group.add(table)
|
|
229
|
+
|
|
230
|
+
// Center cable tray
|
|
231
|
+
const trayGeo = new THREE.BoxGeometry(2.0, 0.01, 0.2)
|
|
232
|
+
const trayMat = materials.getFrameMaterial('#0f172a')
|
|
233
|
+
const tray = new THREE.Mesh(trayGeo, trayMat)
|
|
234
|
+
tray.position.set(0, 0.785, 0)
|
|
235
|
+
group.add(tray)
|
|
236
|
+
|
|
237
|
+
// Heavy pillars
|
|
238
|
+
const pillarGeo = new THREE.CylinderGeometry(0.2, 0.2, 0.7, 16)
|
|
239
|
+
const p1 = new THREE.Mesh(pillarGeo, legMat)
|
|
240
|
+
p1.position.set(-1.4, 0.35, 0)
|
|
241
|
+
group.add(p1)
|
|
242
|
+
|
|
243
|
+
const p2 = new THREE.Mesh(pillarGeo, legMat)
|
|
244
|
+
p2.position.set(1.4, 0.35, 0)
|
|
245
|
+
group.add(p2)
|
|
246
|
+
|
|
247
|
+
// Surround chairs (3 on north, 3 on south, 1 at heads)
|
|
248
|
+
const addChair = (x: number, z: number, rotY: number) => {
|
|
249
|
+
const ch = new THREE.Group()
|
|
250
|
+
ch.position.set(x, 0, z)
|
|
251
|
+
ch.rotation.y = rotY
|
|
252
|
+
|
|
253
|
+
const s = new THREE.Mesh(new THREE.BoxGeometry(0.48, 0.08, 0.44), chairMat)
|
|
254
|
+
s.position.set(0, 0.46, 0)
|
|
255
|
+
ch.add(s)
|
|
256
|
+
|
|
257
|
+
const b = new THREE.Mesh(new THREE.BoxGeometry(0.46, 0.5, 0.06), chairMat)
|
|
258
|
+
b.position.set(0, 0.73, 0.19)
|
|
259
|
+
b.rotation.x = -0.1
|
|
260
|
+
ch.add(b)
|
|
261
|
+
|
|
262
|
+
group.add(ch)
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
// North side
|
|
266
|
+
addChair(-1.3, -1.05, 0)
|
|
267
|
+
addChair(0, -1.05, 0)
|
|
268
|
+
addChair(1.3, -1.05, 0)
|
|
269
|
+
|
|
270
|
+
// South side
|
|
271
|
+
addChair(-1.3, 1.05, Math.PI)
|
|
272
|
+
addChair(0, 1.05, Math.PI)
|
|
273
|
+
addChair(1.3, 1.05, Math.PI)
|
|
274
|
+
|
|
275
|
+
// Heads
|
|
276
|
+
addChair(-2.55, 0, Math.PI / 2)
|
|
277
|
+
addChair(2.55, 0, -Math.PI / 2)
|
|
278
|
+
|
|
279
|
+
return group
|
|
280
|
+
}
|