@wovvmap/renderer-three 0.0.0-stage → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/controllers/ImageController.d.ts +95 -0
- package/dist/controllers/ImageController.d.ts.map +1 -0
- package/dist/controllers/ImageController.js +129 -0
- package/dist/controllers/ShapeController.d.ts +95 -0
- package/dist/controllers/ShapeController.d.ts.map +1 -0
- package/dist/controllers/ShapeController.js +139 -0
- package/dist/controllers/TextController.d.ts +120 -0
- package/dist/controllers/TextController.d.ts.map +1 -0
- package/dist/controllers/TextController.js +161 -0
- package/dist/controllers/ViewerElementsController.d.ts +254 -0
- package/dist/controllers/ViewerElementsController.d.ts.map +1 -0
- package/dist/controllers/ViewerElementsController.js +490 -0
- package/dist/engine/CameraFollow.d.ts +13 -0
- package/dist/engine/CameraFollow.d.ts.map +1 -0
- package/dist/engine/CameraFollow.js +52 -0
- package/dist/engine/CameraManager.d.ts +143 -0
- package/dist/engine/CameraManager.d.ts.map +1 -0
- package/dist/engine/CameraManager.js +566 -0
- package/dist/engine/ControlsManager.d.ts +123 -0
- package/dist/engine/ControlsManager.d.ts.map +1 -0
- package/dist/engine/ControlsManager.js +604 -0
- package/dist/engine/InteractionManager.d.ts +45 -0
- package/dist/engine/InteractionManager.d.ts.map +1 -0
- package/dist/engine/InteractionManager.js +99 -0
- package/dist/engine/LightingManager.d.ts +25 -0
- package/dist/engine/LightingManager.d.ts.map +1 -0
- package/dist/engine/LightingManager.js +74 -0
- package/dist/engine/MapViewerEngine.d.ts +350 -0
- package/dist/engine/MapViewerEngine.d.ts.map +1 -0
- package/dist/engine/MapViewerEngine.js +1041 -0
- package/dist/engine/RendererManager.d.ts +77 -0
- package/dist/engine/RendererManager.d.ts.map +1 -0
- package/dist/engine/RendererManager.js +243 -0
- package/dist/index.d.ts +40 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +39 -0
- package/dist/services/image-services/ImageCacheService.d.ts +49 -0
- package/dist/services/image-services/ImageCacheService.d.ts.map +1 -0
- package/dist/services/image-services/ImageCacheService.js +121 -0
- package/dist/services/image-services/ImagePlaneService.d.ts +29 -0
- package/dist/services/image-services/ImagePlaneService.d.ts.map +1 -0
- package/dist/services/image-services/ImagePlaneService.js +82 -0
- package/dist/services/image-services/ImageService.d.ts +170 -0
- package/dist/services/image-services/ImageService.d.ts.map +1 -0
- package/dist/services/image-services/ImageService.js +537 -0
- package/dist/services/image-services/ImageSpriteService.d.ts +39 -0
- package/dist/services/image-services/ImageSpriteService.d.ts.map +1 -0
- package/dist/services/image-services/ImageSpriteService.js +135 -0
- package/dist/services/routes/RouteArrows.d.ts +34 -0
- package/dist/services/routes/RouteArrows.d.ts.map +1 -0
- package/dist/services/routes/RouteArrows.js +157 -0
- package/dist/services/routes/RouteCursor.d.ts +19 -0
- package/dist/services/routes/RouteCursor.d.ts.map +1 -0
- package/dist/services/routes/RouteCursor.js +68 -0
- package/dist/services/routes/RouteMotion.d.ts +31 -0
- package/dist/services/routes/RouteMotion.d.ts.map +1 -0
- package/dist/services/routes/RouteMotion.js +132 -0
- package/dist/services/routes/RouteRenderer.d.ts +52 -0
- package/dist/services/routes/RouteRenderer.d.ts.map +1 -0
- package/dist/services/routes/RouteRenderer.js +445 -0
- package/dist/services/routes/RouteStepHighlight.d.ts +22 -0
- package/dist/services/routes/RouteStepHighlight.d.ts.map +1 -0
- package/dist/services/routes/RouteStepHighlight.js +84 -0
- package/dist/services/routes/routeMarkers.d.ts +6 -0
- package/dist/services/routes/routeMarkers.d.ts.map +1 -0
- package/dist/services/routes/routeMarkers.js +41 -0
- package/dist/services/selectionPaint.d.ts +12 -0
- package/dist/services/selectionPaint.d.ts.map +1 -0
- package/dist/services/selectionPaint.js +8 -0
- package/dist/services/shape-services/ExtrudeShapeService.d.ts +54 -0
- package/dist/services/shape-services/ExtrudeShapeService.d.ts.map +1 -0
- package/dist/services/shape-services/ExtrudeShapeService.js +204 -0
- package/dist/services/shape-services/FlatShapeService.d.ts +25 -0
- package/dist/services/shape-services/FlatShapeService.d.ts.map +1 -0
- package/dist/services/shape-services/FlatShapeService.js +49 -0
- package/dist/services/shape-services/IShapeService.d.ts +24 -0
- package/dist/services/shape-services/IShapeService.d.ts.map +1 -0
- package/dist/services/shape-services/IShapeService.js +6 -0
- package/dist/services/shape-services/MaterialUtils.d.ts +15 -0
- package/dist/services/shape-services/MaterialUtils.d.ts.map +1 -0
- package/dist/services/shape-services/MaterialUtils.js +71 -0
- package/dist/services/shape-services/ShapeFactory.d.ts +20 -0
- package/dist/services/shape-services/ShapeFactory.d.ts.map +1 -0
- package/dist/services/shape-services/ShapeFactory.js +28 -0
- package/dist/services/shape-services/ShapeHighlightService.d.ts +13 -0
- package/dist/services/shape-services/ShapeHighlightService.d.ts.map +1 -0
- package/dist/services/shape-services/ShapeHighlightService.js +57 -0
- package/dist/services/shape-services/ShapeService.d.ts +129 -0
- package/dist/services/shape-services/ShapeService.d.ts.map +1 -0
- package/dist/services/shape-services/ShapeService.js +480 -0
- package/dist/services/shape-services/preparedGeometry.d.ts +13 -0
- package/dist/services/shape-services/preparedGeometry.d.ts.map +1 -0
- package/dist/services/shape-services/preparedGeometry.js +37 -0
- package/dist/services/text-services/ITextRenderStrategy.d.ts +79 -0
- package/dist/services/text-services/ITextRenderStrategy.d.ts.map +1 -0
- package/dist/services/text-services/ITextRenderStrategy.js +7 -0
- package/dist/services/text-services/Text2DService.d.ts +66 -0
- package/dist/services/text-services/Text2DService.d.ts.map +1 -0
- package/dist/services/text-services/Text2DService.js +483 -0
- package/dist/services/text-services/Text3DService.d.ts +51 -0
- package/dist/services/text-services/Text3DService.d.ts.map +1 -0
- package/dist/services/text-services/Text3DService.js +246 -0
- package/dist/services/text-services/TextCollisionService.d.ts +29 -0
- package/dist/services/text-services/TextCollisionService.d.ts.map +1 -0
- package/dist/services/text-services/TextCollisionService.js +117 -0
- package/dist/services/text-services/TextService.d.ts +159 -0
- package/dist/services/text-services/TextService.d.ts.map +1 -0
- package/dist/services/text-services/TextService.js +398 -0
- package/dist/services/text-services/TextStrategyRegistry.d.ts +36 -0
- package/dist/services/text-services/TextStrategyRegistry.d.ts.map +1 -0
- package/dist/services/text-services/TextStrategyRegistry.js +44 -0
- package/dist/services/threeDisposeHelper.d.ts +12 -0
- package/dist/services/threeDisposeHelper.d.ts.map +1 -0
- package/dist/services/threeDisposeHelper.js +57 -0
- package/package.json +40 -3
- package/README.md +0 -3
|
@@ -0,0 +1,445 @@
|
|
|
1
|
+
import * as THREE from 'three';
|
|
2
|
+
import { ViewerCommandError } from '@wovvmap/contracts';
|
|
3
|
+
import { createRouteMarkers } from './routeMarkers.js';
|
|
4
|
+
import { RouteStepHighlight } from './RouteStepHighlight.js';
|
|
5
|
+
import { RouteArrows } from './RouteArrows.js';
|
|
6
|
+
import { RouteCursor } from './RouteCursor.js';
|
|
7
|
+
export class RouteRenderer {
|
|
8
|
+
scene;
|
|
9
|
+
invalidate;
|
|
10
|
+
follow;
|
|
11
|
+
sets = new Set();
|
|
12
|
+
floor = 0;
|
|
13
|
+
floorBaseDepth;
|
|
14
|
+
color = '#9b0e9b';
|
|
15
|
+
highlightColor = '#f5b942';
|
|
16
|
+
arrowColor = '#ffffff';
|
|
17
|
+
animation;
|
|
18
|
+
/** Only the accepted attached arrow owner ticks; there is no renderer-owned RAF.
|
|
19
|
+
* Hinglish: Engine ki single frame loop hi call kare; hidden/retired sets par work nahi. */
|
|
20
|
+
get hasAnimation() {
|
|
21
|
+
return (!!this.animation &&
|
|
22
|
+
this.animation.root.parent === this.scene &&
|
|
23
|
+
this.animation.root.visible &&
|
|
24
|
+
(this.animation.playback ? this.animation.playback.running : this.animation.arrows.moving));
|
|
25
|
+
}
|
|
26
|
+
update(time) {
|
|
27
|
+
if (!this.hasAnimation)
|
|
28
|
+
return false;
|
|
29
|
+
const animation = this.animation;
|
|
30
|
+
return animation.playback ? animation.playback.tick(time) : animation.arrows.update(time);
|
|
31
|
+
}
|
|
32
|
+
resetAnimationClock() {
|
|
33
|
+
this.animation?.arrows.resetClock();
|
|
34
|
+
this.animation?.playback?.resetClock();
|
|
35
|
+
}
|
|
36
|
+
constructor(scene, invalidate, follow) {
|
|
37
|
+
this.scene = scene;
|
|
38
|
+
this.invalidate = invalidate;
|
|
39
|
+
this.follow = follow;
|
|
40
|
+
}
|
|
41
|
+
setFloor(floor) {
|
|
42
|
+
this.floor = floor;
|
|
43
|
+
for (const set of this.sets) {
|
|
44
|
+
for (const [object, index] of set.floors)
|
|
45
|
+
object.visible = index === floor;
|
|
46
|
+
set.stepFloor();
|
|
47
|
+
}
|
|
48
|
+
this.invalidate();
|
|
49
|
+
}
|
|
50
|
+
/** Hit-test visible ready ribbons; the shared viewer decides whether selection is permitted.
|
|
51
|
+
* Hinglish: Visible path ka tap background clear na bane; choose karna preview stage ka kaam hai. */
|
|
52
|
+
pick(raycaster) {
|
|
53
|
+
for (const set of this.sets) {
|
|
54
|
+
const choice = set.pick(raycaster);
|
|
55
|
+
if (choice)
|
|
56
|
+
return choice;
|
|
57
|
+
}
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
setTheme(theme) {
|
|
61
|
+
this.color = theme.route?.color ?? theme.spriteBackgroundColor;
|
|
62
|
+
this.highlightColor = theme.route?.highlightColor ?? '#f5b942';
|
|
63
|
+
this.arrowColor = theme.route?.arrowColor ?? '#ffffff';
|
|
64
|
+
for (const set of this.sets)
|
|
65
|
+
set.paint();
|
|
66
|
+
this.invalidate();
|
|
67
|
+
}
|
|
68
|
+
/** Only a display delta from the prepared base; never add the already-baked elevation twice.
|
|
69
|
+
* Hinglish: Live wall/base styling ka sirf difference lage; buffer/graph/source dobara na bane. */
|
|
70
|
+
setFloorBaseDepth(value) {
|
|
71
|
+
this.floorBaseDepth = value;
|
|
72
|
+
for (const set of this.sets)
|
|
73
|
+
set.depth();
|
|
74
|
+
this.invalidate();
|
|
75
|
+
}
|
|
76
|
+
prepare(items) {
|
|
77
|
+
const routeSetId = items[0]?.routeSetId;
|
|
78
|
+
const root = new THREE.Group();
|
|
79
|
+
root.name = 'wovvmap-route-set';
|
|
80
|
+
const floors = new Map();
|
|
81
|
+
const options = new Map();
|
|
82
|
+
const meshes = [];
|
|
83
|
+
const markers = [];
|
|
84
|
+
let selected = '';
|
|
85
|
+
let active = false;
|
|
86
|
+
let disposed = false;
|
|
87
|
+
let selectedStep = null;
|
|
88
|
+
let animationMode = 'off';
|
|
89
|
+
const syncArrows = () => {
|
|
90
|
+
for (const [id, record] of options) {
|
|
91
|
+
record.arrows.setFloor(this.floor);
|
|
92
|
+
record.arrows.setColor(this.arrowColor);
|
|
93
|
+
record.cursor.setColor(this.arrowColor);
|
|
94
|
+
record.cursor.setFloor(this.floor);
|
|
95
|
+
record.arrows.setEnabled(active && id === selected && !record.playback && animationMode === 'moving-arrows');
|
|
96
|
+
}
|
|
97
|
+
const record = options.get(selected);
|
|
98
|
+
if (active && record && (record.playback || animationMode === 'moving-arrows'))
|
|
99
|
+
this.animation = { root, arrows: record.arrows, playback: record.playback };
|
|
100
|
+
else if (this.animation?.root === root)
|
|
101
|
+
this.animation = undefined;
|
|
102
|
+
};
|
|
103
|
+
const dispose = () => {
|
|
104
|
+
if (disposed)
|
|
105
|
+
return;
|
|
106
|
+
disposed = true;
|
|
107
|
+
root.removeFromParent();
|
|
108
|
+
for (const option of options.values()) {
|
|
109
|
+
if (option.following)
|
|
110
|
+
this.follow?.(null);
|
|
111
|
+
option.highlight.dispose();
|
|
112
|
+
option.cursor.release();
|
|
113
|
+
option.arrows.dispose();
|
|
114
|
+
}
|
|
115
|
+
if (this.animation?.root === root)
|
|
116
|
+
this.animation = undefined;
|
|
117
|
+
for (const mesh of meshes) {
|
|
118
|
+
mesh.geometry.dispose();
|
|
119
|
+
mesh.material.dispose();
|
|
120
|
+
}
|
|
121
|
+
for (const marker of markers) {
|
|
122
|
+
marker.geometry.dispose();
|
|
123
|
+
marker.material.dispose();
|
|
124
|
+
}
|
|
125
|
+
root.clear();
|
|
126
|
+
this.sets.delete(set);
|
|
127
|
+
this.invalidate();
|
|
128
|
+
};
|
|
129
|
+
const paint = () => {
|
|
130
|
+
for (const [id, record] of options) {
|
|
131
|
+
const option = record.group;
|
|
132
|
+
record.highlight.setColor(this.highlightColor);
|
|
133
|
+
record.arrows.setColor(this.arrowColor);
|
|
134
|
+
record.cursor.setColor(this.arrowColor);
|
|
135
|
+
option.visible = !active || id === selected;
|
|
136
|
+
for (const object of option.children) {
|
|
137
|
+
if (object instanceof THREE.Points) {
|
|
138
|
+
const material = object.material;
|
|
139
|
+
material.uniforms.color.value.set(this.color);
|
|
140
|
+
material.uniforms.opacity.value =
|
|
141
|
+
id === selected ? (selectedStep && selectedStep.action !== 'arrive' ? 0.6 : 1) : 0.28;
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
const mesh = object;
|
|
145
|
+
if (mesh.userData.routeStepHighlight ||
|
|
146
|
+
mesh.userData.routeArrows ||
|
|
147
|
+
mesh.userData.routePlayback)
|
|
148
|
+
continue;
|
|
149
|
+
mesh.material.color.set(this.color);
|
|
150
|
+
mesh.material.opacity = id === selected ? 1 : 0.28;
|
|
151
|
+
mesh.material.depthWrite = id === selected;
|
|
152
|
+
mesh.renderOrder = id === selected ? 12 : 11;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
const depth = () => {
|
|
157
|
+
for (const option of options.values())
|
|
158
|
+
option.group.position.y =
|
|
159
|
+
this.floorBaseDepth === undefined ? 0 : this.floorBaseDepth - option.baseDepth;
|
|
160
|
+
};
|
|
161
|
+
const pick = (raycaster) => {
|
|
162
|
+
if (disposed || root.parent !== this.scene || !root.visible || !routeSetId)
|
|
163
|
+
return null;
|
|
164
|
+
root.updateWorldMatrix(true, true);
|
|
165
|
+
let nearest;
|
|
166
|
+
for (const hit of raycaster.intersectObjects(meshes, false)) {
|
|
167
|
+
if (!hit.object.visible || !hit.object.parent?.visible)
|
|
168
|
+
continue;
|
|
169
|
+
if (!nearest)
|
|
170
|
+
nearest = hit;
|
|
171
|
+
else if (hit.distance - nearest.distance > 0.00001)
|
|
172
|
+
break;
|
|
173
|
+
if (hit.object.userData.routeId === selected) {
|
|
174
|
+
nearest = hit;
|
|
175
|
+
break;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
return nearest
|
|
179
|
+
? {
|
|
180
|
+
selection: { routeSetId, routeId: nearest.object.userData.routeId },
|
|
181
|
+
distance: nearest.distance,
|
|
182
|
+
}
|
|
183
|
+
: null;
|
|
184
|
+
};
|
|
185
|
+
const stepFloor = () => {
|
|
186
|
+
for (const option of options.values())
|
|
187
|
+
option.highlight.setFloor(this.floor);
|
|
188
|
+
syncArrows();
|
|
189
|
+
};
|
|
190
|
+
const set = { root, floors, paint, depth, dispose, pick, stepFloor };
|
|
191
|
+
try {
|
|
192
|
+
for (const item of items) {
|
|
193
|
+
const option = new THREE.Group();
|
|
194
|
+
const arrows = new RouteArrows(option, item.artifact.centerline, item.artifact.placement);
|
|
195
|
+
const runMeshes = new Map();
|
|
196
|
+
const record = {
|
|
197
|
+
group: option,
|
|
198
|
+
baseDepth: item.artifact.source.depthConfig.floorBaseDepth,
|
|
199
|
+
anchors: new Map(),
|
|
200
|
+
runBounds: new Map(),
|
|
201
|
+
highlight: new RouteStepHighlight(option, runMeshes),
|
|
202
|
+
arrows,
|
|
203
|
+
cursor: new RouteCursor(option, arrows.motion, item.artifact.placement.width),
|
|
204
|
+
playbackOptions: {},
|
|
205
|
+
following: false,
|
|
206
|
+
autoStep: null,
|
|
207
|
+
stepsReady: item.artifact.playbackSteps !== undefined,
|
|
208
|
+
};
|
|
209
|
+
options.set(item.routeId, record);
|
|
210
|
+
root.add(option);
|
|
211
|
+
for (const [runIndex, run] of item.artifact.runs.entries()) {
|
|
212
|
+
record.arrows.addRun(run);
|
|
213
|
+
if (!run.geometry) {
|
|
214
|
+
const box = record.anchors.get(run.floorIndex) ?? new THREE.Box3();
|
|
215
|
+
const offset = run.fromPathIndex * 3, data = item.artifact.centerline;
|
|
216
|
+
const point = new THREE.Vector3(data[offset], data[offset + 1], data[offset + 2]);
|
|
217
|
+
box.expandByPoint(point);
|
|
218
|
+
record.runBounds.set(runIndex, new THREE.Box3(point.clone(), point));
|
|
219
|
+
record.anchors.set(run.floorIndex, box);
|
|
220
|
+
continue;
|
|
221
|
+
}
|
|
222
|
+
const geometry = new THREE.BufferGeometry();
|
|
223
|
+
const material = new THREE.MeshBasicMaterial({
|
|
224
|
+
transparent: true,
|
|
225
|
+
side: THREE.DoubleSide,
|
|
226
|
+
polygonOffset: true,
|
|
227
|
+
polygonOffsetFactor: -2,
|
|
228
|
+
polygonOffsetUnits: -2,
|
|
229
|
+
});
|
|
230
|
+
const mesh = new THREE.Mesh(geometry, material);
|
|
231
|
+
runMeshes.set(runIndex, { mesh, floor: run.floorIndex });
|
|
232
|
+
meshes.push(mesh);
|
|
233
|
+
geometry.setAttribute('position', new THREE.Float32BufferAttribute(run.geometry.positions, 3));
|
|
234
|
+
geometry.setAttribute('normal', new THREE.Float32BufferAttribute(run.geometry.normals, 3));
|
|
235
|
+
if (run.geometry.uvs)
|
|
236
|
+
geometry.setAttribute('uv', new THREE.Float32BufferAttribute(run.geometry.uvs, 2));
|
|
237
|
+
if (run.geometry.indices)
|
|
238
|
+
geometry.setIndex([...run.geometry.indices]);
|
|
239
|
+
// Bounds are presentation bookkeeping over received buffers, not CPU ribbon construction.
|
|
240
|
+
// Hinglish: Sirf camera/culling bounds; path naya generate nahi hota.
|
|
241
|
+
geometry.computeBoundingBox();
|
|
242
|
+
record.runBounds.set(runIndex, geometry.boundingBox.clone());
|
|
243
|
+
geometry.computeBoundingSphere();
|
|
244
|
+
mesh.visible = run.floorIndex === this.floor;
|
|
245
|
+
mesh.userData.routeId = item.routeId;
|
|
246
|
+
floors.set(mesh, run.floorIndex);
|
|
247
|
+
option.add(mesh);
|
|
248
|
+
}
|
|
249
|
+
record.arrows.motion.setJourney(item.artifact.playbackJourney);
|
|
250
|
+
if (item.artifact.playbackSteps)
|
|
251
|
+
record.arrows.motion.setSteps(item.artifact.playbackSteps, (step) => record.highlight.validate(step));
|
|
252
|
+
for (const [floor, marker] of createRouteMarkers(item)) {
|
|
253
|
+
markers.push(marker);
|
|
254
|
+
floors.set(marker, floor);
|
|
255
|
+
marker.visible = floor === this.floor;
|
|
256
|
+
option.add(marker);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
this.sets.add(set);
|
|
260
|
+
depth();
|
|
261
|
+
stepFloor();
|
|
262
|
+
const worldPosition = new THREE.Vector3(), worldForward = new THREE.Vector3();
|
|
263
|
+
return {
|
|
264
|
+
hasPlaybackSteps: (id) => !!options.get(id)?.stepsReady,
|
|
265
|
+
setPlaybackSteps: (id, value) => {
|
|
266
|
+
const record = options.get(id);
|
|
267
|
+
if (disposed || !record)
|
|
268
|
+
throw new ViewerCommandError('Route retired.', { code: 'CANCELLED' });
|
|
269
|
+
record.arrows.motion.setSteps(value.playbackSteps, (step) => record.highlight.validate(step));
|
|
270
|
+
record.stepsReady = true;
|
|
271
|
+
},
|
|
272
|
+
playback: (id) => {
|
|
273
|
+
const record = options.get(id);
|
|
274
|
+
const available = () => {
|
|
275
|
+
if (disposed || !record || !active || selected !== id)
|
|
276
|
+
throw new ViewerCommandError('Route playback unavailable.', { code: 'UNAVAILABLE' });
|
|
277
|
+
};
|
|
278
|
+
available();
|
|
279
|
+
return {
|
|
280
|
+
options: (options, running) => {
|
|
281
|
+
if (options.stepSync !== 'highlight' && record.autoStep) {
|
|
282
|
+
record.highlight.show(selectedStep);
|
|
283
|
+
record.autoStep = null;
|
|
284
|
+
}
|
|
285
|
+
record.playbackOptions = options;
|
|
286
|
+
record.following = running && options.cameraFollow === 'follow';
|
|
287
|
+
if (!record.following)
|
|
288
|
+
this.follow?.(null);
|
|
289
|
+
},
|
|
290
|
+
activeStep: (scope, distance) => {
|
|
291
|
+
const step = record.arrows.motion.step(scope, distance);
|
|
292
|
+
return step ? { stepIndex: step.stepIndex, stepId: step.stepId } : null;
|
|
293
|
+
},
|
|
294
|
+
scope: (mode, bound) => {
|
|
295
|
+
available();
|
|
296
|
+
return record.arrows.motion.scope(mode, this.floor, bound);
|
|
297
|
+
},
|
|
298
|
+
next: (scope) => record.arrows.motion.next(scope),
|
|
299
|
+
bind: (driver) => {
|
|
300
|
+
// Detaching an already retired resource is cleanup, not a new playback operation.
|
|
301
|
+
// Hinglish: Engine/resource pehle dispose ho gaya ho tab bhi cleanup safe no-op rahe.
|
|
302
|
+
if (disposed && !driver)
|
|
303
|
+
return;
|
|
304
|
+
available();
|
|
305
|
+
record.playback = driver ?? undefined;
|
|
306
|
+
syncArrows();
|
|
307
|
+
this.invalidate();
|
|
308
|
+
},
|
|
309
|
+
position: (scope, distance, delta = 0) => {
|
|
310
|
+
available();
|
|
311
|
+
record.cursor.position(scope, distance);
|
|
312
|
+
const object = record.cursor.object;
|
|
313
|
+
if (!object)
|
|
314
|
+
return;
|
|
315
|
+
if (record.playbackOptions.stepSync === 'highlight') {
|
|
316
|
+
const step = record.arrows.motion.step(scope, distance);
|
|
317
|
+
if ((step?.stepId ?? null) !== record.autoStep) {
|
|
318
|
+
record.highlight.show(step);
|
|
319
|
+
if (disposed || !record.cursor.object)
|
|
320
|
+
return;
|
|
321
|
+
record.autoStep = step?.stepId ?? null;
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
if (record.following && object) {
|
|
325
|
+
record.group.updateWorldMatrix(true, false);
|
|
326
|
+
worldPosition.copy(object.position).applyMatrix4(record.group.matrixWorld);
|
|
327
|
+
worldForward
|
|
328
|
+
.set(Math.sin(object.rotation.y), 0, Math.cos(object.rotation.y))
|
|
329
|
+
.transformDirection(record.group.matrixWorld);
|
|
330
|
+
this.follow?.(worldPosition, worldForward, delta);
|
|
331
|
+
}
|
|
332
|
+
},
|
|
333
|
+
release: () => {
|
|
334
|
+
if (record?.autoStep) {
|
|
335
|
+
record.highlight.show(null);
|
|
336
|
+
record.autoStep = null;
|
|
337
|
+
}
|
|
338
|
+
record?.cursor.release();
|
|
339
|
+
this.follow?.(null);
|
|
340
|
+
this.invalidate();
|
|
341
|
+
},
|
|
342
|
+
};
|
|
343
|
+
},
|
|
344
|
+
show: (id, guiding) => {
|
|
345
|
+
if (disposed || !options.has(id))
|
|
346
|
+
throw new Error('Route resources unavailable');
|
|
347
|
+
selected = id;
|
|
348
|
+
active = guiding;
|
|
349
|
+
paint();
|
|
350
|
+
this.scene.add(root);
|
|
351
|
+
syncArrows();
|
|
352
|
+
this.invalidate();
|
|
353
|
+
},
|
|
354
|
+
bounds: (id, floor) => {
|
|
355
|
+
const bounds = new THREE.Box3();
|
|
356
|
+
this.scene.updateWorldMatrix(true, false);
|
|
357
|
+
root.updateWorldMatrix(true, true);
|
|
358
|
+
const world = (matrix) => root.parent
|
|
359
|
+
? matrix
|
|
360
|
+
: new THREE.Matrix4().multiplyMatrices(this.scene.matrixWorld, matrix);
|
|
361
|
+
for (const [optionId, { group: option, anchors }] of options) {
|
|
362
|
+
if (id !== null && id !== optionId)
|
|
363
|
+
continue;
|
|
364
|
+
for (const mesh of option.children)
|
|
365
|
+
if (floors.get(mesh) === floor && mesh.geometry.boundingBox) {
|
|
366
|
+
bounds.union(mesh.geometry.boundingBox.clone().applyMatrix4(world(mesh.matrixWorld)));
|
|
367
|
+
}
|
|
368
|
+
// Empty/one-point runs still have a ready anchor; use it without inventing a line.
|
|
369
|
+
// Hinglish: Zero-length run ka existing anchor frame ho; fake ribbon/diagonal na banayein.
|
|
370
|
+
const anchor = anchors.get(floor);
|
|
371
|
+
if (anchor)
|
|
372
|
+
bounds.union(anchor.clone().applyMatrix4(world(option.matrixWorld)));
|
|
373
|
+
}
|
|
374
|
+
return bounds;
|
|
375
|
+
},
|
|
376
|
+
// Cache each accepted visit during upload; repeated floor visits never share a completion frame.
|
|
377
|
+
// Hinglish: Current-floor finish par O(1) exact run bounds; NodePoints/geometry ka extra loop nahi.
|
|
378
|
+
runBounds: (id, runIndex) => {
|
|
379
|
+
const record = options.get(id), bounds = record?.runBounds.get(runIndex);
|
|
380
|
+
if (disposed || !record || !bounds)
|
|
381
|
+
return new THREE.Box3();
|
|
382
|
+
this.scene.updateWorldMatrix(true, false);
|
|
383
|
+
record.group.updateWorldMatrix(true, false);
|
|
384
|
+
const matrix = root.parent
|
|
385
|
+
? record.group.matrixWorld
|
|
386
|
+
: new THREE.Matrix4().multiplyMatrices(this.scene.matrixWorld, record.group.matrixWorld);
|
|
387
|
+
return bounds.clone().applyMatrix4(matrix);
|
|
388
|
+
},
|
|
389
|
+
highlightStep: (id, step) => {
|
|
390
|
+
const option = options.get(id);
|
|
391
|
+
if (disposed || !option || id !== selected)
|
|
392
|
+
throw new Error('Route resources unavailable');
|
|
393
|
+
option.autoStep = null;
|
|
394
|
+
option.highlight.show(step);
|
|
395
|
+
selectedStep = step;
|
|
396
|
+
paint();
|
|
397
|
+
this.invalidate();
|
|
398
|
+
},
|
|
399
|
+
stepDirection: (id, step) => {
|
|
400
|
+
const option = options.get(id);
|
|
401
|
+
if (disposed || !option || !step.focusDirection)
|
|
402
|
+
return undefined;
|
|
403
|
+
// Update only the option/ancestor matrices, not all route meshes; bounds and heading share the space.
|
|
404
|
+
// Hinglish: Direction akela padhein tab bhi rotation sahi ho; mesh children ka extra traversal nahi.
|
|
405
|
+
this.scene.updateWorldMatrix(true, false);
|
|
406
|
+
option.group.updateWorldMatrix(true, false);
|
|
407
|
+
const matrix = root.parent
|
|
408
|
+
? option.group.matrixWorld
|
|
409
|
+
: new THREE.Matrix4().multiplyMatrices(this.scene.matrixWorld, option.group.matrixWorld);
|
|
410
|
+
return new THREE.Vector3(...step.focusDirection).transformDirection(matrix);
|
|
411
|
+
},
|
|
412
|
+
stepBounds: (id, step) => {
|
|
413
|
+
const option = options.get(id), focus = step.focusBounds;
|
|
414
|
+
if (disposed || !option || !focus)
|
|
415
|
+
return new THREE.Box3();
|
|
416
|
+
this.scene.updateWorldMatrix(true, false);
|
|
417
|
+
root.updateWorldMatrix(true, true);
|
|
418
|
+
const matrix = root.parent
|
|
419
|
+
? option.group.matrixWorld
|
|
420
|
+
: new THREE.Matrix4().multiplyMatrices(this.scene.matrixWorld, option.group.matrixWorld);
|
|
421
|
+
return new THREE.Box3(new THREE.Vector3(...focus.min), new THREE.Vector3(...focus.max)).applyMatrix4(matrix);
|
|
422
|
+
},
|
|
423
|
+
dispose,
|
|
424
|
+
setPathAnimation: (mode) => {
|
|
425
|
+
if (disposed)
|
|
426
|
+
throw new Error('Route resources unavailable');
|
|
427
|
+
if (mode === 'moving-arrows')
|
|
428
|
+
for (const record of options.values())
|
|
429
|
+
record.arrows.assertSupported();
|
|
430
|
+
animationMode = mode;
|
|
431
|
+
syncArrows();
|
|
432
|
+
this.invalidate();
|
|
433
|
+
},
|
|
434
|
+
};
|
|
435
|
+
}
|
|
436
|
+
catch (error) {
|
|
437
|
+
dispose();
|
|
438
|
+
throw error;
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
dispose() {
|
|
442
|
+
for (const set of [...this.sets])
|
|
443
|
+
set.dispose();
|
|
444
|
+
}
|
|
445
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import * as THREE from 'three';
|
|
2
|
+
import type { RouteInstruction } from '@wovvmap/contracts';
|
|
3
|
+
/** Reuse uploaded attributes and change draw ranges only; no vertex recoloring or path reconstruction.
|
|
4
|
+
* Hinglish: Sirf selected ready segment ka overlay ho; har click par buffers ya full-floor scan nahi. */
|
|
5
|
+
export declare class RouteStepHighlight {
|
|
6
|
+
private readonly group;
|
|
7
|
+
private readonly runs;
|
|
8
|
+
private readonly overlays;
|
|
9
|
+
private step;
|
|
10
|
+
private floor;
|
|
11
|
+
private color;
|
|
12
|
+
constructor(group: THREE.Group, runs: Map<number, {
|
|
13
|
+
mesh: THREE.Mesh;
|
|
14
|
+
floor: number;
|
|
15
|
+
}>);
|
|
16
|
+
validate(step: Pick<RouteInstruction, 'floorIndex' | 'geometryRanges'> | null): void;
|
|
17
|
+
show(step: Pick<RouteInstruction, 'floorIndex' | 'geometryRanges'> | null): void;
|
|
18
|
+
setFloor(floor: number): void;
|
|
19
|
+
setColor(color: string): void;
|
|
20
|
+
dispose(): void;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=RouteStepHighlight.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RouteStepHighlight.d.ts","sourceRoot":"","sources":["../../../src/services/routes/RouteStepHighlight.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAE1D;yGACyG;AACzG,qBAAa,kBAAkB;IAM3B,OAAO,CAAC,QAAQ,CAAC,KAAK;IACtB,OAAO,CAAC,QAAQ,CAAC,IAAI;IANvB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAkE;IAC3F,OAAO,CAAC,IAAI,CAAuE;IACnF,OAAO,CAAC,KAAK,CAAI;IACjB,OAAO,CAAC,KAAK,CAAY;gBAEN,KAAK,EAAE,KAAK,CAAC,KAAK,EAClB,IAAI,EAAE,GAAG,CAAC,MAAM,EAAE;QAAE,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IAEzE,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,gBAAgB,EAAE,YAAY,GAAG,gBAAgB,CAAC,GAAG,IAAI,GAAG,IAAI;IAoBpF,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,gBAAgB,EAAE,YAAY,GAAG,gBAAgB,CAAC,GAAG,IAAI,GAAG,IAAI;IAqChF,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAO7B,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAI7B,OAAO,IAAI,IAAI;CAQhB"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import * as THREE from 'three';
|
|
2
|
+
/** Reuse uploaded attributes and change draw ranges only; no vertex recoloring or path reconstruction.
|
|
3
|
+
* Hinglish: Sirf selected ready segment ka overlay ho; har click par buffers ya full-floor scan nahi. */
|
|
4
|
+
export class RouteStepHighlight {
|
|
5
|
+
group;
|
|
6
|
+
runs;
|
|
7
|
+
overlays = [];
|
|
8
|
+
step = null;
|
|
9
|
+
floor = 0;
|
|
10
|
+
color = '#f5b942';
|
|
11
|
+
constructor(group, runs) {
|
|
12
|
+
this.group = group;
|
|
13
|
+
this.runs = runs;
|
|
14
|
+
}
|
|
15
|
+
validate(step) {
|
|
16
|
+
// Validate before replacing the previous highlight; a bad range cannot partially paint another run.
|
|
17
|
+
// Hinglish: Repeated floor ka alag run hai; floor number dekh kar dono visits ko join nahi karna.
|
|
18
|
+
for (const range of step?.geometryRanges ?? []) {
|
|
19
|
+
const run = this.runs.get(range.runIndex), geometry = run?.mesh.geometry;
|
|
20
|
+
if (!run ||
|
|
21
|
+
run.floor !== step.floorIndex ||
|
|
22
|
+
!geometry ||
|
|
23
|
+
range.vertexStart < 0 ||
|
|
24
|
+
range.vertexCount < 0 ||
|
|
25
|
+
range.vertexStart + range.vertexCount > geometry.getAttribute('position').count ||
|
|
26
|
+
range.indexStart < 0 ||
|
|
27
|
+
range.indexCount < 0 ||
|
|
28
|
+
(geometry.index && range.indexStart + range.indexCount > geometry.index.count))
|
|
29
|
+
throw new Error('Invalid step geometry range');
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
show(step) {
|
|
33
|
+
this.validate(step);
|
|
34
|
+
this.step = step;
|
|
35
|
+
for (const overlay of this.overlays)
|
|
36
|
+
overlay.visible = false;
|
|
37
|
+
for (const [index, range] of (step?.geometryRanges ?? []).entries()) {
|
|
38
|
+
const base = this.runs.get(range.runIndex).mesh.geometry;
|
|
39
|
+
let overlay = this.overlays[index];
|
|
40
|
+
if (!overlay) {
|
|
41
|
+
overlay = new THREE.Mesh(new THREE.BufferGeometry(), new THREE.MeshBasicMaterial({
|
|
42
|
+
color: this.color,
|
|
43
|
+
side: THREE.DoubleSide,
|
|
44
|
+
polygonOffset: true,
|
|
45
|
+
polygonOffsetFactor: -3,
|
|
46
|
+
polygonOffsetUnits: -3,
|
|
47
|
+
}));
|
|
48
|
+
overlay.renderOrder = 14;
|
|
49
|
+
overlay.userData.routeStepHighlight = true;
|
|
50
|
+
overlay.raycast = () => { };
|
|
51
|
+
this.overlays.push(overlay);
|
|
52
|
+
this.group.add(overlay);
|
|
53
|
+
if (this.overlays[index] !== overlay)
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
for (const [name, attribute] of Object.entries(base.attributes))
|
|
57
|
+
overlay.geometry.setAttribute(name, attribute);
|
|
58
|
+
overlay.geometry.setIndex(base.index);
|
|
59
|
+
overlay.geometry.setDrawRange(base.index ? range.indexStart : range.vertexStart, base.index ? range.indexCount : range.vertexCount);
|
|
60
|
+
overlay.geometry.boundingBox = base.boundingBox;
|
|
61
|
+
overlay.geometry.boundingSphere = base.boundingSphere;
|
|
62
|
+
overlay.visible = step.floorIndex === this.floor;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
setFloor(floor) {
|
|
66
|
+
this.floor = floor;
|
|
67
|
+
this.overlays.forEach((overlay, index) => {
|
|
68
|
+
overlay.visible =
|
|
69
|
+
!!this.step && index < this.step.geometryRanges.length && this.step.floorIndex === floor;
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
setColor(color) {
|
|
73
|
+
this.color = color;
|
|
74
|
+
this.overlays.forEach((overlay) => overlay.material.color.set(color));
|
|
75
|
+
}
|
|
76
|
+
dispose() {
|
|
77
|
+
this.step = null;
|
|
78
|
+
for (const overlay of this.overlays.splice(0)) {
|
|
79
|
+
overlay.removeFromParent();
|
|
80
|
+
overlay.geometry.dispose();
|
|
81
|
+
overlay.material.dispose();
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import * as THREE from 'three';
|
|
2
|
+
import type { RouteGeometryResponse } from '@wovvmap/contracts';
|
|
3
|
+
/** Batch the server's ready marker anchors by floor; no endpoint resolution or path construction.
|
|
4
|
+
* Hinglish: Sirf received anchors upload hon; node scan, height/scale repeat ya connector guessing nahi. */
|
|
5
|
+
export declare function createRouteMarkers(item: RouteGeometryResponse): Map<number, THREE.Points<THREE.BufferGeometry, THREE.ShaderMaterial>>;
|
|
6
|
+
//# sourceMappingURL=routeMarkers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"routeMarkers.d.ts","sourceRoot":"","sources":["../../../src/services/routes/routeMarkers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAA;AAE/D;4GAC4G;AAC5G,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,qBAAqB,GAC1B,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,cAAc,EAAE,KAAK,CAAC,cAAc,CAAC,CAAC,CA0CvE"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import * as THREE from 'three';
|
|
2
|
+
/** Batch the server's ready marker anchors by floor; no endpoint resolution or path construction.
|
|
3
|
+
* Hinglish: Sirf received anchors upload hon; node scan, height/scale repeat ya connector guessing nahi. */
|
|
4
|
+
export function createRouteMarkers(item) {
|
|
5
|
+
const floors = new Map();
|
|
6
|
+
for (const marker of item.artifact.markers) {
|
|
7
|
+
const positions = floors.get(marker.floorIndex) ?? [];
|
|
8
|
+
const offset = marker.pathIndex * 3;
|
|
9
|
+
positions.push(item.artifact.centerline[offset], item.artifact.centerline[offset + 1], item.artifact.centerline[offset + 2]);
|
|
10
|
+
floors.set(marker.floorIndex, positions);
|
|
11
|
+
}
|
|
12
|
+
const result = new Map();
|
|
13
|
+
try {
|
|
14
|
+
for (const [floor, positions] of floors) {
|
|
15
|
+
const geometry = new THREE.BufferGeometry();
|
|
16
|
+
const material = new THREE.ShaderMaterial({
|
|
17
|
+
transparent: true,
|
|
18
|
+
depthTest: false,
|
|
19
|
+
depthWrite: false,
|
|
20
|
+
uniforms: { color: { value: new THREE.Color() }, opacity: { value: 1 } },
|
|
21
|
+
vertexShader: 'void main(){ gl_Position=projectionMatrix*modelViewMatrix*vec4(position,1.0); gl_PointSize=18.0; }',
|
|
22
|
+
fragmentShader: 'uniform vec3 color; uniform float opacity; void main(){ float r=length(gl_PointCoord-vec2(0.5)); if(r>0.5)discard; gl_FragColor=vec4(r>0.36?vec3(1.0):color,opacity);\n#include <colorspace_fragment>\n}',
|
|
23
|
+
});
|
|
24
|
+
const points = new THREE.Points(geometry, material);
|
|
25
|
+
result.set(floor, points);
|
|
26
|
+
geometry.setAttribute('position', new THREE.Float32BufferAttribute(positions, 3));
|
|
27
|
+
geometry.computeBoundingBox();
|
|
28
|
+
geometry.computeBoundingSphere();
|
|
29
|
+
points.userData.routeId = item.routeId;
|
|
30
|
+
points.renderOrder = 14;
|
|
31
|
+
}
|
|
32
|
+
return result;
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
for (const points of result.values()) {
|
|
36
|
+
points.geometry.dispose();
|
|
37
|
+
points.material.dispose();
|
|
38
|
+
}
|
|
39
|
+
throw error;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** Resolved renderer paint, shared by shape/text/sprite owners; never semantic endpoint state.
|
|
2
|
+
* Hinglish: Ek resolved rang-map sab features ko mile; endpoint ka naya writable store nahi. */
|
|
3
|
+
export interface SelectionPaint {
|
|
4
|
+
readonly color: string;
|
|
5
|
+
readonly text2D: string;
|
|
6
|
+
readonly text3D: string;
|
|
7
|
+
}
|
|
8
|
+
export type SelectionPaintMap = ReadonlyMap<string, SelectionPaint>;
|
|
9
|
+
/** Legacy uniform-key calls use the same per-key projection as endpoint roles.
|
|
10
|
+
* Hinglish: Purana same-color API bhi wahi per-key paint use kare; alag implementation nahi. */
|
|
11
|
+
export declare function uniformSelectionPaint(keys: readonly string[], style: SelectionPaint): SelectionPaintMap;
|
|
12
|
+
//# sourceMappingURL=selectionPaint.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"selectionPaint.d.ts","sourceRoot":"","sources":["../../src/services/selectionPaint.ts"],"names":[],"mappings":"AAAA;gGACgG;AAChG,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CACxB;AACD,MAAM,MAAM,iBAAiB,GAAG,WAAW,CAAC,MAAM,EAAE,cAAc,CAAC,CAAA;AAEnE;gGACgG;AAChG,wBAAgB,qBAAqB,CACnC,IAAI,EAAE,SAAS,MAAM,EAAE,EACvB,KAAK,EAAE,cAAc,GACpB,iBAAiB,CAInB"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** Legacy uniform-key calls use the same per-key projection as endpoint roles.
|
|
2
|
+
* Hinglish: Purana same-color API bhi wahi per-key paint use kare; alag implementation nahi. */
|
|
3
|
+
export function uniformSelectionPaint(keys, style) {
|
|
4
|
+
const paint = new Map();
|
|
5
|
+
for (const key of keys)
|
|
6
|
+
paint.set(key, style);
|
|
7
|
+
return paint;
|
|
8
|
+
}
|