@umituz/web-virtual 1.0.1 → 1.0.3

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.
@@ -4,6 +4,8 @@ import {
4
4
  useRef,
5
5
  useState,
6
6
  useCallback,
7
+ forwardRef,
8
+ useImperativeHandle,
7
9
  } from 'react'
8
10
  import * as THREE from 'three'
9
11
  import type {
@@ -11,7 +13,6 @@ import type {
11
13
  WorldEntity,
12
14
  WorldPreset,
13
15
  PinDisplayMode,
14
- EntitySelectedEvent,
15
16
  } from '../core/types'
16
17
  import { WorldEngine } from '../engine/renderer'
17
18
  import { createStylizedAvatar } from '../entities/people/AvatarBuilder'
@@ -20,6 +21,14 @@ import { WorldControls } from './WorldControls'
20
21
  import { EntityInspector } from './EntityInspector'
21
22
  import type { CameraPresetName } from '../engine/camera'
22
23
 
24
+ export interface VirtualWorldRef {
25
+ focusOnEntity: (entityId: string) => void
26
+ setCameraPreset: (preset: CameraPresetName) => void
27
+ resetCamera: () => void
28
+ setNightMode: (isNight: boolean) => void
29
+ resize: () => void
30
+ }
31
+
23
32
  export interface VirtualWorldProps {
24
33
  world: WorldDefinition
25
34
  preset?: WorldPreset
@@ -36,194 +45,226 @@ export interface VirtualWorldProps {
36
45
  renderCustomInspectorActions?: (entity: WorldEntity) => ReactNode
37
46
  }
38
47
 
39
- export function VirtualWorld({
40
- world,
41
- preset,
42
- selectedEntityId,
43
- onSelectEntity,
44
- onHoverEntity,
45
- defaultPinMode = 'pins',
46
- showControls = true,
47
- showInspector = true,
48
- className = '',
49
- style,
50
- children,
51
- renderCustomInspectorContent,
52
- renderCustomInspectorActions,
53
- }: VirtualWorldProps): ReactNode {
54
- const containerRef = useRef<HTMLDivElement>(null)
55
- const canvasRef = useRef<HTMLCanvasElement>(null)
56
- const engineRef = useRef<WorldEngine | null>(null)
57
- const pinElementsRef = useRef<Map<string, HTMLElement>>(new Map())
58
-
59
- const [nightMode, setNightMode] = useState(false)
60
- const [pinMode, setPinMode] = useState<PinDisplayMode>(defaultPinMode)
61
- const [fps, setFps] = useState<number>(60)
62
- const [internalSelectedEntity, setInternalSelectedEntity] = useState<WorldEntity | null>(null)
63
-
64
- // Determine active selected entity (controlled or uncontrolled)
65
- const activeEntity =
66
- selectedEntityId !== undefined
67
- ? world.entities.find((e) => e.id === selectedEntityId) || null
68
- : internalSelectedEntity
69
-
70
- const handleSelectEntity = useCallback(
71
- (entity: WorldEntity | null) => {
72
- setInternalSelectedEntity(entity)
73
- if (onSelectEntity) {
74
- onSelectEntity(entity)
75
- }
76
- },
77
- [onSelectEntity],
78
- )
79
-
80
- const handleRegisterPinElement = useCallback((entityId: string, el: HTMLElement | null) => {
81
- if (el) {
82
- pinElementsRef.current.set(entityId, el)
83
- } else {
84
- pinElementsRef.current.delete(entityId)
85
- }
86
- }, [])
87
-
88
- // Initialize Three.js Engine
89
- useEffect(() => {
90
- const canvas = canvasRef.current
91
- const container = containerRef.current
92
- if (!canvas || !container) return
93
-
94
- const engine = new WorldEngine({
95
- canvas,
48
+ export const VirtualWorld = forwardRef<VirtualWorldRef, VirtualWorldProps>(
49
+ function VirtualWorld(
50
+ {
96
51
  world,
97
- pinElements: pinElementsRef.current,
98
- onSelectEntity: (evt) => {
99
- handleSelectEntity(evt.entity)
100
- },
101
- onHoverEntity: (entity) => {
102
- if (onHoverEntity) onHoverEntity(entity)
103
- },
104
- onFpsUpdate: (currentFps) => {
105
- setFps(currentFps)
52
+ preset,
53
+ selectedEntityId,
54
+ onSelectEntity,
55
+ onHoverEntity,
56
+ defaultPinMode = 'pins',
57
+ showControls = true,
58
+ showInspector = true,
59
+ className = '',
60
+ style,
61
+ children,
62
+ renderCustomInspectorContent,
63
+ renderCustomInspectorActions,
64
+ },
65
+ ref,
66
+ ): ReactNode {
67
+ const containerRef = useRef<HTMLDivElement>(null)
68
+ const canvasRef = useRef<HTMLCanvasElement>(null)
69
+ const engineRef = useRef<WorldEngine | null>(null)
70
+ const pinElementsRef = useRef<Map<string, HTMLElement>>(new Map())
71
+
72
+ const [nightMode, setNightMode] = useState(false)
73
+ const [pinMode, setPinMode] = useState<PinDisplayMode>(defaultPinMode)
74
+ const [fps, setFps] = useState<number>(60)
75
+ const [internalSelectedEntity, setInternalSelectedEntity] = useState<WorldEntity | null>(null)
76
+
77
+ // Determine active selected entity (controlled or uncontrolled)
78
+ const activeEntity =
79
+ selectedEntityId !== undefined
80
+ ? world.entities.find((e) => e.id === selectedEntityId) || null
81
+ : internalSelectedEntity
82
+
83
+ const handleSelectEntity = useCallback(
84
+ (entity: WorldEntity | null) => {
85
+ setInternalSelectedEntity(entity)
86
+ if (onSelectEntity) {
87
+ onSelectEntity(entity)
88
+ }
106
89
  },
107
- })
108
- engineRef.current = engine
109
-
110
- // 1. Build environment from preset or custom scene builder
111
- const activePreset = preset
112
- if (activePreset && activePreset.buildScene) {
113
- activePreset.buildScene(engine.scene, {
114
- nightMode,
115
- theme: world.theme,
90
+ [onSelectEntity],
91
+ )
92
+
93
+ const handleRegisterPinElement = useCallback((entityId: string, el: HTMLElement | null) => {
94
+ if (el) {
95
+ pinElementsRef.current.set(entityId, el)
96
+ } else {
97
+ pinElementsRef.current.delete(entityId)
98
+ }
99
+ }, [])
100
+
101
+ // Initialize Three.js Engine
102
+ useEffect(() => {
103
+ const canvas = canvasRef.current
104
+ const container = containerRef.current
105
+ if (!canvas || !container) return
106
+
107
+ const engine = new WorldEngine({
108
+ canvas,
109
+ world,
110
+ pinElements: pinElementsRef.current,
111
+ onSelectEntity: (evt) => {
112
+ handleSelectEntity(evt.entity)
113
+ },
114
+ onHoverEntity: (entity) => {
115
+ if (onHoverEntity) onHoverEntity(entity)
116
+ },
117
+ onFpsUpdate: (currentFps) => {
118
+ setFps(currentFps)
119
+ },
120
+ })
121
+ engineRef.current = engine
122
+
123
+ // 1. Build environment from preset or custom scene builder
124
+ const activePreset = preset
125
+ if (activePreset && activePreset.buildScene) {
126
+ activePreset.buildScene(engine.scene, {
127
+ nightMode,
128
+ theme: world.theme,
129
+ })
130
+ }
131
+
132
+ // 2. Build 3D Avatars for people/actor entities
133
+ const avatarGroup = new THREE.Group()
134
+ avatarGroup.name = 'world-avatars'
135
+
136
+ for (const entity of world.entities) {
137
+ if (entity.type === 'person' || entity.type === 'actor') {
138
+ const { group, animate } = createStylizedAvatar(entity, engine.materials)
139
+ avatarGroup.add(group)
140
+ engine.animators.push(animate)
141
+ engine.interactiveObjects.push(group)
142
+ }
143
+ }
144
+ engine.scene.add(avatarGroup)
145
+
146
+ // Resize Observer
147
+ const resizeObserver = new ResizeObserver((entries) => {
148
+ for (const entry of entries) {
149
+ const { width, height } = entry.contentRect
150
+ if (width > 0 && height > 0) {
151
+ engine.resize(width, height)
152
+ }
153
+ }
116
154
  })
117
- }
118
-
119
- // 2. Build 3D Avatars for people/actor entities
120
- const avatarGroup = new THREE.Group()
121
- avatarGroup.name = 'world-avatars'
122
-
123
- for (const entity of world.entities) {
124
- if (entity.type === 'person' || entity.type === 'actor') {
125
- const { group, animate } = createStylizedAvatar(entity, engine.materials)
126
- avatarGroup.add(group)
127
- engine.animators.push(animate)
128
- engine.interactiveObjects.push(group)
155
+ resizeObserver.observe(container)
156
+
157
+ return () => {
158
+ resizeObserver.disconnect()
159
+ engine.dispose()
160
+ engineRef.current = null
161
+ pinElementsRef.current.clear()
129
162
  }
130
- }
131
- engine.scene.add(avatarGroup)
132
-
133
- // Resize Observer
134
- const resizeObserver = new ResizeObserver((entries) => {
135
- for (const entry of entries) {
136
- const { width, height } = entry.contentRect
137
- if (width > 0 && height > 0) {
138
- engine.resize(width, height)
163
+ }, [world, preset, handleSelectEntity, onHoverEntity])
164
+
165
+ // Handle Night Mode Toggle
166
+ const handleToggleNightMode = useCallback(() => {
167
+ setNightMode((prev) => {
168
+ const next = !prev
169
+ if (engineRef.current) {
170
+ engineRef.current.setNightMode(next)
139
171
  }
172
+ return next
173
+ })
174
+ }, [])
175
+
176
+ // Handle Camera Presets
177
+ const handleCameraPreset = useCallback((presetName: CameraPresetName) => {
178
+ if (engineRef.current) {
179
+ engineRef.current.setCameraPreset(presetName)
180
+ }
181
+ }, [])
182
+
183
+ const handleResetCamera = useCallback(() => {
184
+ if (engineRef.current) {
185
+ engineRef.current.resetCamera()
140
186
  }
141
- })
142
- resizeObserver.observe(container)
143
-
144
- return () => {
145
- resizeObserver.disconnect()
146
- engine.dispose()
147
- engineRef.current = null
148
- pinElementsRef.current.clear()
149
- }
150
- }, [world, preset, handleSelectEntity, onHoverEntity])
151
-
152
- // Handle Night Mode Toggle
153
- const handleToggleNightMode = useCallback(() => {
154
- setNightMode((prev) => {
155
- const next = !prev
187
+ }, [])
188
+
189
+ const handleFocusEntity = useCallback((entity: WorldEntity) => {
156
190
  if (engineRef.current) {
157
- engineRef.current.setNightMode(next)
191
+ engineRef.current.focusOnEntity(entity.id)
158
192
  }
159
- return next
160
- })
161
- }, [])
162
-
163
- // Handle Camera Presets
164
- const handleCameraPreset = useCallback((presetName: CameraPresetName) => {
165
- if (engineRef.current) {
166
- engineRef.current.setCameraPreset(presetName)
167
- }
168
- }, [])
169
-
170
- const handleResetCamera = useCallback(() => {
171
- if (engineRef.current) {
172
- engineRef.current.resetCamera()
173
- }
174
- }, [])
175
-
176
- const handleFocusEntity = useCallback((entity: WorldEntity) => {
177
- if (engineRef.current) {
178
- engineRef.current.focusOnEntity(entity.id)
179
- }
180
- }, [])
181
-
182
- return (
183
- <div
184
- ref={containerRef}
185
- className={`wv-container ${className}`}
186
- style={style}
187
- role="region"
188
- aria-label={`${world.name} 3D Sanal Ortamı`}
189
- >
190
- <canvas ref={canvasRef} className="wv-canvas" />
191
-
192
- {/* Floating 60fps GPU Projected Pins */}
193
- <EntityPins
194
- entities={world.entities}
195
- mode={pinMode}
196
- selectedEntityId={activeEntity?.id}
197
- onSelectEntity={handleSelectEntity}
198
- onRegisterElement={handleRegisterPinElement}
199
- />
200
-
201
- {/* Floating View Controls */}
202
- {showControls && (
203
- <WorldControls
204
- nightMode={nightMode}
205
- onToggleNightMode={handleToggleNightMode}
206
- pinMode={pinMode}
207
- onChangePinMode={setPinMode}
208
- onSelectCameraPreset={handleCameraPreset}
209
- onResetCamera={handleResetCamera}
210
- fps={fps}
211
- />
212
- )}
213
-
214
- {/* Slide-out Entity Contextual Inspector */}
215
- {showInspector && activeEntity && (
216
- <EntityInspector
217
- entity={activeEntity}
218
- onClose={() => handleSelectEntity(null)}
219
- onFocusEntity={handleFocusEntity}
220
- renderCustomContent={renderCustomInspectorContent}
221
- renderCustomActions={renderCustomInspectorActions}
193
+ }, [])
194
+
195
+ // Imperative API for parent refs
196
+ useImperativeHandle(
197
+ ref,
198
+ () => ({
199
+ focusOnEntity: (id: string) => {
200
+ if (engineRef.current) engineRef.current.focusOnEntity(id)
201
+ },
202
+ setCameraPreset: (presetName: CameraPresetName) => {
203
+ if (engineRef.current) engineRef.current.setCameraPreset(presetName)
204
+ },
205
+ resetCamera: () => {
206
+ if (engineRef.current) engineRef.current.resetCamera()
207
+ },
208
+ setNightMode: (isNight: boolean) => {
209
+ setNightMode(isNight)
210
+ if (engineRef.current) engineRef.current.setNightMode(isNight)
211
+ },
212
+ resize: () => {
213
+ if (engineRef.current && containerRef.current) {
214
+ const { clientWidth, clientHeight } = containerRef.current
215
+ engineRef.current.resize(clientWidth, clientHeight)
216
+ }
217
+ },
218
+ }),
219
+ [],
220
+ )
221
+
222
+ return (
223
+ <div
224
+ ref={containerRef}
225
+ className={`wv-container ${className}`}
226
+ style={style}
227
+ role="region"
228
+ aria-label={`${world.name} 3D Sanal Ortamı`}
229
+ >
230
+ <canvas ref={canvasRef} className="wv-canvas" />
231
+
232
+ {/* Floating 60fps GPU Projected Pins */}
233
+ <EntityPins
234
+ entities={world.entities}
235
+ mode={pinMode}
236
+ selectedEntityId={activeEntity?.id}
237
+ onSelectEntity={handleSelectEntity}
238
+ onRegisterElement={handleRegisterPinElement}
222
239
  />
223
- )}
224
240
 
225
- {/* Consumer UI Overlays (e.g., bottom dispatch bar, top mode switcher) */}
226
- {children}
227
- </div>
228
- )
229
- }
241
+ {/* Floating View Controls */}
242
+ {showControls && (
243
+ <WorldControls
244
+ nightMode={nightMode}
245
+ onToggleNightMode={handleToggleNightMode}
246
+ pinMode={pinMode}
247
+ onChangePinMode={setPinMode}
248
+ onSelectCameraPreset={handleCameraPreset}
249
+ onResetCamera={handleResetCamera}
250
+ fps={fps}
251
+ />
252
+ )}
253
+
254
+ {/* Slide-out Entity Contextual Inspector */}
255
+ {showInspector && activeEntity && (
256
+ <EntityInspector
257
+ entity={activeEntity}
258
+ onClose={() => handleSelectEntity(null)}
259
+ onFocusEntity={handleFocusEntity}
260
+ renderCustomContent={renderCustomInspectorContent}
261
+ renderCustomActions={renderCustomInspectorActions}
262
+ />
263
+ )}
264
+
265
+ {/* Consumer UI Overlays (e.g., bottom dispatch bar, top mode switcher) */}
266
+ {children}
267
+ </div>
268
+ )
269
+ },
270
+ )
@@ -2,3 +2,8 @@ export * from './VirtualWorld'
2
2
  export * from './WorldControls'
3
3
  export * from './EntityPins'
4
4
  export * from './EntityInspector'
5
+ export * from './VirtualCommandBar'
6
+ export * from './VirtualRoster'
7
+ export * from './VirtualEntityDrawer'
8
+ export * from './VirtualReportModal'
9
+ export * from './DigitalHQView'
@@ -1,5 +1,4 @@
1
1
  import * as THREE from 'three'
2
- import type { WorldTheme } from '../core/types'
3
2
 
4
3
  export class MaterialPalette {
5
4
  private materials: Map<string, THREE.Material> = new Map()
@@ -1,5 +1,4 @@
1
1
  import * as THREE from 'three'
2
- import type { WorldEntity } from '../core/types'
3
2
 
4
3
  export interface RaycastHit {
5
4
  entityId: string
@@ -1,5 +1,5 @@
1
1
  import * as THREE from 'three'
2
- import type { WorldDefinition, WorldEntity, PinDisplayMode, EntitySelectedEvent } from '../core/types'
2
+ import type { WorldDefinition, WorldEntity, EntitySelectedEvent } from '../core/types'
3
3
  import { MaterialPalette } from './materials'
4
4
  import { WorldLighting } from './lighting'
5
5
  import { WorldCamera, type CameraPresetName } from './camera'
@@ -4,7 +4,6 @@ import { MaterialPalette } from '../engine/materials'
4
4
  import { buildOfficeArchitecture } from '../entities/architecture/OfficeArchitectureBuilder'
5
5
  import { createModernWorkstation, createExecutiveDesk, createConferenceTable } from '../entities/furniture/DeskBuilder'
6
6
  import { createFicusPlant } from '../entities/props/PlantBuilder'
7
- import { createStylizedAvatar } from '../entities/people/AvatarBuilder'
8
7
 
9
8
  export const DEFAULT_OFFICE_ZONES: WorldZone[] = [
10
9
  {
@@ -51,6 +50,76 @@ export const DEFAULT_OFFICE_ZONES: WorldZone[] = [
51
50
  },
52
51
  ]
53
52
 
53
+ export interface DepartmentInfo {
54
+ id: string
55
+ name: string
56
+ slug: string
57
+ description: string
58
+ managerSlotId: string
59
+ managerRole: string
60
+ color: string
61
+ slotIds: string[]
62
+ iconName?: 'briefcase' | 'palette' | 'megaphone' | 'shield' | 'globe'
63
+ }
64
+
65
+ export const DEFAULT_OFFICE_DEPARTMENTS: DepartmentInfo[] = [
66
+ {
67
+ id: 'dept-management',
68
+ name: 'Genel Yönetim & Strateji',
69
+ slug: 'management',
70
+ description: 'Şirket vizyonu, departman koordinasyonu, stratejik iş planlaması ve onay denetimleri.',
71
+ managerSlotId: 'slot-1',
72
+ managerRole: 'Dijital Ajans Yöneticisi (Genel Müdür)',
73
+ color: '#3b82f6',
74
+ slotIds: ['slot-1', 'slot-13'],
75
+ iconName: 'briefcase',
76
+ },
77
+ {
78
+ id: 'dept-creative',
79
+ name: 'İçerik & Kreatif Tasarım',
80
+ slug: 'creative',
81
+ description: 'Sosyal medya içerikleri, görsel konseptler, reklam kancaları ve viral video prodüksiyonu.',
82
+ managerSlotId: 'slot-3',
83
+ managerRole: 'Kreatif Görsel Direktörü',
84
+ color: '#a855f7',
85
+ slotIds: ['slot-2', 'slot-3', 'slot-4', 'slot-5'],
86
+ iconName: 'palette',
87
+ },
88
+ {
89
+ id: 'dept-marketing',
90
+ name: 'Pazarlama & Büyüme',
91
+ slug: 'marketing',
92
+ description: 'Google & Meta reklamları, organik SEO, e-posta funnel otomasyonu ve müşteri ilişkileri (CRM).',
93
+ managerSlotId: 'slot-6',
94
+ managerRole: 'Performans Pazarlama & Medya Satın Alma',
95
+ color: '#10b981',
96
+ slotIds: ['slot-6', 'slot-7', 'slot-8', 'slot-9', 'slot-14'],
97
+ iconName: 'megaphone',
98
+ },
99
+ {
100
+ id: 'dept-tech',
101
+ name: 'Teknoloji, UI/UX & Veri',
102
+ slug: 'tech',
103
+ description: 'Dönüşüm odaklı web arayüzleri, açılış sayfaları tel kafesleri ve kampanya büyüme analitiği.',
104
+ managerSlotId: 'slot-11',
105
+ managerRole: 'UI/UX & Web Arayüz Tasarımcısı',
106
+ color: '#06b6d4',
107
+ slotIds: ['slot-11', 'slot-12'],
108
+ iconName: 'globe',
109
+ },
110
+ {
111
+ id: 'dept-operations',
112
+ name: 'Operasyon, Kalite & Finans',
113
+ slug: 'operations',
114
+ description: 'Gelir/gider dengesi, bütçe denetimi, kalite güvence kontrolleri ve kurumsal bilgi arşivi.',
115
+ managerSlotId: 'slot-10',
116
+ managerRole: 'Ajans Muhasebecisi & Finans Uzmanı',
117
+ color: '#f59e0b',
118
+ slotIds: ['slot-10', 'slot-15', 'slot-16', 'slot-17'],
119
+ iconName: 'shield',
120
+ },
121
+ ]
122
+
54
123
  // 17 standard desk positions matching the reference architectural layout
55
124
  export const DEFAULT_OFFICE_ENTITIES: WorldEntity[] = [
56
125
  // 1. Genel Müdür / Executive Suite