@wovvmap/renderer-three 0.0.0-stage → 1.2.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/dist/controllers/ImageController.d.ts +95 -0
- package/dist/controllers/ImageController.d.ts.map +1 -0
- package/dist/controllers/ImageController.js +129 -0
- package/dist/controllers/ShapeController.d.ts +95 -0
- package/dist/controllers/ShapeController.d.ts.map +1 -0
- package/dist/controllers/ShapeController.js +139 -0
- package/dist/controllers/TextController.d.ts +120 -0
- package/dist/controllers/TextController.d.ts.map +1 -0
- package/dist/controllers/TextController.js +161 -0
- package/dist/controllers/ViewerElementsController.d.ts +254 -0
- package/dist/controllers/ViewerElementsController.d.ts.map +1 -0
- package/dist/controllers/ViewerElementsController.js +490 -0
- package/dist/engine/CameraFollow.d.ts +13 -0
- package/dist/engine/CameraFollow.d.ts.map +1 -0
- package/dist/engine/CameraFollow.js +52 -0
- package/dist/engine/CameraManager.d.ts +143 -0
- package/dist/engine/CameraManager.d.ts.map +1 -0
- package/dist/engine/CameraManager.js +566 -0
- package/dist/engine/ControlsManager.d.ts +123 -0
- package/dist/engine/ControlsManager.d.ts.map +1 -0
- package/dist/engine/ControlsManager.js +604 -0
- package/dist/engine/InteractionManager.d.ts +45 -0
- package/dist/engine/InteractionManager.d.ts.map +1 -0
- package/dist/engine/InteractionManager.js +99 -0
- package/dist/engine/LightingManager.d.ts +25 -0
- package/dist/engine/LightingManager.d.ts.map +1 -0
- package/dist/engine/LightingManager.js +74 -0
- package/dist/engine/MapViewerEngine.d.ts +350 -0
- package/dist/engine/MapViewerEngine.d.ts.map +1 -0
- package/dist/engine/MapViewerEngine.js +1041 -0
- package/dist/engine/RendererManager.d.ts +77 -0
- package/dist/engine/RendererManager.d.ts.map +1 -0
- package/dist/engine/RendererManager.js +243 -0
- package/dist/index.d.ts +40 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +39 -0
- package/dist/services/image-services/ImageCacheService.d.ts +49 -0
- package/dist/services/image-services/ImageCacheService.d.ts.map +1 -0
- package/dist/services/image-services/ImageCacheService.js +121 -0
- package/dist/services/image-services/ImagePlaneService.d.ts +29 -0
- package/dist/services/image-services/ImagePlaneService.d.ts.map +1 -0
- package/dist/services/image-services/ImagePlaneService.js +82 -0
- package/dist/services/image-services/ImageService.d.ts +170 -0
- package/dist/services/image-services/ImageService.d.ts.map +1 -0
- package/dist/services/image-services/ImageService.js +537 -0
- package/dist/services/image-services/ImageSpriteService.d.ts +39 -0
- package/dist/services/image-services/ImageSpriteService.d.ts.map +1 -0
- package/dist/services/image-services/ImageSpriteService.js +135 -0
- package/dist/services/routes/RouteArrows.d.ts +34 -0
- package/dist/services/routes/RouteArrows.d.ts.map +1 -0
- package/dist/services/routes/RouteArrows.js +157 -0
- package/dist/services/routes/RouteCursor.d.ts +19 -0
- package/dist/services/routes/RouteCursor.d.ts.map +1 -0
- package/dist/services/routes/RouteCursor.js +68 -0
- package/dist/services/routes/RouteMotion.d.ts +31 -0
- package/dist/services/routes/RouteMotion.d.ts.map +1 -0
- package/dist/services/routes/RouteMotion.js +132 -0
- package/dist/services/routes/RouteRenderer.d.ts +52 -0
- package/dist/services/routes/RouteRenderer.d.ts.map +1 -0
- package/dist/services/routes/RouteRenderer.js +445 -0
- package/dist/services/routes/RouteStepHighlight.d.ts +22 -0
- package/dist/services/routes/RouteStepHighlight.d.ts.map +1 -0
- package/dist/services/routes/RouteStepHighlight.js +84 -0
- package/dist/services/routes/routeMarkers.d.ts +6 -0
- package/dist/services/routes/routeMarkers.d.ts.map +1 -0
- package/dist/services/routes/routeMarkers.js +41 -0
- package/dist/services/selectionPaint.d.ts +12 -0
- package/dist/services/selectionPaint.d.ts.map +1 -0
- package/dist/services/selectionPaint.js +8 -0
- package/dist/services/shape-services/ExtrudeShapeService.d.ts +54 -0
- package/dist/services/shape-services/ExtrudeShapeService.d.ts.map +1 -0
- package/dist/services/shape-services/ExtrudeShapeService.js +204 -0
- package/dist/services/shape-services/FlatShapeService.d.ts +25 -0
- package/dist/services/shape-services/FlatShapeService.d.ts.map +1 -0
- package/dist/services/shape-services/FlatShapeService.js +49 -0
- package/dist/services/shape-services/IShapeService.d.ts +24 -0
- package/dist/services/shape-services/IShapeService.d.ts.map +1 -0
- package/dist/services/shape-services/IShapeService.js +6 -0
- package/dist/services/shape-services/MaterialUtils.d.ts +15 -0
- package/dist/services/shape-services/MaterialUtils.d.ts.map +1 -0
- package/dist/services/shape-services/MaterialUtils.js +71 -0
- package/dist/services/shape-services/ShapeFactory.d.ts +20 -0
- package/dist/services/shape-services/ShapeFactory.d.ts.map +1 -0
- package/dist/services/shape-services/ShapeFactory.js +28 -0
- package/dist/services/shape-services/ShapeHighlightService.d.ts +13 -0
- package/dist/services/shape-services/ShapeHighlightService.d.ts.map +1 -0
- package/dist/services/shape-services/ShapeHighlightService.js +57 -0
- package/dist/services/shape-services/ShapeService.d.ts +129 -0
- package/dist/services/shape-services/ShapeService.d.ts.map +1 -0
- package/dist/services/shape-services/ShapeService.js +480 -0
- package/dist/services/shape-services/preparedGeometry.d.ts +13 -0
- package/dist/services/shape-services/preparedGeometry.d.ts.map +1 -0
- package/dist/services/shape-services/preparedGeometry.js +37 -0
- package/dist/services/text-services/ITextRenderStrategy.d.ts +79 -0
- package/dist/services/text-services/ITextRenderStrategy.d.ts.map +1 -0
- package/dist/services/text-services/ITextRenderStrategy.js +7 -0
- package/dist/services/text-services/Text2DService.d.ts +66 -0
- package/dist/services/text-services/Text2DService.d.ts.map +1 -0
- package/dist/services/text-services/Text2DService.js +483 -0
- package/dist/services/text-services/Text3DService.d.ts +51 -0
- package/dist/services/text-services/Text3DService.d.ts.map +1 -0
- package/dist/services/text-services/Text3DService.js +246 -0
- package/dist/services/text-services/TextCollisionService.d.ts +29 -0
- package/dist/services/text-services/TextCollisionService.d.ts.map +1 -0
- package/dist/services/text-services/TextCollisionService.js +117 -0
- package/dist/services/text-services/TextService.d.ts +159 -0
- package/dist/services/text-services/TextService.d.ts.map +1 -0
- package/dist/services/text-services/TextService.js +398 -0
- package/dist/services/text-services/TextStrategyRegistry.d.ts +36 -0
- package/dist/services/text-services/TextStrategyRegistry.d.ts.map +1 -0
- package/dist/services/text-services/TextStrategyRegistry.js +44 -0
- package/dist/services/threeDisposeHelper.d.ts +12 -0
- package/dist/services/threeDisposeHelper.d.ts.map +1 -0
- package/dist/services/threeDisposeHelper.js +57 -0
- package/package.json +40 -3
- package/README.md +0 -3
|
@@ -0,0 +1,1041 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file MapViewerEngine.ts
|
|
3
|
+
* @description Framework-neutral 3D map viewer composition root and orchestrator.
|
|
4
|
+
* English: Headless 3D Map Engine coordinating renderers and centrally resolving theme override precedence.
|
|
5
|
+
* Hinglish: Managers (Renderer, Camera, Controls, Lighting, Interaction) ko coordinate karne wala clean orchestrator jisme theme overrides ki precedence centrally resolve hoti hai.
|
|
6
|
+
*/
|
|
7
|
+
import * as THREE from 'three';
|
|
8
|
+
import { resolveMapTheme } from '@wovvmap/contracts';
|
|
9
|
+
import { ViewerElementsController } from '../controllers/ViewerElementsController.js';
|
|
10
|
+
import { disposeThreeObject } from '../services/threeDisposeHelper.js';
|
|
11
|
+
import { RouteRenderer } from '../services/routes/RouteRenderer.js';
|
|
12
|
+
import { RendererManager } from './RendererManager.js';
|
|
13
|
+
import { CameraManager } from './CameraManager.js';
|
|
14
|
+
import { ControlsManager } from './ControlsManager.js';
|
|
15
|
+
import { LightingManager } from './LightingManager.js';
|
|
16
|
+
import { InteractionManager } from './InteractionManager.js';
|
|
17
|
+
/**
|
|
18
|
+
* Pure Three.js Headless 3D Map Engine Orchestrator.
|
|
19
|
+
* Follows SOLID principles: Delegates specific responsibilities to specialized managers.
|
|
20
|
+
*
|
|
21
|
+
* Map viewer ke sabhi managers ko aapas me connect aur coordinate karta hai.
|
|
22
|
+
*/
|
|
23
|
+
export class MapViewerEngine {
|
|
24
|
+
scene;
|
|
25
|
+
routes;
|
|
26
|
+
rendererManager;
|
|
27
|
+
cameraManager;
|
|
28
|
+
controlsManager;
|
|
29
|
+
lightingManager;
|
|
30
|
+
interactionManager;
|
|
31
|
+
elementsController;
|
|
32
|
+
activeFloorGroup = new THREE.Group();
|
|
33
|
+
activeFloor = 0;
|
|
34
|
+
currentMode = '3D';
|
|
35
|
+
labelsVisible = true;
|
|
36
|
+
imagesVisible = true;
|
|
37
|
+
shapesVisible = true;
|
|
38
|
+
controlsEnabled = true;
|
|
39
|
+
lightsEnabled = true;
|
|
40
|
+
frameloop = 'demand';
|
|
41
|
+
currentTheme;
|
|
42
|
+
depthConfig;
|
|
43
|
+
// Explicit child component overrides preserving precedence over base theme
|
|
44
|
+
cameraConfigOverride;
|
|
45
|
+
spriteThemeOverride;
|
|
46
|
+
lightsOverride;
|
|
47
|
+
shapeEdgeColorOverride;
|
|
48
|
+
anchorGradientOverride;
|
|
49
|
+
customColorsOverride;
|
|
50
|
+
textColorsOverride;
|
|
51
|
+
container = null;
|
|
52
|
+
canvas = null;
|
|
53
|
+
rafId = null;
|
|
54
|
+
frameDocument;
|
|
55
|
+
hostActive = true;
|
|
56
|
+
contextLost = false;
|
|
57
|
+
renderSuspended = false;
|
|
58
|
+
/** Surface lifetime notification; the SDK's shared route owner retires pending presentation.
|
|
59
|
+
* Hinglish: Browser/Native outage par callback se wahi route state pause ho; engine doosra store na rakhe. */
|
|
60
|
+
onRenderUnavailable;
|
|
61
|
+
onVisibilityChange = () => {
|
|
62
|
+
this.syncRenderAvailability();
|
|
63
|
+
this.invalidate();
|
|
64
|
+
};
|
|
65
|
+
onContextLost = (event) => {
|
|
66
|
+
event.preventDefault();
|
|
67
|
+
this.contextLost = true;
|
|
68
|
+
this.syncRenderAvailability();
|
|
69
|
+
};
|
|
70
|
+
onContextRestored = () => {
|
|
71
|
+
this.contextLost = false;
|
|
72
|
+
this.onVisibilityChange();
|
|
73
|
+
};
|
|
74
|
+
isInvalidated = false;
|
|
75
|
+
isDisposed = false;
|
|
76
|
+
activePresetTransitionId = 0;
|
|
77
|
+
onCameraIntent;
|
|
78
|
+
routeCameraView = 'street';
|
|
79
|
+
onCameraTransitionCancelled;
|
|
80
|
+
activeModeTransitionId = 0;
|
|
81
|
+
activeModeTransition;
|
|
82
|
+
/**
|
|
83
|
+
* Settles any in-flight mode transition promise with false.
|
|
84
|
+
* Chalu mode transition request ko cancel karke promise ko false se settle karein.
|
|
85
|
+
*/
|
|
86
|
+
cancelActiveModeTransition() {
|
|
87
|
+
if (this.activeModeTransition) {
|
|
88
|
+
const prevResolve = this.activeModeTransition.resolve;
|
|
89
|
+
this.activeModeTransition = undefined;
|
|
90
|
+
prevResolve(false);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Registers a callback invoked whenever a direct engine camera preset animation begins.
|
|
95
|
+
* Direct camera animation shuru hone par external transitions (e.g. coordinator) ko cancel karne ka hook.
|
|
96
|
+
*/
|
|
97
|
+
setOnCameraTransitionCancelled(cb) {
|
|
98
|
+
this.onCameraTransitionCancelled = cb;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Cancels active direct camera preset transition so superseded callbacks do not touch controls/limits.
|
|
102
|
+
* Direct camera preset transition ko cancel karein.
|
|
103
|
+
*/
|
|
104
|
+
cancelActiveCameraTransitions() {
|
|
105
|
+
this.activePresetTransitionId++;
|
|
106
|
+
}
|
|
107
|
+
/** Existing engine intent identity also advances for direct button zoom, independently of coordinator focus.
|
|
108
|
+
* Hinglish: Naya counter nahi; zoom/preset ka existing ID pending route focus ko supersede karne de. */
|
|
109
|
+
get cameraTransitionId() {
|
|
110
|
+
return this.activePresetTransitionId;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Returns whether this engine has been disposed.
|
|
114
|
+
* English: Public lifecycle check indicating if WebGL resources have been torn down.
|
|
115
|
+
* Hinglish: Check karein ki engine dispose ho chuka hai ya abhi active hai.
|
|
116
|
+
*/
|
|
117
|
+
get disposed() {
|
|
118
|
+
return this.isDisposed;
|
|
119
|
+
}
|
|
120
|
+
hasPendingCollision = false;
|
|
121
|
+
forceImmediateCollision = false;
|
|
122
|
+
lastCollisionTime = 0;
|
|
123
|
+
collisionSettledTimer = null;
|
|
124
|
+
collisionThrottleTimer = null;
|
|
125
|
+
static COLLISION_THROTTLE_MS = 100;
|
|
126
|
+
constructor(options) {
|
|
127
|
+
this.scene = new THREE.Scene();
|
|
128
|
+
this.scene.name = 'wovvmap-root-scene';
|
|
129
|
+
this.routes = new RouteRenderer(this.scene, () => this.invalidate(), (position, forward, delta) => {
|
|
130
|
+
if (position && !this.routeAnimationReady())
|
|
131
|
+
return;
|
|
132
|
+
if (this.cameraManager.followRoute(position, forward, this.controls, this.routeCameraView, delta))
|
|
133
|
+
this.invalidate();
|
|
134
|
+
});
|
|
135
|
+
this.rendererManager = new RendererManager();
|
|
136
|
+
this.cameraManager = new CameraManager();
|
|
137
|
+
this.controlsManager = new ControlsManager();
|
|
138
|
+
this.lightingManager = new LightingManager();
|
|
139
|
+
this.interactionManager = new InteractionManager();
|
|
140
|
+
this.elementsController = options?.elementsController || new ViewerElementsController();
|
|
141
|
+
this.currentTheme = resolveMapTheme(options?.theme);
|
|
142
|
+
this.routes.setTheme(this.currentTheme);
|
|
143
|
+
this.elementsController.setTheme(this.currentTheme);
|
|
144
|
+
this.depthConfig = options?.depthConfig;
|
|
145
|
+
this.routes.setFloorBaseDepth(this.depthConfig?.floorBaseDepth);
|
|
146
|
+
this.activeFloor = options?.defaultFloor ?? 0;
|
|
147
|
+
this.currentMode = options?.viewMode ?? '3D';
|
|
148
|
+
this.controlsEnabled = options?.controlsEnabled ?? true;
|
|
149
|
+
this.lightsEnabled = options?.lightsEnabled ?? true;
|
|
150
|
+
// Setup scene graph hierarchy
|
|
151
|
+
this.activeFloorGroup.name = 'wovvmap-active-floor-group';
|
|
152
|
+
this.scene.add(this.lightingManager.lightsGroup);
|
|
153
|
+
this.scene.add(this.activeFloorGroup);
|
|
154
|
+
this.elementsController.setOnInvalidate(() => this.invalidate());
|
|
155
|
+
}
|
|
156
|
+
// --- Convenience Getters for Symmetry ---
|
|
157
|
+
get glRenderer() {
|
|
158
|
+
return this.rendererManager.glRenderer;
|
|
159
|
+
}
|
|
160
|
+
get labelRenderer() {
|
|
161
|
+
return this.rendererManager.labelRenderer;
|
|
162
|
+
}
|
|
163
|
+
get camera() {
|
|
164
|
+
return this.cameraManager.getCamera();
|
|
165
|
+
}
|
|
166
|
+
get controls() {
|
|
167
|
+
return this.controlsManager.controls;
|
|
168
|
+
}
|
|
169
|
+
/** Explicit button zoom shares camera math and cancels only the superseded camera transition.
|
|
170
|
+
* Hinglish: Button zoom ka math CameraManager mein hai; purana camera tween hi cancel hoga. */
|
|
171
|
+
zoomBy(factor) {
|
|
172
|
+
const controls = this.controls;
|
|
173
|
+
if (this.isDisposed ||
|
|
174
|
+
!this.controlsEnabled ||
|
|
175
|
+
!controls?.enabled ||
|
|
176
|
+
!controls.enableZoom ||
|
|
177
|
+
!Number.isFinite(factor) ||
|
|
178
|
+
factor <= 0)
|
|
179
|
+
return false;
|
|
180
|
+
if (this.onCameraIntent?.() === false)
|
|
181
|
+
return false;
|
|
182
|
+
this.cancelActiveCameraTransitions();
|
|
183
|
+
const cancelled = this.onCameraTransitionCancelled;
|
|
184
|
+
this.onCameraTransitionCancelled = undefined;
|
|
185
|
+
cancelled?.();
|
|
186
|
+
this.cameraManager.killAnimations();
|
|
187
|
+
this.controlsManager.restoreLimits();
|
|
188
|
+
const changed = this.cameraManager.zoomBy(factor, controls);
|
|
189
|
+
if (changed)
|
|
190
|
+
this.invalidate();
|
|
191
|
+
return changed;
|
|
192
|
+
}
|
|
193
|
+
get lightsGroup() {
|
|
194
|
+
return this.lightingManager.lightsGroup;
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Returns actively attached DOM container element.
|
|
198
|
+
* Actively attached DOM container prapt karein.
|
|
199
|
+
*/
|
|
200
|
+
get attachedContainer() {
|
|
201
|
+
return this.container;
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Returns actively attached DOM canvas element.
|
|
205
|
+
* Actively attached DOM canvas prapt karein.
|
|
206
|
+
*/
|
|
207
|
+
get attachedCanvas() {
|
|
208
|
+
return this.canvas;
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Initializes renderers on provided DOM elements and begins render loop.
|
|
212
|
+
* Renderers aur canvas ko initialize karke rendering start karein.
|
|
213
|
+
*/
|
|
214
|
+
/**
|
|
215
|
+
* Returns whether the engine is actively attached to DOM container and canvas.
|
|
216
|
+
* Check karein ki engine container aur canvas par attached hai ya nahi.
|
|
217
|
+
*/
|
|
218
|
+
isAttached() {
|
|
219
|
+
return Boolean(this.container && this.canvas);
|
|
220
|
+
}
|
|
221
|
+
init(container, canvas, glConfig, dpr, frameloop = 'demand') {
|
|
222
|
+
if (this.container === container && this.canvas === canvas) {
|
|
223
|
+
// English: Live update frameloop and dpr on existing WebGLRenderer without duplicate initialization.
|
|
224
|
+
// Hinglish: WebGLRenderer ko dobara init kiye bina frameloop aur dpr ko live update karein.
|
|
225
|
+
if (frameloop !== undefined && this.frameloop !== frameloop) {
|
|
226
|
+
this.frameloop = frameloop;
|
|
227
|
+
if (frameloop === 'always') {
|
|
228
|
+
this.startRafLoop();
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
if (dpr !== undefined) {
|
|
232
|
+
this.rendererManager.setPixelRatio(dpr);
|
|
233
|
+
}
|
|
234
|
+
// Reusing a detached canvas must wake the existing demand scheduler, not recreate the renderer.
|
|
235
|
+
// Hinglish: Wahi DOM canvas wapas aaye to clock reset/resume ho; camera/controls dobara setup nahi.
|
|
236
|
+
if (this.routes.hasAnimation) {
|
|
237
|
+
this.routes.resetAnimationClock();
|
|
238
|
+
this.invalidate();
|
|
239
|
+
}
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
this.canvas?.removeEventListener?.('webglcontextlost', this.onContextLost);
|
|
243
|
+
this.canvas?.removeEventListener?.('webglcontextrestored', this.onContextRestored);
|
|
244
|
+
this.contextLost = false;
|
|
245
|
+
this.container = container;
|
|
246
|
+
this.canvas = canvas;
|
|
247
|
+
canvas.addEventListener?.('webglcontextlost', this.onContextLost);
|
|
248
|
+
canvas.addEventListener?.('webglcontextrestored', this.onContextRestored);
|
|
249
|
+
this.frameloop = frameloop;
|
|
250
|
+
this.routes.resetAnimationClock();
|
|
251
|
+
const frameDocument = canvas.ownerDocument;
|
|
252
|
+
if (this.frameDocument !== frameDocument) {
|
|
253
|
+
this.frameDocument?.removeEventListener('visibilitychange', this.onVisibilityChange);
|
|
254
|
+
this.frameDocument = frameDocument;
|
|
255
|
+
this.frameDocument?.addEventListener('visibilitychange', this.onVisibilityChange);
|
|
256
|
+
}
|
|
257
|
+
this.rendererManager.init(container, canvas, glConfig, dpr, (w, h) => {
|
|
258
|
+
this.handleResize(w, h);
|
|
259
|
+
});
|
|
260
|
+
this.rendererManager.updateTheme(this.currentTheme);
|
|
261
|
+
const width = container.clientWidth || 800;
|
|
262
|
+
const height = container.clientHeight || 600;
|
|
263
|
+
this.setupCamera(this.cameraConfigOverride, width / (height || 1));
|
|
264
|
+
if (this.frameloop === 'always') {
|
|
265
|
+
this.startRafLoop();
|
|
266
|
+
}
|
|
267
|
+
else {
|
|
268
|
+
this.invalidate();
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Updates dynamic depth configuration and rescales floor elements.
|
|
273
|
+
* Dynamic depth update karke active floor ke shapes ki height adjust karein.
|
|
274
|
+
*/
|
|
275
|
+
setDynamicDepth(depthConfig) {
|
|
276
|
+
this.cancelActiveModeTransition();
|
|
277
|
+
this.depthConfig = { ...this.depthConfig, ...depthConfig };
|
|
278
|
+
this.routes.setFloorBaseDepth(this.depthConfig.floorBaseDepth);
|
|
279
|
+
this.elementsController.setFloorScale(this.activeFloor, this.currentMode, this.depthConfig);
|
|
280
|
+
this.invalidate();
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* Updates CSS label style overrides on RendererManager.
|
|
284
|
+
* 2D DOM labels ke container styles update karein.
|
|
285
|
+
*/
|
|
286
|
+
updateLabelStyles(styles) {
|
|
287
|
+
this.rendererManager.setLabelStyles(styles);
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* Switches view mode (3D, 2D, etc.).
|
|
291
|
+
* View mode ('2D' ya '3D') switch karein aur camera/depth sync karein.
|
|
292
|
+
*/
|
|
293
|
+
setViewMode(mode, animate = true, durationMs = 400) {
|
|
294
|
+
if (this.onCameraIntent?.() === false)
|
|
295
|
+
return Promise.resolve(false);
|
|
296
|
+
this.currentMode = mode;
|
|
297
|
+
this.cancelActiveModeTransition();
|
|
298
|
+
const transitionId = ++this.activeModeTransitionId;
|
|
299
|
+
let outerResolve;
|
|
300
|
+
const promise = new Promise((resolve) => {
|
|
301
|
+
outerResolve = resolve;
|
|
302
|
+
});
|
|
303
|
+
this.activeModeTransition = { id: transitionId, resolve: outerResolve };
|
|
304
|
+
const onUpdate = () => {
|
|
305
|
+
if (this.activeModeTransition?.id !== transitionId)
|
|
306
|
+
return;
|
|
307
|
+
// Point 4: Request throttled collision pass during transition
|
|
308
|
+
this.hasPendingCollision = true;
|
|
309
|
+
this.invalidate();
|
|
310
|
+
};
|
|
311
|
+
const onComplete = () => {
|
|
312
|
+
if (this.activeModeTransition?.id === transitionId) {
|
|
313
|
+
this.activeModeTransition = undefined;
|
|
314
|
+
// Point 4: Final unthrottled collision pass when transition settles
|
|
315
|
+
this.hasPendingCollision = true;
|
|
316
|
+
this.forceImmediateCollision = true;
|
|
317
|
+
this.invalidate();
|
|
318
|
+
outerResolve(true);
|
|
319
|
+
}
|
|
320
|
+
};
|
|
321
|
+
this.elementsController.setFloorScale(this.activeFloor, mode, this.depthConfig, animate, onUpdate, durationMs, onComplete);
|
|
322
|
+
if (!animate) {
|
|
323
|
+
if (this.activeModeTransition?.id === transitionId) {
|
|
324
|
+
this.activeModeTransition = undefined;
|
|
325
|
+
this.hasPendingCollision = true;
|
|
326
|
+
this.forceImmediateCollision = true;
|
|
327
|
+
this.invalidate();
|
|
328
|
+
outerResolve(true);
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
return promise;
|
|
332
|
+
}
|
|
333
|
+
/**
|
|
334
|
+
* Returns active explicit camera configuration override, or undefined if using default mode camera.
|
|
335
|
+
* English: Exposes caller-configured camera override so attachment preserves declarative <MapCamera /> props.
|
|
336
|
+
* Hinglish: Caller ke explicit camera overrides prapt karein taaki canvas attach hone par <MapCamera /> props retain rahein.
|
|
337
|
+
*/
|
|
338
|
+
getCameraConfigOverride() {
|
|
339
|
+
return this.cameraConfigOverride;
|
|
340
|
+
}
|
|
341
|
+
/**
|
|
342
|
+
* Configures camera mode (3D, 2D, SkyView, StreetView, or custom).
|
|
343
|
+
* English: Creates the initial camera or applies updated camera configuration while preserving active pose on repeated bindings.
|
|
344
|
+
* Hinglish: Initial camera create karein ya existing camera par configuration apply karein bina repeated binding par active pose reset kiye.
|
|
345
|
+
*/
|
|
346
|
+
setupCamera(config, forcedAspect) {
|
|
347
|
+
const effectiveConfig = this.cameraManager.resolveConfig(config, this.cameraConfigOverride, this.currentMode);
|
|
348
|
+
const override = this.cameraConfigOverride;
|
|
349
|
+
const changed = config !== undefined &&
|
|
350
|
+
Object.entries(config).some(([key, value]) => {
|
|
351
|
+
const previous = override?.[key];
|
|
352
|
+
return Array.isArray(value) && Array.isArray(previous)
|
|
353
|
+
? value.some((item, i) => item !== previous[i])
|
|
354
|
+
: value !== previous;
|
|
355
|
+
});
|
|
356
|
+
if (forcedAspect === undefined && changed && this.onCameraIntent?.() === false)
|
|
357
|
+
return;
|
|
358
|
+
if (config !== undefined || override !== undefined)
|
|
359
|
+
this.cameraConfigOverride = effectiveConfig;
|
|
360
|
+
const width = this.container?.clientWidth || 800;
|
|
361
|
+
const height = this.container?.clientHeight || 600;
|
|
362
|
+
const aspect = forcedAspect ?? width / (height || 1);
|
|
363
|
+
const previousCamera = this.cameraManager.getCamera();
|
|
364
|
+
const lookAtChanged = effectiveConfig.lookAt !== undefined &&
|
|
365
|
+
!this.cameraManager.isSameAppliedLookAt(effectiveConfig.lookAt);
|
|
366
|
+
const positionChanged = effectiveConfig.position !== undefined &&
|
|
367
|
+
!this.cameraManager.isSameAppliedPosition(effectiveConfig.position);
|
|
368
|
+
const cam = previousCamera
|
|
369
|
+
? this.cameraManager.applyConfig(effectiveConfig, aspect)
|
|
370
|
+
: this.cameraManager.setup(effectiveConfig, aspect);
|
|
371
|
+
// Rebind controls only when the camera instance is replaced or explicit pose (lookAt/position) genuinely changed
|
|
372
|
+
// Camera instance replace hone ya explicit lookAt/position genuinely change hone par hi controls rebind aur update karein.
|
|
373
|
+
if (previousCamera !== cam || lookAtChanged || positionChanged) {
|
|
374
|
+
const targetLookAt = effectiveConfig.lookAt ??
|
|
375
|
+
(previousCamera !== cam
|
|
376
|
+
? (this.cameraManager.getPreset(effectiveConfig.mode ?? this.currentMode)
|
|
377
|
+
?.defaultLookAt ?? [0, 0, 0])
|
|
378
|
+
: undefined);
|
|
379
|
+
if ((previousCamera !== cam || lookAtChanged) && targetLookAt) {
|
|
380
|
+
this.controlsManager.setPreservedTarget(targetLookAt[0], targetLookAt[1], targetLookAt[2]);
|
|
381
|
+
}
|
|
382
|
+
if (this.controlsManager.controls) {
|
|
383
|
+
this.controlsManager.controls.object = cam;
|
|
384
|
+
if ((previousCamera !== cam || lookAtChanged) && targetLookAt) {
|
|
385
|
+
this.controlsManager.controls.target.set(targetLookAt[0], targetLookAt[1], targetLookAt[2]);
|
|
386
|
+
}
|
|
387
|
+
this.controlsManager.controls.update();
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
// Mark collision pending exempt from movement throttle for new camera mode
|
|
391
|
+
// Naye camera mode (2D ya 3D) ke mutabik unthrottled collision pending mark karein.
|
|
392
|
+
this.hasPendingCollision = true;
|
|
393
|
+
this.forceImmediateCollision = true;
|
|
394
|
+
this.invalidate();
|
|
395
|
+
}
|
|
396
|
+
/**
|
|
397
|
+
* Declaratively replaces controls configuration with declared props (used by React adapter).
|
|
398
|
+
* Restores defaults for any omitted/removed props to eliminate stale overrides.
|
|
399
|
+
* React adapter ke declared props ke anusar controls configuration synchronize karta hai.
|
|
400
|
+
*/
|
|
401
|
+
setControlsConfig(config) {
|
|
402
|
+
this.controlsManager.setDeclarativeConfig(config);
|
|
403
|
+
this.invalidate();
|
|
404
|
+
}
|
|
405
|
+
/**
|
|
406
|
+
* Dynamically updates active OrbitControls configuration without recreation.
|
|
407
|
+
* Controls configuration update karein.
|
|
408
|
+
*/
|
|
409
|
+
updateControls(config) {
|
|
410
|
+
this.controlsManager.updateConfig(config);
|
|
411
|
+
this.invalidate();
|
|
412
|
+
}
|
|
413
|
+
/**
|
|
414
|
+
* Configures OrbitControls with camera rotation sync and text collision hooks.
|
|
415
|
+
* Marks controlsEnabled true so deferred canvas attachment preserves declarative intent.
|
|
416
|
+
* OrbitControls attach karein aur camera rotation listener bind karein.
|
|
417
|
+
*/
|
|
418
|
+
setupControls(config) {
|
|
419
|
+
this.controlsEnabled = true;
|
|
420
|
+
if (config !== undefined) {
|
|
421
|
+
this.controlsManager.setCallerConfig(config);
|
|
422
|
+
}
|
|
423
|
+
const cam = this.cameraManager.getCamera();
|
|
424
|
+
if (!cam || !this.canvas)
|
|
425
|
+
return;
|
|
426
|
+
const effectiveConfig = config ?? this.controlsManager.config;
|
|
427
|
+
this.controlsManager.attach(cam, this.canvas, effectiveConfig, () => {
|
|
428
|
+
// Dynamically resolve active camera to prevent stale camera reference after 2D/3D mode switch
|
|
429
|
+
// 2D/3D mode switch ke baad stale camera reference se bachne ke liye current active camera retrieve karein.
|
|
430
|
+
const activeCam = this.controlsManager.controls?.object ?? this.cameraManager.getCamera();
|
|
431
|
+
if (!activeCam)
|
|
432
|
+
return;
|
|
433
|
+
this.elementsController.updateCameraRotation(activeCam.rotation.z, this.activeFloor);
|
|
434
|
+
// Mark collision pending for post-render execution
|
|
435
|
+
this.hasPendingCollision = true;
|
|
436
|
+
// Trailing timer: when damping or drag settles, run final post-render collision pass
|
|
437
|
+
if (this.collisionSettledTimer !== null) {
|
|
438
|
+
clearTimeout(this.collisionSettledTimer);
|
|
439
|
+
}
|
|
440
|
+
this.collisionSettledTimer = setTimeout(() => {
|
|
441
|
+
this.collisionSettledTimer = null;
|
|
442
|
+
this.hasPendingCollision = true;
|
|
443
|
+
this.forceImmediateCollision = true;
|
|
444
|
+
this.invalidate();
|
|
445
|
+
}, 80);
|
|
446
|
+
this.invalidate();
|
|
447
|
+
});
|
|
448
|
+
}
|
|
449
|
+
/**
|
|
450
|
+
* Disables and disposes active OrbitControls and clears pending collision timers.
|
|
451
|
+
* English: Tears down OrbitControls and marks controlsEnabled false so re-attach will not recreate them.
|
|
452
|
+
* Hinglish: OrbitControls aur input listeners ko dispose karein aur controlsEnabled false mark karein.
|
|
453
|
+
*/
|
|
454
|
+
disposeControls() {
|
|
455
|
+
this.controlsEnabled = false;
|
|
456
|
+
if (this.collisionSettledTimer !== null) {
|
|
457
|
+
clearTimeout(this.collisionSettledTimer);
|
|
458
|
+
this.collisionSettledTimer = null;
|
|
459
|
+
}
|
|
460
|
+
this.controlsManager.dispose();
|
|
461
|
+
this.invalidate();
|
|
462
|
+
}
|
|
463
|
+
/**
|
|
464
|
+
* Returns active explicit lighting overrides, or undefined if lights follow base theme.
|
|
465
|
+
* Active explicit lighting overrides prapt karein ya undefined agar lights theme follow kar rahi hain.
|
|
466
|
+
*/
|
|
467
|
+
getLightsOverride() {
|
|
468
|
+
return this.lightsOverride;
|
|
469
|
+
}
|
|
470
|
+
/**
|
|
471
|
+
* Configures scene lights via LightingManager.
|
|
472
|
+
* Explicit overrides are merged on top of theme lights and preserved across theme switches.
|
|
473
|
+
*
|
|
474
|
+
* English: Enables and configures scene lights with explicit override retention across theme switches.
|
|
475
|
+
* Hinglish: Scene lights enable aur configure karein; explicit overrides theme badalne par bhi retain rahenge.
|
|
476
|
+
*/
|
|
477
|
+
setupLights(config) {
|
|
478
|
+
this.lightsEnabled = true;
|
|
479
|
+
if (config !== undefined) {
|
|
480
|
+
const hasProps = Boolean(config.ambient || config.hemisphere || config.directionalMain || config.directionalBack);
|
|
481
|
+
this.lightsOverride = hasProps ? config : undefined;
|
|
482
|
+
}
|
|
483
|
+
else {
|
|
484
|
+
this.lightsOverride = undefined;
|
|
485
|
+
}
|
|
486
|
+
const themeLights = this.currentTheme.lights;
|
|
487
|
+
const effectiveConfig = this.lightsOverride
|
|
488
|
+
? {
|
|
489
|
+
ambient: { ...themeLights?.ambient, ...this.lightsOverride.ambient },
|
|
490
|
+
hemisphere: { ...themeLights?.hemisphere, ...this.lightsOverride.hemisphere },
|
|
491
|
+
directionalMain: {
|
|
492
|
+
...themeLights?.directionalMain,
|
|
493
|
+
...this.lightsOverride.directionalMain,
|
|
494
|
+
},
|
|
495
|
+
directionalBack: {
|
|
496
|
+
...themeLights?.directionalBack,
|
|
497
|
+
...this.lightsOverride.directionalBack,
|
|
498
|
+
},
|
|
499
|
+
}
|
|
500
|
+
: themeLights;
|
|
501
|
+
this.lightingManager.setup(effectiveConfig);
|
|
502
|
+
this.invalidate();
|
|
503
|
+
}
|
|
504
|
+
/**
|
|
505
|
+
* Disables and disposes managed scene lights and clears lighting overrides.
|
|
506
|
+
* English: Tears down scene lights and marks lightsEnabled false so theme updates or re-attach do not recreate them.
|
|
507
|
+
* Hinglish: Scene lights aur overrides ko dispose karein aur lightsEnabled false mark karein taaki theme change par wapas na banein.
|
|
508
|
+
*/
|
|
509
|
+
disposeLights() {
|
|
510
|
+
this.lightsEnabled = false;
|
|
511
|
+
this.lightsOverride = undefined;
|
|
512
|
+
this.lightingManager.dispose();
|
|
513
|
+
this.invalidate();
|
|
514
|
+
}
|
|
515
|
+
/**
|
|
516
|
+
* Switches active map theme across scene lights, image sprites, canvas, and 2D labels.
|
|
517
|
+
* Explicit child component overrides are strictly preserved over base theme defaults.
|
|
518
|
+
* Base theme update karein; explicit component overrides defaults se overwrite nahi honge.
|
|
519
|
+
*/
|
|
520
|
+
setTheme(theme) {
|
|
521
|
+
this.currentTheme = resolveMapTheme(theme);
|
|
522
|
+
this.routes.setTheme(this.currentTheme);
|
|
523
|
+
// English: Only reapply scene lights when lighting is enabled and already active in the scene.
|
|
524
|
+
// Hinglish: Scene lights tabhi reapply karein jab lighting enabled ho aur scene me active ho.
|
|
525
|
+
if (this.lightsEnabled && this.lightsGroup.children.length > 0) {
|
|
526
|
+
this.setupLights(this.lightsOverride);
|
|
527
|
+
}
|
|
528
|
+
if (this.currentTheme.backgroundColor) {
|
|
529
|
+
this.rendererManager.setClearColor(this.currentTheme.backgroundColor, 0);
|
|
530
|
+
}
|
|
531
|
+
this.rendererManager.updateTheme(this.currentTheme);
|
|
532
|
+
// Central Precedence Resolution: Overrides take precedence over base theme
|
|
533
|
+
this.elementsController.setTheme(this.currentTheme);
|
|
534
|
+
if (this.spriteThemeOverride !== undefined) {
|
|
535
|
+
this.elementsController.updateSpriteThemes(this.spriteThemeOverride);
|
|
536
|
+
}
|
|
537
|
+
const effectiveGradient = this.anchorGradientOverride !== undefined
|
|
538
|
+
? this.anchorGradientOverride
|
|
539
|
+
: this.currentTheme.anchorStoreGradient;
|
|
540
|
+
if (effectiveGradient) {
|
|
541
|
+
this.elementsController.updateAnchorGradient(effectiveGradient);
|
|
542
|
+
}
|
|
543
|
+
const effectiveEdgeColor = this.shapeEdgeColorOverride !== undefined
|
|
544
|
+
? this.shapeEdgeColorOverride
|
|
545
|
+
: this.currentTheme.shapeEdgeColor;
|
|
546
|
+
this.elementsController.updateEdgeColor(effectiveEdgeColor);
|
|
547
|
+
if (this.customColorsOverride) {
|
|
548
|
+
this.elementsController.updateShapeColors(this.customColorsOverride);
|
|
549
|
+
}
|
|
550
|
+
if (this.textColorsOverride !== undefined) {
|
|
551
|
+
this.elementsController.updateTextColors(this.textColorsOverride);
|
|
552
|
+
}
|
|
553
|
+
this.invalidate();
|
|
554
|
+
}
|
|
555
|
+
get theme() {
|
|
556
|
+
return this.currentTheme;
|
|
557
|
+
}
|
|
558
|
+
/**
|
|
559
|
+
* Toggles visibility and filter criteria for brand logos and sprites.
|
|
560
|
+
* Logos aur sprites ki visibility aur filters toggle karein.
|
|
561
|
+
*/
|
|
562
|
+
toggleImages(visible, filter) {
|
|
563
|
+
this.imagesVisible = visible;
|
|
564
|
+
this.elementsController.toggleImages(visible, filter);
|
|
565
|
+
this.invalidate();
|
|
566
|
+
}
|
|
567
|
+
/**
|
|
568
|
+
* Updates transit/amenity icon sprite background badge colors.
|
|
569
|
+
* Sprites ke background badge colors update karein.
|
|
570
|
+
*/
|
|
571
|
+
updateSpriteThemes(colorOrMap) {
|
|
572
|
+
// English: Store caller explicit override; pass undefined through on reset so service clears explicit overrides.
|
|
573
|
+
// Hinglish: Caller ka explicit override store karein; reset par undefined pass karein taaki underlying service me explicit override genuinely clear ho.
|
|
574
|
+
this.spriteThemeOverride = colorOrMap;
|
|
575
|
+
this.elementsController.updateSpriteThemes(colorOrMap);
|
|
576
|
+
this.invalidate();
|
|
577
|
+
}
|
|
578
|
+
/**
|
|
579
|
+
* Updates anchor store gradient fill colors.
|
|
580
|
+
* Anchor store shapes ke gradient colors update karein.
|
|
581
|
+
*/
|
|
582
|
+
updateAnchorGradient(gradient) {
|
|
583
|
+
this.anchorGradientOverride = gradient;
|
|
584
|
+
const effective = gradient !== undefined ? gradient : this.currentTheme.anchorStoreGradient;
|
|
585
|
+
this.elementsController.updateAnchorGradient(effective);
|
|
586
|
+
this.invalidate();
|
|
587
|
+
}
|
|
588
|
+
/**
|
|
589
|
+
* Toggles visibility of extruded 3D store shapes.
|
|
590
|
+
* 3D unit store shapes ki visibility toggle karein.
|
|
591
|
+
*/
|
|
592
|
+
toggleShapes(visible) {
|
|
593
|
+
const changed = this.shapesVisible !== visible;
|
|
594
|
+
this.shapesVisible = visible;
|
|
595
|
+
this.elementsController.toggleShapes(visible);
|
|
596
|
+
if (changed) {
|
|
597
|
+
this.invalidate();
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
/**
|
|
601
|
+
* Updates edge outline stroke color for 3D store meshes.
|
|
602
|
+
* Store meshes ke outline edges ka rang badlein.
|
|
603
|
+
*/
|
|
604
|
+
updateEdgeColor(color) {
|
|
605
|
+
this.shapeEdgeColorOverride = color;
|
|
606
|
+
const effective = color !== undefined ? color : this.currentTheme.shapeEdgeColor;
|
|
607
|
+
this.elementsController.updateEdgeColor(effective);
|
|
608
|
+
this.invalidate();
|
|
609
|
+
}
|
|
610
|
+
/**
|
|
611
|
+
* Applies custom per-store fill colors map.
|
|
612
|
+
* Unit-level custom colors map update karein.
|
|
613
|
+
*/
|
|
614
|
+
updateShapeColors(colorsMap) {
|
|
615
|
+
this.customColorsOverride =
|
|
616
|
+
colorsMap && Object.keys(colorsMap).length > 0 ? colorsMap : undefined;
|
|
617
|
+
this.elementsController.updateShapeColors(colorsMap ?? {});
|
|
618
|
+
this.invalidate();
|
|
619
|
+
}
|
|
620
|
+
/**
|
|
621
|
+
* Sets camera preset with smooth animation and controls alignment.
|
|
622
|
+
* English: Moves camera to named preset configuration with animation.
|
|
623
|
+
* Hinglish: Camera ko preset configuration (sky, street, 3D, 2D) me smoothly animate karta hai.
|
|
624
|
+
*/
|
|
625
|
+
setCameraPreset(mode, durationSec = 1.0) {
|
|
626
|
+
const preset = this.cameraManager.getPreset(mode);
|
|
627
|
+
if (!preset)
|
|
628
|
+
return Promise.resolve(false);
|
|
629
|
+
// English: Release coordinator ownership before starting direct preset so old transition settles and limits listener detaches.
|
|
630
|
+
// Hinglish: Direct preset start hone se pehle registered coordinator transition ko cancel aur detach karein.
|
|
631
|
+
if (this.onCameraTransitionCancelled) {
|
|
632
|
+
const cb = this.onCameraTransitionCancelled;
|
|
633
|
+
this.onCameraTransitionCancelled = undefined;
|
|
634
|
+
cb();
|
|
635
|
+
}
|
|
636
|
+
const transitionId = ++this.activePresetTransitionId;
|
|
637
|
+
this.controlsManager.unlockLimits();
|
|
638
|
+
return this.cameraManager
|
|
639
|
+
.animateTo(preset.defaultPosition, preset.defaultLookAt, durationSec, () => {
|
|
640
|
+
// Point 4: renderFrame() owns controls update; onUpdate only invalidates
|
|
641
|
+
this.invalidate();
|
|
642
|
+
}, this.controlsManager.controls?.target)
|
|
643
|
+
.then((completed) => {
|
|
644
|
+
// If superseded by a newer preset request, do not mutate controls or restore limits!
|
|
645
|
+
if (this.activePresetTransitionId !== transitionId) {
|
|
646
|
+
return false;
|
|
647
|
+
}
|
|
648
|
+
if (completed) {
|
|
649
|
+
const p1 = new THREE.Vector3(...preset.defaultPosition);
|
|
650
|
+
const p2 = new THREE.Vector3(...preset.defaultLookAt);
|
|
651
|
+
const distance = p1.distanceTo(p2);
|
|
652
|
+
const minDistance = Math.max(15, distance * 0.35);
|
|
653
|
+
const maxDistance = Math.max(distance * 1.5, minDistance + 50);
|
|
654
|
+
const maxPolarAngle = Math.PI / 2.5;
|
|
655
|
+
this.controlsManager.setDistanceLimits(minDistance, maxDistance, maxPolarAngle);
|
|
656
|
+
this.invalidate();
|
|
657
|
+
}
|
|
658
|
+
else {
|
|
659
|
+
if (!this.cameraManager.isAnimating) {
|
|
660
|
+
this.controlsManager.restoreLimits();
|
|
661
|
+
this.invalidate();
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
return completed;
|
|
665
|
+
});
|
|
666
|
+
}
|
|
667
|
+
/**
|
|
668
|
+
* Toggles store labels visibility across 2D DOM and 3D Troika text.
|
|
669
|
+
* Store labels (2D aur 3D) ki visibility toggle karein.
|
|
670
|
+
*/
|
|
671
|
+
toggleLabels(visible) {
|
|
672
|
+
const changed = this.labelsVisible !== visible;
|
|
673
|
+
this.labelsVisible = visible;
|
|
674
|
+
this.elementsController.toggleLabels(visible);
|
|
675
|
+
if (changed) {
|
|
676
|
+
this.invalidate();
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
/**
|
|
680
|
+
* Updates text colors globally or per category.
|
|
681
|
+
* Text labels ke colors update karein.
|
|
682
|
+
*/
|
|
683
|
+
updateTextColors(colorOrMap) {
|
|
684
|
+
this.textColorsOverride = colorOrMap;
|
|
685
|
+
this.elementsController.updateTextColors(colorOrMap);
|
|
686
|
+
this.invalidate();
|
|
687
|
+
}
|
|
688
|
+
/**
|
|
689
|
+
* Switches active text label rendering type ('2D' DOM or '3D' Troika mesh).
|
|
690
|
+
* Active text label rendering type ('2D' ya '3D') set karein.
|
|
691
|
+
*/
|
|
692
|
+
setTextType(type) {
|
|
693
|
+
if (this.elementsController.getTextType() === type)
|
|
694
|
+
return;
|
|
695
|
+
this.elementsController.setTextType(type);
|
|
696
|
+
this.invalidate();
|
|
697
|
+
}
|
|
698
|
+
/**
|
|
699
|
+
* Returns current active text label type ('2D' or '3D').
|
|
700
|
+
* Active text label type prapt karein.
|
|
701
|
+
*/
|
|
702
|
+
getTextType() {
|
|
703
|
+
return this.elementsController.getTextType();
|
|
704
|
+
}
|
|
705
|
+
requestCollisionPass() {
|
|
706
|
+
const cam = this.cameraManager.getCamera();
|
|
707
|
+
if (cam) {
|
|
708
|
+
this.elementsController.updateTextCollision(cam, this.activeFloor);
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
/** Paint only changed selection keys and request one redraw/collision pass without camera work.
|
|
712
|
+
* Hinglish: Sirf badle hue store ka paint aur redraw ho; floor/camera recreate nahi hota. */
|
|
713
|
+
setSelection(key) {
|
|
714
|
+
this.setSelectionKeys(key === null ? [] : [key]);
|
|
715
|
+
}
|
|
716
|
+
/** Paint a member-key difference in one frame without changing floor or camera state.
|
|
717
|
+
* Hinglish: Group ki badli hui keys ek frame mein paint hon; floor/camera ka flow same rahe. */
|
|
718
|
+
setSelectionKeys(keys) {
|
|
719
|
+
if (this.isDisposed || !this.elementsController.setSelectionKeys(keys))
|
|
720
|
+
return;
|
|
721
|
+
this.hasPendingCollision = true;
|
|
722
|
+
this.forceImmediateCollision = true;
|
|
723
|
+
this.invalidate();
|
|
724
|
+
}
|
|
725
|
+
/** Project both endpoint roles in one paint/collision update; no semantic or camera mutation.
|
|
726
|
+
* Hinglish: Dono roles ka paint ek update mein ho; state/setFloor/camera command yahan nahi. */
|
|
727
|
+
setEndpointSelectionKeys(origin, destination) {
|
|
728
|
+
if (this.isDisposed || !this.elementsController.setEndpointSelectionKeys(origin, destination))
|
|
729
|
+
return;
|
|
730
|
+
this.hasPendingCollision = true;
|
|
731
|
+
this.forceImmediateCollision = true;
|
|
732
|
+
this.invalidate();
|
|
733
|
+
}
|
|
734
|
+
/**
|
|
735
|
+
* Schedules or executes text collision check.
|
|
736
|
+
* Text collision resolution run karne wala delegate method.
|
|
737
|
+
*/
|
|
738
|
+
scheduleTextCollision() {
|
|
739
|
+
const cam = this.cameraManager.getCamera();
|
|
740
|
+
this.elementsController.scheduleTextCollision(cam ?? undefined, this.activeFloor);
|
|
741
|
+
}
|
|
742
|
+
/**
|
|
743
|
+
* Resolves pointer / tap coordinate against interactive scene objects.
|
|
744
|
+
* Pointer event coordinate ko scene mesh se raycast karke hit detect karein.
|
|
745
|
+
*/
|
|
746
|
+
resolvePointer(event, intersectObjects) {
|
|
747
|
+
const cam = this.cameraManager.getCamera();
|
|
748
|
+
const bounds = this.canvas?.getBoundingClientRect() ??
|
|
749
|
+
{ left: 0, top: 0, width: 800, height: 600 };
|
|
750
|
+
const clientX = 'clientX' in event ? event.clientX : (event.touches?.[0]?.clientX ?? 0);
|
|
751
|
+
const clientY = 'clientY' in event ? event.clientY : (event.touches?.[0]?.clientY ?? 0);
|
|
752
|
+
return this.interactionManager.onPointerUp(clientX, clientY, bounds, cam, intersectObjects?.[0] ?? this.activeFloorGroup);
|
|
753
|
+
}
|
|
754
|
+
/**
|
|
755
|
+
* Mounts the active floor's shapes, logos, and labels into activeFloorGroup.
|
|
756
|
+
* Active floor ke sabhi shapes, images aur text ko scene me attach karein.
|
|
757
|
+
*/
|
|
758
|
+
loadFloor(floorIndex) {
|
|
759
|
+
this.routes.setFloor(floorIndex);
|
|
760
|
+
this.cancelActiveModeTransition();
|
|
761
|
+
this.elementsController.cleanupTextDOM();
|
|
762
|
+
// Clear previous floor elements
|
|
763
|
+
while (this.activeFloorGroup.children.length > 0) {
|
|
764
|
+
this.activeFloorGroup.remove(this.activeFloorGroup.children[0]);
|
|
765
|
+
}
|
|
766
|
+
this.activeFloor = floorIndex;
|
|
767
|
+
// Attach Shapes for this floor
|
|
768
|
+
const shapes = this.elementsController.getFloorWiseShapes(floorIndex);
|
|
769
|
+
if (shapes) {
|
|
770
|
+
shapes.visible = this.shapesVisible;
|
|
771
|
+
this.activeFloorGroup.add(shapes);
|
|
772
|
+
}
|
|
773
|
+
// Attach Images / Transit Icons
|
|
774
|
+
const images = this.elementsController.getFloorWiseImages(floorIndex);
|
|
775
|
+
if (images) {
|
|
776
|
+
images.visible = this.imagesVisible;
|
|
777
|
+
this.activeFloorGroup.add(images);
|
|
778
|
+
}
|
|
779
|
+
// Attach Text Labels
|
|
780
|
+
const texts = this.elementsController.getFloorWiseTexts(floorIndex);
|
|
781
|
+
if (texts) {
|
|
782
|
+
texts.visible = this.labelsVisible;
|
|
783
|
+
this.activeFloorGroup.add(texts);
|
|
784
|
+
}
|
|
785
|
+
// Coordinate 2D vs 3D scale and dynamic depth across newly attached floor elements
|
|
786
|
+
// Naye floor par active mode (2D/3D) aur dynamic depth scaling turant sync karein.
|
|
787
|
+
this.elementsController.setFloorScale(this.activeFloor, this.currentMode, this.depthConfig);
|
|
788
|
+
// Immediately synchronize camera orientation across newly mounted floor images and 3D labels
|
|
789
|
+
// English: Applies current camera rotation to newly mounted images and 3D text labels to prevent inverted text.
|
|
790
|
+
// Hinglish: Naye floor ke images aur 3D labels par current camera rotation turant apply karein taaki text ulta na dikhe.
|
|
791
|
+
const cam = this.cameraManager.getCamera();
|
|
792
|
+
if (cam) {
|
|
793
|
+
this.elementsController.updateCameraRotation(cam.rotation.z, this.activeFloor);
|
|
794
|
+
}
|
|
795
|
+
// Mark collision pending exempt from movement throttle (guarantees zero flash on floor change)
|
|
796
|
+
// Floor change par initial collision pass movement throttle se exempt rahe taaki zero flash guarantee ho.
|
|
797
|
+
this.hasPendingCollision = true;
|
|
798
|
+
this.forceImmediateCollision = true;
|
|
799
|
+
this.invalidate();
|
|
800
|
+
}
|
|
801
|
+
/**
|
|
802
|
+
* Captures pointer down coordinate for drag threshold tracking.
|
|
803
|
+
* Pointer down coordinate record karein taaki drag detect ho sake.
|
|
804
|
+
*/
|
|
805
|
+
// --- Pointer & Raycasting Interaction ---
|
|
806
|
+
handlePointerDown(clientX, clientY) {
|
|
807
|
+
this.interactionManager.onPointerDown(clientX, clientY);
|
|
808
|
+
}
|
|
809
|
+
/** Forward gesture movement/cancellation to the existing interaction owner.
|
|
810
|
+
* Hinglish: Route tap aur orbit/cancel ek hi pointer lifecycle se resolve hon. */
|
|
811
|
+
handlePointerMove(clientX, clientY) {
|
|
812
|
+
this.interactionManager.onPointerMove(clientX, clientY);
|
|
813
|
+
}
|
|
814
|
+
cancelPointerGesture() {
|
|
815
|
+
this.interactionManager.dispose();
|
|
816
|
+
}
|
|
817
|
+
/**
|
|
818
|
+
* Evaluates pointer up against click threshold and returns hit result.
|
|
819
|
+
* Pointer up par click evaluate karein aur clicked unit object return karein.
|
|
820
|
+
*/
|
|
821
|
+
handlePointerUp(clientX, clientY, canvasBounds) {
|
|
822
|
+
const cam = this.cameraManager.getCamera();
|
|
823
|
+
return this.interactionManager.onPointerUp(clientX, clientY, canvasBounds, cam, this.activeFloorGroup, (raycaster) => this.routes.pick(raycaster));
|
|
824
|
+
}
|
|
825
|
+
/**
|
|
826
|
+
* Schedules a frame render on demand.
|
|
827
|
+
* Scene invalidation par agla animation frame schedule karein.
|
|
828
|
+
*/
|
|
829
|
+
invalidate() {
|
|
830
|
+
if (this.isDisposed)
|
|
831
|
+
return;
|
|
832
|
+
this.isInvalidated = true;
|
|
833
|
+
this.startRafLoop();
|
|
834
|
+
}
|
|
835
|
+
/** Hosts supply activity only; route state remains in the shared route owner.
|
|
836
|
+
* Hinglish: Native AppState aur browser visibility ek hi render gate use karein; naya store/RAF nahi. */
|
|
837
|
+
setHostActive(active) {
|
|
838
|
+
if (this.isDisposed || this.hostActive === active)
|
|
839
|
+
return;
|
|
840
|
+
this.hostActive = active;
|
|
841
|
+
this.onVisibilityChange();
|
|
842
|
+
}
|
|
843
|
+
surfaceReady() {
|
|
844
|
+
return (!this.isDisposed &&
|
|
845
|
+
this.isAttached() &&
|
|
846
|
+
this.hostActive &&
|
|
847
|
+
!this.contextLost &&
|
|
848
|
+
this.canvas?.isConnected !== false &&
|
|
849
|
+
this.frameDocument?.visibilityState !== 'hidden' &&
|
|
850
|
+
!this.glRenderer?.getContext?.()?.isContextLost());
|
|
851
|
+
}
|
|
852
|
+
syncRenderAvailability() {
|
|
853
|
+
if (this.surfaceReady()) {
|
|
854
|
+
this.renderSuspended = false;
|
|
855
|
+
this.routes.resetAnimationClock();
|
|
856
|
+
return true;
|
|
857
|
+
}
|
|
858
|
+
if (this.rafId !== null) {
|
|
859
|
+
if (typeof cancelAnimationFrame !== 'undefined')
|
|
860
|
+
cancelAnimationFrame(this.rafId);
|
|
861
|
+
this.rafId = null;
|
|
862
|
+
}
|
|
863
|
+
if (!this.renderSuspended) {
|
|
864
|
+
this.renderSuspended = true;
|
|
865
|
+
this.cameraManager.killAnimations();
|
|
866
|
+
this.cancelActiveModeTransition();
|
|
867
|
+
for (const finish of [...this.routeFrameWaiters])
|
|
868
|
+
finish(false);
|
|
869
|
+
this.routes.resetAnimationClock();
|
|
870
|
+
this.onRenderUnavailable?.();
|
|
871
|
+
}
|
|
872
|
+
return false;
|
|
873
|
+
}
|
|
874
|
+
routeAnimationReady() {
|
|
875
|
+
const context = this.glRenderer?.getContext?.();
|
|
876
|
+
return this.surfaceReady() && !!context && !context.isContextLost();
|
|
877
|
+
}
|
|
878
|
+
/** Commands use the same render-readiness gate as RAF; suspended time is not visual movement.
|
|
879
|
+
* Hinglish: Hidden/detached/context-lost canvas par speed edits se cursor aage nahi badhe.
|
|
880
|
+
*/
|
|
881
|
+
routeFrameWaiters = new Set();
|
|
882
|
+
/** Reuse the engine's demand frame; no polling, second RAF or image/font readiness dependency.
|
|
883
|
+
* Hinglish: Floor upload/render ke baad hi playback chale; cancel/dispose/timeout par waiter hat jaye. */
|
|
884
|
+
waitForRouteFrame(signal) {
|
|
885
|
+
if (!this.routeAnimationReady() || signal.aborted)
|
|
886
|
+
return Promise.resolve(false);
|
|
887
|
+
return new Promise((resolve) => {
|
|
888
|
+
const finish = (ready) => {
|
|
889
|
+
clearTimeout(deadline);
|
|
890
|
+
signal.removeEventListener('abort', aborted);
|
|
891
|
+
this.routeFrameWaiters.delete(finish);
|
|
892
|
+
resolve(ready);
|
|
893
|
+
};
|
|
894
|
+
const aborted = () => finish(false);
|
|
895
|
+
const deadline = setTimeout(() => finish(false), 8000);
|
|
896
|
+
signal.addEventListener('abort', aborted, { once: true });
|
|
897
|
+
this.routeFrameWaiters.add(finish);
|
|
898
|
+
this.invalidate();
|
|
899
|
+
});
|
|
900
|
+
}
|
|
901
|
+
getRouteAnimationTime() {
|
|
902
|
+
return this.routeAnimationReady() ? performance.now() : Number.NaN;
|
|
903
|
+
}
|
|
904
|
+
renderFrame(time = performance.now()) {
|
|
905
|
+
this.rafId = null;
|
|
906
|
+
if (this.isDisposed)
|
|
907
|
+
return;
|
|
908
|
+
if (!this.surfaceReady()) {
|
|
909
|
+
this.syncRenderAvailability();
|
|
910
|
+
return;
|
|
911
|
+
}
|
|
912
|
+
this.renderSuspended = false;
|
|
913
|
+
const arrowsReady = this.routeAnimationReady();
|
|
914
|
+
const moving = arrowsReady && this.routes.hasAnimation;
|
|
915
|
+
if (!moving)
|
|
916
|
+
this.routes.resetAnimationClock();
|
|
917
|
+
const arrowFrame = moving && this.routes.update(time);
|
|
918
|
+
if (this.frameloop === 'always' || this.isInvalidated || arrowFrame) {
|
|
919
|
+
const externallyDirty = this.isInvalidated;
|
|
920
|
+
this.isInvalidated = false;
|
|
921
|
+
if (this.controlsManager.controls && !this.cameraManager.isRouteFollowing) {
|
|
922
|
+
this.controlsManager.controls.update();
|
|
923
|
+
}
|
|
924
|
+
const cam = this.cameraManager.getCamera();
|
|
925
|
+
if (cam) {
|
|
926
|
+
// Arrow-only demand frames reuse DOM label placement; controls may dirty it during update.
|
|
927
|
+
// Hinglish: Arrows se CSS2D loop nahi; camera/damping/label invalidation ka update miss bhi nahi.
|
|
928
|
+
const updateLabels = this.frameloop === 'always' ||
|
|
929
|
+
externallyDirty ||
|
|
930
|
+
this.isInvalidated ||
|
|
931
|
+
this.hasPendingCollision;
|
|
932
|
+
this.rendererManager.render(this.scene, cam, updateLabels);
|
|
933
|
+
if (this.routeAnimationReady())
|
|
934
|
+
for (const finish of [...this.routeFrameWaiters])
|
|
935
|
+
finish(true);
|
|
936
|
+
// POST-RENDER COLLISION:
|
|
937
|
+
// Runs right after CSS2DRenderer has positioned all labels in the DOM for this exact camera frame.
|
|
938
|
+
// CSS2DRenderer ke DOM elements position karne ke turant baad latest coordinates par collision run karein.
|
|
939
|
+
if (updateLabels && this.hasPendingCollision) {
|
|
940
|
+
const now = performance.now();
|
|
941
|
+
const elapsed = now - this.lastCollisionTime;
|
|
942
|
+
if (this.forceImmediateCollision || elapsed >= MapViewerEngine.COLLISION_THROTTLE_MS) {
|
|
943
|
+
this.hasPendingCollision = false;
|
|
944
|
+
this.forceImmediateCollision = false;
|
|
945
|
+
this.lastCollisionTime = now;
|
|
946
|
+
if (this.collisionThrottleTimer !== null) {
|
|
947
|
+
clearTimeout(this.collisionThrottleTimer);
|
|
948
|
+
this.collisionThrottleTimer = null;
|
|
949
|
+
}
|
|
950
|
+
this.elementsController.updateTextCollision(cam, this.activeFloor);
|
|
951
|
+
}
|
|
952
|
+
else if (this.collisionThrottleTimer === null) {
|
|
953
|
+
const remaining = MapViewerEngine.COLLISION_THROTTLE_MS - elapsed;
|
|
954
|
+
this.collisionThrottleTimer = setTimeout(() => {
|
|
955
|
+
this.collisionThrottleTimer = null;
|
|
956
|
+
this.forceImmediateCollision = true;
|
|
957
|
+
this.invalidate();
|
|
958
|
+
}, remaining);
|
|
959
|
+
}
|
|
960
|
+
}
|
|
961
|
+
}
|
|
962
|
+
}
|
|
963
|
+
// Rendering can synchronously hide/dispose the surface; reuse the same readiness gate before scheduling again.
|
|
964
|
+
// Hinglish: onAfterRender/unmount ke baad old frame naya RAF na banaye; ek hi scheduler owner rahe.
|
|
965
|
+
if (this.frameloop === 'always' || (arrowsReady && this.routes.hasAnimation))
|
|
966
|
+
this.startRafLoop();
|
|
967
|
+
}
|
|
968
|
+
startRafLoop() {
|
|
969
|
+
if (typeof requestAnimationFrame === 'undefined' || !this.surfaceReady())
|
|
970
|
+
return;
|
|
971
|
+
if (this.rafId === null) {
|
|
972
|
+
this.rafId = requestAnimationFrame((time) => this.renderFrame(time));
|
|
973
|
+
}
|
|
974
|
+
}
|
|
975
|
+
/**
|
|
976
|
+
* Handles container resize and camera aspect ratio update.
|
|
977
|
+
* Viewport resize hone par camera aspect ratio aur canvas size update karein.
|
|
978
|
+
*/
|
|
979
|
+
handleResize(width, height) {
|
|
980
|
+
const aspect = width / (height || 1);
|
|
981
|
+
this.cameraManager.updateAspect(aspect);
|
|
982
|
+
// Mark unthrottled collision pending so labels re-evaluate for the new viewport dimensions
|
|
983
|
+
// Viewport dimensions change hone par updated coordinates ke sath unthrottled collision run karein.
|
|
984
|
+
this.hasPendingCollision = true;
|
|
985
|
+
this.forceImmediateCollision = true;
|
|
986
|
+
this.invalidate();
|
|
987
|
+
}
|
|
988
|
+
/**
|
|
989
|
+
* Disposes all managers and frees scene memory cleanly.
|
|
990
|
+
* Sabhi managers ko dispose karein aur WebGL/DOM resources clean karein.
|
|
991
|
+
*/
|
|
992
|
+
dispose() {
|
|
993
|
+
this.canvas?.removeEventListener?.('webglcontextlost', this.onContextLost);
|
|
994
|
+
this.canvas?.removeEventListener?.('webglcontextrestored', this.onContextRestored);
|
|
995
|
+
this.onRenderUnavailable = undefined;
|
|
996
|
+
this.frameDocument?.removeEventListener('visibilitychange', this.onVisibilityChange);
|
|
997
|
+
this.frameDocument = undefined;
|
|
998
|
+
this.routes.dispose();
|
|
999
|
+
if (this.isDisposed)
|
|
1000
|
+
return;
|
|
1001
|
+
this.isDisposed = true;
|
|
1002
|
+
for (const finish of [...this.routeFrameWaiters])
|
|
1003
|
+
finish(false);
|
|
1004
|
+
this.cancelActiveModeTransition();
|
|
1005
|
+
if (this.rafId !== null) {
|
|
1006
|
+
if (typeof cancelAnimationFrame !== 'undefined') {
|
|
1007
|
+
cancelAnimationFrame(this.rafId);
|
|
1008
|
+
}
|
|
1009
|
+
this.rafId = null;
|
|
1010
|
+
}
|
|
1011
|
+
if (this.collisionSettledTimer !== null) {
|
|
1012
|
+
clearTimeout(this.collisionSettledTimer);
|
|
1013
|
+
this.collisionSettledTimer = null;
|
|
1014
|
+
}
|
|
1015
|
+
if (this.collisionThrottleTimer !== null) {
|
|
1016
|
+
clearTimeout(this.collisionThrottleTimer);
|
|
1017
|
+
this.collisionThrottleTimer = null;
|
|
1018
|
+
}
|
|
1019
|
+
this.elementsController.cleanupTextDOM();
|
|
1020
|
+
this.elementsController.clear();
|
|
1021
|
+
this.controlsManager.dispose();
|
|
1022
|
+
this.cameraManager.dispose();
|
|
1023
|
+
this.lightingManager.dispose();
|
|
1024
|
+
this.interactionManager.dispose();
|
|
1025
|
+
this.rendererManager.dispose();
|
|
1026
|
+
if (this.scene && typeof this.scene.traverse === 'function') {
|
|
1027
|
+
const objectsToDispose = [];
|
|
1028
|
+
this.scene.traverse((obj) => {
|
|
1029
|
+
if (obj !== this.scene) {
|
|
1030
|
+
objectsToDispose.push(obj);
|
|
1031
|
+
}
|
|
1032
|
+
});
|
|
1033
|
+
this.scene.clear();
|
|
1034
|
+
objectsToDispose.forEach((obj) => {
|
|
1035
|
+
disposeThreeObject(obj);
|
|
1036
|
+
});
|
|
1037
|
+
}
|
|
1038
|
+
this.container = null;
|
|
1039
|
+
this.canvas = null;
|
|
1040
|
+
}
|
|
1041
|
+
}
|