@team-geospan/struct3d 1.0.5 → 1.0.6

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.
@@ -40,15 +40,18 @@ function SelectedInfo({ structureCollection, selectedId }) {
40
40
  const [structureIndex, elementId] = selectedId.split("-");
41
41
  const structure = structureCollection.structures[parseInt(structureIndex)];
42
42
 
43
- let unitLabel = "sq. m.";
43
+ let unitLabel = "";
44
44
  let value = 0.0;
45
45
  if (structure.edges[elementId]) {
46
46
  // use as edge
47
47
  unitLabel = "m.";
48
48
  value = structure.edges[elementId].properties.length;
49
- } else {
50
- // assume a surface
49
+ } else if (structure.surfaces[elementId]) {
50
+ // use as surface
51
+ unitLabel = "sq. m.";
51
52
  value = structure.surfaces[elementId].properties.area;
53
+ } else if (structure.points[elementId]) {
54
+ value = structure.points[elementId].label;
52
55
  }
53
56
 
54
57
  return (
package/lib/draw.js CHANGED
@@ -214,6 +214,42 @@ export function createReferences(scene, groundColor = 0x315d0a) {
214
214
  scene.add(gridHelper);
215
215
  }
216
216
 
217
+ export function createAccessories(structureCollection, baseElevation) {
218
+ const [x0, y0, minz] = getAnchor(structureCollection);
219
+ const points = structureCollection.structures[0].points;
220
+ const pois = structureCollection.structures.flatMap((structure, stIdx) => {
221
+ return Object.keys(structure.surfaces).flatMap((surfaceId) => {
222
+ const surface = structure.surfaces[surfaceId];
223
+ const poiIDs = surface.properties?.accessories || [];
224
+
225
+ return poiIDs.map((poiID) => {
226
+ const pinGeom = new THREE.SphereGeometry(0.3, 32, 32);
227
+ const poiColor = points[poiID].color;
228
+ const poiLabel = points[poiID].label;
229
+ const material = new THREE.MeshBasicMaterial({
230
+ color: poiColor,
231
+ });
232
+ const pin = new THREE.Mesh(pinGeom, material);
233
+ const point = points[poiID].coordinates;
234
+ const coords = [
235
+ point[0] - x0,
236
+ point[2] - minz + baseElevation,
237
+ y0 - point[1],
238
+ ];
239
+ pin.position.fromArray(coords);
240
+ pin.userData = {
241
+ id: `${stIdx}-${poiID}`,
242
+ layer: "accessories",
243
+ label: poiLabel,
244
+ color: poiColor,
245
+ };
246
+ return pin;
247
+ });
248
+ });
249
+ });
250
+ return pois;
251
+ }
252
+
217
253
  export function addLights(scene, center, bounds) {
218
254
  const intensity = 5000;
219
255
  const ambient = new THREE.AmbientLight(0xffffff);
package/lib/index.js CHANGED
@@ -28,6 +28,7 @@ import {
28
28
  clearScene,
29
29
  createFacets,
30
30
  createLines,
31
+ createAccessories,
31
32
  createReferences,
32
33
  } from "./draw";
33
34
 
@@ -124,6 +125,11 @@ const renderModel = (
124
125
  scene.add(line);
125
126
  });
126
127
 
128
+ const pois = createAccessories(collection, baseElevation);
129
+ pois.forEach((poi) => {
130
+ scene.add(poi);
131
+ });
132
+
127
133
  const center = new THREE.Vector3();
128
134
  boundingBox.getCenter(center);
129
135
 
@@ -251,12 +257,12 @@ export default function StructureThreeD({
251
257
  true,
252
258
  );
253
259
  const ids = intersects
254
- .map((f) => f.object.userData)
255
- .map((f) => f.id)
260
+ .map((f) => f.object.userData.id)
256
261
  // ensure the object has an ID
257
262
  .filter((id) => !!id);
258
263
  if (onClick) {
259
- onClick(ids);
264
+ // only return the closest intersected object
265
+ onClick(ids.slice(0, 1));
260
266
  }
261
267
  },
262
268
  [onClick],
@@ -267,10 +273,18 @@ export default function StructureThreeD({
267
273
  sceneRef.current.traverse((object) => {
268
274
  // ensure the object has a material set and the userData has our layer specified
269
275
  if (object.material && Boolean(object.userData?.layer)) {
270
- let color =
271
- object.userData.layer === "facets"
272
- ? facetColors[object.userData?.material || "asphalt"]
273
- : edgeColors[object.userData.kind] || "#00000000";
276
+ let color = null;
277
+ switch (object.userData.layer) {
278
+ case "accessories":
279
+ color = object.userData?.color || "#FFF";
280
+ break;
281
+ case "facets":
282
+ color = facetColors[object.userData?.material || "asphalt"];
283
+ break;
284
+ case "edges":
285
+ color = edgeColors[object.userData.kind] || "#00000000";
286
+ break;
287
+ }
274
288
  if (selectedIds.includes(object.userData?.id)) {
275
289
  color = selectionColor;
276
290
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@team-geospan/struct3d",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "description": "The 3D Viewer component for StructuresJSON models.",
5
5
  "license": "Apache-2.0",
6
6
  "author": "GEOSPAN Corp and Contributors",
@@ -37,6 +37,7 @@
37
37
  }
38
38
  },
39
39
  "dependencies": {
40
+ "@team-geospan/structuresio": "^0.0.7",
40
41
  "@turf/projection": "^6.5.0",
41
42
  "earcut": "^3.0.1",
42
43
  "react-resize-detector": "^12.0.2",
Binary file