@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 @@
1
+ {"version":3,"file":"ControlsManager.d.ts","sourceRoot":"","sources":["../../src/engine/ControlsManager.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,604 @@
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
+ /**
9
+ * Encapsulates OrbitControls lifecycle, distance limits, and damping updates.
10
+ */
11
+ export const DEFAULT_CONTROLS_CONFIG = {
12
+ enableZoom: true,
13
+ enableDamping: false,
14
+ dampingFactor: 0.05,
15
+ screenSpacePanning: false, // Old frontend required default
16
+ minDistance: 30,
17
+ maxDistance: 2000,
18
+ minPolarAngle: 0,
19
+ maxPolarAngle: Math.PI / 2.5,
20
+ mouseButtons: {
21
+ LEFT: THREE.MOUSE.PAN,
22
+ MIDDLE: THREE.MOUSE.DOLLY,
23
+ RIGHT: THREE.MOUSE.ROTATE,
24
+ },
25
+ touches: {
26
+ ONE: THREE.TOUCH.PAN,
27
+ TWO: THREE.TOUCH.DOLLY_ROTATE,
28
+ },
29
+ };
30
+ export class ControlsManager {
31
+ controls = null;
32
+ onUserIntent;
33
+ startListener = () => this.onUserIntent?.();
34
+ keyListener = (event) => {
35
+ if (['ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight'].includes(event.code))
36
+ this.onUserIntent?.();
37
+ };
38
+ changeListener = null;
39
+ callerConfig;
40
+ baseFramingLimits = null;
41
+ lastAppliedLimits = null;
42
+ limitsUnlocked = false;
43
+ onLimitsChanged;
44
+ preservedTarget = new THREE.Vector3(0, 0, 0);
45
+ /**
46
+ * Updates the fallback target used when OrbitControls is attached or re-attached without an explicit target prop.
47
+ * OrbitControls attach/re-attach hone par bina explicit target ke use hone wala fallback target set karein.
48
+ */
49
+ setPreservedTarget(x, y, z) {
50
+ this.preservedTarget.set(x, y, z);
51
+ }
52
+ setOnLimitsChanged(cb) {
53
+ this.onLimitsChanged = cb;
54
+ }
55
+ hasLimitsChanged(prev, next) {
56
+ if (!prev && !next)
57
+ return false;
58
+ return (prev?.minDistance !== next?.minDistance ||
59
+ prev?.maxDistance !== next?.maxDistance ||
60
+ prev?.minPolarAngle !== next?.minPolarAngle ||
61
+ prev?.maxPolarAngle !== next?.maxPolarAngle ||
62
+ prev?.minZoom !== next?.minZoom ||
63
+ prev?.maxZoom !== next?.maxZoom);
64
+ }
65
+ /**
66
+ * Attaches OrbitControls to the active camera and canvas.
67
+ * Camera aur canvas par OrbitControls bind karein.
68
+ */
69
+ setCallerConfig(config) {
70
+ this.callerConfig = config;
71
+ }
72
+ attach(camera, canvas, config, onChange) {
73
+ this.callerConfig = config;
74
+ if (typeof window === 'undefined')
75
+ return null;
76
+ try {
77
+ this.dispose();
78
+ this.callerConfig = config;
79
+ this.controls = new OrbitControls(camera, canvas);
80
+ this.controls.enableZoom = config?.enableZoom ?? DEFAULT_CONTROLS_CONFIG.enableZoom;
81
+ // Old frontend required defaults: Damping disabled, screenSpacePanning false
82
+ this.controls.enableDamping = config?.enableDamping ?? DEFAULT_CONTROLS_CONFIG.enableDamping;
83
+ this.controls.dampingFactor = config?.dampingFactor ?? DEFAULT_CONTROLS_CONFIG.dampingFactor;
84
+ this.controls.screenSpacePanning =
85
+ config?.screenSpacePanning ?? DEFAULT_CONTROLS_CONFIG.screenSpacePanning;
86
+ // Mouse bindings: Left = Pan, Middle = Dolly, Right = Rotate
87
+ this.controls.mouseButtons = {
88
+ LEFT: config?.mouseButtons?.LEFT ?? DEFAULT_CONTROLS_CONFIG.mouseButtons.LEFT,
89
+ MIDDLE: config?.mouseButtons?.MIDDLE ?? DEFAULT_CONTROLS_CONFIG.mouseButtons.MIDDLE,
90
+ RIGHT: config?.mouseButtons?.RIGHT ?? DEFAULT_CONTROLS_CONFIG.mouseButtons.RIGHT,
91
+ };
92
+ // Touch bindings: One finger = Pan, Two fingers = Dolly + Rotate
93
+ this.controls.touches = {
94
+ ONE: config?.touches?.ONE ?? DEFAULT_CONTROLS_CONFIG.touches.ONE,
95
+ TWO: config?.touches?.TWO ?? DEFAULT_CONTROLS_CONFIG.touches.TWO,
96
+ };
97
+ this.controls.minDistance = config?.minDistance ?? DEFAULT_CONTROLS_CONFIG.minDistance;
98
+ this.controls.maxDistance = config?.maxDistance ?? DEFAULT_CONTROLS_CONFIG.maxDistance;
99
+ this.controls.minPolarAngle = config?.minPolarAngle ?? DEFAULT_CONTROLS_CONFIG.minPolarAngle;
100
+ this.controls.maxPolarAngle = config?.maxPolarAngle ?? DEFAULT_CONTROLS_CONFIG.maxPolarAngle;
101
+ if (config?.minZoom !== undefined)
102
+ this.controls.minZoom = config.minZoom;
103
+ if (config?.maxZoom !== undefined)
104
+ this.controls.maxZoom = config.maxZoom;
105
+ if (config?.target) {
106
+ this.controls.target.set(config.target[0], config.target[1], config.target[2]);
107
+ this.preservedTarget.set(config.target[0], config.target[1], config.target[2]);
108
+ }
109
+ else {
110
+ this.controls.target.copy(this.preservedTarget);
111
+ }
112
+ this.changeListener = () => {
113
+ if (onChange)
114
+ onChange();
115
+ };
116
+ this.controls.addEventListener('change', this.changeListener);
117
+ this.controls.addEventListener('start', this.startListener);
118
+ canvas.addEventListener('keydown', this.keyListener, true);
119
+ // Initial limits and floor baseline snapshots: pure defaults without caller override contamination (Gap 1)
120
+ this.baseFramingLimits = {
121
+ type: camera instanceof THREE.OrthographicCamera ? 'ortho' : 'perspective',
122
+ minDistance: DEFAULT_CONTROLS_CONFIG.minDistance,
123
+ maxDistance: DEFAULT_CONTROLS_CONFIG.maxDistance,
124
+ minPolarAngle: DEFAULT_CONTROLS_CONFIG.minPolarAngle,
125
+ maxPolarAngle: DEFAULT_CONTROLS_CONFIG.maxPolarAngle,
126
+ minZoom: 0,
127
+ maxZoom: Infinity,
128
+ };
129
+ this.lastAppliedLimits = {
130
+ type: camera instanceof THREE.OrthographicCamera ? 'ortho' : 'perspective',
131
+ minDistance: this.controls.minDistance,
132
+ maxDistance: this.controls.maxDistance,
133
+ minPolarAngle: this.controls.minPolarAngle,
134
+ maxPolarAngle: this.controls.maxPolarAngle,
135
+ minZoom: this.controls.minZoom,
136
+ maxZoom: this.controls.maxZoom,
137
+ };
138
+ this.limitsUnlocked = false;
139
+ this.controls.update();
140
+ return this.controls;
141
+ }
142
+ catch (err) {
143
+ console.warn('Failed to attach OrbitControls:', err);
144
+ return null;
145
+ }
146
+ }
147
+ /**
148
+ * Dynamically updates OrbitControls configuration without recreating instances or resetting target.
149
+ * Existing controls configuration ko update karein bina target reset ya recreate kiye.
150
+ */
151
+ /**
152
+ * Declaratively replaces controls configuration with declared props (used by React adapter).
153
+ * Restores defaults for any omitted/removed props to eliminate stale overrides.
154
+ * Declarative props sync: Jab koi prop remove ho jaye toh respective default restore karta hai.
155
+ */
156
+ /**
157
+ * Resolves mathematically consistent limits (min <= max) against base framing limits.
158
+ * Single-sided updates ko consistent valid interval me resolve karta hai taaki min > max na ho.
159
+ */
160
+ resolveEffectiveLimits(config) {
161
+ // Distance limits
162
+ const baseMinDist = this.baseFramingLimits?.minDistance ?? DEFAULT_CONTROLS_CONFIG.minDistance;
163
+ const baseMaxDist = this.baseFramingLimits?.maxDistance ?? DEFAULT_CONTROLS_CONFIG.maxDistance;
164
+ let resolvedMaxDist;
165
+ if (config?.maxDistance !== undefined) {
166
+ resolvedMaxDist = Math.max(0.1, config.maxDistance);
167
+ }
168
+ else if (config?.minDistance !== undefined) {
169
+ resolvedMaxDist = Math.max(config.minDistance + 50, baseMaxDist);
170
+ }
171
+ else {
172
+ resolvedMaxDist = baseMaxDist;
173
+ }
174
+ let resolvedMinDist = config?.minDistance !== undefined ? config.minDistance : baseMinDist;
175
+ if (resolvedMinDist > resolvedMaxDist) {
176
+ if (config?.minDistance !== undefined && config?.maxDistance === undefined) {
177
+ resolvedMaxDist = resolvedMinDist + 50;
178
+ }
179
+ else {
180
+ resolvedMinDist = resolvedMaxDist;
181
+ }
182
+ }
183
+ // Polar limits
184
+ const baseMinPolar = this.baseFramingLimits?.minPolarAngle ?? DEFAULT_CONTROLS_CONFIG.minPolarAngle;
185
+ const baseMaxPolar = this.baseFramingLimits?.maxPolarAngle ?? DEFAULT_CONTROLS_CONFIG.maxPolarAngle;
186
+ const resolvedMaxPolar = config?.maxPolarAngle ??
187
+ (config?.minPolarAngle !== undefined
188
+ ? Math.max(config.minPolarAngle, baseMaxPolar)
189
+ : baseMaxPolar);
190
+ let resolvedMinPolar = config?.minPolarAngle ?? baseMinPolar;
191
+ if (resolvedMinPolar > resolvedMaxPolar) {
192
+ resolvedMinPolar = resolvedMaxPolar;
193
+ }
194
+ // Zoom limits
195
+ const baseMinZoom = this.baseFramingLimits?.minZoom ?? 0.0001;
196
+ const baseMaxZoom = this.baseFramingLimits?.maxZoom ?? Infinity;
197
+ let resolvedMaxZoom;
198
+ if (config?.maxZoom !== undefined) {
199
+ resolvedMaxZoom = Math.max(0.0001, config.maxZoom);
200
+ }
201
+ else if (config?.minZoom !== undefined) {
202
+ resolvedMaxZoom = Math.max(config.minZoom * 2, baseMaxZoom);
203
+ }
204
+ else {
205
+ resolvedMaxZoom = baseMaxZoom;
206
+ }
207
+ let resolvedMinZoom = config?.minZoom !== undefined ? config.minZoom : baseMinZoom;
208
+ if (resolvedMinZoom > resolvedMaxZoom) {
209
+ if (config?.minZoom !== undefined && config?.maxZoom === undefined) {
210
+ resolvedMaxZoom = Math.max(resolvedMinZoom * 2, resolvedMinZoom + 0.1);
211
+ }
212
+ else {
213
+ resolvedMinZoom = resolvedMaxZoom;
214
+ }
215
+ }
216
+ return {
217
+ minDistance: resolvedMinDist,
218
+ maxDistance: resolvedMaxDist,
219
+ minPolarAngle: resolvedMinPolar,
220
+ maxPolarAngle: resolvedMaxPolar,
221
+ minZoom: resolvedMinZoom,
222
+ maxZoom: resolvedMaxZoom,
223
+ };
224
+ }
225
+ setDeclarativeConfig(config) {
226
+ const limitsChanged = this.hasLimitsChanged(this.callerConfig, config);
227
+ this.callerConfig = { ...config };
228
+ const resolvedLimits = this.resolveEffectiveLimits(this.callerConfig);
229
+ // Snapshot for settlement or cancellation restore
230
+ this.lastAppliedLimits = {
231
+ type: this.baseFramingLimits?.type ?? 'perspective',
232
+ ...resolvedLimits,
233
+ };
234
+ if (!this.controls) {
235
+ if (limitsChanged && this.onLimitsChanged) {
236
+ this.onLimitsChanged();
237
+ }
238
+ return;
239
+ }
240
+ this.controls.enableZoom = config.enableZoom ?? DEFAULT_CONTROLS_CONFIG.enableZoom;
241
+ this.controls.enableDamping = config.enableDamping ?? DEFAULT_CONTROLS_CONFIG.enableDamping;
242
+ this.controls.dampingFactor = config.dampingFactor ?? DEFAULT_CONTROLS_CONFIG.dampingFactor;
243
+ this.controls.screenSpacePanning =
244
+ config.screenSpacePanning ?? DEFAULT_CONTROLS_CONFIG.screenSpacePanning;
245
+ // Point 3: If an animation is in flight (limitsUnlocked === true),
246
+ // PRESERVE temporary unlocked distance/zoom limits on controls so transition is not clamped!
247
+ if (!this.limitsUnlocked) {
248
+ this.controls.minDistance = resolvedLimits.minDistance;
249
+ this.controls.maxDistance = resolvedLimits.maxDistance;
250
+ this.controls.minPolarAngle = resolvedLimits.minPolarAngle;
251
+ this.controls.maxPolarAngle = resolvedLimits.maxPolarAngle;
252
+ this.controls.minZoom = resolvedLimits.minZoom;
253
+ this.controls.maxZoom = resolvedLimits.maxZoom;
254
+ }
255
+ this.controls.mouseButtons = {
256
+ LEFT: config.mouseButtons?.LEFT ?? DEFAULT_CONTROLS_CONFIG.mouseButtons.LEFT,
257
+ MIDDLE: config.mouseButtons?.MIDDLE ?? DEFAULT_CONTROLS_CONFIG.mouseButtons.MIDDLE,
258
+ RIGHT: config.mouseButtons?.RIGHT ?? DEFAULT_CONTROLS_CONFIG.mouseButtons.RIGHT,
259
+ };
260
+ this.controls.touches = {
261
+ ONE: config.touches?.ONE ?? DEFAULT_CONTROLS_CONFIG.touches.ONE,
262
+ TWO: config.touches?.TWO ?? DEFAULT_CONTROLS_CONFIG.touches.TWO,
263
+ };
264
+ if (config.target && Array.isArray(config.target) && config.target.length === 3) {
265
+ const [tx, ty, tz] = config.target;
266
+ if (this.controls.target.x !== tx ||
267
+ this.controls.target.y !== ty ||
268
+ this.controls.target.z !== tz) {
269
+ this.controls.target.set(tx, ty, tz);
270
+ }
271
+ }
272
+ this.controls.update();
273
+ if (limitsChanged && this.onLimitsChanged) {
274
+ this.onLimitsChanged();
275
+ }
276
+ }
277
+ /**
278
+ * Imperatively patches OrbitControls configuration without resetting unmentioned props.
279
+ * Imperative partial update bina unmentioned properties ko reset kiye.
280
+ */
281
+ updateConfig(config) {
282
+ if (!this.controls)
283
+ return;
284
+ // Deep merge nested mouseButtons and touches to preserve existing bindings
285
+ const mergedMouse = config.mouseButtons
286
+ ? {
287
+ ...(this.callerConfig?.mouseButtons ?? DEFAULT_CONTROLS_CONFIG.mouseButtons),
288
+ ...config.mouseButtons,
289
+ }
290
+ : this.callerConfig?.mouseButtons;
291
+ const mergedTouches = config.touches
292
+ ? {
293
+ ...(this.callerConfig?.touches ?? DEFAULT_CONTROLS_CONFIG.touches),
294
+ ...config.touches,
295
+ }
296
+ : this.callerConfig?.touches;
297
+ const nextConfig = {
298
+ ...this.callerConfig,
299
+ ...config,
300
+ ...(mergedMouse ? { mouseButtons: mergedMouse } : {}),
301
+ ...(mergedTouches ? { touches: mergedTouches } : {}),
302
+ };
303
+ const limitsChanged = this.hasLimitsChanged(this.callerConfig, nextConfig);
304
+ this.callerConfig = nextConfig;
305
+ if (config.enableZoom !== undefined)
306
+ this.controls.enableZoom = config.enableZoom;
307
+ if (config.enableDamping !== undefined)
308
+ this.controls.enableDamping = config.enableDamping;
309
+ if (config.dampingFactor !== undefined)
310
+ this.controls.dampingFactor = config.dampingFactor;
311
+ if (config.screenSpacePanning !== undefined)
312
+ this.controls.screenSpacePanning = config.screenSpacePanning;
313
+ const resolvedLimits = this.resolveEffectiveLimits(nextConfig);
314
+ this.lastAppliedLimits = {
315
+ type: this.baseFramingLimits?.type ?? 'perspective',
316
+ ...resolvedLimits,
317
+ };
318
+ if (!this.limitsUnlocked) {
319
+ this.controls.minDistance = resolvedLimits.minDistance;
320
+ this.controls.maxDistance = resolvedLimits.maxDistance;
321
+ this.controls.minPolarAngle = resolvedLimits.minPolarAngle;
322
+ this.controls.maxPolarAngle = resolvedLimits.maxPolarAngle;
323
+ this.controls.minZoom = resolvedLimits.minZoom;
324
+ this.controls.maxZoom = resolvedLimits.maxZoom;
325
+ }
326
+ if (mergedMouse) {
327
+ this.controls.mouseButtons = {
328
+ LEFT: mergedMouse.LEFT ?? DEFAULT_CONTROLS_CONFIG.mouseButtons.LEFT,
329
+ MIDDLE: mergedMouse.MIDDLE ?? DEFAULT_CONTROLS_CONFIG.mouseButtons.MIDDLE,
330
+ RIGHT: mergedMouse.RIGHT ?? DEFAULT_CONTROLS_CONFIG.mouseButtons.RIGHT,
331
+ };
332
+ }
333
+ if (mergedTouches) {
334
+ this.controls.touches = {
335
+ ONE: mergedTouches.ONE ?? DEFAULT_CONTROLS_CONFIG.touches.ONE,
336
+ TWO: mergedTouches.TWO ?? DEFAULT_CONTROLS_CONFIG.touches.TWO,
337
+ };
338
+ }
339
+ if (config.target && Array.isArray(config.target) && config.target.length === 3) {
340
+ const [tx, ty, tz] = config.target;
341
+ if (this.controls.target.x !== tx ||
342
+ this.controls.target.y !== ty ||
343
+ this.controls.target.z !== tz) {
344
+ this.controls.target.set(tx, ty, tz);
345
+ }
346
+ }
347
+ this.controls.update();
348
+ if (limitsChanged && this.onLimitsChanged) {
349
+ this.onLimitsChanged();
350
+ }
351
+ }
352
+ /**
353
+ * Updates camera target focus point.
354
+ */
355
+ setTarget(x, y, z) {
356
+ this.preservedTarget.set(x, y, z);
357
+ if (this.controls) {
358
+ this.controls.target.set(x, y, z);
359
+ this.controls.update();
360
+ }
361
+ }
362
+ /**
363
+ * Sets dynamic min/max zoom distance limits and optional polar angle limit.
364
+ * Explicit caller overrides from attach() take precedence if specified.
365
+ * Dynamic zoom limits update karein. Caller ke explicit overrides ko preserve karein.
366
+ */
367
+ setDistanceLimits(minDistance, maxDistance, maxPolarAngle, minPolarAngle) {
368
+ if (!this.controls)
369
+ return;
370
+ // Record floor-derived baseline (Point 2)
371
+ this.baseFramingLimits = {
372
+ ...this.baseFramingLimits,
373
+ type: 'perspective',
374
+ minDistance,
375
+ maxDistance,
376
+ maxPolarAngle: maxPolarAngle ??
377
+ this.baseFramingLimits?.maxPolarAngle ??
378
+ DEFAULT_CONTROLS_CONFIG.maxPolarAngle,
379
+ };
380
+ // Caller overrides take precedence without collapsing zoom range
381
+ const callerMin = this.callerConfig?.minDistance;
382
+ const callerMax = this.callerConfig?.maxDistance;
383
+ let effectiveMax;
384
+ if (callerMax !== undefined) {
385
+ effectiveMax = Math.max(0.1, callerMax);
386
+ }
387
+ else if (callerMin !== undefined) {
388
+ effectiveMax = Math.max(callerMin + 50, maxDistance);
389
+ }
390
+ else {
391
+ effectiveMax = Math.max(0, maxDistance);
392
+ }
393
+ let effectiveMin;
394
+ if (callerMin !== undefined) {
395
+ effectiveMin = Math.min(callerMin, effectiveMax);
396
+ }
397
+ else {
398
+ effectiveMin = Math.min(Math.max(0, minDistance), effectiveMax);
399
+ }
400
+ const safeMin = Math.max(0, effectiveMin);
401
+ const safeMax = Math.max(safeMin, effectiveMax);
402
+ this.controls.minDistance = safeMin;
403
+ this.controls.maxDistance = safeMax;
404
+ // Use shared resolveEffectiveLimits polar rules to prevent invalid minPolarAngle > maxPolarAngle interval
405
+ const callerMinPolar = this.callerConfig?.minPolarAngle;
406
+ const callerMaxPolar = this.callerConfig?.maxPolarAngle;
407
+ const effectiveMinInput = callerMinPolar ?? minPolarAngle;
408
+ let effectiveMaxInput;
409
+ if (callerMaxPolar !== undefined) {
410
+ effectiveMaxInput = callerMaxPolar;
411
+ }
412
+ else if (callerMinPolar !== undefined) {
413
+ effectiveMaxInput =
414
+ maxPolarAngle !== undefined ? Math.max(callerMinPolar, maxPolarAngle) : callerMinPolar;
415
+ }
416
+ else {
417
+ effectiveMaxInput = maxPolarAngle;
418
+ }
419
+ const polarLimits = this.resolveEffectiveLimits({
420
+ minPolarAngle: effectiveMinInput,
421
+ maxPolarAngle: effectiveMaxInput,
422
+ });
423
+ this.controls.minPolarAngle = polarLimits.minPolarAngle;
424
+ this.controls.maxPolarAngle = polarLimits.maxPolarAngle;
425
+ this.lastAppliedLimits = {
426
+ type: 'perspective',
427
+ minDistance: safeMin,
428
+ maxDistance: safeMax,
429
+ minPolarAngle: this.controls.minPolarAngle,
430
+ maxPolarAngle: this.controls.maxPolarAngle,
431
+ };
432
+ this.limitsUnlocked = false;
433
+ this.controls.update();
434
+ }
435
+ /**
436
+ * Temporarily unlocks distance constraints so transitions are not clamped midway.
437
+ * Animation ke dauran limits temporarily unlock karein.
438
+ */
439
+ /**
440
+ * Returns actively configured caller overrides.
441
+ * Caller ke dwara provide ki gayi explicit controls configuration prapt karein.
442
+ */
443
+ get config() {
444
+ return this.callerConfig;
445
+ }
446
+ /**
447
+ * Sets dynamic min/max zoom limits for OrthographicCamera.
448
+ * Explicit caller overrides from attach() take precedence if specified.
449
+ * Orthographic camera ke liye zoom limits update karein.
450
+ */
451
+ setZoomLimits(minZoom, maxZoom, maxPolarAngle, minPolarAngle) {
452
+ if (!this.controls)
453
+ return;
454
+ const callerMin = this.callerConfig?.minZoom;
455
+ const callerMax = this.callerConfig?.maxZoom;
456
+ let effectiveMax;
457
+ if (callerMax !== undefined) {
458
+ effectiveMax = Math.max(0.0001, callerMax);
459
+ }
460
+ else if (callerMin !== undefined) {
461
+ effectiveMax = Math.max(callerMin * 2, maxZoom);
462
+ }
463
+ else {
464
+ effectiveMax = Math.max(0.0001, maxZoom);
465
+ }
466
+ let effectiveMin;
467
+ if (callerMin !== undefined) {
468
+ effectiveMin = Math.min(callerMin, effectiveMax);
469
+ }
470
+ else {
471
+ effectiveMin = Math.min(Math.max(0.0001, minZoom), effectiveMax);
472
+ }
473
+ const safeMin = Math.max(0.0001, effectiveMin);
474
+ const safeMax = Math.max(safeMin, effectiveMax);
475
+ this.controls.minZoom = safeMin;
476
+ this.controls.maxZoom = safeMax;
477
+ // Point 2: Effective polar angles for Orthographic using shared resolver
478
+ const polarLimits = this.resolveEffectiveLimits({
479
+ minPolarAngle: this.callerConfig?.minPolarAngle ?? minPolarAngle,
480
+ maxPolarAngle: this.callerConfig?.maxPolarAngle ?? maxPolarAngle,
481
+ });
482
+ this.controls.minPolarAngle = polarLimits.minPolarAngle;
483
+ this.controls.maxPolarAngle = polarLimits.maxPolarAngle;
484
+ // Record floor-derived baseline
485
+ this.baseFramingLimits = {
486
+ ...this.baseFramingLimits,
487
+ type: 'ortho',
488
+ minZoom,
489
+ maxZoom,
490
+ minPolarAngle: minPolarAngle ??
491
+ this.baseFramingLimits?.minPolarAngle ??
492
+ DEFAULT_CONTROLS_CONFIG.minPolarAngle,
493
+ maxPolarAngle: maxPolarAngle ??
494
+ this.baseFramingLimits?.maxPolarAngle ??
495
+ DEFAULT_CONTROLS_CONFIG.maxPolarAngle,
496
+ };
497
+ this.lastAppliedLimits = {
498
+ type: 'ortho',
499
+ minZoom: safeMin,
500
+ maxZoom: safeMax,
501
+ minPolarAngle: polarLimits.minPolarAngle,
502
+ maxPolarAngle: polarLimits.maxPolarAngle,
503
+ };
504
+ this.limitsUnlocked = false;
505
+ this.controls.update();
506
+ }
507
+ /**
508
+ * Temporarily unlocks distance and zoom constraints so transitions are not clamped midway.
509
+ * Animation ke dauran limits temporarily unlock karein.
510
+ */
511
+ unlockLimits() {
512
+ if (this.controls) {
513
+ if (!this.lastAppliedLimits) {
514
+ this.lastAppliedLimits = {
515
+ type: 'perspective',
516
+ minDistance: this.controls.minDistance,
517
+ maxDistance: this.controls.maxDistance,
518
+ minPolarAngle: this.controls.minPolarAngle,
519
+ maxPolarAngle: this.controls.maxPolarAngle,
520
+ minZoom: this.controls.minZoom,
521
+ maxZoom: this.controls.maxZoom,
522
+ };
523
+ }
524
+ this.limitsUnlocked = true;
525
+ this.controls.minDistance = 0;
526
+ this.controls.maxDistance = Infinity;
527
+ this.controls.minZoom = 0;
528
+ this.controls.maxZoom = Infinity;
529
+ this.controls.minPolarAngle = 0;
530
+ this.controls.maxPolarAngle = Math.PI;
531
+ }
532
+ }
533
+ /**
534
+ * Restores previously applied limits if controls are currently unlocked.
535
+ * English: Restores last valid distance/zoom limits on cancelled or superseded transitions.
536
+ * Hinglish: Agar limits unlocked the aur transition interrupt hua, toh pichli valid limits restore karta hai.
537
+ */
538
+ restoreLimits() {
539
+ if (!this.controls || !this.limitsUnlocked || !this.lastAppliedLimits)
540
+ return;
541
+ if (this.lastAppliedLimits.type === 'ortho') {
542
+ if (this.lastAppliedLimits.minZoom !== undefined &&
543
+ this.lastAppliedLimits.maxZoom !== undefined) {
544
+ this.controls.minZoom = this.lastAppliedLimits.minZoom;
545
+ this.controls.maxZoom = this.lastAppliedLimits.maxZoom;
546
+ }
547
+ if (this.lastAppliedLimits.minPolarAngle !== undefined) {
548
+ this.controls.minPolarAngle = this.lastAppliedLimits.minPolarAngle;
549
+ }
550
+ if (this.lastAppliedLimits.maxPolarAngle !== undefined) {
551
+ this.controls.maxPolarAngle = this.lastAppliedLimits.maxPolarAngle;
552
+ }
553
+ }
554
+ else {
555
+ if (this.lastAppliedLimits.minDistance !== undefined &&
556
+ this.lastAppliedLimits.maxDistance !== undefined) {
557
+ this.controls.minDistance = this.lastAppliedLimits.minDistance;
558
+ this.controls.maxDistance = this.lastAppliedLimits.maxDistance;
559
+ if (this.lastAppliedLimits.maxPolarAngle !== undefined) {
560
+ this.controls.maxPolarAngle = this.lastAppliedLimits.maxPolarAngle;
561
+ }
562
+ if (this.lastAppliedLimits.minPolarAngle !== undefined) {
563
+ this.controls.minPolarAngle = this.lastAppliedLimits.minPolarAngle;
564
+ }
565
+ }
566
+ }
567
+ this.limitsUnlocked = false;
568
+ this.controls.update();
569
+ }
570
+ get isLimitsUnlocked() {
571
+ return this.limitsUnlocked;
572
+ }
573
+ get currentLimits() {
574
+ return this.lastAppliedLimits;
575
+ }
576
+ get baseLimits() {
577
+ return this.baseFramingLimits;
578
+ }
579
+ /**
580
+ * Updates damping inertia during render loop.
581
+ */
582
+ update() {
583
+ if (this.controls && this.controls.enableDamping) {
584
+ this.controls.update();
585
+ }
586
+ }
587
+ /**
588
+ * Cleans up controls and removes event listeners.
589
+ */
590
+ dispose() {
591
+ this.callerConfig = undefined;
592
+ if (this.controls) {
593
+ this.preservedTarget.copy(this.controls.target);
594
+ if (this.changeListener) {
595
+ this.controls.removeEventListener('change', this.changeListener);
596
+ this.controls.removeEventListener('start', this.startListener);
597
+ this.controls.domElement?.removeEventListener('keydown', this.keyListener, true);
598
+ this.changeListener = null;
599
+ }
600
+ this.controls.dispose();
601
+ this.controls = null;
602
+ }
603
+ }
604
+ }
@@ -0,0 +1,45 @@
1
+ /**
2
+ * @file InteractionManager.ts
3
+ * @description Manages Raycasting, pointer gestures (click vs drag), and store unit hit resolution.
4
+ * Pointer interaction, drag threshold detection aur store raycasting ko handle karne wala manager.
5
+ */
6
+ import * as THREE from 'three';
7
+ import type { RouteSelection } from '@wovvmap/contracts';
8
+ export interface PointerResolutionResult {
9
+ key: string | null;
10
+ isDrag: boolean;
11
+ route?: RouteSelection;
12
+ }
13
+ /**
14
+ * Handles pointer events and raycasts against map meshes.
15
+ */
16
+ export declare class InteractionManager {
17
+ private readonly raycaster;
18
+ private pointerDownPos;
19
+ private readonly dragThresholdSq;
20
+ private dragged;
21
+ /**
22
+ * Records pointer down coordinates.
23
+ */
24
+ onPointerDown(clientX: number, clientY: number): void;
25
+ /** A gesture that moved away and returned is still an orbit drag, never a route tap.
26
+ * Hinglish: Drag wapas starting point par aaye tab bhi route select/start nahi hona chahiye. */
27
+ onPointerMove(clientX: number, clientY: number): void;
28
+ /**
29
+ * Evaluates pointer release, determines if gesture was a drag, and resolves clicked store node key.
30
+ */
31
+ onPointerUp(clientX: number, clientY: number, canvasBounds: DOMRect, camera: THREE.Camera | null, targetGroup: THREE.Group, pickRoute?: (raycaster: THREE.Raycaster) => {
32
+ selection: RouteSelection;
33
+ distance: number;
34
+ } | null): PointerResolutionResult;
35
+ /**
36
+ * Checks whether a 3D object and all of its ancestors in the scene graph are visible.
37
+ * Object aur uske sabhi ancestor groups visible hain ya nahi ye check karein.
38
+ */
39
+ private isObjectEffectivelyVisible;
40
+ /**
41
+ * Resets interaction tracking.
42
+ */
43
+ dispose(): void;
44
+ }
45
+ //# sourceMappingURL=InteractionManager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"InteractionManager.d.ts","sourceRoot":"","sources":["../../src/engine/InteractionManager.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AAExD,MAAM,WAAW,uBAAuB;IACtC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAA;IAClB,MAAM,EAAE,OAAO,CAAA;IACf,KAAK,CAAC,EAAE,cAAc,CAAA;CACvB;AAED;;GAEG;AACH,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAyC;IACnE,OAAO,CAAC,cAAc,CAAwC;IAC9D,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAa;IAC7C,OAAO,CAAC,OAAO,CAAQ;IAEvB;;OAEG;IACI,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI;IAI5D;oGACgG;IACzF,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI;IAO5D;;OAEG;IACI,WAAW,CAChB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,EACf,YAAY,EAAE,OAAO,EACrB,MAAM,EAAE,KAAK,CAAC,MAAM,GAAG,IAAI,EAC3B,WAAW,EAAE,KAAK,CAAC,KAAK,EACxB,SAAS,CAAC,EAAE,CACV,SAAS,EAAE,KAAK,CAAC,SAAS,KACvB;QAAE,SAAS,EAAE,cAAc,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,GAC1D,uBAAuB;IAoD1B;;;OAGG;IACH,OAAO,CAAC,0BAA0B;IAWlC;;OAEG;IACI,OAAO,IAAI,IAAI;CAIvB"}