@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,129 @@
1
+ /**
2
+ * @file ShapeService.ts
3
+ * @description Central manager service managing Three.js shapes, floor groupings, and theme updates.
4
+ * English: Shape management service owning per-viewer strategy instances and declarative reset semantics.
5
+ * Hinglish: Three.js shapes aur floor groups ko manage karne wali central service jo viewer-owned strategies rakhti hai.
6
+ */
7
+ import * as THREE from 'three';
8
+ import { type SelectionPaintMap } from '../selectionPaint.js';
9
+ import type { shapeDetail } from '@wovvmap/contracts';
10
+ import { type ShapeType } from './ShapeFactory.js';
11
+ import type { IShapeService } from './IShapeService.js';
12
+ export declare class ShapeService {
13
+ private readonly allShapeMap;
14
+ private readonly floorWiseShapeMap;
15
+ private readonly strategies;
16
+ private currentAnchorGradient?;
17
+ private currentEdgeColor?;
18
+ private currentCustomColors?;
19
+ private isShapesVisible;
20
+ private readonly highlight;
21
+ private selectionPaint;
22
+ /**
23
+ * Retrieves viewer-scoped strategy instance for the given shape type.
24
+ * Viewer-specific strategy instance prapt karein.
25
+ */
26
+ getStrategy(type?: ShapeType): IShapeService;
27
+ /**
28
+ * Constructs a shape via ShapeFactory strategy and groups it under its floor level.
29
+ * Shape banakar use uske floor group (floor-0, floor-1) me add karein.
30
+ */
31
+ createShape(type: ShapeType, shapeDetail: shapeDetail, id: string): THREE.Object3D;
32
+ /**
33
+ * Returns all shape objects managed across all floors.
34
+ * Sabhi shapes ki array prapt karein.
35
+ */
36
+ getAllShapes(): THREE.Object3D[];
37
+ /**
38
+ * Retrieves the container group for shapes on a specific floor.
39
+ * Specific floor ka Three.js group prapt karein.
40
+ */
41
+ getFloorWiseShapes(z: number): THREE.Group | undefined;
42
+ /**
43
+ * Looks up a specific shape mesh by its unique key.
44
+ * Unique key se specific store mesh dhoondein.
45
+ */
46
+ getShapeByKey(key: string): THREE.Object3D | undefined;
47
+ /** Paint only the previous/new selection; an unloaded key is applied when its shape arrives.
48
+ * Hinglish: Sirf purani/nayi selection paint ho; abhi na bani shape par creation ke waqt lagega. */
49
+ setSelection(key: string | null, color: string): void;
50
+ /** Diff only selected memberships; retained shapes keep their material overlay unchanged.
51
+ * Hinglish: Sirf selection se nikli/aayi keys badlein; common shapes ka paint dobara na bane. */
52
+ setSelectionKeys(keys: readonly string[], color: string): void;
53
+ /** Apply the resolved key/color difference; retained members keep their material resources.
54
+ * Hinglish: Sirf badli keys/rang paint hon; same members ke materials dobara na banein. */
55
+ setSelectionPaint(next: SelectionPaintMap): void;
56
+ private applySelection;
57
+ /** Base updates must never mutate selection clones or restore already-disposed gradient materials.
58
+ * Hinglish: Asli style par update ho; selection clones ya dispose hue gradient wapas na lagayein. */
59
+ private updateBaseStyle;
60
+ /**
61
+ * Removes a shape mesh by key and safely cleans up its WebGL resources.
62
+ * Shape ko map aur floor group se remove karke memory dispose karein.
63
+ */
64
+ removeShape(id: string): boolean;
65
+ /**
66
+ * Updates visual theme colors for a shape mesh.
67
+ * Shape mesh ka visual color update karein.
68
+ */
69
+ updateTheme(type: ShapeType, mesh: THREE.Object3D, shapeDetail: shapeDetail): void;
70
+ /**
71
+ * Changes vertical scale of shapes between 2D (flattened) and 3D (extruded height).
72
+ * 2D aur 3D modes ke mutabik group ke shapes ki height scale set karein.
73
+ */
74
+ private activeViewModeAnimationId;
75
+ private activeAnimationRafId;
76
+ /**
77
+ * Cancels active view mode height animations.
78
+ * Chalu view mode height animation ko cancel karein.
79
+ */
80
+ cancelAnimation(): void;
81
+ /**
82
+ * Resolves target rendered depth and floor base metadata for an extruded shape mesh.
83
+ * English: Shared target depth resolver reused across animated and instant mode transitions.
84
+ * Hinglish: Animated aur instant mode transitions ke bich shared target depth resolver.
85
+ */
86
+ resolveTargetDepth(mesh: THREE.Mesh, mode: '2D' | '3D', depth2D?: number, depth3D?: number, configuredBaseDepth?: number): {
87
+ targetDepth: number;
88
+ original: number;
89
+ isFloorBase: boolean;
90
+ } | null;
91
+ /**
92
+ * Smoothly animates vertical scale of shapes between 2D (flattened) and 3D (extruded height).
93
+ * 2D aur 3D modes ke mutabik group ke shapes ki height scale smoothly animate karein.
94
+ */
95
+ animateViewModeToGroup(group: THREE.Group, mode: '2D' | '3D', depth2D?: number, depth3D?: number, configuredBaseDepth?: number, onUpdate?: () => void, durationMs?: number, onComplete?: () => void): void;
96
+ applyViewModeToGroup(group: THREE.Group, mode: '2D' | '3D', depth2D?: number, depth3D?: number, configuredBaseDepth?: number): void;
97
+ /**
98
+ * Updates vertical gradient palette across all anchor store meshes.
99
+ * Sabhi anchor store meshes ka gradient update karein.
100
+ */
101
+ updateAnchorGradient(gradient?: [string, string]): void;
102
+ /**
103
+ * Toggles visibility of all floor shapes.
104
+ * Sabhi floor shapes ki visibility toggle karein.
105
+ */
106
+ toggleShapes(visible: boolean): void;
107
+ /**
108
+ * Applies explicit or derived darker border color onto a shape's LineSegments children.
109
+ * English: Applies explicit edge override or derives darker shade (effectiveFill * 0.3) on shape edges.
110
+ * Hinglish: Shape ke LineSegments par explicit edge color ya effective fill ka darker shade apply karein.
111
+ */
112
+ private applyEdgeColorToShape;
113
+ /**
114
+ * Updates custom colors for unit shapes mapped by unit key or category name with declarative reset.
115
+ * Specific units ya categories ke liye custom color overrides apply karein ya reset karein.
116
+ */
117
+ updateShapeColors(colorsMap?: Record<string, string>): void;
118
+ /**
119
+ * Updates edge line colors on all active unit shapes with fallback support.
120
+ * Sabhi unit shapes ki boundary edge lines ka color update karein.
121
+ */
122
+ updateEdgeColor(color?: string): void;
123
+ /**
124
+ * Cleans all shapes, empties floor groups, and releases WebGL memory.
125
+ * Sabhi shapes clear karke memory release karein.
126
+ */
127
+ clear(): void;
128
+ }
129
+ //# sourceMappingURL=ShapeService.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ShapeService.d.ts","sourceRoot":"","sources":["../../../src/services/shape-services/ShapeService.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,480 @@
1
+ /**
2
+ * @file ShapeService.ts
3
+ * @description Central manager service managing Three.js shapes, floor groupings, and theme updates.
4
+ * English: Shape management service owning per-viewer strategy instances and declarative reset semantics.
5
+ * Hinglish: Three.js shapes aur floor groups ko manage karne wali central service jo viewer-owned strategies rakhti hai.
6
+ */
7
+ import * as THREE from 'three';
8
+ import { uniformSelectionPaint } from '../selectionPaint.js';
9
+ import { ShapeFactory } from './ShapeFactory.js';
10
+ import { ExtrudeShapeService } from './ExtrudeShapeService.js';
11
+ import { FlatShapeService } from './FlatShapeService.js';
12
+ import { ShapeHighlightService } from './ShapeHighlightService.js';
13
+ import { setGradientMaterial } from './MaterialUtils.js';
14
+ import { disposeThreeObject } from '../threeDisposeHelper.js';
15
+ export class ShapeService {
16
+ allShapeMap = new Map();
17
+ floorWiseShapeMap = new Map();
18
+ strategies = new Map([
19
+ ['extruded', new ExtrudeShapeService()],
20
+ ['flat', new FlatShapeService()],
21
+ ]);
22
+ currentAnchorGradient;
23
+ currentEdgeColor;
24
+ currentCustomColors;
25
+ isShapesVisible = true;
26
+ highlight = new ShapeHighlightService();
27
+ selectionPaint = new Map();
28
+ /**
29
+ * Retrieves viewer-scoped strategy instance for the given shape type.
30
+ * Viewer-specific strategy instance prapt karein.
31
+ */
32
+ getStrategy(type = 'extruded') {
33
+ return this.strategies.get(type) ?? ShapeFactory.getStrategy(type);
34
+ }
35
+ /**
36
+ * Constructs a shape via ShapeFactory strategy and groups it under its floor level.
37
+ * Shape banakar use uske floor group (floor-0, floor-1) me add karein.
38
+ */
39
+ createShape(type, shapeDetail, id) {
40
+ const extrudeStrategy = this.getStrategy('extruded');
41
+ if (this.currentAnchorGradient &&
42
+ extrudeStrategy &&
43
+ typeof extrudeStrategy.setAnchorGradient === 'function') {
44
+ extrudeStrategy.setAnchorGradient(this.currentAnchorGradient);
45
+ }
46
+ const service = this.getStrategy(type);
47
+ const shape = service.createShape(shapeDetail, id);
48
+ if (shape) {
49
+ this.removeShape(id);
50
+ shape.userData.id = id;
51
+ if (shapeDetail.floorBash !== undefined) {
52
+ shape.userData.floorBash = Boolean(shapeDetail.floorBash);
53
+ shape.userData.isFloorBase = Boolean(shapeDetail.floorBash);
54
+ }
55
+ if (shapeDetail.category && !shape.userData.category) {
56
+ shape.userData.category = shapeDetail.category;
57
+ }
58
+ // If persistent custom color matches this shape, apply immediately
59
+ if (this.currentCustomColors && extrudeStrategy) {
60
+ const targetColor = this.currentCustomColors[id] ||
61
+ (shape.userData?.category && this.currentCustomColors[shape.userData.category]);
62
+ if (targetColor) {
63
+ extrudeStrategy.updateTheme(shape, { color: targetColor });
64
+ }
65
+ }
66
+ // If persistent edge color is configured, apply immediately to new shape
67
+ if (this.currentEdgeColor) {
68
+ this.applyEdgeColorToShape(shape, this.currentEdgeColor);
69
+ }
70
+ this.allShapeMap.set(id, shape);
71
+ // Extract floor z index from key "x,y,z"
72
+ const parts = id.split(',');
73
+ const z = parts.length >= 3 ? Number(parts[2]) || 0 : 0;
74
+ let group = this.floorWiseShapeMap.get(z);
75
+ if (!group) {
76
+ group = new THREE.Group();
77
+ group.name = `floor-${z}`;
78
+ group.userData.floorIndex = z;
79
+ group.visible = this.isShapesVisible;
80
+ this.floorWiseShapeMap.set(z, group);
81
+ }
82
+ group.add(shape);
83
+ const paint = this.selectionPaint.get(id);
84
+ if (paint)
85
+ this.highlight.apply(shape, paint.color);
86
+ }
87
+ return shape;
88
+ }
89
+ /**
90
+ * Returns all shape objects managed across all floors.
91
+ * Sabhi shapes ki array prapt karein.
92
+ */
93
+ getAllShapes() {
94
+ return Array.from(this.allShapeMap.values());
95
+ }
96
+ /**
97
+ * Retrieves the container group for shapes on a specific floor.
98
+ * Specific floor ka Three.js group prapt karein.
99
+ */
100
+ getFloorWiseShapes(z) {
101
+ return this.floorWiseShapeMap.get(z);
102
+ }
103
+ /**
104
+ * Looks up a specific shape mesh by its unique key.
105
+ * Unique key se specific store mesh dhoondein.
106
+ */
107
+ getShapeByKey(key) {
108
+ return this.allShapeMap.get(key);
109
+ }
110
+ /** Paint only the previous/new selection; an unloaded key is applied when its shape arrives.
111
+ * Hinglish: Sirf purani/nayi selection paint ho; abhi na bani shape par creation ke waqt lagega. */
112
+ setSelection(key, color) {
113
+ this.setSelectionKeys(key === null ? [] : [key], color);
114
+ }
115
+ /** Diff only selected memberships; retained shapes keep their material overlay unchanged.
116
+ * Hinglish: Sirf selection se nikli/aayi keys badlein; common shapes ka paint dobara na bane. */
117
+ setSelectionKeys(keys, color) {
118
+ this.setSelectionPaint(uniformSelectionPaint(keys, { color, text2D: color, text3D: color }));
119
+ }
120
+ /** Apply the resolved key/color difference; retained members keep their material resources.
121
+ * Hinglish: Sirf badli keys/rang paint hon; same members ke materials dobara na banein. */
122
+ setSelectionPaint(next) {
123
+ for (const key of this.selectionPaint.keys()) {
124
+ if (!next.has(key)) {
125
+ const shape = this.getShapeByKey(key);
126
+ if (shape)
127
+ this.highlight.detach(shape);
128
+ }
129
+ }
130
+ for (const [key, paint] of next) {
131
+ if (paint.color !== this.selectionPaint.get(key)?.color) {
132
+ const shape = this.getShapeByKey(key);
133
+ if (shape)
134
+ this.highlight.apply(shape, paint.color);
135
+ }
136
+ }
137
+ this.selectionPaint = next;
138
+ }
139
+ applySelection() {
140
+ for (const [key, paint] of this.selectionPaint) {
141
+ const shape = this.getShapeByKey(key);
142
+ if (shape)
143
+ this.highlight.apply(shape, paint.color);
144
+ }
145
+ }
146
+ /** Base updates must never mutate selection clones or restore already-disposed gradient materials.
147
+ * Hinglish: Asli style par update ho; selection clones ya dispose hue gradient wapas na lagayein. */
148
+ updateBaseStyle(update, shape) {
149
+ const affectsSelection = shape ? this.highlight.has(shape) : this.selectionPaint.size > 0;
150
+ if (!affectsSelection) {
151
+ update();
152
+ return;
153
+ }
154
+ this.highlight.detach(shape);
155
+ try {
156
+ update();
157
+ }
158
+ finally {
159
+ if (shape) {
160
+ const paint = this.selectionPaint.get(shape.userData.id);
161
+ if (paint)
162
+ this.highlight.apply(shape, paint.color);
163
+ }
164
+ else
165
+ this.applySelection();
166
+ }
167
+ }
168
+ /**
169
+ * Removes a shape mesh by key and safely cleans up its WebGL resources.
170
+ * Shape ko map aur floor group se remove karke memory dispose karein.
171
+ */
172
+ removeShape(id) {
173
+ const shape = this.allShapeMap.get(id);
174
+ if (!shape)
175
+ return false;
176
+ if (this.selectionPaint.has(id))
177
+ this.highlight.detach(shape);
178
+ this.allShapeMap.delete(id);
179
+ // Remove from floor group
180
+ const parts = id.split(',');
181
+ const z = parts.length >= 3 ? Number(parts[2]) || 0 : 0;
182
+ const group = this.floorWiseShapeMap.get(z);
183
+ if (group) {
184
+ group.remove(shape);
185
+ }
186
+ // Safely dispose WebGL geometries and materials
187
+ disposeThreeObject(shape);
188
+ return true;
189
+ }
190
+ /**
191
+ * Updates visual theme colors for a shape mesh.
192
+ * Shape mesh ka visual color update karein.
193
+ */
194
+ updateTheme(type, mesh, shapeDetail) {
195
+ this.updateBaseStyle(() => {
196
+ const service = this.getStrategy(type);
197
+ service.updateTheme(mesh, shapeDetail);
198
+ if (this.currentEdgeColor) {
199
+ this.applyEdgeColorToShape(mesh, this.currentEdgeColor);
200
+ }
201
+ }, mesh);
202
+ }
203
+ /**
204
+ * Changes vertical scale of shapes between 2D (flattened) and 3D (extruded height).
205
+ * 2D aur 3D modes ke mutabik group ke shapes ki height scale set karein.
206
+ */
207
+ activeViewModeAnimationId = 0;
208
+ activeAnimationRafId = null;
209
+ /**
210
+ * Cancels active view mode height animations.
211
+ * Chalu view mode height animation ko cancel karein.
212
+ */
213
+ cancelAnimation() {
214
+ this.activeViewModeAnimationId++;
215
+ if (this.activeAnimationRafId !== null && typeof cancelAnimationFrame !== 'undefined') {
216
+ cancelAnimationFrame(this.activeAnimationRafId);
217
+ this.activeAnimationRafId = null;
218
+ }
219
+ }
220
+ /**
221
+ * Resolves target rendered depth and floor base metadata for an extruded shape mesh.
222
+ * English: Shared target depth resolver reused across animated and instant mode transitions.
223
+ * Hinglish: Animated aur instant mode transitions ke bich shared target depth resolver.
224
+ */
225
+ resolveTargetDepth(mesh, mode, depth2D = 0.1, depth3D = 6, configuredBaseDepth) {
226
+ if (!mesh.userData || mesh.userData.originalDepth === undefined)
227
+ return null;
228
+ const original = Number(mesh.userData.originalDepth);
229
+ if (original <= 0)
230
+ return null;
231
+ const isFloorBase = mesh.userData.floorBash === true || mesh.userData.isFloorBase === true || original <= 0.2;
232
+ let targetDepth;
233
+ if (isFloorBase) {
234
+ if (mode === '2D') {
235
+ targetDepth = Math.min(0.02, original * 0.2);
236
+ }
237
+ else {
238
+ targetDepth =
239
+ configuredBaseDepth !== undefined
240
+ ? configuredBaseDepth
241
+ : (mesh.userData.floorBaseDepth ?? (original <= 0.2 ? original : 0.05));
242
+ }
243
+ }
244
+ else {
245
+ targetDepth = mode === '2D' ? depth2D : depth3D;
246
+ }
247
+ return { targetDepth, original, isFloorBase };
248
+ }
249
+ /**
250
+ * Smoothly animates vertical scale of shapes between 2D (flattened) and 3D (extruded height).
251
+ * 2D aur 3D modes ke mutabik group ke shapes ki height scale smoothly animate karein.
252
+ */
253
+ animateViewModeToGroup(group, mode, depth2D = 0.1, depth3D = 6, configuredBaseDepth, onUpdate, durationMs = 400, onComplete) {
254
+ this.cancelAnimation();
255
+ if (typeof requestAnimationFrame === 'undefined') {
256
+ this.applyViewModeToGroup(group, mode, depth2D, depth3D, configuredBaseDepth);
257
+ if (onUpdate)
258
+ onUpdate();
259
+ if (onComplete)
260
+ onComplete();
261
+ return;
262
+ }
263
+ const animId = ++this.activeViewModeAnimationId;
264
+ const startTime = performance.now();
265
+ const targets = new Map();
266
+ group.children.forEach((child) => {
267
+ const mesh = child;
268
+ const res = this.resolveTargetDepth(mesh, mode, depth2D, depth3D, configuredBaseDepth);
269
+ if (res) {
270
+ targets.set(mesh.uuid, {
271
+ startScale: mesh.scale.z,
272
+ targetScale: res.targetDepth / res.original,
273
+ });
274
+ }
275
+ });
276
+ const step = (time) => {
277
+ if (this.activeViewModeAnimationId !== animId)
278
+ return;
279
+ const elapsed = time - startTime;
280
+ const progress = Math.min(elapsed / durationMs, 1);
281
+ const ease = 1 - Math.pow(1 - progress, 3);
282
+ group.children.forEach((child) => {
283
+ const item = targets.get(child.uuid);
284
+ if (item) {
285
+ const currentScale = item.startScale + (item.targetScale - item.startScale) * ease;
286
+ child.scale.set(1, 1, currentScale);
287
+ }
288
+ });
289
+ if (onUpdate)
290
+ onUpdate();
291
+ if (progress < 1) {
292
+ this.activeAnimationRafId = requestAnimationFrame(step);
293
+ }
294
+ else {
295
+ this.activeAnimationRafId = null;
296
+ this.applyViewModeToGroup(group, mode, depth2D, depth3D, configuredBaseDepth);
297
+ if (onUpdate)
298
+ onUpdate();
299
+ if (onComplete)
300
+ onComplete();
301
+ }
302
+ };
303
+ this.activeAnimationRafId = requestAnimationFrame(step);
304
+ }
305
+ applyViewModeToGroup(group, mode, depth2D = 0.1, depth3D = 6, configuredBaseDepth) {
306
+ this.cancelAnimation();
307
+ group.children.forEach((child) => {
308
+ const mesh = child;
309
+ const res = this.resolveTargetDepth(mesh, mode, depth2D, depth3D, configuredBaseDepth);
310
+ if (res) {
311
+ mesh.userData.renderedDepth = res.targetDepth;
312
+ if (res.isFloorBase && configuredBaseDepth !== undefined) {
313
+ mesh.userData.configuredBaseDepth = configuredBaseDepth;
314
+ }
315
+ mesh.scale.set(1, 1, res.targetDepth / res.original);
316
+ }
317
+ });
318
+ }
319
+ /**
320
+ * Updates vertical gradient palette across all anchor store meshes.
321
+ * Sabhi anchor store meshes ka gradient update karein.
322
+ */
323
+ updateAnchorGradient(gradient) {
324
+ if (this.currentAnchorGradient &&
325
+ gradient &&
326
+ this.currentAnchorGradient[0] === gradient[0] &&
327
+ this.currentAnchorGradient[1] === gradient[1]) {
328
+ return;
329
+ }
330
+ if (!this.currentAnchorGradient && !gradient) {
331
+ return;
332
+ }
333
+ this.currentAnchorGradient = gradient;
334
+ const extrudeStrategy = this.getStrategy('extruded');
335
+ if (extrudeStrategy && typeof extrudeStrategy.setAnchorGradient === 'function') {
336
+ extrudeStrategy.setAnchorGradient(gradient ?? ExtrudeShapeService.DEFAULT_ANCHOR_GRADIENT);
337
+ }
338
+ this.updateBaseStyle(() => {
339
+ this.allShapeMap.forEach((shape, key) => {
340
+ if (shape instanceof THREE.Mesh &&
341
+ (shape.userData?.isAnchorStore || shape.userData?.originalIsAnchorStore)) {
342
+ // If this mesh currently has an explicit custom color override, preserve it
343
+ // Custom color overrides take precedence over general anchor store gradient updates
344
+ const hasCustom = shape.userData?.hasCustomColor ||
345
+ Boolean(this.currentCustomColors &&
346
+ (this.currentCustomColors[key] ||
347
+ (shape.userData?.category && this.currentCustomColors[shape.userData.category]) ||
348
+ (shape.userData?.id && this.currentCustomColors[shape.userData.id])));
349
+ if (hasCustom) {
350
+ return;
351
+ }
352
+ if (gradient) {
353
+ shape.userData.isAnchorStore = true;
354
+ if (extrudeStrategy && typeof extrudeStrategy.applyAnchorGradient === 'function') {
355
+ extrudeStrategy.applyAnchorGradient(shape, gradient);
356
+ }
357
+ else {
358
+ shape.userData.effectiveColor = gradient[0];
359
+ setGradientMaterial(shape, gradient);
360
+ }
361
+ }
362
+ else if (extrudeStrategy && typeof extrudeStrategy.updateTheme === 'function') {
363
+ extrudeStrategy.updateTheme(shape, {});
364
+ }
365
+ if (this.currentEdgeColor) {
366
+ this.applyEdgeColorToShape(shape, this.currentEdgeColor);
367
+ }
368
+ }
369
+ });
370
+ });
371
+ }
372
+ /**
373
+ * Toggles visibility of all floor shapes.
374
+ * Sabhi floor shapes ki visibility toggle karein.
375
+ */
376
+ toggleShapes(visible) {
377
+ this.isShapesVisible = visible;
378
+ this.floorWiseShapeMap.forEach((group) => {
379
+ group.visible = visible;
380
+ });
381
+ }
382
+ /**
383
+ * Applies explicit or derived darker border color onto a shape's LineSegments children.
384
+ * English: Applies explicit edge override or derives darker shade (effectiveFill * 0.3) on shape edges.
385
+ * Hinglish: Shape ke LineSegments par explicit edge color ya effective fill ka darker shade apply karein.
386
+ */
387
+ applyEdgeColorToShape(shape, color) {
388
+ const threeColor = color instanceof THREE.Color
389
+ ? color
390
+ : color
391
+ ? new THREE.Color(color)
392
+ : new THREE.Color(shape.userData?.effectiveColor ??
393
+ shape.userData?.originalColor ??
394
+ '#CCCCCC').multiplyScalar(0.3);
395
+ shape.children.forEach((child) => {
396
+ if (child instanceof THREE.LineSegments &&
397
+ child.material instanceof THREE.LineBasicMaterial) {
398
+ child.material.color.copy(threeColor);
399
+ }
400
+ });
401
+ }
402
+ /**
403
+ * Updates custom colors for unit shapes mapped by unit key or category name with declarative reset.
404
+ * Specific units ya categories ke liye custom color overrides apply karein ya reset karein.
405
+ */
406
+ updateShapeColors(colorsMap) {
407
+ const hasColors = Boolean(colorsMap && Object.keys(colorsMap).length > 0);
408
+ // Skip processing if custom colors configuration is identical
409
+ // English: Early return if requested custom colors match active colors.
410
+ // Hinglish: Agar custom colors map pehle se applied map ke barabar hai toh repeat processing skip karein.
411
+ if (!this.currentCustomColors && !hasColors) {
412
+ return;
413
+ }
414
+ if (this.currentCustomColors && hasColors && colorsMap) {
415
+ const prevKeys = Object.keys(this.currentCustomColors);
416
+ const nextKeys = Object.keys(colorsMap);
417
+ if (prevKeys.length === nextKeys.length &&
418
+ prevKeys.every((k) => this.currentCustomColors[k] === colorsMap[k])) {
419
+ return;
420
+ }
421
+ }
422
+ const extrudeStrategy = this.getStrategy('extruded');
423
+ this.currentCustomColors = hasColors ? { ...colorsMap } : undefined;
424
+ const activeEdgeColor = this.currentEdgeColor ? new THREE.Color(this.currentEdgeColor) : null;
425
+ this.updateBaseStyle(() => {
426
+ this.allShapeMap.forEach((shape, key) => {
427
+ if (hasColors && colorsMap) {
428
+ const targetColor = colorsMap[key] ||
429
+ (shape.userData?.category && colorsMap[shape.userData.category]) ||
430
+ (shape.userData?.id && colorsMap[shape.userData.id]);
431
+ if (targetColor) {
432
+ extrudeStrategy.updateTheme(shape, { color: targetColor });
433
+ if (activeEdgeColor) {
434
+ this.applyEdgeColorToShape(shape, activeEdgeColor);
435
+ }
436
+ return;
437
+ }
438
+ }
439
+ // If no color matches or colorsMap is empty/undefined, restore original styling
440
+ extrudeStrategy.updateTheme(shape, {});
441
+ if (activeEdgeColor) {
442
+ this.applyEdgeColorToShape(shape, activeEdgeColor);
443
+ }
444
+ });
445
+ });
446
+ }
447
+ /**
448
+ * Updates edge line colors on all active unit shapes with fallback support.
449
+ * Sabhi unit shapes ki boundary edge lines ka color update karein.
450
+ */
451
+ updateEdgeColor(color) {
452
+ if (this.currentEdgeColor === color)
453
+ return;
454
+ this.currentEdgeColor = color;
455
+ const explicitThreeColor = color ? new THREE.Color(color) : undefined;
456
+ this.updateBaseStyle(() => {
457
+ this.allShapeMap.forEach((shape) => {
458
+ this.applyEdgeColorToShape(shape, explicitThreeColor);
459
+ });
460
+ });
461
+ }
462
+ /**
463
+ * Cleans all shapes, empties floor groups, and releases WebGL memory.
464
+ * Sabhi shapes clear karke memory release karein.
465
+ */
466
+ clear() {
467
+ this.cancelAnimation();
468
+ this.highlight.detach();
469
+ this.selectionPaint = new Map();
470
+ this.allShapeMap.forEach((shape) => {
471
+ disposeThreeObject(shape);
472
+ });
473
+ this.allShapeMap.clear();
474
+ this.floorWiseShapeMap.forEach((group) => {
475
+ group.clear();
476
+ disposeThreeObject(group);
477
+ });
478
+ this.floorWiseShapeMap.clear();
479
+ }
480
+ }
@@ -0,0 +1,13 @@
1
+ import { BufferGeometry } from 'three';
2
+ import type { shapeDetail } from '@wovvmap/contracts';
3
+ /** Upload validated buffers; proprietary polygon/extrusion/edge generation stays on the server.
4
+ * Hinglish: Client par sirf ready buffer upload hai; shape algorithm dobara nahi chalta. */
5
+ export declare function uploadPreparedGeometry(detail: shapeDetail): {
6
+ geometry: BufferGeometry<import("three").NormalBufferAttributes, import("three").BufferGeometryEventMap>;
7
+ edges: BufferGeometry<import("three").NormalBufferAttributes, import("three").BufferGeometryEventMap>;
8
+ originalDepth: number | null;
9
+ isFloorBase: boolean;
10
+ position: import("@wovvmap/contracts").Point3D;
11
+ rotation: import("@wovvmap/contracts").Point3D;
12
+ };
13
+ //# sourceMappingURL=preparedGeometry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"preparedGeometry.d.ts","sourceRoot":"","sources":["../../../src/services/shape-services/preparedGeometry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,cAAc,EAAmC,MAAM,OAAO,CAAA;AAC7E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAErD;4FAC4F;AAC5F,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,WAAW;;;;;;;EAgCzD"}
@@ -0,0 +1,37 @@
1
+ import { Box3, BufferGeometry, Float32BufferAttribute, Vector3 } from 'three';
2
+ /** Upload validated buffers; proprietary polygon/extrusion/edge generation stays on the server.
3
+ * Hinglish: Client par sirf ready buffer upload hai; shape algorithm dobara nahi chalta. */
4
+ export function uploadPreparedGeometry(detail) {
5
+ const shape = detail.prepared;
6
+ if (!shape)
7
+ throw new Error('Prepared shape buffers are required');
8
+ const data = shape.geometry;
9
+ const geometry = new BufferGeometry();
10
+ const edges = new BufferGeometry();
11
+ try {
12
+ geometry.setAttribute('position', new Float32BufferAttribute(data.positions, 3));
13
+ geometry.setAttribute('normal', new Float32BufferAttribute(data.normals, 3));
14
+ if (data.uvs)
15
+ geometry.setAttribute('uv', new Float32BufferAttribute(data.uvs, 2));
16
+ if (data.indices)
17
+ geometry.setIndex(Array.from(data.indices));
18
+ for (const group of data.groups)
19
+ geometry.addGroup(group.start, group.count, group.materialIndex);
20
+ if (data.bounds)
21
+ geometry.boundingBox = new Box3(new Vector3(data.bounds.min.x, data.bounds.min.y, data.bounds.min.z), new Vector3(data.bounds.max.x, data.bounds.max.y, data.bounds.max.z));
22
+ edges.setAttribute('position', new Float32BufferAttribute(data.edgePositions, 3));
23
+ return {
24
+ geometry,
25
+ edges,
26
+ originalDepth: shape.originalDepth,
27
+ isFloorBase: shape.isFloorBase,
28
+ position: shape.position,
29
+ rotation: shape.rotation,
30
+ };
31
+ }
32
+ catch (error) {
33
+ geometry.dispose();
34
+ edges.dispose();
35
+ throw error;
36
+ }
37
+ }