@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.
Files changed (116) hide show
  1. package/dist/controllers/ImageController.d.ts +95 -0
  2. package/dist/controllers/ImageController.d.ts.map +1 -0
  3. package/dist/controllers/ImageController.js +129 -0
  4. package/dist/controllers/ShapeController.d.ts +95 -0
  5. package/dist/controllers/ShapeController.d.ts.map +1 -0
  6. package/dist/controllers/ShapeController.js +139 -0
  7. package/dist/controllers/TextController.d.ts +120 -0
  8. package/dist/controllers/TextController.d.ts.map +1 -0
  9. package/dist/controllers/TextController.js +161 -0
  10. package/dist/controllers/ViewerElementsController.d.ts +254 -0
  11. package/dist/controllers/ViewerElementsController.d.ts.map +1 -0
  12. package/dist/controllers/ViewerElementsController.js +490 -0
  13. package/dist/engine/CameraFollow.d.ts +13 -0
  14. package/dist/engine/CameraFollow.d.ts.map +1 -0
  15. package/dist/engine/CameraFollow.js +52 -0
  16. package/dist/engine/CameraManager.d.ts +143 -0
  17. package/dist/engine/CameraManager.d.ts.map +1 -0
  18. package/dist/engine/CameraManager.js +566 -0
  19. package/dist/engine/ControlsManager.d.ts +123 -0
  20. package/dist/engine/ControlsManager.d.ts.map +1 -0
  21. package/dist/engine/ControlsManager.js +604 -0
  22. package/dist/engine/InteractionManager.d.ts +45 -0
  23. package/dist/engine/InteractionManager.d.ts.map +1 -0
  24. package/dist/engine/InteractionManager.js +99 -0
  25. package/dist/engine/LightingManager.d.ts +25 -0
  26. package/dist/engine/LightingManager.d.ts.map +1 -0
  27. package/dist/engine/LightingManager.js +74 -0
  28. package/dist/engine/MapViewerEngine.d.ts +350 -0
  29. package/dist/engine/MapViewerEngine.d.ts.map +1 -0
  30. package/dist/engine/MapViewerEngine.js +1041 -0
  31. package/dist/engine/RendererManager.d.ts +77 -0
  32. package/dist/engine/RendererManager.d.ts.map +1 -0
  33. package/dist/engine/RendererManager.js +243 -0
  34. package/dist/index.d.ts +40 -0
  35. package/dist/index.d.ts.map +1 -0
  36. package/dist/index.js +39 -0
  37. package/dist/services/image-services/ImageCacheService.d.ts +49 -0
  38. package/dist/services/image-services/ImageCacheService.d.ts.map +1 -0
  39. package/dist/services/image-services/ImageCacheService.js +121 -0
  40. package/dist/services/image-services/ImagePlaneService.d.ts +29 -0
  41. package/dist/services/image-services/ImagePlaneService.d.ts.map +1 -0
  42. package/dist/services/image-services/ImagePlaneService.js +82 -0
  43. package/dist/services/image-services/ImageService.d.ts +170 -0
  44. package/dist/services/image-services/ImageService.d.ts.map +1 -0
  45. package/dist/services/image-services/ImageService.js +537 -0
  46. package/dist/services/image-services/ImageSpriteService.d.ts +39 -0
  47. package/dist/services/image-services/ImageSpriteService.d.ts.map +1 -0
  48. package/dist/services/image-services/ImageSpriteService.js +135 -0
  49. package/dist/services/routes/RouteArrows.d.ts +34 -0
  50. package/dist/services/routes/RouteArrows.d.ts.map +1 -0
  51. package/dist/services/routes/RouteArrows.js +157 -0
  52. package/dist/services/routes/RouteCursor.d.ts +19 -0
  53. package/dist/services/routes/RouteCursor.d.ts.map +1 -0
  54. package/dist/services/routes/RouteCursor.js +68 -0
  55. package/dist/services/routes/RouteMotion.d.ts +31 -0
  56. package/dist/services/routes/RouteMotion.d.ts.map +1 -0
  57. package/dist/services/routes/RouteMotion.js +132 -0
  58. package/dist/services/routes/RouteRenderer.d.ts +52 -0
  59. package/dist/services/routes/RouteRenderer.d.ts.map +1 -0
  60. package/dist/services/routes/RouteRenderer.js +445 -0
  61. package/dist/services/routes/RouteStepHighlight.d.ts +22 -0
  62. package/dist/services/routes/RouteStepHighlight.d.ts.map +1 -0
  63. package/dist/services/routes/RouteStepHighlight.js +84 -0
  64. package/dist/services/routes/routeMarkers.d.ts +6 -0
  65. package/dist/services/routes/routeMarkers.d.ts.map +1 -0
  66. package/dist/services/routes/routeMarkers.js +41 -0
  67. package/dist/services/selectionPaint.d.ts +12 -0
  68. package/dist/services/selectionPaint.d.ts.map +1 -0
  69. package/dist/services/selectionPaint.js +8 -0
  70. package/dist/services/shape-services/ExtrudeShapeService.d.ts +54 -0
  71. package/dist/services/shape-services/ExtrudeShapeService.d.ts.map +1 -0
  72. package/dist/services/shape-services/ExtrudeShapeService.js +204 -0
  73. package/dist/services/shape-services/FlatShapeService.d.ts +25 -0
  74. package/dist/services/shape-services/FlatShapeService.d.ts.map +1 -0
  75. package/dist/services/shape-services/FlatShapeService.js +49 -0
  76. package/dist/services/shape-services/IShapeService.d.ts +24 -0
  77. package/dist/services/shape-services/IShapeService.d.ts.map +1 -0
  78. package/dist/services/shape-services/IShapeService.js +6 -0
  79. package/dist/services/shape-services/MaterialUtils.d.ts +15 -0
  80. package/dist/services/shape-services/MaterialUtils.d.ts.map +1 -0
  81. package/dist/services/shape-services/MaterialUtils.js +71 -0
  82. package/dist/services/shape-services/ShapeFactory.d.ts +20 -0
  83. package/dist/services/shape-services/ShapeFactory.d.ts.map +1 -0
  84. package/dist/services/shape-services/ShapeFactory.js +28 -0
  85. package/dist/services/shape-services/ShapeHighlightService.d.ts +13 -0
  86. package/dist/services/shape-services/ShapeHighlightService.d.ts.map +1 -0
  87. package/dist/services/shape-services/ShapeHighlightService.js +57 -0
  88. package/dist/services/shape-services/ShapeService.d.ts +129 -0
  89. package/dist/services/shape-services/ShapeService.d.ts.map +1 -0
  90. package/dist/services/shape-services/ShapeService.js +480 -0
  91. package/dist/services/shape-services/preparedGeometry.d.ts +13 -0
  92. package/dist/services/shape-services/preparedGeometry.d.ts.map +1 -0
  93. package/dist/services/shape-services/preparedGeometry.js +37 -0
  94. package/dist/services/text-services/ITextRenderStrategy.d.ts +79 -0
  95. package/dist/services/text-services/ITextRenderStrategy.d.ts.map +1 -0
  96. package/dist/services/text-services/ITextRenderStrategy.js +7 -0
  97. package/dist/services/text-services/Text2DService.d.ts +66 -0
  98. package/dist/services/text-services/Text2DService.d.ts.map +1 -0
  99. package/dist/services/text-services/Text2DService.js +483 -0
  100. package/dist/services/text-services/Text3DService.d.ts +51 -0
  101. package/dist/services/text-services/Text3DService.d.ts.map +1 -0
  102. package/dist/services/text-services/Text3DService.js +246 -0
  103. package/dist/services/text-services/TextCollisionService.d.ts +29 -0
  104. package/dist/services/text-services/TextCollisionService.d.ts.map +1 -0
  105. package/dist/services/text-services/TextCollisionService.js +117 -0
  106. package/dist/services/text-services/TextService.d.ts +159 -0
  107. package/dist/services/text-services/TextService.d.ts.map +1 -0
  108. package/dist/services/text-services/TextService.js +398 -0
  109. package/dist/services/text-services/TextStrategyRegistry.d.ts +36 -0
  110. package/dist/services/text-services/TextStrategyRegistry.d.ts.map +1 -0
  111. package/dist/services/text-services/TextStrategyRegistry.js +44 -0
  112. package/dist/services/threeDisposeHelper.d.ts +12 -0
  113. package/dist/services/threeDisposeHelper.d.ts.map +1 -0
  114. package/dist/services/threeDisposeHelper.js +57 -0
  115. package/package.json +40 -3
  116. package/README.md +0 -3
