@umituz/web-virtual 1.0.3 → 1.0.5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umituz/web-virtual",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "description": "Universal 3D Virtual Environment Engine for Web & React — Offices, Farms, Factories, Schools, Hospitals with 60fps performance, raycasting and interactive entities.",
5
5
  "type": "module",
6
6
  "main": "./src/index.ts",
@@ -4,7 +4,6 @@ import {
4
4
  useRef,
5
5
  useCallback,
6
6
  useMemo,
7
- useEffect,
8
7
  } from 'react'
9
8
  import {
10
9
  Building2,
@@ -32,7 +32,7 @@ export function EntityPins({
32
32
  className="wv-pin-anchor"
33
33
  style={{ display: 'none' }} // initially hidden until projector places it
34
34
  >
35
- {mode === 'pins' && !isSelected && !isRunning ? (
35
+ {mode === 'pins' && !isSelected ? (
36
36
  <button
37
37
  type="button"
38
38
  className={`wv-pin-circle ${isSelected ? 'is-selected' : ''}`}
@@ -53,10 +53,11 @@ export function EntityPins({
53
53
  e.stopPropagation()
54
54
  onSelectEntity(entity)
55
55
  }}
56
+ title={`${entity.name} (${entity.role || entity.type})`}
56
57
  >
57
58
  <span className={`wv-status-pip ${entity.status || 'idle'}`} />
58
- <span style={{ fontWeight: 700 }}>{pinText}</span>
59
- <span>{entity.pinLabel || entity.name}</span>
59
+ <span style={{ fontWeight: 700, flexShrink: 0 }}>{pinText}</span>
60
+ <span className="wv-pin-label-text">{entity.pinLabel || entity.name}</span>
60
61
  </button>
61
62
  )}
62
63
  </div>
@@ -143,6 +143,15 @@ export const VirtualWorld = forwardRef<VirtualWorldRef, VirtualWorldProps>(
143
143
  }
144
144
  engine.scene.add(avatarGroup)
145
145
 
146
+ // 3. Register all interactive objects with entityId (workstations, chairs, monitors, avatars)
147
+ engine.scene.traverse((obj) => {
148
+ if (obj.userData && obj.userData.entityId) {
149
+ if (!engine.interactiveObjects.includes(obj)) {
150
+ engine.interactiveObjects.push(obj)
151
+ }
152
+ }
153
+ })
154
+
146
155
  // Resize Observer
147
156
  const resizeObserver = new ResizeObserver((entries) => {
148
157
  for (const entry of entries) {
@@ -30,7 +30,11 @@ export class WorldCamera {
30
30
 
31
31
  this.controls = new OrbitControls(this.camera, canvas)
32
32
  this.controls.enableDamping = config.enableDamping ?? true
33
- this.controls.dampingFactor = config.dampingFactor ?? 0.05
33
+ this.controls.dampingFactor = config.dampingFactor ?? 0.08
34
+ this.controls.rotateSpeed = 0.95
35
+ this.controls.zoomSpeed = 1.25
36
+ this.controls.panSpeed = 1.0
37
+ this.controls.screenSpacePanning = true
34
38
  this.controls.maxPolarAngle = config.maxPolarAngle ?? Math.PI / 2 - 0.05
35
39
  this.controls.minDistance = config.minDistance ?? 8
36
40
  this.controls.maxDistance = config.maxDistance ?? 65
@@ -1,3 +1,4 @@
1
+ export * from './textures'
1
2
  export * from './materials'
2
3
  export * from './lighting'
3
4
  export * from './camera'
@@ -7,22 +7,24 @@ export class WorldLighting {
7
7
  private fillLight: THREE.DirectionalLight
8
8
  private nightLight: THREE.DirectionalLight
9
9
  private hemisphereLight: THREE.HemisphereLight
10
+ private execSpot: THREE.SpotLight
11
+ private confSpot: THREE.SpotLight
10
12
 
11
13
  constructor(
12
14
  private scene: THREE.Scene,
13
15
  private config: LightingConfiguration = {},
14
16
  ) {
15
17
  const ambientColor = new THREE.Color(config.ambientColor || '#ffffff')
16
- this.ambientLight = new THREE.AmbientLight(ambientColor, config.ambientIntensity ?? 0.85)
18
+ this.ambientLight = new THREE.AmbientLight(ambientColor, config.ambientIntensity ?? 0.82)
17
19
  this.scene.add(this.ambientLight)
18
20
 
19
- this.hemisphereLight = new THREE.HemisphereLight(0xffffff, 0x444455, 0.4)
21
+ this.hemisphereLight = new THREE.HemisphereLight(0xfffbf5, 0x334155, 0.45)
20
22
  this.hemisphereLight.position.set(0, 50, 0)
21
23
  this.scene.add(this.hemisphereLight)
22
24
 
23
- const sunColor = new THREE.Color(config.sunColor || '#fff5ea')
24
- this.mainSun = new THREE.DirectionalLight(sunColor, config.sunIntensity ?? 1.1)
25
- const sunPos = config.sunPosition || [20, 30, 15]
25
+ const sunColor = new THREE.Color(config.sunColor || '#fff7ed')
26
+ this.mainSun = new THREE.DirectionalLight(sunColor, config.sunIntensity ?? 1.15)
27
+ const sunPos = config.sunPosition || [22, 32, 18]
26
28
  this.mainSun.position.set(sunPos[0], sunPos[1], sunPos[2])
27
29
 
28
30
  if (config.shadows !== false) {
@@ -35,16 +37,29 @@ export class WorldLighting {
35
37
  this.mainSun.shadow.camera.right = 30
36
38
  this.mainSun.shadow.camera.top = 30
37
39
  this.mainSun.shadow.camera.bottom = -30
38
- this.mainSun.shadow.bias = -0.0005
40
+ this.mainSun.shadow.bias = -0.0003
39
41
  }
40
42
  this.scene.add(this.mainSun)
41
43
 
42
- this.fillLight = new THREE.DirectionalLight(0xdbeafe, 0.4)
44
+ this.fillLight = new THREE.DirectionalLight(0xe0f2fe, 0.38)
43
45
  this.fillLight.position.set(-20, 18, -15)
44
46
  this.scene.add(this.fillLight)
45
47
 
48
+ // Warm Architectural Interior Downlights
49
+ this.execSpot = new THREE.SpotLight(0xfef3c7, 0.55, 18, Math.PI / 4, 0.5, 1.2)
50
+ this.execSpot.position.set(11, 7.5, -5.5)
51
+ this.execSpot.target.position.set(11, 0, -5.5)
52
+ this.scene.add(this.execSpot)
53
+ this.scene.add(this.execSpot.target)
54
+
55
+ this.confSpot = new THREE.SpotLight(0xfef3c7, 0.55, 18, Math.PI / 3.5, 0.5, 1.2)
56
+ this.confSpot.position.set(11, 7.5, 2.5)
57
+ this.confSpot.target.position.set(11, 0, 2.5)
58
+ this.scene.add(this.confSpot)
59
+ this.scene.add(this.confSpot.target)
60
+
46
61
  this.nightLight = new THREE.DirectionalLight(
47
- new THREE.Color(config.nightSunColor || '#60a5fa'),
62
+ new THREE.Color(config.nightSunColor || '#38bdf8'),
48
63
  0,
49
64
  )
50
65
  this.nightLight.position.set(-15, 25, 20)
@@ -53,21 +68,25 @@ export class WorldLighting {
53
68
 
54
69
  setNightMode(isNight: boolean): void {
55
70
  if (isNight) {
56
- this.ambientLight.intensity = this.config.nightAmbientIntensity ?? 0.35
71
+ this.ambientLight.intensity = this.config.nightAmbientIntensity ?? 0.3
57
72
  this.ambientLight.color.set(this.config.nightAmbientColor || '#1e293b')
58
- this.mainSun.intensity = 0.15
73
+ this.mainSun.intensity = 0.1
59
74
  this.mainSun.color.set('#3b82f6')
60
75
  this.fillLight.intensity = 0.1
61
- this.nightLight.intensity = this.config.nightSunIntensity ?? 0.5
76
+ this.nightLight.intensity = this.config.nightSunIntensity ?? 0.6
62
77
  this.hemisphereLight.intensity = 0.15
78
+ this.execSpot.intensity = 0.8
79
+ this.confSpot.intensity = 0.8
63
80
  } else {
64
- this.ambientLight.intensity = this.config.ambientIntensity ?? 0.85
81
+ this.ambientLight.intensity = this.config.ambientIntensity ?? 0.82
65
82
  this.ambientLight.color.set(this.config.ambientColor || '#ffffff')
66
- this.mainSun.intensity = this.config.sunIntensity ?? 1.1
67
- this.mainSun.color.set(this.config.sunColor || '#fff5ea')
68
- this.fillLight.intensity = 0.4
83
+ this.mainSun.intensity = this.config.sunIntensity ?? 1.15
84
+ this.mainSun.color.set(this.config.sunColor || '#fff7ed')
85
+ this.fillLight.intensity = 0.38
69
86
  this.nightLight.intensity = 0
70
- this.hemisphereLight.intensity = 0.4
87
+ this.hemisphereLight.intensity = 0.45
88
+ this.execSpot.intensity = 0.55
89
+ this.confSpot.intensity = 0.55
71
90
  }
72
91
  }
73
92
 
@@ -77,5 +96,9 @@ export class WorldLighting {
77
96
  this.scene.remove(this.fillLight)
78
97
  this.scene.remove(this.nightLight)
79
98
  this.scene.remove(this.hemisphereLight)
99
+ this.scene.remove(this.execSpot)
100
+ this.scene.remove(this.execSpot.target)
101
+ this.scene.remove(this.confSpot)
102
+ this.scene.remove(this.confSpot.target)
80
103
  }
81
104
  }
@@ -1,4 +1,5 @@
1
1
  import * as THREE from 'three'
2
+ import { ProceduralTextureFactory } from './textures'
2
3
 
3
4
  export class MaterialPalette {
4
5
  private materials: Map<string, THREE.Material> = new Map()
@@ -11,22 +12,26 @@ export class MaterialPalette {
11
12
  }
12
13
 
13
14
  // Floors
14
- getTileFloor(color = '#e2e8f0'): THREE.MeshStandardMaterial {
15
+ getTileFloor(color = '#f1f5f9'): THREE.MeshStandardMaterial {
15
16
  return this.getMaterial(`floor:tile:${color}`, () => {
17
+ const tex = ProceduralTextureFactory.getTileFloorTexture()
16
18
  return new THREE.MeshStandardMaterial({
17
19
  color: new THREE.Color(color),
18
- roughness: 0.35,
19
- metalness: 0.05,
20
+ map: tex,
21
+ roughness: 0.28,
22
+ metalness: 0.04,
20
23
  })
21
24
  })
22
25
  }
23
26
 
24
- getWoodParquet(color = '#b48a58'): THREE.MeshStandardMaterial {
27
+ getWoodParquet(color = '#b68957'): THREE.MeshStandardMaterial {
25
28
  return this.getMaterial(`floor:wood:${color}`, () => {
29
+ const tex = ProceduralTextureFactory.getWoodParquetTexture()
26
30
  return new THREE.MeshStandardMaterial({
27
31
  color: new THREE.Color(color),
28
- roughness: 0.45,
29
- metalness: 0.1,
32
+ map: tex,
33
+ roughness: 0.35,
34
+ metalness: 0.06,
30
35
  })
31
36
  })
32
37
  }
@@ -41,6 +46,19 @@ export class MaterialPalette {
41
46
  })
42
47
  }
43
48
 
49
+ // Contact Shadow Material
50
+ getContactShadowMaterial(): THREE.MeshBasicMaterial {
51
+ return this.getMaterial('shadow:contact', () => {
52
+ const shadowTex = ProceduralTextureFactory.getSoftShadowTexture()
53
+ return new THREE.MeshBasicMaterial({
54
+ map: shadowTex,
55
+ transparent: true,
56
+ opacity: 0.7,
57
+ depthWrite: false,
58
+ })
59
+ })
60
+ }
61
+
44
62
  // Walls & Partitions
45
63
  getWallMaterial(color = '#f8fafc'): THREE.MeshStandardMaterial {
46
64
  return this.getMaterial(`wall:${color}`, () => {
@@ -56,23 +74,23 @@ export class MaterialPalette {
56
74
  return this.getMaterial(`frame:${color}`, () => {
57
75
  return new THREE.MeshStandardMaterial({
58
76
  color: new THREE.Color(color),
59
- roughness: 0.3,
60
- metalness: 0.7,
77
+ roughness: 0.25,
78
+ metalness: 0.8,
61
79
  })
62
80
  })
63
81
  }
64
82
 
65
- getGlassMaterial(color = '#93c5fd', opacity = 0.28): THREE.MeshPhysicalMaterial {
83
+ getGlassMaterial(color = '#93c5fd', opacity = 0.24): THREE.MeshPhysicalMaterial {
66
84
  return this.getMaterial(`glass:${color}:${opacity}`, () => {
67
85
  return new THREE.MeshPhysicalMaterial({
68
86
  color: new THREE.Color(color),
69
87
  transparent: true,
70
88
  opacity,
71
- roughness: 0.08,
89
+ roughness: 0.05,
72
90
  metalness: 0.1,
73
- transmission: 0.85,
74
- ior: 1.5,
75
- reflectivity: 0.7,
91
+ transmission: 0.9,
92
+ ior: 1.52,
93
+ reflectivity: 0.8,
76
94
  depthWrite: false,
77
95
  })
78
96
  })
@@ -83,8 +101,8 @@ export class MaterialPalette {
83
101
  return this.getMaterial(`furniture:desktop:${color}`, () => {
84
102
  return new THREE.MeshStandardMaterial({
85
103
  color: new THREE.Color(color),
86
- roughness: 0.4,
87
- metalness: 0.1,
104
+ roughness: 0.35,
105
+ metalness: 0.08,
88
106
  })
89
107
  })
90
108
  }
@@ -93,7 +111,7 @@ export class MaterialPalette {
93
111
  return this.getMaterial('furniture:executive_wood', () => {
94
112
  return new THREE.MeshStandardMaterial({
95
113
  color: new THREE.Color('#382212'),
96
- roughness: 0.3,
114
+ roughness: 0.28,
97
115
  metalness: 0.15,
98
116
  })
99
117
  })
@@ -103,7 +121,7 @@ export class MaterialPalette {
103
121
  return this.getMaterial(`furniture:leather:${color}`, () => {
104
122
  return new THREE.MeshStandardMaterial({
105
123
  color: new THREE.Color(color),
106
- roughness: 0.6,
124
+ roughness: 0.55,
107
125
  metalness: 0.05,
108
126
  })
109
127
  })
@@ -112,7 +130,7 @@ export class MaterialPalette {
112
130
  getMetalLegMaterial(): THREE.MeshStandardMaterial {
113
131
  return this.getMaterial('furniture:metal_legs', () => {
114
132
  return new THREE.MeshStandardMaterial({
115
- color: new THREE.Color('#334155'),
133
+ color: new THREE.Color('#1e293b'),
116
134
  roughness: 0.2,
117
135
  metalness: 0.85,
118
136
  })
@@ -123,16 +141,17 @@ export class MaterialPalette {
123
141
  return this.getMaterial('tech:bezel', () => {
124
142
  return new THREE.MeshStandardMaterial({
125
143
  color: new THREE.Color('#090d16'),
126
- roughness: 0.25,
127
- metalness: 0.75,
144
+ roughness: 0.2,
145
+ metalness: 0.8,
128
146
  })
129
147
  })
130
148
  }
131
149
 
132
- getMonitorScreenMaterial(active = true, color = '#38bdf8'): THREE.MeshBasicMaterial {
133
- return this.getMaterial(`tech:screen:${active}:${color}`, () => {
150
+ getMonitorScreenMaterial(type: 'code' | 'dashboard' | 'charts' = 'dashboard'): THREE.MeshBasicMaterial {
151
+ return this.getMaterial(`tech:screen:${type}`, () => {
152
+ const tex = ProceduralTextureFactory.getScreenTexture(type)
134
153
  return new THREE.MeshBasicMaterial({
135
- color: new THREE.Color(active ? color : '#0f172a'),
154
+ map: tex,
136
155
  })
137
156
  })
138
157
  }
@@ -141,7 +160,7 @@ export class MaterialPalette {
141
160
  return this.getMaterial('nature:ficus_leaves', () => {
142
161
  return new THREE.MeshStandardMaterial({
143
162
  color: new THREE.Color('#15803d'),
144
- roughness: 0.5,
163
+ roughness: 0.45,
145
164
  metalness: 0.05,
146
165
  })
147
166
  })
@@ -157,13 +176,13 @@ export class MaterialPalette {
157
176
  })
158
177
  }
159
178
 
160
- // Avatars / People
179
+ // Realistic Avatars / People
161
180
  getSkinMaterial(color = '#fbcfe8'): THREE.MeshStandardMaterial {
162
181
  return this.getMaterial(`person:skin:${color}`, () => {
163
182
  return new THREE.MeshStandardMaterial({
164
183
  color: new THREE.Color(color),
165
- roughness: 0.6,
166
- metalness: 0.05,
184
+ roughness: 0.5,
185
+ metalness: 0.02,
167
186
  })
168
187
  })
169
188
  }
@@ -172,8 +191,8 @@ export class MaterialPalette {
172
191
  return this.getMaterial(`person:hair:${color}`, () => {
173
192
  return new THREE.MeshStandardMaterial({
174
193
  color: new THREE.Color(color),
175
- roughness: 0.7,
176
- metalness: 0.05,
194
+ roughness: 0.65,
195
+ metalness: 0.04,
177
196
  })
178
197
  })
179
198
  }
@@ -182,8 +201,8 @@ export class MaterialPalette {
182
201
  return this.getMaterial(`person:clothes:${color}`, () => {
183
202
  return new THREE.MeshStandardMaterial({
184
203
  color: new THREE.Color(color),
185
- roughness: 0.65,
186
- metalness: 0.08,
204
+ roughness: 0.6,
205
+ metalness: 0.06,
187
206
  })
188
207
  })
189
208
  }
@@ -200,7 +219,7 @@ export class MaterialPalette {
200
219
  return new THREE.MeshBasicMaterial({
201
220
  color: new THREE.Color(color),
202
221
  transparent: true,
203
- opacity: 0.8,
222
+ opacity: 0.85,
204
223
  })
205
224
  })
206
225
  }
@@ -54,11 +54,14 @@ export class DirectDOMProjector {
54
54
  const el = elementMap.get(entity.id)
55
55
  if (!el) continue
56
56
 
57
- // Head / top of desk elevation offset (+ 1.5 units)
57
+ // Elevation offset above avatar head (chair seated at z offset)
58
+ const isExec = entity.id === 'slot-1' || entity.zoneId === 'executive'
59
+ const seatZ = isExec ? 0.62 : 0.44
60
+
58
61
  this.tempVec.set(
59
62
  entity.position[0],
60
- entity.position[1] + 1.45,
61
- entity.position[2],
63
+ entity.position[1] + 1.6,
64
+ entity.position[2] + seatZ,
62
65
  )
63
66
 
64
67
  this.tempVec.project(camera)
@@ -74,6 +77,7 @@ export class DirectDOMProjector {
74
77
  const screenY = -(this.tempVec.y * halfH) + halfH
75
78
 
76
79
  el.style.transform = `translate3d(${screenX}px, ${screenY}px, 0)`
80
+ el.style.zIndex = String(Math.max(1, Math.round((1 - this.tempVec.z) * 1000)))
77
81
  }
78
82
  }
79
83
  }
@@ -68,8 +68,20 @@ export class WorldEngine {
68
68
  }
69
69
 
70
70
  private initEventListeners(canvas: HTMLCanvasElement): void {
71
+ let pointerDownX = 0
72
+ let pointerDownY = 0
73
+
71
74
  const handlePointerDown = (e: MouseEvent) => {
75
+ pointerDownX = e.clientX
76
+ pointerDownY = e.clientY
77
+ }
78
+
79
+ const handleClick = (e: MouseEvent) => {
72
80
  if (e.button !== 0) return // Left click only
81
+ // If mouse moved more than 6px between mousedown and mouseup/click, it was a camera drag
82
+ const dragDist = Math.hypot(e.clientX - pointerDownX, e.clientY - pointerDownY)
83
+ if (dragDist > 6) return
84
+
73
85
  const rect = canvas.getBoundingClientRect()
74
86
  const hit = this.raycaster.intersect(
75
87
  e.clientX,
@@ -115,12 +127,14 @@ export class WorldEngine {
115
127
  }
116
128
  }
117
129
 
118
- canvas.addEventListener('click', handlePointerDown)
130
+ canvas.addEventListener('pointerdown', handlePointerDown)
131
+ canvas.addEventListener('click', handleClick)
119
132
  canvas.addEventListener('mousemove', handlePointerMove)
120
133
 
121
134
  // Store unbind callbacks on instance
122
135
  this.unbindEvents = () => {
123
- canvas.removeEventListener('click', handlePointerDown)
136
+ canvas.removeEventListener('pointerdown', handlePointerDown)
137
+ canvas.removeEventListener('click', handleClick)
124
138
  canvas.removeEventListener('mousemove', handlePointerMove)
125
139
  }
126
140
  }
@@ -0,0 +1,224 @@
1
+ import * as THREE from 'three'
2
+
3
+ export class ProceduralTextureFactory {
4
+ private static cache: Map<string, THREE.CanvasTexture> = new Map()
5
+
6
+ // 1. Warm Architectural Wood Parquet Texture
7
+ static getWoodParquetTexture(): THREE.CanvasTexture {
8
+ const key = 'tex:wood:parquet'
9
+ if (this.cache.has(key)) return this.cache.get(key)!
10
+
11
+ const canvas = document.createElement('canvas')
12
+ canvas.width = 512
13
+ canvas.height = 512
14
+ const ctx = canvas.getContext('2d')
15
+
16
+ if (ctx) {
17
+ // Base wood tone
18
+ ctx.fillStyle = '#b68957'
19
+ ctx.fillRect(0, 0, 512, 512)
20
+
21
+ const plankHeight = 32
22
+ const numPlanks = 512 / plankHeight
23
+ const tones = ['#b88d5c', '#ae8250', '#c29664', '#a87a48', '#bc9261', '#9f7241']
24
+
25
+ for (let i = 0; i < numPlanks; i++) {
26
+ const y = i * plankHeight
27
+ const tone = tones[i % tones.length] || '#b88d5c'
28
+ ctx.fillStyle = tone
29
+ ctx.fillRect(0, y, 512, plankHeight - 1)
30
+
31
+ // Wood grain micro-fibers
32
+ ctx.fillStyle = 'rgba(0, 0, 0, 0.04)'
33
+ for (let g = 0; g < 4; g++) {
34
+ const gy = y + Math.random() * plankHeight
35
+ ctx.fillRect(0, gy, 512, 1)
36
+ }
37
+
38
+ // Dark bevel seam
39
+ ctx.fillStyle = 'rgba(40, 20, 5, 0.25)'
40
+ ctx.fillRect(0, y + plankHeight - 1, 512, 1)
41
+
42
+ // Vertical plank end joints staggered
43
+ const offset = (i % 3) * 170
44
+ for (let x = offset; x < 512; x += 170) {
45
+ ctx.fillStyle = 'rgba(40, 20, 5, 0.3)'
46
+ ctx.fillRect(x, y, 1, plankHeight)
47
+ }
48
+ }
49
+ }
50
+
51
+ const texture = new THREE.CanvasTexture(canvas)
52
+ texture.wrapS = THREE.RepeatWrapping
53
+ texture.wrapT = THREE.RepeatWrapping
54
+ texture.repeat.set(4, 4)
55
+ this.cache.set(key, texture)
56
+ return texture
57
+ }
58
+
59
+ // 2. Modern Porcelain Floor Tile Texture
60
+ static getTileFloorTexture(): THREE.CanvasTexture {
61
+ const key = 'tex:floor:tile'
62
+ if (this.cache.has(key)) return this.cache.get(key)!
63
+
64
+ const canvas = document.createElement('canvas')
65
+ canvas.width = 512
66
+ canvas.height = 512
67
+ const ctx = canvas.getContext('2d')
68
+
69
+ if (ctx) {
70
+ // Base off-white tile tone
71
+ ctx.fillStyle = '#f1f5f9'
72
+ ctx.fillRect(0, 0, 512, 512)
73
+
74
+ const tileSize = 64
75
+ for (let x = 0; x < 512; x += tileSize) {
76
+ for (let y = 0; y < 512; y += tileSize) {
77
+ // Subtle tone variation
78
+ const shade = (x / tileSize + y / tileSize) % 2 === 0 ? '#f8fafc' : '#f1f5f9'
79
+ ctx.fillStyle = shade
80
+ ctx.fillRect(x, y, tileSize - 1, tileSize - 1)
81
+
82
+ // Grout seam
83
+ ctx.fillStyle = '#cbd5e1'
84
+ ctx.fillRect(x + tileSize - 1, y, 1, tileSize)
85
+ ctx.fillRect(x, y + tileSize - 1, tileSize, 1)
86
+ }
87
+ }
88
+ }
89
+
90
+ const texture = new THREE.CanvasTexture(canvas)
91
+ texture.wrapS = THREE.RepeatWrapping
92
+ texture.wrapT = THREE.RepeatWrapping
93
+ texture.repeat.set(6, 6)
94
+ this.cache.set(key, texture)
95
+ return texture
96
+ }
97
+
98
+ // 3. Realistic Dark-Mode Active Dashboard / Code Screen
99
+ static getScreenTexture(type: 'code' | 'dashboard' | 'charts' = 'dashboard'): THREE.CanvasTexture {
100
+ const key = `tex:screen:${type}`
101
+ if (this.cache.has(key)) return this.cache.get(key)!
102
+
103
+ const canvas = document.createElement('canvas')
104
+ canvas.width = 512
105
+ canvas.height = 288
106
+ const ctx = canvas.getContext('2d')
107
+
108
+ if (ctx) {
109
+ // Screen background
110
+ ctx.fillStyle = '#090d16'
111
+ ctx.fillRect(0, 0, 512, 288)
112
+
113
+ // Top titlebar
114
+ ctx.fillStyle = '#1e293b'
115
+ ctx.fillRect(0, 0, 512, 28)
116
+
117
+ // 3 OS window control dots
118
+ ctx.fillStyle = '#ef4444'
119
+ ctx.beginPath()
120
+ ctx.arc(14, 14, 4, 0, Math.PI * 2)
121
+ ctx.fill()
122
+
123
+ ctx.fillStyle = '#f59e0b'
124
+ ctx.beginPath()
125
+ ctx.arc(28, 14, 4, 0, Math.PI * 2)
126
+ ctx.fill()
127
+
128
+ ctx.fillStyle = '#22c55e'
129
+ ctx.beginPath()
130
+ ctx.arc(42, 14, 4, 0, Math.PI * 2)
131
+ ctx.fill()
132
+
133
+ // Left sidebar
134
+ ctx.fillStyle = '#0f172a'
135
+ ctx.fillRect(0, 28, 48, 260)
136
+
137
+ if (type === 'code') {
138
+ // Code lines
139
+ const colors = ['#c084fc', '#38bdf8', '#4ade80', '#fbbf24', '#f43f5e', '#e2e8f0']
140
+ let curY = 48
141
+ for (let i = 0; i < 14; i++) {
142
+ const indent = 64 + (i % 3) * 24
143
+ const width = 80 + (Math.sin(i * 3.7) * 0.5 + 0.5) * 220
144
+ ctx.fillStyle = colors[i % colors.length] || '#38bdf8'
145
+ ctx.fillRect(indent, curY, width, 8)
146
+ curY += 16
147
+ }
148
+ } else {
149
+ // Dashboard cards & graphs
150
+ // Card 1: Metric stat
151
+ ctx.fillStyle = '#1e293b'
152
+ ctx.fillRect(64, 42, 120, 60)
153
+ ctx.fillStyle = '#38bdf8'
154
+ ctx.fillRect(74, 52, 60, 6)
155
+ ctx.fillStyle = '#4ade80'
156
+ ctx.fillRect(74, 68, 80, 14)
157
+
158
+ // Card 2: Metric stat
159
+ ctx.fillStyle = '#1e293b'
160
+ ctx.fillRect(198, 42, 120, 60)
161
+ ctx.fillStyle = '#a855f7'
162
+ ctx.fillRect(208, 52, 60, 6)
163
+ ctx.fillStyle = '#38bdf8'
164
+ ctx.fillRect(208, 68, 70, 14)
165
+
166
+ // Card 3: Line chart
167
+ ctx.fillStyle = '#1e293b'
168
+ ctx.fillRect(332, 42, 160, 60)
169
+ ctx.strokeStyle = '#38bdf8'
170
+ ctx.lineWidth = 3
171
+ ctx.beginPath()
172
+ ctx.moveTo(344, 85)
173
+ ctx.lineTo(370, 65)
174
+ ctx.lineTo(400, 78)
175
+ ctx.lineTo(440, 52)
176
+ ctx.lineTo(480, 62)
177
+ ctx.stroke()
178
+
179
+ // Big Bottom Analytics Area
180
+ ctx.fillStyle = '#1e293b'
181
+ ctx.fillRect(64, 116, 428, 154)
182
+
183
+ // Multi-bar chart
184
+ const barColors = ['#3b82f6', '#06b6d4', '#10b981', '#f59e0b', '#8b5cf6', '#ec4899']
185
+ for (let b = 0; b < 10; b++) {
186
+ const bx = 84 + b * 40
187
+ const h = 30 + ((b * 19) % 90)
188
+ const by = 240 - h
189
+ ctx.fillStyle = barColors[b % barColors.length] || '#3b82f6'
190
+ ctx.fillRect(bx, by, 24, h)
191
+ }
192
+ }
193
+ }
194
+
195
+ const texture = new THREE.CanvasTexture(canvas)
196
+ this.cache.set(key, texture)
197
+ return texture
198
+ }
199
+
200
+ // 4. Soft Contact Ambient Occlusion Drop Shadow Texture
201
+ static getSoftShadowTexture(): THREE.CanvasTexture {
202
+ const key = 'tex:shadow:contact'
203
+ if (this.cache.has(key)) return this.cache.get(key)!
204
+
205
+ const canvas = document.createElement('canvas')
206
+ canvas.width = 128
207
+ canvas.height = 128
208
+ const ctx = canvas.getContext('2d')
209
+
210
+ if (ctx) {
211
+ const grad = ctx.createRadialGradient(64, 64, 10, 64, 64, 60)
212
+ grad.addColorStop(0, 'rgba(0, 0, 0, 0.55)')
213
+ grad.addColorStop(0.5, 'rgba(0, 0, 0, 0.22)')
214
+ grad.addColorStop(1, 'rgba(0, 0, 0, 0)')
215
+
216
+ ctx.fillStyle = grad
217
+ ctx.fillRect(0, 0, 128, 128)
218
+ }
219
+
220
+ const texture = new THREE.CanvasTexture(canvas)
221
+ this.cache.set(key, texture)
222
+ return texture
223
+ }
224
+ }
@@ -162,7 +162,7 @@ export function buildOfficeArchitecture(
162
162
 
163
163
  const boardScreen = new THREE.Mesh(
164
164
  new THREE.PlaneGeometry(3.5, 1.7),
165
- materials.getMonitorScreenMaterial(true, '#1e3a8a'),
165
+ materials.getMonitorScreenMaterial('charts'),
166
166
  )
167
167
  boardScreen.position.set(0, 0, 0.032)
168
168
  boardGroup.add(boardScreen)
@@ -18,8 +18,21 @@ export function createModernWorkstation(
18
18
  const desktopMat = materials.getDeskTopMaterial(options.topColor || '#f8fafc')
19
19
  const legMat = materials.getMetalLegMaterial()
20
20
  const bezelMat = materials.getMonitorBezelMaterial()
21
- const screenMat = materials.getMonitorScreenMaterial(true, '#38bdf8')
21
+ const screenMat1 = materials.getMonitorScreenMaterial('dashboard')
22
+ const screenMat2 = materials.getMonitorScreenMaterial('code')
22
23
  const chairMat = materials.getLeatherMaterial('#334155')
24
+ const shadowMat = materials.getContactShadowMaterial()
25
+
26
+ // 0. Contact Ambient Occlusion Drop Shadows (grounds furniture on floor)
27
+ const deskShadow = new THREE.Mesh(new THREE.PlaneGeometry(1.9, 1.1), shadowMat)
28
+ deskShadow.rotation.x = -Math.PI / 2
29
+ deskShadow.position.set(0, 0.003, 0)
30
+ group.add(deskShadow)
31
+
32
+ const chairShadow = new THREE.Mesh(new THREE.PlaneGeometry(0.85, 0.85), shadowMat)
33
+ chairShadow.rotation.x = -Math.PI / 2
34
+ chairShadow.position.set(0, 0.003, 0.48)
35
+ group.add(chairShadow)
23
36
 
24
37
  // 1. Desktop surface (1.6m x 0.8m x 0.04m)
25
38
  const topGeo = new THREE.BoxGeometry(1.6, 0.04, 0.8)
@@ -30,27 +43,31 @@ export function createModernWorkstation(
30
43
  if (options.entityId) topMesh.userData = { entityId: options.entityId }
31
44
  group.add(topMesh)
32
45
 
33
- // 2. Desk Legs (T-frame metal legs)
46
+ // 2. Desk Legs (Modern metal legs)
34
47
  const legGeo = new THREE.BoxGeometry(0.06, 0.72, 0.7)
35
48
  const leftLeg = new THREE.Mesh(legGeo, legMat)
36
49
  leftLeg.position.set(-0.7, 0.36, 0)
37
50
  leftLeg.castShadow = true
51
+ if (options.entityId) leftLeg.userData = { entityId: options.entityId }
38
52
  group.add(leftLeg)
39
53
 
40
54
  const rightLeg = new THREE.Mesh(legGeo, legMat)
41
55
  rightLeg.position.set(0.7, 0.36, 0)
42
56
  rightLeg.castShadow = true
57
+ if (options.entityId) rightLeg.userData = { entityId: options.entityId }
43
58
  group.add(rightLeg)
44
59
 
45
- // 3. Ergonomic Chair
60
+ // 3. Ergonomic Office Chair
46
61
  const chairGroup = new THREE.Group()
47
- chairGroup.position.set(0, 0, 0.5)
62
+ chairGroup.position.set(0, 0, 0.48)
63
+ if (options.entityId) chairGroup.userData = { entityId: options.entityId }
48
64
 
49
65
  // Seat
50
66
  const seatGeo = new THREE.BoxGeometry(0.48, 0.08, 0.46)
51
67
  const seat = new THREE.Mesh(seatGeo, chairMat)
52
68
  seat.position.set(0, 0.46, 0)
53
69
  seat.castShadow = true
70
+ if (options.entityId) seat.userData = { entityId: options.entityId }
54
71
  chairGroup.add(seat)
55
72
 
56
73
  // Backrest
@@ -59,6 +76,7 @@ export function createModernWorkstation(
59
76
  back.position.set(0, 0.74, 0.2)
60
77
  back.rotation.x = -0.1
61
78
  back.castShadow = true
79
+ if (options.entityId) back.userData = { entityId: options.entityId }
62
80
  chairGroup.add(back)
63
81
 
64
82
  // Base stand & wheels
@@ -94,7 +112,7 @@ export function createModernWorkstation(
94
112
 
95
113
  // Screen display
96
114
  const dispGeo = new THREE.PlaneGeometry(0.64, 0.36)
97
- const disp = new THREE.Mesh(dispGeo, screenMat)
115
+ const disp = new THREE.Mesh(dispGeo, screenMat1)
98
116
  disp.position.set(0, 0.32, 0.016)
99
117
  if (options.entityId) disp.userData = { entityId: options.entityId }
100
118
  monitorGroup.add(disp)
@@ -103,27 +121,49 @@ export function createModernWorkstation(
103
121
 
104
122
  // 5. Secondary Monitor (Dual Monitor Setup)
105
123
  if (options.dualMonitor) {
106
- const monitor2 = monitorGroup.clone()
124
+ const monitor2 = new THREE.Group()
107
125
  monitor2.position.set(0.35, 0.76, -0.2)
108
126
  monitor2.rotation.y = -Math.PI / 8
127
+
128
+ const m2Stand = new THREE.Mesh(mStandGeo, legMat)
129
+ m2Stand.position.set(0, 0.14, 0)
130
+ monitor2.add(m2Stand)
131
+
132
+ const m2Base = new THREE.Mesh(mBaseGeo, legMat)
133
+ m2Base.position.set(0, 0.01, 0)
134
+ monitor2.add(m2Base)
135
+
136
+ const m2Frame = new THREE.Mesh(frameGeo, bezelMat)
137
+ m2Frame.position.set(0, 0.32, 0)
138
+ m2Frame.castShadow = true
139
+ if (options.entityId) m2Frame.userData = { entityId: options.entityId }
140
+ monitor2.add(m2Frame)
141
+
142
+ const m2Disp = new THREE.Mesh(dispGeo, screenMat2)
143
+ m2Disp.position.set(0, 0.32, 0.016)
144
+ if (options.entityId) m2Disp.userData = { entityId: options.entityId }
145
+ monitor2.add(m2Disp)
146
+
109
147
  group.add(monitor2)
110
148
  }
111
149
 
112
150
  // 6. Laptop (if enabled)
113
151
  if (options.hasLaptop) {
114
152
  const laptopGroup = new THREE.Group()
115
- laptopGroup.position.set(0.45, 0.76, -0.05)
153
+ laptopGroup.position.set(0.48, 0.76, -0.05)
116
154
  laptopGroup.rotation.y = -Math.PI / 6
117
155
 
118
156
  const baseG = new THREE.BoxGeometry(0.3, 0.015, 0.2)
119
157
  const baseM = new THREE.Mesh(baseG, bezelMat)
120
158
  baseM.position.set(0, 0.007, 0)
159
+ if (options.entityId) baseM.userData = { entityId: options.entityId }
121
160
  laptopGroup.add(baseM)
122
161
 
123
162
  const screenG = new THREE.BoxGeometry(0.3, 0.2, 0.01)
124
163
  const scrM = new THREE.Mesh(screenG, bezelMat)
125
164
  scrM.position.set(0, 0.1, -0.1)
126
165
  scrM.rotation.x = -Math.PI / 12
166
+ if (options.entityId) scrM.userData = { entityId: options.entityId }
127
167
  laptopGroup.add(scrM)
128
168
 
129
169
  group.add(laptopGroup)
@@ -133,11 +173,13 @@ export function createModernWorkstation(
133
173
  const kbGeo = new THREE.BoxGeometry(0.42, 0.01, 0.14)
134
174
  const kb = new THREE.Mesh(kbGeo, bezelMat)
135
175
  kb.position.set(0, 0.765, 0.08)
176
+ if (options.entityId) kb.userData = { entityId: options.entityId }
136
177
  group.add(kb)
137
178
 
138
179
  const mouseGeo = new THREE.BoxGeometry(0.06, 0.015, 0.1)
139
180
  const mouse = new THREE.Mesh(mouseGeo, bezelMat)
140
181
  mouse.position.set(0.3, 0.765, 0.08)
182
+ if (options.entityId) mouse.userData = { entityId: options.entityId }
141
183
  group.add(mouse)
142
184
 
143
185
  // 8. Ceramic Coffee Mug
@@ -160,7 +202,19 @@ export function createExecutiveDesk(
160
202
  const woodMat = materials.getExecutiveWoodMaterial()
161
203
  const chairMat = materials.getLeatherMaterial('#0f172a')
162
204
  const bezelMat = materials.getMonitorBezelMaterial()
163
- const screenMat = materials.getMonitorScreenMaterial(true, '#38bdf8')
205
+ const screenMat = materials.getMonitorScreenMaterial('charts')
206
+ const shadowMat = materials.getContactShadowMaterial()
207
+
208
+ // Contact Ambient Occlusion Drop Shadow
209
+ const shadow = new THREE.Mesh(new THREE.PlaneGeometry(2.6, 1.4), shadowMat)
210
+ shadow.rotation.x = -Math.PI / 2
211
+ shadow.position.set(0, 0.003, 0)
212
+ group.add(shadow)
213
+
214
+ const chairShadow = new THREE.Mesh(new THREE.PlaneGeometry(0.95, 0.95), shadowMat)
215
+ chairShadow.rotation.x = -Math.PI / 2
216
+ chairShadow.position.set(0, 0.003, 0.65)
217
+ group.add(chairShadow)
164
218
 
165
219
  // Main Executive Table (2.2m x 0.9m)
166
220
  const mainGeo = new THREE.BoxGeometry(2.2, 0.08, 0.9)
@@ -175,6 +229,7 @@ export function createExecutiveDesk(
175
229
  const baseL = new THREE.Mesh(baseLGeo, woodMat)
176
230
  baseL.position.set(-0.85, 0.35, 0)
177
231
  baseL.castShadow = true
232
+ if (options.entityId) baseL.userData = { entityId: options.entityId }
178
233
  group.add(baseL)
179
234
 
180
235
  const baseR = baseL.clone()
@@ -184,15 +239,19 @@ export function createExecutiveDesk(
184
239
  // High-back Executive Leather Chair
185
240
  const chair = new THREE.Group()
186
241
  chair.position.set(0, 0, 0.65)
242
+ if (options.entityId) chair.userData = { entityId: options.entityId }
243
+
187
244
  const seatGeo = new THREE.BoxGeometry(0.58, 0.1, 0.54)
188
245
  const seat = new THREE.Mesh(seatGeo, chairMat)
189
246
  seat.position.set(0, 0.48, 0)
247
+ if (options.entityId) seat.userData = { entityId: options.entityId }
190
248
  chair.add(seat)
191
249
 
192
250
  const backGeo = new THREE.BoxGeometry(0.56, 0.8, 0.08)
193
251
  const back = new THREE.Mesh(backGeo, chairMat)
194
252
  back.position.set(0, 0.88, 0.22)
195
253
  back.rotation.x = -0.1
254
+ if (options.entityId) back.userData = { entityId: options.entityId }
196
255
  chair.add(back)
197
256
 
198
257
  group.add(chair)
@@ -202,11 +261,13 @@ export function createExecutiveDesk(
202
261
  const screen = new THREE.Mesh(screenGeo, bezelMat)
203
262
  screen.position.set(0, 1.08, -0.2)
204
263
  screen.castShadow = true
264
+ if (options.entityId) screen.userData = { entityId: options.entityId }
205
265
  group.add(screen)
206
266
 
207
267
  const dispGeo = new THREE.PlaneGeometry(1.06, 0.41)
208
268
  const disp = new THREE.Mesh(dispGeo, screenMat)
209
269
  disp.position.set(0, 1.08, -0.178)
270
+ if (options.entityId) disp.userData = { entityId: options.entityId }
210
271
  group.add(disp)
211
272
 
212
273
  return group
@@ -218,6 +279,13 @@ export function createConferenceTable(materials: MaterialPalette): THREE.Group {
218
279
  const woodMat = materials.getExecutiveWoodMaterial()
219
280
  const legMat = materials.getMetalLegMaterial()
220
281
  const chairMat = materials.getLeatherMaterial('#334155')
282
+ const shadowMat = materials.getContactShadowMaterial()
283
+
284
+ // Contact Ambient Occlusion Drop Shadow
285
+ const shadow = new THREE.Mesh(new THREE.PlaneGeometry(5.2, 2.4), shadowMat)
286
+ shadow.rotation.x = -Math.PI / 2
287
+ shadow.position.set(0, 0.003, 0)
288
+ group.add(shadow)
221
289
 
222
290
  // Large Conference Table (4.5m x 1.6m)
223
291
  const tableGeo = new THREE.BoxGeometry(4.5, 0.08, 1.6)
@@ -244,7 +312,7 @@ export function createConferenceTable(materials: MaterialPalette): THREE.Group {
244
312
  p2.position.set(1.4, 0.35, 0)
245
313
  group.add(p2)
246
314
 
247
- // Surround chairs (3 on north, 3 on south, 1 at heads)
315
+ // Surround chairs
248
316
  const addChair = (x: number, z: number, rotY: number) => {
249
317
  const ch = new THREE.Group()
250
318
  ch.position.set(x, 0, z)
@@ -15,98 +15,271 @@ export function createStylizedAvatar(
15
15
  group.name = `avatar-${entity.id}`
16
16
  group.userData = { entityId: entity.id, type: 'person' }
17
17
 
18
- // Material selection based on entity configuration
18
+ // Unique phase seed per entity for desynchronized organic movements
19
+ const pinNum = typeof entity.pinNumber === 'number'
20
+ ? entity.pinNumber
21
+ : parseInt(String(entity.pinNumber || '1'), 10) || 1
22
+ const seed = (pinNum * 2.39996) + ((entity.id.charCodeAt(0) || 1) * 0.15)
23
+
24
+ // Material selection
19
25
  const skinMat = materials.getSkinMaterial()
20
26
  const hairMat = materials.getHairMaterial(entity.avatarHair || '#1e1b4b')
21
27
  const clothesMat = materials.getClothingMaterial(entity.avatarColor || '#2563eb')
28
+ const pantsMat = materials.getDarkSlate('#1e293b')
22
29
  const statusMat = materials.getStatusGlow(entity.status || 'idle')
23
30
 
24
- // 1. Torso / Shirt
25
- const torsoGeo = new THREE.CylinderGeometry(0.24, 0.28, 0.55, 12)
31
+ // Seated offset relative to workstation center (chair seat is at z = +0.45)
32
+ // For executive desk (slot-1), chair is at z = +0.65
33
+ const isExecutive = entity.id === 'slot-1' || entity.zoneId === 'executive'
34
+ const seatZ = isExecutive ? 0.62 : 0.44
35
+
36
+ // Root avatar container positioned at the chair
37
+ const avatarRoot = new THREE.Group()
38
+ avatarRoot.position.set(0, 0, seatZ)
39
+ group.add(avatarRoot)
40
+
41
+ // 1. Invisible Click Raycast Proxy (ensures easy clicking)
42
+ const clickProxyGeo = new THREE.CylinderGeometry(0.55, 0.55, 1.6, 8)
43
+ const clickProxyMat = new THREE.MeshBasicMaterial({ visible: false })
44
+ const clickProxy = new THREE.Mesh(clickProxyGeo, clickProxyMat)
45
+ clickProxy.position.set(0, 0.8, -0.1)
46
+ clickProxy.userData = { entityId: entity.id }
47
+ avatarRoot.add(clickProxy)
48
+
49
+ // 2. Seated Thighs & Lower Legs in Dark Slacks
50
+ const thighsGeo = new THREE.BoxGeometry(0.36, 0.12, 0.38)
51
+ const thighs = new THREE.Mesh(thighsGeo, pantsMat)
52
+ thighs.position.set(0, 0.48, -0.16)
53
+ thighs.userData = { entityId: entity.id }
54
+ avatarRoot.add(thighs)
55
+
56
+ const leftShin = new THREE.Mesh(new THREE.BoxGeometry(0.12, 0.38, 0.12), pantsMat)
57
+ leftShin.position.set(-0.11, 0.22, -0.32)
58
+ leftShin.userData = { entityId: entity.id }
59
+ avatarRoot.add(leftShin)
60
+
61
+ const rightShin = leftShin.clone()
62
+ rightShin.position.x = 0.11
63
+ avatarRoot.add(rightShin)
64
+
65
+ // 3. Pelvis / Hips
66
+ const hipsGeo = new THREE.BoxGeometry(0.38, 0.14, 0.26)
67
+ const hips = new THREE.Mesh(hipsGeo, pantsMat)
68
+ hips.position.set(0, 0.52, 0)
69
+ hips.userData = { entityId: entity.id }
70
+ avatarRoot.add(hips)
71
+
72
+ // 4. Upper Torso / Tailored Polo or Shirt
73
+ const torsoGroup = new THREE.Group()
74
+ torsoGroup.position.set(0, 0.6, 0)
75
+ avatarRoot.add(torsoGroup)
76
+
77
+ const torsoGeo = new THREE.CylinderGeometry(0.20, 0.17, 0.44, 12)
26
78
  const torso = new THREE.Mesh(torsoGeo, clothesMat)
27
- torso.position.set(0, 0.75, 0)
79
+ torso.position.set(0, 0.22, 0)
28
80
  torso.castShadow = true
29
81
  torso.userData = { entityId: entity.id }
30
- group.add(torso)
82
+ torsoGroup.add(torso)
31
83
 
32
- // 2. Neck
33
- const neckGeo = new THREE.CylinderGeometry(0.08, 0.08, 0.1, 8)
84
+ // Collar / neckline detail
85
+ const collarGeo = new THREE.CylinderGeometry(0.13, 0.14, 0.06, 10)
86
+ const collar = new THREE.Mesh(collarGeo, clothesMat)
87
+ collar.position.set(0, 0.44, 0)
88
+ collar.userData = { entityId: entity.id }
89
+ torsoGroup.add(collar)
90
+
91
+ // 5. Neck & Sculpted Head
92
+ const neckGeo = new THREE.CylinderGeometry(0.065, 0.075, 0.1, 10)
34
93
  const neck = new THREE.Mesh(neckGeo, skinMat)
35
- neck.position.set(0, 1.05, 0)
94
+ neck.position.set(0, 0.5, 0)
36
95
  neck.userData = { entityId: entity.id }
37
- group.add(neck)
96
+ torsoGroup.add(neck)
97
+
98
+ const headGroup = new THREE.Group()
99
+ headGroup.position.set(0, 0.66, 0)
100
+ torsoGroup.add(headGroup)
38
101
 
39
- // 3. Head
40
- const headGeo = new THREE.SphereGeometry(0.2, 16, 16)
102
+ const headGeo = new THREE.SphereGeometry(0.17, 18, 18)
41
103
  const head = new THREE.Mesh(headGeo, skinMat)
42
- head.position.set(0, 1.25, 0)
43
104
  head.castShadow = true
44
105
  head.userData = { entityId: entity.id }
45
- group.add(head)
46
-
47
- // 4. Stylized Hair
48
- const hairGeo = new THREE.SphereGeometry(0.21, 14, 14, 0, Math.PI * 2, 0, Math.PI / 2)
49
- const hair = new THREE.Mesh(hairGeo, hairMat)
50
- hair.position.set(0, 1.28, 0)
51
- hair.rotation.x = -0.15
52
- hair.userData = { entityId: entity.id }
53
- group.add(hair)
54
-
55
- // 5. Arms (positioned over desk typing)
56
- const leftArmGeo = new THREE.CylinderGeometry(0.06, 0.06, 0.38, 8)
57
- const leftArm = new THREE.Mesh(leftArmGeo, clothesMat)
58
- leftArm.position.set(-0.28, 0.72, 0.15)
59
- leftArm.rotation.x = Math.PI / 3.5
60
- leftArm.rotation.z = 0.2
61
- leftArm.userData = { entityId: entity.id }
62
- group.add(leftArm)
63
-
64
- const rightArmGeo = new THREE.CylinderGeometry(0.06, 0.06, 0.38, 8)
65
- const rightArm = new THREE.Mesh(rightArmGeo, clothesMat)
66
- rightArm.position.set(0.28, 0.72, 0.15)
67
- rightArm.rotation.x = Math.PI / 3.5
68
- rightArm.rotation.z = -0.2
69
- rightArm.userData = { entityId: entity.id }
70
- group.add(rightArm)
71
-
72
- // 6. Sitting Legs
73
- const legsGeo = new THREE.BoxGeometry(0.36, 0.15, 0.42)
74
- const legs = new THREE.Mesh(legsGeo, clothesMat)
75
- legs.position.set(0, 0.45, 0.1)
76
- legs.userData = { entityId: entity.id }
77
- group.add(legs)
78
-
79
- // 7. Status Halo Ring (hovering above head)
80
- const haloGeo = new THREE.RingGeometry(0.12, 0.16, 24)
81
- const halo = new THREE.Mesh(haloGeo, statusMat)
82
- halo.position.set(0, 1.55, 0)
83
- halo.rotation.x = -Math.PI / 2
84
- halo.userData = { entityId: entity.id }
85
- group.add(halo)
86
-
87
- // Dynamic animation callback
88
- const initialTorsoY = torso.position.y
106
+ headGroup.add(head)
107
+
108
+ // Nose & stylized face profile hint
109
+ const noseGeo = new THREE.ConeGeometry(0.03, 0.06, 6)
110
+ const nose = new THREE.Mesh(noseGeo, skinMat)
111
+ nose.position.set(0, 0, -0.175)
112
+ nose.rotation.x = -Math.PI / 2
113
+ headGroup.add(nose)
114
+
115
+ // 6. Stylized Hair (3 distinct styles for visual diversity)
116
+ const hairStyle = pinNum % 3
117
+ if (hairStyle === 0) {
118
+ // Executive side-part / neat crop
119
+ const hairCropGeo = new THREE.SphereGeometry(0.178, 14, 14, 0, Math.PI * 2, 0, Math.PI * 0.55)
120
+ const hair = new THREE.Mesh(hairCropGeo, hairMat)
121
+ hair.position.set(0, 0.03, 0)
122
+ hair.rotation.x = -0.1
123
+ headGroup.add(hair)
124
+
125
+ // Side part sweep
126
+ const sweepGeo = new THREE.BoxGeometry(0.18, 0.06, 0.12)
127
+ const sweep = new THREE.Mesh(sweepGeo, hairMat)
128
+ sweep.position.set(0.05, 0.14, -0.06)
129
+ sweep.rotation.z = -0.15
130
+ headGroup.add(sweep)
131
+ } else if (hairStyle === 1) {
132
+ // Textured fringe / pompadour
133
+ const hairCapGeo = new THREE.SphereGeometry(0.18, 14, 14, 0, Math.PI * 2, 0, Math.PI * 0.52)
134
+ const hairCap = new THREE.Mesh(hairCapGeo, hairMat)
135
+ hairCap.position.set(0, 0.035, 0)
136
+ headGroup.add(hairCap)
137
+
138
+ const fringeGeo = new THREE.CylinderGeometry(0.14, 0.15, 0.08, 10)
139
+ const fringe = new THREE.Mesh(fringeGeo, hairMat)
140
+ fringe.position.set(0, 0.14, -0.05)
141
+ fringe.rotation.x = -0.3
142
+ headGroup.add(fringe)
143
+ } else {
144
+ // Elegant top bun / sleek bob
145
+ const hairBobGeo = new THREE.SphereGeometry(0.182, 14, 14, 0, Math.PI * 2, 0, Math.PI * 0.6)
146
+ const hairBob = new THREE.Mesh(hairBobGeo, hairMat)
147
+ hairBob.position.set(0, 0.02, 0)
148
+ headGroup.add(hairBob)
149
+
150
+ const bunGeo = new THREE.SphereGeometry(0.08, 12, 12)
151
+ const bun = new THREE.Mesh(bunGeo, hairMat)
152
+ bun.position.set(0, 0.16, 0.12)
153
+ headGroup.add(bun)
154
+ }
155
+
156
+ // 7. Articulated Left Arm (Shoulder -> Forearm -> Hand on Keyboard)
157
+ const leftShoulder = new THREE.Group()
158
+ leftShoulder.position.set(-0.21, 0.38, 0)
159
+ torsoGroup.add(leftShoulder)
160
+
161
+ const leftUpperArm = new THREE.Mesh(new THREE.CylinderGeometry(0.05, 0.045, 0.26, 8), clothesMat)
162
+ leftUpperArm.position.set(0, -0.12, -0.04)
163
+ leftUpperArm.rotation.x = 0.35
164
+ leftShoulder.add(leftUpperArm)
165
+
166
+ const leftElbow = new THREE.Group()
167
+ leftElbow.position.set(0, -0.24, -0.08)
168
+ leftShoulder.add(leftElbow)
169
+
170
+ const leftForearm = new THREE.Mesh(new THREE.CylinderGeometry(0.042, 0.038, 0.24, 8), clothesMat)
171
+ leftForearm.position.set(0, 0.02, -0.12)
172
+ leftForearm.rotation.x = -Math.PI / 2.3
173
+ leftElbow.add(leftForearm)
174
+
175
+ const leftHand = new THREE.Mesh(new THREE.SphereGeometry(0.04, 8, 8), skinMat)
176
+ leftHand.position.set(0, 0.02, -0.24)
177
+ leftHand.userData = { entityId: entity.id }
178
+ leftElbow.add(leftHand)
179
+
180
+ // 8. Articulated Right Arm (Shoulder -> Forearm -> Hand on Keyboard / Mouse)
181
+ const rightShoulder = new THREE.Group()
182
+ rightShoulder.position.set(0.21, 0.38, 0)
183
+ torsoGroup.add(rightShoulder)
184
+
185
+ const rightUpperArm = new THREE.Mesh(new THREE.CylinderGeometry(0.05, 0.045, 0.26, 8), clothesMat)
186
+ rightUpperArm.position.set(0, -0.12, -0.04)
187
+ rightUpperArm.rotation.x = 0.35
188
+ rightShoulder.add(rightUpperArm)
189
+
190
+ const rightElbow = new THREE.Group()
191
+ rightElbow.position.set(0, -0.24, -0.08)
192
+ rightShoulder.add(rightElbow)
193
+
194
+ const rightForearm = new THREE.Mesh(new THREE.CylinderGeometry(0.042, 0.038, 0.24, 8), clothesMat)
195
+ rightForearm.position.set(0, 0.02, -0.12)
196
+ rightForearm.rotation.x = -Math.PI / 2.3
197
+ rightElbow.add(rightForearm)
198
+
199
+ const rightHand = new THREE.Mesh(new THREE.SphereGeometry(0.04, 8, 8), skinMat)
200
+ rightHand.position.set(0, 0.02, -0.24)
201
+ rightHand.userData = { entityId: entity.id }
202
+ rightElbow.add(rightHand)
203
+
204
+ // 9. Floating Status Pin Indicator (Compact, elegant glow disk)
205
+ const statusHalo = new THREE.Mesh(
206
+ new THREE.RingGeometry(0.07, 0.11, 24),
207
+ statusMat,
208
+ )
209
+ statusHalo.position.set(0, 1.05, 0)
210
+ statusHalo.rotation.x = -Math.PI / 2
211
+ statusHalo.userData = { entityId: entity.id }
212
+ headGroup.add(statusHalo)
213
+
214
+ // 10. Realistic Procedural Animation Function
215
+ const baseTorsoY = 0.6
89
216
  const isWorking = entity.status === 'running' || entity.status === 'working'
217
+ const isAwaiting = entity.status === 'awaiting_approval'
218
+ const breathFreq = 1.3 + (seed % 0.4)
219
+ const glanceFreq = 0.22 + ((seed * 3) % 0.15)
90
220
 
91
221
  const animate = (_delta: number, elapsed: number) => {
92
- // Subtle breathing animation
93
- const breath = Math.sin(elapsed * 2.5 + Number(entity.pinNumber || 0)) * 0.015
94
- torso.position.y = initialTorsoY + breath
95
- head.position.y = 1.25 + breath
222
+ // A. Natural Non-Synchronized Breathing (Multi-harmonic sine wave)
223
+ const breath = Math.sin(elapsed * breathFreq + seed) * 0.007
224
+ + Math.sin(elapsed * (breathFreq * 0.5) + seed) * 0.003
225
+ torsoGroup.position.y = baseTorsoY + breath
226
+ torso.rotation.x = Math.sin(elapsed * breathFreq + seed) * 0.012
227
+
228
+ // B. Natural Gaze / Head Turning Between Dual Monitors
229
+ // Smooth transitions between center screen, secondary screen and keyboard
230
+ const glanceCycle = Math.sin(elapsed * glanceFreq + seed)
231
+ const keyboardLook = Math.cos(elapsed * (glanceFreq * 1.7) + seed)
96
232
 
97
233
  if (isWorking) {
98
- // Typing agitation
99
- const typing1 = Math.sin(elapsed * 12 + Number(entity.pinNumber || 0)) * 0.06
100
- const typing2 = Math.cos(elapsed * 14 + Number(entity.pinNumber || 0)) * 0.06
101
- leftArm.rotation.x = Math.PI / 3.5 + typing1
102
- rightArm.rotation.x = Math.PI / 3.5 + typing2
103
-
104
- // Pulsing halo
105
- halo.scale.setScalar(1 + Math.sin(elapsed * 4) * 0.2)
234
+ // Focused worker shifts gaze between main display and side display
235
+ headGroup.rotation.y = glanceCycle * 0.28
236
+ headGroup.rotation.x = keyboardLook > 0.65 ? 0.14 : -0.04
237
+ headGroup.rotation.z = 0
238
+
239
+ // Active keystrokes (asymmetric micro-movements on forearms & hands)
240
+ const typeLeft = Math.sin(elapsed * 13 + seed) * 0.035
241
+ const typeRight = Math.cos(elapsed * 15 + seed) * 0.035
242
+ leftElbow.rotation.x = typeLeft
243
+ rightElbow.rotation.x = typeRight
244
+
245
+ // Periodic shift of right hand to mouse (every ~7 seconds)
246
+ const mouseCycle = Math.sin(elapsed * 0.9 + seed)
247
+ if (mouseCycle > 0.3) {
248
+ // Move right forearm slightly outward to mouse position
249
+ rightShoulder.rotation.y = 0.18
250
+ rightElbow.position.x = 0.08
251
+ rightElbow.rotation.x = Math.sin(elapsed * 6) * 0.015 // mouse click micro-clicks
252
+ } else {
253
+ rightShoulder.rotation.y = 0
254
+ rightElbow.position.x = 0
255
+ }
256
+
257
+ // Status indicator pulsing
258
+ statusHalo.scale.setScalar(1 + Math.sin(elapsed * 3.5 + seed) * 0.15)
259
+ } else if (isAwaiting) {
260
+ // Thoughtful tilted posture waiting for approval
261
+ headGroup.rotation.y = Math.sin(elapsed * 0.4 + seed) * 0.15
262
+ headGroup.rotation.z = 0.12 // slight tilt
263
+ headGroup.rotation.x = 0.05
264
+ leftElbow.rotation.x = 0
265
+ rightElbow.rotation.x = 0
266
+ rightShoulder.rotation.y = 0
267
+ rightElbow.position.x = 0
268
+ statusHalo.scale.setScalar(1 + Math.sin(elapsed * 2) * 0.2)
269
+ } else {
270
+ // Idle / ready posture: relaxed, occasional glances around
271
+ headGroup.rotation.y = glanceCycle * 0.18
272
+ headGroup.rotation.x = 0
273
+ headGroup.rotation.z = 0
274
+ leftElbow.rotation.x = 0
275
+ rightElbow.rotation.x = 0
276
+ rightShoulder.rotation.y = 0
277
+ rightElbow.position.x = 0
278
+ statusHalo.scale.setScalar(1)
106
279
  }
107
280
  }
108
281
 
109
- // Position the group
282
+ // Set world position and orientation
110
283
  group.position.set(entity.position[0], entity.position[1], entity.position[2])
111
284
  if (entity.rotation) {
112
285
  group.rotation.set(entity.rotation[0], entity.rotation[1], entity.rotation[2])
@@ -103,7 +103,7 @@ export const schoolPreset: WorldPreset = {
103
103
  // Teacher podium / Smartboard
104
104
  const board = new THREE.Mesh(
105
105
  new THREE.BoxGeometry(4.5, 2.2, 0.08),
106
- materials.getMonitorScreenMaterial(true, '#1e1b4b'),
106
+ materials.getMonitorScreenMaterial('dashboard'),
107
107
  )
108
108
  board.position.set(-6, 2.0, -9)
109
109
  scene.add(board)
@@ -39,15 +39,16 @@
39
39
  transform: translate(-50%, -100%);
40
40
  display: inline-flex;
41
41
  align-items: center;
42
- gap: 6px;
43
- padding: 4px 8px;
42
+ gap: 5px;
43
+ padding: 3px 8px;
44
+ max-width: 135px;
44
45
  border-radius: 9999px;
45
- background-color: rgba(255, 255, 255, 0.94);
46
- backdrop-filter: blur(8px);
47
- border: 1px solid rgba(203, 213, 225, 0.8);
48
- box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
46
+ background-color: rgba(255, 255, 255, 0.95);
47
+ backdrop-filter: blur(10px);
48
+ border: 1px solid rgba(203, 213, 225, 0.85);
49
+ box-shadow: 0 4px 12px rgba(0, 0, 0, 0.16);
49
50
  font-family: inherit;
50
- font-size: 11px;
51
+ font-size: 10.5px;
51
52
  font-weight: 600;
52
53
  color: #0f172a;
53
54
  cursor: pointer;
@@ -56,15 +57,24 @@
56
57
  }
57
58
 
58
59
  .wv-pin-chip:hover {
59
- transform: translate(-50%, -100%) scale(1.08);
60
+ transform: translate(-50%, -100%) scale(1.06);
60
61
  background-color: #ffffff;
61
62
  border-color: #3b82f6;
63
+ max-width: 220px;
62
64
  z-index: 50;
63
65
  }
64
66
 
65
67
  .wv-pin-chip.is-selected {
68
+ max-width: 220px;
66
69
  border-color: #3b82f6;
67
70
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.4), 0 6px 16px rgba(0, 0, 0, 0.2);
71
+ z-index: 40;
72
+ }
73
+
74
+ .wv-pin-label-text {
75
+ overflow: hidden;
76
+ text-overflow: ellipsis;
77
+ white-space: nowrap;
68
78
  }
69
79
 
70
80
  .wv-pin-circle {