@ifc-lite/spatial 1.14.4 → 1.14.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.
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @ifc-lite/spatial
|
|
2
2
|
|
|
3
|
-
Spatial indexing for IFClite. Builds BVH (Bounding Volume Hierarchy)
|
|
3
|
+
Spatial indexing for IFClite. Builds a BVH (Bounding Volume Hierarchy) over your meshes and serves three query primitives: AABB intersection, raycast, and frustum culling.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -8,24 +8,69 @@ Spatial indexing for IFClite. Builds BVH (Bounding Volume Hierarchy) structures
|
|
|
8
8
|
npm install @ifc-lite/spatial
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
##
|
|
11
|
+
## Build an index
|
|
12
12
|
|
|
13
13
|
```typescript
|
|
14
14
|
import { buildSpatialIndex } from '@ifc-lite/spatial';
|
|
15
15
|
|
|
16
|
-
const index = buildSpatialIndex(
|
|
17
|
-
|
|
16
|
+
const index = buildSpatialIndex(meshes); // MeshData[] from @ifc-lite/geometry
|
|
17
|
+
|
|
18
|
+
// For very large models (50K+ meshes), build off the main thread:
|
|
19
|
+
import { buildSpatialIndexAsync } from '@ifc-lite/spatial';
|
|
20
|
+
const indexAsync = await buildSpatialIndexAsync(meshes);
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Raycast (entity picking)
|
|
24
|
+
|
|
25
|
+
```typescript
|
|
26
|
+
const origin: [number, number, number] = [0, 5, 10];
|
|
27
|
+
const direction: [number, number, number] = [0, -1, 0];
|
|
28
|
+
|
|
29
|
+
const hits = index.raycast(origin, direction);
|
|
30
|
+
// → expressIds of meshes the ray intersects, in hit order
|
|
31
|
+
|
|
32
|
+
if (hits.length > 0) {
|
|
33
|
+
console.log(`First hit: expressId ${hits[0]}`);
|
|
34
|
+
}
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## AABB query (region select)
|
|
38
|
+
|
|
39
|
+
```typescript
|
|
40
|
+
const region = {
|
|
41
|
+
min: [-5, 0, -5],
|
|
42
|
+
max: [5, 3, 5],
|
|
43
|
+
} as const;
|
|
44
|
+
|
|
45
|
+
const hits = index.queryAABB(region);
|
|
46
|
+
// → expressIds of every mesh whose bounds intersect the box
|
|
47
|
+
|
|
48
|
+
console.log(`${hits.length} entities in region`);
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Frustum culling
|
|
52
|
+
|
|
53
|
+
```typescript
|
|
54
|
+
import { FrustumUtils } from '@ifc-lite/spatial';
|
|
55
|
+
|
|
56
|
+
// Build a frustum from a view-projection matrix (column-major 4×4)
|
|
57
|
+
const frustum = FrustumUtils.fromMatrix(viewProjMatrix);
|
|
58
|
+
|
|
59
|
+
const visible = index.queryFrustum(frustum);
|
|
60
|
+
// → expressIds visible to the camera; renderer only draws these
|
|
18
61
|
```
|
|
19
62
|
|
|
20
|
-
##
|
|
63
|
+
## When to use this
|
|
64
|
+
|
|
65
|
+
The renderer (`@ifc-lite/renderer`) ships its own GPU-side picking and culling — for typical use you don't need this package directly. Reach for `@ifc-lite/spatial` when you're:
|
|
21
66
|
|
|
22
|
-
-
|
|
23
|
-
-
|
|
24
|
-
-
|
|
67
|
+
- Building a custom renderer (Three.js, Babylon.js, custom WebGPU)
|
|
68
|
+
- Running CPU-side raycasts for measurements / snapping / hit-tests outside the GPU pipeline
|
|
69
|
+
- Doing offline analysis (e.g. server-side intersection tests)
|
|
25
70
|
|
|
26
71
|
## API
|
|
27
72
|
|
|
28
|
-
See the [API Reference](
|
|
73
|
+
See the [API Reference](https://ltplus-ag.github.io/ifc-lite/api/typescript/#ifc-litespatial).
|
|
29
74
|
|
|
30
75
|
## License
|
|
31
76
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"spatial-index-builder.d.ts","sourceRoot":"","sources":["../src/spatial-index-builder.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,GAAG,EAAuB,MAAM,UAAU,CAAC;AAEpD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"spatial-index-builder.d.ts","sourceRoot":"","sources":["../src/spatial-index-builder.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,GAAG,EAAuB,MAAM,UAAU,CAAC;AAEpD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAgBnD;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,QAAQ,EAAE,GAAG,GAAG,CAUzD;AAED;;;;;;;;GAQG;AACH,wBAAsB,sBAAsB,CAC1C,MAAM,EAAE,QAAQ,EAAE,EAClB,QAAQ,GAAE,MAAU,GACnB,OAAO,CAAC,GAAG,CAAC,CAsBd"}
|
|
@@ -5,6 +5,17 @@
|
|
|
5
5
|
* Spatial index builder - builds BVH from geometry results
|
|
6
6
|
*/
|
|
7
7
|
import { BVH } from './bvh.js';
|
|
8
|
+
function yieldToEventLoop() {
|
|
9
|
+
const maybeScheduler = globalThis.scheduler;
|
|
10
|
+
if (typeof maybeScheduler?.yield === 'function') {
|
|
11
|
+
return maybeScheduler.yield();
|
|
12
|
+
}
|
|
13
|
+
return new Promise((resolve) => {
|
|
14
|
+
const channel = new MessageChannel();
|
|
15
|
+
channel.port1.onmessage = () => resolve();
|
|
16
|
+
channel.port2.postMessage(null);
|
|
17
|
+
});
|
|
18
|
+
}
|
|
8
19
|
/**
|
|
9
20
|
* Build BVH spatial index from geometry meshes
|
|
10
21
|
*/
|
|
@@ -40,8 +51,7 @@ export async function buildSpatialIndexAsync(meshes, budgetMs = 4) {
|
|
|
40
51
|
};
|
|
41
52
|
i++;
|
|
42
53
|
if (i % 500 === 0 && performance.now() - chunkStart >= budgetMs) {
|
|
43
|
-
|
|
44
|
-
await new Promise(r => setTimeout(r, 0));
|
|
54
|
+
await yieldToEventLoop();
|
|
45
55
|
break;
|
|
46
56
|
}
|
|
47
57
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"spatial-index-builder.js","sourceRoot":"","sources":["../src/spatial-index-builder.ts"],"names":[],"mappings":"AAAA;;+DAE+D;AAE/D;;GAEG;AAEH,OAAO,EAAE,GAAG,EAAuB,MAAM,UAAU,CAAC;AAIpD;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAAC,MAAkB;IAClD,MAAM,gBAAgB,GAAqB,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE;QAC3D,MAAM,MAAM,GAAG,iBAAiB,CAAC,IAAI,CAAC,CAAC;QACvC,OAAO;YACL,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,MAAM;SACP,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,OAAO,GAAG,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC;AACrC,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAC1C,MAAkB,EAClB,WAAmB,CAAC;IAEpB,MAAM,gBAAgB,GAAqB,IAAI,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAEpE,gDAAgD;IAChD,IAAI,CAAC,GAAG,CAAC,CAAC;IACV,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC;QACzB,MAAM,UAAU,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC;QACrC,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC;YACzB,gBAAgB,CAAC,CAAC,CAAC,GAAG;gBACpB,SAAS,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS;gBAC9B,MAAM,EAAE,iBAAiB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;aACrC,CAAC;YACF,CAAC,EAAE,CAAC;YACJ,IAAI,CAAC,GAAG,GAAG,KAAK,CAAC,IAAI,WAAW,CAAC,GAAG,EAAE,GA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AAS,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;QAC7C,MAAM,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC;QACvB,MAAM,CAAC,GAAG,SAAS,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;QAC3B,MAAM,CAAC,GAAG,SAAS,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;QAE3B,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;QACzB,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;QACzB,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;QACzB,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;QACzB,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;QACzB,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;IAC3B,CAAC;IAED,OAAO;QACL,GAAG,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC;QACvB,GAAG,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC;KACxB,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ifc-lite/spatial",
|
|
3
|
-
"version": "1.14.
|
|
3
|
+
"version": "1.14.6",
|
|
4
4
|
"description": "Spatial indexing for IFC-Lite",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -12,20 +12,20 @@
|
|
|
12
12
|
}
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@ifc-lite/geometry": "^
|
|
15
|
+
"@ifc-lite/geometry": "^2.0.0"
|
|
16
16
|
},
|
|
17
17
|
"devDependencies": {
|
|
18
|
-
"typescript": "^
|
|
18
|
+
"typescript": "^6.0.3"
|
|
19
19
|
},
|
|
20
20
|
"license": "MPL-2.0",
|
|
21
21
|
"author": "Louis True",
|
|
22
22
|
"repository": {
|
|
23
23
|
"type": "git",
|
|
24
|
-
"url": "https://github.com/
|
|
24
|
+
"url": "https://github.com/LTplus-AG/ifc-lite.git",
|
|
25
25
|
"directory": "packages/spatial"
|
|
26
26
|
},
|
|
27
|
-
"homepage": "https://
|
|
28
|
-
"bugs": "https://github.com/
|
|
27
|
+
"homepage": "https://ltplus-ag.github.io/ifc-lite/",
|
|
28
|
+
"bugs": "https://github.com/LTplus-AG/ifc-lite/issues",
|
|
29
29
|
"keywords": [
|
|
30
30
|
"ifc",
|
|
31
31
|
"bim",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"README.md"
|
|
42
42
|
],
|
|
43
43
|
"scripts": {
|
|
44
|
-
"build": "tsc",
|
|
45
|
-
"dev": "tsc --watch"
|
|
44
|
+
"build": "pnpm exec tsc",
|
|
45
|
+
"dev": "pnpm exec tsc --watch"
|
|
46
46
|
}
|
|
47
47
|
}
|