@@ -0,0 +1,566 @@
1
+ /**
2
+ * @file CameraManager.ts
3
+ * @description Decoupled Camera Manager separating Camera Projection Types from View Modes/Presets.
4
+ * Camera projection (Perspective vs Orthographic vs Custom) ko strategy registry se dynamically resolve karta hai.
5
+ */
6
+ import * as THREE from 'three';
7
+ import { CameraFollow } from './CameraFollow.js';
8
+ import { gsap } from 'gsap';
9
+ /**
10
+ * Open/Closed Camera Manager.
11
+ * Fully decoupled from hardcoded modes: Any mode can use Perspective or Orthographic projections.
12
+ *
13
+ * Camera projection aur view presets ko coordinate karne wala extensible manager.
14
+ */
15
+ export class CameraManager {
16
+ camera = null;
17
+ presets = new Map();
18
+ cameraFactories = new Map();
19
+ cameraAspectUpdaters = new Map();
20
+ activeCameraType = null;
21
+ activeMode = null;
22
+ currentConfig;
23
+ lastAppliedPosition;
24
+ lastAppliedLookAt;
25
+ lastAppliedZoom;
26
+ routeFollow = new CameraFollow();
27
+ activeTween = null;
28
+ /**
29
+ * Resolves an incoming camera configuration against the active mode/projection and previous saved config.
30
+ * Discards stale pose and projection overrides when switching modes or projection types, while preserving active mode/projection on partial updates.
31
+ * Mode ya projection switch hone par purane pose/projection overrides hata kar consistent effective config resolve karein.
32
+ */
33
+ resolveConfig(config, previousOverride, fallbackMode = '3D') {
34
+ const baseOverride = previousOverride ?? this.currentConfig;
35
+ const prevMode = baseOverride?.mode ?? this.activeMode ?? fallbackMode;
36
+ const requestedMode = config?.mode ?? prevMode ?? '3D';
37
+ const preset = this.presets.get(requestedMode);
38
+ const modeChanged = config?.mode !== undefined && prevMode !== null && requestedMode !== prevMode;
39
+ const prevCameraType = (baseOverride?.cameraType ?? this.activeCameraType)?.toLowerCase() ?? null;
40
+ const rawType = config?.cameraType ??
41
+ (modeChanged
42
+ ? preset?.defaultCameraType
43
+ : (baseOverride?.cameraType ?? this.activeCameraType ?? preset?.defaultCameraType)) ??
44
+ 'perspective';
45
+ const cameraTypeKey = rawType.toLowerCase();
46
+ const cameraTypeChanged = config?.cameraType !== undefined &&
47
+ prevCameraType !== null &&
48
+ cameraTypeKey !== prevCameraType;
49
+ if (!config) {
50
+ if (baseOverride) {
51
+ return {
52
+ ...baseOverride,
53
+ mode: requestedMode,
54
+ cameraType: rawType,
55
+ };
56
+ }
57
+ return {
58
+ mode: requestedMode,
59
+ cameraType: rawType,
60
+ };
61
+ }
62
+ if (modeChanged || cameraTypeChanged) {
63
+ return {
64
+ ...config,
65
+ mode: requestedMode,
66
+ cameraType: rawType,
67
+ };
68
+ }
69
+ return {
70
+ ...baseOverride,
71
+ ...config,
72
+ mode: requestedMode,
73
+ cameraType: rawType,
74
+ };
75
+ }
76
+ isTuple3Equal(a, b) {
77
+ return Boolean(a && b && a[0] === b[0] && a[1] === b[1] && a[2] === b[2]);
78
+ }
79
+ /**
80
+ * Returns true when the given position matches the last explicitly applied camera position.
81
+ * Check karein ki diya gaya position last applied explicit camera position ke barabar hai ya nahi.
82
+ */
83
+ isSameAppliedPosition(position) {
84
+ if (!position)
85
+ return true;
86
+ return this.isTuple3Equal(this.lastAppliedPosition, position);
87
+ }
88
+ /**
89
+ * Returns true when the given lookAt target matches the last explicitly applied camera lookAt target.
90
+ * Check karein ki diya gaya lookAt target last applied explicit camera lookAt ke barabar hai ya nahi.
91
+ */
92
+ isSameAppliedLookAt(lookAt) {
93
+ if (!lookAt)
94
+ return true;
95
+ return this.isTuple3Equal(this.lastAppliedLookAt, lookAt);
96
+ }
97
+ /**
98
+ * Indicates whether a camera animation tween is currently active.
99
+ * Camera animation active hai ya nahi ye verify karta hai.
100
+ */
101
+ get isAnimating() {
102
+ return this.activeTween !== null;
103
+ }
104
+ constructor() {
105
+ this.registerDefaultPresets();
106
+ this.registerDefaultFactories();
107
+ }
108
+ /**
109
+ * Registers default built-in view presets.
110
+ */
111
+ registerDefaultPresets() {
112
+ // 1. Standard 3D Angled View (Default: Perspective)
113
+ this.registerPreset('3D', {
114
+ defaultCameraType: 'perspective',
115
+ defaultPosition: [0, 150, 70],
116
+ defaultLookAt: [0, 0, 0],
117
+ fov: 45,
118
+ });
119
+ // 2. Standard 2D Top-Down View (Default: Orthographic)
120
+ this.registerPreset('2D', {
121
+ defaultCameraType: 'orthographic',
122
+ defaultPosition: [0, 500, 0],
123
+ defaultLookAt: [0, 0, 0],
124
+ frustumSize: 400,
125
+ });
126
+ // 3. Isometric Architectural View (Default: Orthographic angled)
127
+ this.registerPreset('Isometric', {
128
+ defaultCameraType: 'orthographic',
129
+ defaultPosition: [200, 200, 200],
130
+ defaultLookAt: [0, 0, 0],
131
+ frustumSize: 400,
132
+ });
133
+ // 4. SkyView: High-altitude bird-eye perspective view
134
+ this.registerPreset('SkyView', {
135
+ defaultCameraType: 'perspective',
136
+ defaultPosition: [0, 800, 1],
137
+ defaultLookAt: [0, 0, 0],
138
+ fov: 60,
139
+ });
140
+ // 5. StreetView: Human eye-level immersive viewpoint
141
+ this.registerPreset('StreetView', {
142
+ defaultCameraType: 'perspective',
143
+ defaultPosition: [0, 2, 0],
144
+ defaultLookAt: [0, 2, -10],
145
+ fov: 75,
146
+ });
147
+ // Convenient aliases matching wovvmap_frontend
148
+ const sky = this.presets.get('SkyView');
149
+ if (sky)
150
+ this.registerPreset('sky', sky);
151
+ const street = this.presets.get('StreetView');
152
+ if (street)
153
+ this.registerPreset('street', street);
154
+ }
155
+ /**
156
+ * Registers default built-in camera factories (Perspective and Orthographic).
157
+ * Built-in perspective aur orthographic camera strategies register karta hai.
158
+ */
159
+ registerDefaultFactories() {
160
+ // 1. Perspective Camera
161
+ this.registerCameraType('perspective', ({ aspect, config, preset, position, lookAt, near, far }) => {
162
+ const fov = config?.fov ?? preset?.fov ?? 45;
163
+ const pCam = new THREE.PerspectiveCamera(fov, aspect, near, far);
164
+ if (config?.zoom !== undefined && Number.isFinite(config.zoom) && config.zoom > 0) {
165
+ pCam.zoom = config.zoom;
166
+ }
167
+ pCam.position.set(position[0], position[1], position[2]);
168
+ pCam.lookAt(lookAt[0], lookAt[1], lookAt[2]);
169
+ pCam.updateProjectionMatrix();
170
+ return pCam;
171
+ }, (cam, aspect) => {
172
+ if (cam instanceof THREE.PerspectiveCamera) {
173
+ cam.aspect = aspect;
174
+ cam.updateProjectionMatrix();
175
+ }
176
+ });
177
+ // 2. Orthographic Camera
178
+ this.registerCameraType('orthographic', ({ aspect, config, preset, position, lookAt, near, far }) => {
179
+ const frustumSize = config?.frustumSize ?? preset?.frustumSize ?? 400;
180
+ const oCam = new THREE.OrthographicCamera((frustumSize * aspect) / -2, (frustumSize * aspect) / 2, frustumSize / 2, frustumSize / -2, near, far);
181
+ oCam.userData.frustumSize = frustumSize;
182
+ if (config?.zoom) {
183
+ oCam.zoom = config.zoom;
184
+ }
185
+ oCam.position.set(position[0], position[1], position[2]);
186
+ oCam.lookAt(lookAt[0], lookAt[1], lookAt[2]);
187
+ oCam.updateProjectionMatrix();
188
+ return oCam;
189
+ }, (cam, aspect) => {
190
+ if (cam instanceof THREE.OrthographicCamera) {
191
+ const currentHeight = Math.abs(cam.top - cam.bottom);
192
+ const frustumSize = typeof cam.userData?.frustumSize === 'number' && cam.userData.frustumSize > 0
193
+ ? cam.userData.frustumSize
194
+ : currentHeight > 0
195
+ ? currentHeight
196
+ : 400;
197
+ cam.left = (frustumSize * aspect) / -2;
198
+ cam.right = (frustumSize * aspect) / 2;
199
+ cam.top = frustumSize / 2;
200
+ cam.bottom = frustumSize / -2;
201
+ cam.updateProjectionMatrix();
202
+ }
203
+ });
204
+ }
205
+ /**
206
+ * Registers a camera projection factory and optional aspect updater.
207
+ * Enables adding new projection types (e.g. fisheye, isometric, custom) without modifying CameraManager.
208
+ *
209
+ * Naya camera projection type dynamically register karein (Open/Closed Principle).
210
+ */
211
+ registerCameraType(type, factory, aspectUpdater) {
212
+ const key = type.toLowerCase();
213
+ this.cameraFactories.set(key, factory);
214
+ if (aspectUpdater) {
215
+ this.cameraAspectUpdaters.set(key, aspectUpdater);
216
+ }
217
+ }
218
+ /**
219
+ * Registers a new camera preset dynamically without editing CameraManager code.
220
+ * Naya view preset dynamically register karein.
221
+ */
222
+ /**
223
+ * Retrieves a registered camera preset by name.
224
+ */
225
+ getPreset(mode) {
226
+ return this.presets.get(mode);
227
+ }
228
+ registerPreset(mode, preset) {
229
+ this.presets.set(mode, preset);
230
+ }
231
+ /**
232
+ * Applies configuration parameters to the existing camera without resetting its active pose unless explicitly requested.
233
+ * English: Reconfigures an existing camera's projection parameters (fov, near, far, frustumSize, aspect) while preserving current position, quaternion/rotation, and zoom unless config explicitly overrides them or switches projection/preset.
234
+ * Hinglish: Existing camera ke projection parameters update karein bina active position, rotation ya zoom ko reset kiye (jab tak explicit override ya projection/preset switch na ho).
235
+ */
236
+ applyConfig(config, forcedAspect) {
237
+ const effectiveConfig = this.resolveConfig(config, this.currentConfig);
238
+ const requestedMode = effectiveConfig.mode ?? '3D';
239
+ const preset = this.presets.get(requestedMode);
240
+ const modeChanged = config?.mode !== undefined && this.activeMode !== null && requestedMode !== this.activeMode;
241
+ const rawType = effectiveConfig.cameraType ?? preset?.defaultCameraType ?? 'perspective';
242
+ const cameraTypeKey = rawType.toLowerCase();
243
+ if (!this.camera || this.activeCameraType !== cameraTypeKey || modeChanged) {
244
+ return this.setup(effectiveConfig, forcedAspect);
245
+ }
246
+ this.currentConfig = effectiveConfig;
247
+ const cam = this.camera;
248
+ const aspect = forcedAspect ??
249
+ (cam instanceof THREE.PerspectiveCamera
250
+ ? cam.aspect
251
+ : cam instanceof THREE.OrthographicCamera &&
252
+ Math.abs(cam.top - cam.bottom) > 0 &&
253
+ Math.abs(cam.right - cam.left) > 0
254
+ ? Math.abs(cam.right - cam.left) / Math.abs(cam.top - cam.bottom)
255
+ : typeof window !== 'undefined'
256
+ ? window.innerWidth / (window.innerHeight || 1)
257
+ : 16 / 9);
258
+ if (config?.near !== undefined) {
259
+ cam.near = config.near;
260
+ }
261
+ if (config?.far !== undefined) {
262
+ cam.far = config.far;
263
+ }
264
+ if (config?.zoom !== undefined && Number.isFinite(config.zoom) && config.zoom > 0) {
265
+ if (this.lastAppliedZoom !== config.zoom) {
266
+ cam.zoom = config.zoom;
267
+ this.lastAppliedZoom = config.zoom;
268
+ }
269
+ }
270
+ if (cam instanceof THREE.PerspectiveCamera && config?.fov !== undefined) {
271
+ cam.fov = config.fov;
272
+ }
273
+ if (cam instanceof THREE.OrthographicCamera && config?.frustumSize !== undefined) {
274
+ cam.userData.frustumSize = config.frustumSize;
275
+ }
276
+ if (forcedAspect !== undefined ||
277
+ (cam instanceof THREE.OrthographicCamera && config?.frustumSize !== undefined)) {
278
+ this.updateAspect(aspect);
279
+ }
280
+ else if (typeof cam.updateProjectionMatrix ===
281
+ 'function') {
282
+ ;
283
+ cam.updateProjectionMatrix();
284
+ }
285
+ const positionChanged = Boolean(config?.position) && !this.isTuple3Equal(this.lastAppliedPosition, config?.position);
286
+ const lookAtChanged = Boolean(config?.lookAt) && !this.isTuple3Equal(this.lastAppliedLookAt, config?.lookAt);
287
+ if (positionChanged && config?.position) {
288
+ cam.position.set(config.position[0], config.position[1], config.position[2]);
289
+ this.lastAppliedPosition = [config.position[0], config.position[1], config.position[2]];
290
+ }
291
+ if ((lookAtChanged || positionChanged) && config?.lookAt) {
292
+ cam.lookAt(config.lookAt[0], config.lookAt[1], config.lookAt[2]);
293
+ this.lastAppliedLookAt = [config.lookAt[0], config.lookAt[1], config.lookAt[2]];
294
+ }
295
+ return cam;
296
+ }
297
+ /**
298
+ * Configures and creates the camera based on independent projection type and view presets.
299
+ * Camera create karein: User chahe to 3D me Orthographic ya 2D me Perspective pass kar sakta hai.
300
+ */
301
+ setup(config, forcedAspect) {
302
+ const aspect = forcedAspect ??
303
+ (typeof window !== 'undefined' ? window.innerWidth / (window.innerHeight || 1) : 16 / 9);
304
+ const mode = config?.mode ?? '3D';
305
+ const preset = this.presets.get(mode);
306
+ // 1. Determine Camera Type: Explicit config takes highest priority, then preset fallback
307
+ const rawType = config?.cameraType ?? preset?.defaultCameraType ?? 'perspective';
308
+ const cameraTypeKey = rawType.toLowerCase();
309
+ // 2. Determine Coordinates & Targets
310
+ const position = config?.position ?? preset?.defaultPosition ?? [0, 150, 70];
311
+ const lookAt = config?.lookAt ?? preset?.defaultLookAt ?? [0, 0, 0];
312
+ const near = config?.near ?? 0.1;
313
+ const far = config?.far ?? 10000;
314
+ // 3. Construct specific camera projection via Strategy Registry (Open/Closed Principle)
315
+ const factory = this.cameraFactories.get(cameraTypeKey);
316
+ if (!factory) {
317
+ throw new Error('Unsupported camera type: ' +
318
+ rawType +
319
+ '. Please register via cameraManager.registerCameraType().');
320
+ }
321
+ const createdCamera = factory({
322
+ aspect,
323
+ config,
324
+ preset,
325
+ position,
326
+ lookAt,
327
+ near,
328
+ far,
329
+ });
330
+ this.activeCameraType = cameraTypeKey;
331
+ this.activeMode = mode;
332
+ this.currentConfig = {
333
+ ...config,
334
+ mode,
335
+ cameraType: rawType,
336
+ };
337
+ this.lastAppliedPosition = config?.position
338
+ ? [config.position[0], config.position[1], config.position[2]]
339
+ : undefined;
340
+ this.lastAppliedLookAt = config?.lookAt
341
+ ? [config.lookAt[0], config.lookAt[1], config.lookAt[2]]
342
+ : undefined;
343
+ this.lastAppliedZoom =
344
+ config?.zoom !== undefined && Number.isFinite(config.zoom) && config.zoom > 0
345
+ ? config.zoom
346
+ : undefined;
347
+ this.camera = createdCamera;
348
+ return createdCamera;
349
+ }
350
+ /**
351
+ * Updates camera aspect ratio and projection matrix on viewport resize.
352
+ * Viewport resize hone par projection matrix update karein.
353
+ */
354
+ updateAspect(aspect) {
355
+ if (!this.camera)
356
+ return;
357
+ if (this.activeCameraType && this.cameraAspectUpdaters.has(this.activeCameraType)) {
358
+ this.cameraAspectUpdaters.get(this.activeCameraType)(this.camera, aspect);
359
+ return;
360
+ }
361
+ // Fallback standard instance checks
362
+ if (this.camera instanceof THREE.PerspectiveCamera) {
363
+ this.camera.aspect = aspect;
364
+ this.camera.updateProjectionMatrix();
365
+ }
366
+ else if (this.camera instanceof THREE.OrthographicCamera) {
367
+ const currentHeight = Math.abs(this.camera.top - this.camera.bottom);
368
+ const frustumSize = typeof this.camera.userData?.frustumSize === 'number' &&
369
+ this.camera.userData.frustumSize > 0
370
+ ? this.camera.userData.frustumSize
371
+ : currentHeight > 0
372
+ ? currentHeight
373
+ : 400;
374
+ this.camera.left = (frustumSize * aspect) / -2;
375
+ this.camera.right = (frustumSize * aspect) / 2;
376
+ this.camera.top = frustumSize / 2;
377
+ this.camera.bottom = frustumSize / -2;
378
+ this.camera.updateProjectionMatrix();
379
+ }
380
+ }
381
+ /**
382
+ * Smoothly animates camera to target coordinates using gsap.
383
+ * Camera ko smooth animation ke sath target position par move karein.
384
+ */
385
+ settleActiveAnimation = null;
386
+ /**
387
+ * Cancels any in-flight camera animations and resolves pending transition.
388
+ * Active camera tween ko cancel karein aur pending promise ko settle karein.
389
+ */
390
+ killAnimations() {
391
+ const tween = this.activeTween;
392
+ const settle = this.settleActiveAnimation;
393
+ this.activeTween = null;
394
+ this.settleActiveAnimation = null;
395
+ if (tween) {
396
+ tween.kill();
397
+ }
398
+ if (this.camera) {
399
+ gsap.killTweensOf(this.camera.position);
400
+ gsap.killTweensOf(this.camera);
401
+ }
402
+ if (settle) {
403
+ settle(false);
404
+ }
405
+ }
406
+ /**
407
+ * Smoothly animates camera and controls target coordinates using gsap.
408
+ * English: Concurrently animates camera position, controls target, and orthographic zoom on a single transition.
409
+ * Hinglish: Camera position, controls target aur zoom ko ek hi transition owner ke saath smoothly animate karta hai.
410
+ */
411
+ animateTo(targetPosition, targetLookAt, durationSec = 1.0, onUpdate, controlsTarget, targetZoom) {
412
+ if (!this.camera)
413
+ return Promise.resolve(true);
414
+ this.killAnimations();
415
+ if (durationSec <= 0) {
416
+ this.camera.position.set(targetPosition[0], targetPosition[1], targetPosition[2]);
417
+ if (controlsTarget) {
418
+ controlsTarget.set(targetLookAt[0], targetLookAt[1], targetLookAt[2]);
419
+ }
420
+ this.camera.lookAt(targetLookAt[0], targetLookAt[1], targetLookAt[2]);
421
+ if (typeof targetZoom === 'number' && Number.isFinite(targetZoom) && targetZoom > 0) {
422
+ this.camera.zoom = targetZoom;
423
+ this.camera.updateProjectionMatrix();
424
+ }
425
+ if (onUpdate)
426
+ onUpdate();
427
+ return Promise.resolve(true);
428
+ }
429
+ return new Promise((resolve) => {
430
+ let settled = false;
431
+ const settle = (completed) => {
432
+ if (settled)
433
+ return;
434
+ settled = true;
435
+ gsap.ticker.remove(advance);
436
+ if (completed)
437
+ tween.kill();
438
+ if (this.settleActiveAnimation === settle) {
439
+ this.activeTween = null;
440
+ this.settleActiveAnimation = null;
441
+ }
442
+ resolve(completed);
443
+ };
444
+ this.settleActiveAnimation = settle;
445
+ const currentZoom = typeof this.camera?.zoom === 'number' &&
446
+ Number.isFinite(this.camera.zoom) &&
447
+ this.camera.zoom > 0
448
+ ? this.camera.zoom
449
+ : 1;
450
+ const initialZoom = currentZoom;
451
+ const destZoom = typeof targetZoom === 'number' && Number.isFinite(targetZoom) && targetZoom > 0
452
+ ? targetZoom
453
+ : currentZoom;
454
+ const tweenState = {
455
+ x: this.camera.position.x,
456
+ y: this.camera.position.y,
457
+ z: this.camera.position.z,
458
+ tx: controlsTarget ? controlsTarget.x : targetLookAt[0],
459
+ ty: controlsTarget ? controlsTarget.y : targetLookAt[1],
460
+ tz: controlsTarget ? controlsTarget.z : targetLookAt[2],
461
+ zoom: initialZoom,
462
+ };
463
+ // Camera readiness uses elapsed time, not GSAP's globally lag-smoothed clock.
464
+ // Hinglish: Slow frame par focus ki duration na badhe; host app ka GSAP clock bhi na badlein.
465
+ const startedAt = performance.now();
466
+ const advance = () => {
467
+ tween.totalTime((performance.now() - startedAt) / 1000);
468
+ };
469
+ const tween = gsap.to(tweenState, {
470
+ paused: true,
471
+ x: targetPosition[0],
472
+ y: targetPosition[1],
473
+ z: targetPosition[2],
474
+ tx: targetLookAt[0],
475
+ ty: targetLookAt[1],
476
+ tz: targetLookAt[2],
477
+ zoom: destZoom,
478
+ duration: durationSec,
479
+ ease: 'power2.inOut',
480
+ onUpdate: () => {
481
+ if (settled)
482
+ return;
483
+ if (this.camera) {
484
+ this.camera.position.set(tweenState.x, tweenState.y, tweenState.z);
485
+ if (controlsTarget) {
486
+ controlsTarget.set(tweenState.tx, tweenState.ty, tweenState.tz);
487
+ }
488
+ this.camera.lookAt(tweenState.tx, tweenState.ty, tweenState.tz);
489
+ if (typeof targetZoom === 'number' && Number.isFinite(targetZoom) && targetZoom > 0) {
490
+ this.camera.zoom = tweenState.zoom;
491
+ this.camera.updateProjectionMatrix();
492
+ }
493
+ if (onUpdate)
494
+ onUpdate();
495
+ }
496
+ },
497
+ onComplete: () => {
498
+ if (!settled) {
499
+ settle(true);
500
+ }
501
+ },
502
+ });
503
+ this.activeTween = tween;
504
+ gsap.ticker.add(advance);
505
+ });
506
+ }
507
+ /** Follow and explicit tweens share one camera owner; release never moves the camera.
508
+ * Hinglish: Pehle purana tween band, phir same frame sample; Pause par pose wahi rahe. */
509
+ get isRouteFollowing() {
510
+ return this.routeFollow.active;
511
+ }
512
+ followRoute(position, forward, controls, view = 'street', delta = 0) {
513
+ if (!position) {
514
+ this.routeFollow.reset();
515
+ return false;
516
+ }
517
+ if (!this.camera || !controls || !forward)
518
+ return false;
519
+ if (!this.routeFollow.active)
520
+ this.killAnimations();
521
+ return this.routeFollow.update(this.camera, controls, position, forward, view, delta);
522
+ }
523
+ getCamera() {
524
+ return this.camera;
525
+ }
526
+ /** Zooms around the existing target within active limits without changing camera orientation.
527
+ * Hinglish: Existing target, bearing aur pitch same rakhkar active limits ke andar zoom karta hai. */
528
+ zoomBy(factor, controls) {
529
+ const camera = this.camera;
530
+ if (!camera || !Number.isFinite(factor) || factor <= 0)
531
+ return false;
532
+ if (camera instanceof THREE.OrthographicCamera) {
533
+ const zoom = THREE.MathUtils.clamp(camera.zoom * factor, controls.minZoom, controls.maxZoom);
534
+ if (zoom === camera.zoom)
535
+ return false;
536
+ camera.zoom = zoom;
537
+ camera.updateProjectionMatrix();
538
+ }
539
+ else {
540
+ const offset = camera.position.clone().sub(controls.target);
541
+ const currentDistance = offset.length();
542
+ if (currentDistance === 0)
543
+ return false;
544
+ const distance = THREE.MathUtils.clamp(currentDistance / factor, controls.minDistance, controls.maxDistance);
545
+ if (distance === currentDistance)
546
+ return false;
547
+ camera.position.copy(controls.target).add(offset.multiplyScalar(distance / currentDistance));
548
+ }
549
+ camera.updateMatrixWorld();
550
+ return true;
551
+ }
552
+ /**
553
+ * Releases camera resources and stops active animation tweens.
554
+ */
555
+ dispose() {
556
+ this.routeFollow.reset();
557
+ this.killAnimations();
558
+ this.activeCameraType = null;
559
+ this.activeMode = null;
560
+ this.currentConfig = undefined;
561
+ this.lastAppliedPosition = undefined;
562
+ this.lastAppliedLookAt = undefined;
563
+ this.lastAppliedZoom = undefined;
564
+ this.camera = null;
565
+ }
566
+ }
@@ -0,0 +1,123 @@
1
+ /**
2
+ * @file ControlsManager.ts
3
+ * @description Manages OrbitControls lifecycle, damping, constraints, and change event subscriptions.
4
+ * OrbitControls ke lifecycle, dynamic distance limits, aur event listeners ko manage karne wala manager.
5
+ */
6
+ import * as THREE from 'three';
7
+ import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls.js';
8
+ import type { OrbitControlsConfig } from '@wovvmap/contracts';
9
+ export type { OrbitControlsConfig } from '@wovvmap/contracts';
10
+ /**
11
+ * Encapsulates OrbitControls lifecycle, distance limits, and damping updates.
12
+ */
13
+ export declare const DEFAULT_CONTROLS_CONFIG: Required<Omit<OrbitControlsConfig, 'target' | 'minZoom' | 'maxZoom'>>;
14
+ export interface ActiveControlsLimits {
15
+ type: 'perspective' | 'ortho';
16
+ minDistance?: number;
17
+ maxDistance?: number;
18
+ minPolarAngle?: number;
19
+ maxPolarAngle?: number;
20
+ minZoom?: number;
21
+ maxZoom?: number;
22
+ }
23
+ export declare class ControlsManager {
24
+ controls: OrbitControls | null;
25
+ onUserIntent?: () => void;
26
+ private readonly startListener;
27
+ private readonly keyListener;
28
+ private changeListener;
29
+ private callerConfig?;
30
+ private baseFramingLimits;
31
+ private lastAppliedLimits;
32
+ private limitsUnlocked;
33
+ private onLimitsChanged?;
34
+ private readonly preservedTarget;
35
+ /**
36
+ * Updates the fallback target used when OrbitControls is attached or re-attached without an explicit target prop.
37
+ * OrbitControls attach/re-attach hone par bina explicit target ke use hone wala fallback target set karein.
38
+ */
39
+ setPreservedTarget(x: number, y: number, z: number): void;
40
+ setOnLimitsChanged(cb?: () => void): void;
41
+ private hasLimitsChanged;
42
+ /**
43
+ * Attaches OrbitControls to the active camera and canvas.
44
+ * Camera aur canvas par OrbitControls bind karein.
45
+ */
46
+ setCallerConfig(config?: OrbitControlsConfig): void;
47
+ attach(camera: THREE.Camera, canvas: HTMLCanvasElement, config?: OrbitControlsConfig, onChange?: () => void): OrbitControls | null;
48
+ /**
49
+ * Dynamically updates OrbitControls configuration without recreating instances or resetting target.
50
+ * Existing controls configuration ko update karein bina target reset ya recreate kiye.
51
+ */
52
+ /**
53
+ * Declaratively replaces controls configuration with declared props (used by React adapter).
54
+ * Restores defaults for any omitted/removed props to eliminate stale overrides.
55
+ * Declarative props sync: Jab koi prop remove ho jaye toh respective default restore karta hai.
56
+ */
57
+ /**
58
+ * Resolves mathematically consistent limits (min <= max) against base framing limits.
59
+ * Single-sided updates ko consistent valid interval me resolve karta hai taaki min > max na ho.
60
+ */
61
+ resolveEffectiveLimits(config?: Partial<OrbitControlsConfig>): {
62
+ minDistance: number;
63
+ maxDistance: number;
64
+ minPolarAngle: number;
65
+ maxPolarAngle: number;
66
+ minZoom: number;
67
+ maxZoom: number;
68
+ };
69
+ setDeclarativeConfig(config: OrbitControlsConfig): void;
70
+ /**
71
+ * Imperatively patches OrbitControls configuration without resetting unmentioned props.
72
+ * Imperative partial update bina unmentioned properties ko reset kiye.
73
+ */
74
+ updateConfig(config: Partial<OrbitControlsConfig>): void;
75
+ /**
76
+ * Updates camera target focus point.
77
+ */
78
+ setTarget(x: number, y: number, z: number): void;
79
+ /**
80
+ * Sets dynamic min/max zoom distance limits and optional polar angle limit.
81
+ * Explicit caller overrides from attach() take precedence if specified.
82
+ * Dynamic zoom limits update karein. Caller ke explicit overrides ko preserve karein.
83
+ */
84
+ setDistanceLimits(minDistance: number, maxDistance: number, maxPolarAngle?: number, minPolarAngle?: number): void;
85
+ /**
86
+ * Temporarily unlocks distance constraints so transitions are not clamped midway.
87
+ * Animation ke dauran limits temporarily unlock karein.
88
+ */
89
+ /**
90
+ * Returns actively configured caller overrides.
91
+ * Caller ke dwara provide ki gayi explicit controls configuration prapt karein.
92
+ */
93
+ get config(): OrbitControlsConfig | undefined;
94
+ /**
95
+ * Sets dynamic min/max zoom limits for OrthographicCamera.
96
+ * Explicit caller overrides from attach() take precedence if specified.
97
+ * Orthographic camera ke liye zoom limits update karein.
98
+ */
99
+ setZoomLimits(minZoom: number, maxZoom: number, maxPolarAngle?: number, minPolarAngle?: number): void;
100
+ /**
101
+ * Temporarily unlocks distance and zoom constraints so transitions are not clamped midway.
102
+ * Animation ke dauran limits temporarily unlock karein.
103
+ */
104
+ unlockLimits(): void;
105
+ /**
106
+ * Restores previously applied limits if controls are currently unlocked.
107
+ * English: Restores last valid distance/zoom limits on cancelled or superseded transitions.
108
+ * Hinglish: Agar limits unlocked the aur transition interrupt hua, toh pichli valid limits restore karta hai.
109
+ */
110
+ restoreLimits(): void;
111
+ get isLimitsUnlocked(): boolean;
112
+ get currentLimits(): ActiveControlsLimits | null;
113
+ get baseLimits(): ActiveControlsLimits | null;
114
+ /**
115
+ * Updates damping inertia during render loop.
116
+ */
117
+ update(): void;
118
+ /**
119
+ * Cleans up controls and removes event listeners.
120
+ */
121
+ dispose(): void;
122
+ }
123
+ //# sourceMappingURL=ControlsManager.d.ts.map