@ifc-lite/geometry 1.0.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/LICENSE +373 -0
- package/dist/buffer-builder.d.ts +21 -0
- package/dist/buffer-builder.d.ts.map +1 -0
- package/dist/buffer-builder.js +44 -0
- package/dist/buffer-builder.js.map +1 -0
- package/dist/coordinate-handler.d.ts +91 -0
- package/dist/coordinate-handler.d.ts.map +1 -0
- package/dist/coordinate-handler.js +324 -0
- package/dist/coordinate-handler.js.map +1 -0
- package/dist/default-materials.d.ts +22 -0
- package/dist/default-materials.d.ts.map +1 -0
- package/dist/default-materials.js +113 -0
- package/dist/default-materials.js.map +1 -0
- package/dist/geometry.worker.d.ts +2 -0
- package/dist/geometry.worker.d.ts.map +1 -0
- package/dist/geometry.worker.js +118 -0
- package/dist/geometry.worker.js.map +1 -0
- package/dist/ifc-lite-bridge.d.ts +32 -0
- package/dist/ifc-lite-bridge.d.ts.map +1 -0
- package/dist/ifc-lite-bridge.js +58 -0
- package/dist/ifc-lite-bridge.js.map +1 -0
- package/dist/ifc-lite-mesh-collector.d.ts +28 -0
- package/dist/ifc-lite-mesh-collector.d.ts.map +1 -0
- package/dist/ifc-lite-mesh-collector.js +131 -0
- package/dist/ifc-lite-mesh-collector.js.map +1 -0
- package/dist/index.d.ts +72 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +172 -0
- package/dist/index.js.map +1 -0
- package/dist/lod.d.ts +60 -0
- package/dist/lod.d.ts.map +1 -0
- package/dist/lod.js +113 -0
- package/dist/lod.js.map +1 -0
- package/dist/progressive-loader.d.ts +48 -0
- package/dist/progressive-loader.d.ts.map +1 -0
- package/dist/progressive-loader.js +143 -0
- package/dist/progressive-loader.js.map +1 -0
- package/dist/style-cache.d.ts +36 -0
- package/dist/style-cache.d.ts.map +1 -0
- package/dist/style-cache.js +127 -0
- package/dist/style-cache.js.map +1 -0
- package/dist/types.d.ts +32 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +5 -0
- package/dist/types.js.map +1 -0
- package/dist/worker-pool.d.ts +56 -0
- package/dist/worker-pool.d.ts.map +1 -0
- package/dist/worker-pool.js +160 -0
- package/dist/worker-pool.js.map +1 -0
- package/package.json +47 -0
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
2
|
+
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
3
|
+
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
|
4
|
+
/**
|
|
5
|
+
* IFC-Lite bridge - initializes and manages IFC-Lite WASM for geometry processing
|
|
6
|
+
* Replaces web-ifc-bridge.ts with native IFC-Lite implementation (1.9x faster)
|
|
7
|
+
*/
|
|
8
|
+
import init, { IfcAPI } from '@ifc-lite/wasm';
|
|
9
|
+
export class IfcLiteBridge {
|
|
10
|
+
ifcApi = null;
|
|
11
|
+
initialized = false;
|
|
12
|
+
/**
|
|
13
|
+
* Initialize IFC-Lite WASM
|
|
14
|
+
*/
|
|
15
|
+
async init(wasmPath = '/') {
|
|
16
|
+
if (this.initialized)
|
|
17
|
+
return;
|
|
18
|
+
// Initialize WASM module
|
|
19
|
+
const wasmUrl = wasmPath.endsWith('/')
|
|
20
|
+
? `${wasmPath}ifc_lite_wasm_bg.wasm`
|
|
21
|
+
: `${wasmPath}/ifc_lite_wasm_bg.wasm`;
|
|
22
|
+
await init(wasmUrl);
|
|
23
|
+
this.ifcApi = new IfcAPI();
|
|
24
|
+
this.initialized = true;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Parse IFC content and return mesh collection
|
|
28
|
+
* Returns individual meshes with express IDs and colors
|
|
29
|
+
*/
|
|
30
|
+
parseMeshes(content) {
|
|
31
|
+
if (!this.ifcApi) {
|
|
32
|
+
throw new Error('IFC-Lite not initialized. Call init() first.');
|
|
33
|
+
}
|
|
34
|
+
return this.ifcApi.parseMeshes(content);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Get IFC-Lite API instance
|
|
38
|
+
*/
|
|
39
|
+
getApi() {
|
|
40
|
+
if (!this.ifcApi) {
|
|
41
|
+
throw new Error('IFC-Lite not initialized. Call init() first.');
|
|
42
|
+
}
|
|
43
|
+
return this.ifcApi;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Check if initialized
|
|
47
|
+
*/
|
|
48
|
+
isInitialized() {
|
|
49
|
+
return this.initialized;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Get version
|
|
53
|
+
*/
|
|
54
|
+
getVersion() {
|
|
55
|
+
return this.ifcApi?.version ?? 'unknown';
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=ifc-lite-bridge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ifc-lite-bridge.js","sourceRoot":"","sources":["../src/ifc-lite-bridge.ts"],"names":[],"mappings":"AAAA;;+DAE+D;AAE/D;;;GAGG;AAEH,OAAO,IAAI,EAAE,EAAE,MAAM,EAAkB,MAAM,gBAAgB,CAAC;AAG9D,MAAM,OAAO,aAAa;IAChB,MAAM,GAAkB,IAAI,CAAC;IAC7B,WAAW,GAAY,KAAK,CAAC;IAErC;;OAEG;IACH,KAAK,CAAC,IAAI,CAAC,WAAmB,GAAG;QAC/B,IAAI,IAAI,CAAC,WAAW;YAAE,OAAO;QAE7B,yBAAyB;QACzB,MAAM,OAAO,GAAG,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC;YACpC,CAAC,CAAC,GAAG,QAAQ,uBAAuB;YACpC,CAAC,CAAC,GAAG,QAAQ,wBAAwB,CAAC;QAExC,MAAM,IAAI,CAAC,OAAO,CAAC,CAAC;QACpB,IAAI,CAAC,MAAM,GAAG,IAAI,MAAM,EAAE,CAAC;QAC3B,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;IAC1B,CAAC;IAED;;;OAGG;IACH,WAAW,CAAC,OAAe;QACzB,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;YACjB,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAC;QAClE,CAAC;QACD,OAAO,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IAC1C,CAAC;IAED;;OAEG;IACH,MAAM;QACJ,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;YACjB,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAC;QAClE,CAAC;QACD,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED;;OAEG;IACH,aAAa;QACX,OAAO,IAAI,CAAC,WAAW,CAAC;IAC1B,CAAC;IAED;;OAEG;IACH,UAAU;QACR,OAAO,IAAI,CAAC,MAAM,EAAE,OAAO,IAAI,SAAS,CAAC;IAC3C,CAAC;CACF"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* IFC-Lite Mesh Collector - extracts triangle data from IFC-Lite WASM
|
|
3
|
+
* Replaces mesh-collector.ts - uses native Rust geometry processing (1.9x faster)
|
|
4
|
+
*/
|
|
5
|
+
import type { IfcAPI } from '@ifc-lite/wasm';
|
|
6
|
+
import type { MeshData } from './types.js';
|
|
7
|
+
export declare class IfcLiteMeshCollector {
|
|
8
|
+
private ifcApi;
|
|
9
|
+
private content;
|
|
10
|
+
constructor(ifcApi: IfcAPI, content: string);
|
|
11
|
+
/**
|
|
12
|
+
* Convert IFC Z-up coordinates to WebGL Y-up coordinates
|
|
13
|
+
* IFC uses Z-up (Z points up), WebGL uses Y-up (Y points up)
|
|
14
|
+
* Transformation: swap Y and Z, then negate new Z to maintain right-handedness
|
|
15
|
+
*/
|
|
16
|
+
private convertZUpToYUp;
|
|
17
|
+
/**
|
|
18
|
+
* Collect all meshes from IFC-Lite
|
|
19
|
+
* Much faster than web-ifc (~1.9x speedup)
|
|
20
|
+
*/
|
|
21
|
+
collectMeshes(): MeshData[];
|
|
22
|
+
/**
|
|
23
|
+
* Collect meshes incrementally, yielding batches for progressive rendering
|
|
24
|
+
* @param batchSize Number of meshes per batch (default: 100)
|
|
25
|
+
*/
|
|
26
|
+
collectMeshesStreaming(batchSize?: number): AsyncGenerator<MeshData[]>;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=ifc-lite-mesh-collector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ifc-lite-mesh-collector.d.ts","sourceRoot":"","sources":["../src/ifc-lite-mesh-collector.ts"],"names":[],"mappings":"AAIA;;;GAGG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C,qBAAa,oBAAoB;IAC/B,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,OAAO,CAAS;gBAEZ,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;IAK3C;;;;OAIG;IACH,OAAO,CAAC,eAAe;IAUvB;;;OAGG;IACH,aAAa,IAAI,QAAQ,EAAE;IAwD3B;;;OAGG;IACI,sBAAsB,CAAC,SAAS,GAAE,MAAY,GAAG,cAAc,CAAC,QAAQ,EAAE,CAAC;CA8DnF"}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
2
|
+
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
3
|
+
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
|
4
|
+
export class IfcLiteMeshCollector {
|
|
5
|
+
ifcApi;
|
|
6
|
+
content;
|
|
7
|
+
constructor(ifcApi, content) {
|
|
8
|
+
this.ifcApi = ifcApi;
|
|
9
|
+
this.content = content;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Convert IFC Z-up coordinates to WebGL Y-up coordinates
|
|
13
|
+
* IFC uses Z-up (Z points up), WebGL uses Y-up (Y points up)
|
|
14
|
+
* Transformation: swap Y and Z, then negate new Z to maintain right-handedness
|
|
15
|
+
*/
|
|
16
|
+
convertZUpToYUp(coords) {
|
|
17
|
+
for (let i = 0; i < coords.length; i += 3) {
|
|
18
|
+
const y = coords[i + 1];
|
|
19
|
+
const z = coords[i + 2];
|
|
20
|
+
// Swap Y and Z: Z-up → Y-up
|
|
21
|
+
coords[i + 1] = z; // New Y = old Z (vertical)
|
|
22
|
+
coords[i + 2] = -y; // New Z = -old Y (depth, negated for right-hand rule)
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Collect all meshes from IFC-Lite
|
|
27
|
+
* Much faster than web-ifc (~1.9x speedup)
|
|
28
|
+
*/
|
|
29
|
+
collectMeshes() {
|
|
30
|
+
// const totalStart = performance.now();
|
|
31
|
+
// const parseStart = performance.now();
|
|
32
|
+
const collection = this.ifcApi.parseMeshes(this.content);
|
|
33
|
+
// const parseTime = performance.now() - parseStart;
|
|
34
|
+
const meshes = [];
|
|
35
|
+
// const conversionStart = performance.now();
|
|
36
|
+
// Convert MeshCollection to MeshData[]
|
|
37
|
+
for (let i = 0; i < collection.length; i++) {
|
|
38
|
+
const mesh = collection.get(i);
|
|
39
|
+
if (!mesh)
|
|
40
|
+
continue;
|
|
41
|
+
// Get color array [r, g, b, a]
|
|
42
|
+
const colorArray = mesh.color;
|
|
43
|
+
const color = [
|
|
44
|
+
colorArray[0],
|
|
45
|
+
colorArray[1],
|
|
46
|
+
colorArray[2],
|
|
47
|
+
colorArray[3],
|
|
48
|
+
];
|
|
49
|
+
// Capture arrays once (WASM creates new copies on each access)
|
|
50
|
+
const positions = mesh.positions;
|
|
51
|
+
const normals = mesh.normals;
|
|
52
|
+
const indices = mesh.indices;
|
|
53
|
+
// Convert IFC Z-up to WebGL Y-up (modify captured arrays)
|
|
54
|
+
this.convertZUpToYUp(positions);
|
|
55
|
+
this.convertZUpToYUp(normals);
|
|
56
|
+
meshes.push({
|
|
57
|
+
expressId: mesh.expressId,
|
|
58
|
+
positions,
|
|
59
|
+
normals,
|
|
60
|
+
indices,
|
|
61
|
+
color,
|
|
62
|
+
});
|
|
63
|
+
// Free the individual mesh to avoid memory leaks
|
|
64
|
+
mesh.free();
|
|
65
|
+
}
|
|
66
|
+
// Store stats before freeing
|
|
67
|
+
// const totalVertices = collection.totalVertices;
|
|
68
|
+
// const totalTriangles = collection.totalTriangles;
|
|
69
|
+
// Free the collection
|
|
70
|
+
collection.free();
|
|
71
|
+
// const conversionTime = performance.now() - conversionStart;
|
|
72
|
+
return meshes;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Collect meshes incrementally, yielding batches for progressive rendering
|
|
76
|
+
* @param batchSize Number of meshes per batch (default: 100)
|
|
77
|
+
*/
|
|
78
|
+
async *collectMeshesStreaming(batchSize = 100) {
|
|
79
|
+
// const totalStart = performance.now();
|
|
80
|
+
// const parseStart = performance.now();
|
|
81
|
+
const collection = this.ifcApi.parseMeshes(this.content);
|
|
82
|
+
// const parseTime = performance.now() - parseStart;
|
|
83
|
+
let batch = [];
|
|
84
|
+
let processedCount = 0;
|
|
85
|
+
// Process meshes in batches
|
|
86
|
+
for (let i = 0; i < collection.length; i++) {
|
|
87
|
+
const mesh = collection.get(i);
|
|
88
|
+
if (!mesh)
|
|
89
|
+
continue;
|
|
90
|
+
// Get color array [r, g, b, a]
|
|
91
|
+
const colorArray = mesh.color;
|
|
92
|
+
const color = [
|
|
93
|
+
colorArray[0],
|
|
94
|
+
colorArray[1],
|
|
95
|
+
colorArray[2],
|
|
96
|
+
colorArray[3],
|
|
97
|
+
];
|
|
98
|
+
// Capture arrays once (WASM creates new copies on each access)
|
|
99
|
+
const positions = mesh.positions;
|
|
100
|
+
const normals = mesh.normals;
|
|
101
|
+
const indices = mesh.indices;
|
|
102
|
+
// Convert IFC Z-up to WebGL Y-up (modify captured arrays)
|
|
103
|
+
this.convertZUpToYUp(positions);
|
|
104
|
+
this.convertZUpToYUp(normals);
|
|
105
|
+
batch.push({
|
|
106
|
+
expressId: mesh.expressId,
|
|
107
|
+
positions,
|
|
108
|
+
normals,
|
|
109
|
+
indices,
|
|
110
|
+
color,
|
|
111
|
+
});
|
|
112
|
+
// Free the individual mesh
|
|
113
|
+
mesh.free();
|
|
114
|
+
processedCount++;
|
|
115
|
+
// Yield batch when full
|
|
116
|
+
if (batch.length >= batchSize) {
|
|
117
|
+
yield batch;
|
|
118
|
+
batch = [];
|
|
119
|
+
// Yield to UI thread
|
|
120
|
+
await new Promise(resolve => setTimeout(resolve, 0));
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
// Yield remaining meshes
|
|
124
|
+
if (batch.length > 0) {
|
|
125
|
+
yield batch;
|
|
126
|
+
}
|
|
127
|
+
// Free the collection
|
|
128
|
+
collection.free();
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
//# sourceMappingURL=ifc-lite-mesh-collector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ifc-lite-mesh-collector.js","sourceRoot":"","sources":["../src/ifc-lite-mesh-collector.ts"],"names":[],"mappings":"AAAA;;+DAE+D;AAU/D,MAAM,OAAO,oBAAoB;IACvB,MAAM,CAAS;IACf,OAAO,CAAS;IAExB,YAAY,MAAc,EAAE,OAAe;QACzC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAED;;;;OAIG;IACK,eAAe,CAAC,MAAoB;QAC1C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;YAC1C,MAAM,CAAC,GAAG,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;YACxB,MAAM,CAAC,GAAG,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;YACxB,4BAA4B;YAC5B,MAAM,CAAC,CA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,SAAS,EAAE,IAAI,CAAC,SAAS;gBACzB,SAAS;gBACT,OAAO;gBACP,OAAO;gBACP,KAAK;aACN,CAAC,CAAC;YAEH,2BAA2B;YAC3B,IAAI,CAAC,IAAI,EAAE,CAAC;YACZ,cAAc,EAAE,CAAC;YAEjB,wBAAwB;YACxB,IAAI,KAAK,CAAC,MAAM,IAAI,SAAS,EAAE,CAAC;gBAC9B,MAAM,KAAK,CAAC;gBACZ,KAAK,GAAG,EAAE,CAAC;gBACX,qBAAqB;gBACrB,MAAM,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC;YACvD,CAAC;QACH,CAAC;QAED,yBAAyB;QACzB,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACrB,MAAM,KAAK,CAAC;QACd,CAAC;QAED,sBAAsB;QACtB,UAAU,CAAC,IAAI,EAAE,CAAC;IACpB,CAAC;CACF"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @ifc-lite/geometry - Geometry processing bridge
|
|
3
|
+
* Now powered by IFC-Lite native Rust WASM (1.9x faster than web-ifc)
|
|
4
|
+
*/
|
|
5
|
+
export { IfcLiteBridge } from './ifc-lite-bridge.js';
|
|
6
|
+
export { IfcLiteMeshCollector } from './ifc-lite-mesh-collector.js';
|
|
7
|
+
export { BufferBuilder } from './buffer-builder.js';
|
|
8
|
+
export { CoordinateHandler } from './coordinate-handler.js';
|
|
9
|
+
export { WorkerPool } from './worker-pool.js';
|
|
10
|
+
export { GeometryQuality } from './progressive-loader.js';
|
|
11
|
+
export { LODGenerator, type LODConfig, type LODMesh } from './lod.js';
|
|
12
|
+
export * from './types.js';
|
|
13
|
+
export * from './default-materials.js';
|
|
14
|
+
export { IfcLiteBridge as WebIfcBridge } from './ifc-lite-bridge.js';
|
|
15
|
+
import { GeometryQuality } from './progressive-loader.js';
|
|
16
|
+
import type { GeometryResult, MeshData } from './types.js';
|
|
17
|
+
export interface GeometryProcessorOptions {
|
|
18
|
+
useWorkers?: boolean;
|
|
19
|
+
quality?: GeometryQuality;
|
|
20
|
+
}
|
|
21
|
+
export type StreamingGeometryEvent = {
|
|
22
|
+
type: 'start';
|
|
23
|
+
totalEstimate: number;
|
|
24
|
+
} | {
|
|
25
|
+
type: 'model-open';
|
|
26
|
+
modelID: number;
|
|
27
|
+
} | {
|
|
28
|
+
type: 'batch';
|
|
29
|
+
meshes: MeshData[];
|
|
30
|
+
totalSoFar: number;
|
|
31
|
+
coordinateInfo?: import('./types.js').CoordinateInfo;
|
|
32
|
+
} | {
|
|
33
|
+
type: 'complete';
|
|
34
|
+
totalMeshes: number;
|
|
35
|
+
coordinateInfo: import('./types.js').CoordinateInfo;
|
|
36
|
+
};
|
|
37
|
+
export declare class GeometryProcessor {
|
|
38
|
+
private bridge;
|
|
39
|
+
private bufferBuilder;
|
|
40
|
+
private coordinateHandler;
|
|
41
|
+
private workerPool;
|
|
42
|
+
private wasmPath;
|
|
43
|
+
private useWorkers;
|
|
44
|
+
constructor(options?: GeometryProcessorOptions);
|
|
45
|
+
/**
|
|
46
|
+
* Initialize IFC-Lite WASM and worker pool
|
|
47
|
+
*/
|
|
48
|
+
init(wasmPath?: string): Promise<void>;
|
|
49
|
+
/**
|
|
50
|
+
* Process IFC file and extract geometry
|
|
51
|
+
* @param buffer IFC file buffer
|
|
52
|
+
* @param entityIndex Optional entity index for priority-based loading
|
|
53
|
+
*/
|
|
54
|
+
process(buffer: Uint8Array, entityIndex?: Map<number, any>): Promise<GeometryResult>;
|
|
55
|
+
/**
|
|
56
|
+
* Collect meshes on main thread using IFC-Lite
|
|
57
|
+
*/
|
|
58
|
+
private collectMeshesMainThread;
|
|
59
|
+
/**
|
|
60
|
+
* Process IFC file with streaming output for progressive rendering
|
|
61
|
+
* Uses IFC-Lite for native Rust geometry processing (1.9x faster)
|
|
62
|
+
* @param buffer IFC file buffer
|
|
63
|
+
* @param entityIndex Optional entity index for priority-based loading
|
|
64
|
+
* @param batchSize Number of meshes per batch (default: 100)
|
|
65
|
+
*/
|
|
66
|
+
processStreaming(buffer: Uint8Array, _entityIndex?: Map<number, any>, batchSize?: number): AsyncGenerator<StreamingGeometryEvent>;
|
|
67
|
+
/**
|
|
68
|
+
* Cleanup resources
|
|
69
|
+
*/
|
|
70
|
+
dispose(): void;
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA;;;GAGG;AAGH,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AAGpE,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAE,KAAK,SAAS,EAAE,KAAK,OAAO,EAAE,MAAM,UAAU,CAAC;AACtE,cAAc,YAAY,CAAC;AAC3B,cAAc,wBAAwB,CAAC;AAGvC,OAAO,EAAE,aAAa,IAAI,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAOrE,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,KAAK,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3D,MAAM,WAAW,wBAAwB;IACvC,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,OAAO,CAAC,EAAE,eAAe,CAAC;CAC3B;AAED,MAAM,MAAM,sBAAsB,GAC9B;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,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PL was not distributed with this
|
|
3
|
+
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
|
4
|
+
/**
|
|
5
|
+
* @ifc-lite/geometry - Geometry processing bridge
|
|
6
|
+
* Now powered by IFC-Lite native Rust WASM (1.9x faster than web-ifc)
|
|
7
|
+
*/
|
|
8
|
+
// IFC-Lite components (recommended - faster)
|
|
9
|
+
export { IfcLiteBridge } from './ifc-lite-bridge.js';
|
|
10
|
+
export { IfcLiteMeshCollector } from './ifc-lite-mesh-collector.js';
|
|
11
|
+
// Support components
|
|
12
|
+
export { BufferBuilder } from './buffer-builder.js';
|
|
13
|
+
export { CoordinateHandler } from './coordinate-handler.js';
|
|
14
|
+
export { WorkerPool } from './worker-pool.js';
|
|
15
|
+
export { GeometryQuality } from './progressive-loader.js';
|
|
16
|
+
export { LODGenerator } from './lod.js';
|
|
17
|
+
export * from './types.js';
|
|
18
|
+
export * from './default-materials.js';
|
|
19
|
+
// Legacy exports for compatibility (deprecated)
|
|
20
|
+
export { IfcLiteBridge as WebIfcBridge } from './ifc-lite-bridge.js';
|
|
21
|
+
import { IfcLiteBridge } from './ifc-lite-bridge.js';
|
|
22
|
+
import { IfcLiteMeshCollector } from './ifc-lite-mesh-collector.js';
|
|
23
|
+
import { BufferBuilder } from './buffer-builder.js';
|
|
24
|
+
import { CoordinateHandler } from './coordinate-handler.js';
|
|
25
|
+
import { WorkerPool } from './worker-pool.js';
|
|
26
|
+
export class GeometryProcessor {
|
|
27
|
+
bridge;
|
|
28
|
+
bufferBuilder;
|
|
29
|
+
coordinateHandler;
|
|
30
|
+
workerPool = null;
|
|
31
|
+
wasmPath = '/';
|
|
32
|
+
useWorkers = false;
|
|
33
|
+
constructor(options = {}) {
|
|
34
|
+
this.bridge = new IfcLiteBridge();
|
|
35
|
+
this.bufferBuilder = new BufferBuilder();
|
|
36
|
+
this.coordinateHandler = new CoordinateHandler();
|
|
37
|
+
this.useWorkers = options.useWorkers ?? false;
|
|
38
|
+
// Note: quality option is accepted for API compatibility but IFC-Lite always processes at full quality
|
|
39
|
+
void options.quality;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Initialize IFC-Lite WASM and worker pool
|
|
43
|
+
*/
|
|
44
|
+
async init(wasmPath = '/') {
|
|
45
|
+
this.wasmPath = wasmPath;
|
|
46
|
+
await this.bridge.init(wasmPath);
|
|
47
|
+
// Initialize worker pool if available (lazy - only when needed)
|
|
48
|
+
// Don't initialize workers upfront to avoid overhead
|
|
49
|
+
// Workers will be initialized on first use if needed
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Process IFC file and extract geometry
|
|
53
|
+
* @param buffer IFC file buffer
|
|
54
|
+
* @param entityIndex Optional entity index for priority-based loading
|
|
55
|
+
*/
|
|
56
|
+
async process(buffer, entityIndex) {
|
|
57
|
+
if (!this.bridge.isInitialized()) {
|
|
58
|
+
await this.init();
|
|
59
|
+
}
|
|
60
|
+
// entityIndex is used in collectMeshesMainThread for priority-based loading
|
|
61
|
+
void entityIndex;
|
|
62
|
+
let meshes;
|
|
63
|
+
// const meshCollectionStart = performance.now();
|
|
64
|
+
// Use workers only if explicitly enabled (they add overhead)
|
|
65
|
+
if (this.useWorkers) {
|
|
66
|
+
// Try to use worker pool if available (lazy init)
|
|
67
|
+
if (!this.workerPool) {
|
|
68
|
+
try {
|
|
69
|
+
let workerUrl;
|
|
70
|
+
try {
|
|
71
|
+
workerUrl = new URL('./geometry.worker.ts', import.meta.url);
|
|
72
|
+
}
|
|
73
|
+
catch (e) {
|
|
74
|
+
workerUrl = './geometry.worker.ts';
|
|
75
|
+
}
|
|
76
|
+
this.workerPool = new WorkerPool(workerUrl, 1); // Use single worker for now
|
|
77
|
+
await this.workerPool.init();
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
console.warn('[GeometryProcessor] Worker pool initialization failed, will use main thread:', error);
|
|
81
|
+
this.workerPool = null;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
if (this.workerPool?.isAvailable()) {
|
|
85
|
+
try {
|
|
86
|
+
meshes = await this.workerPool.submit('mesh-collection', {
|
|
87
|
+
buffer: buffer.buffer,
|
|
88
|
+
wasmPath: this.wasmPath,
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
catch (error) {
|
|
92
|
+
console.warn('[Geometry] Worker pool failed, falling back to main thread:', error);
|
|
93
|
+
meshes = await this.collectMeshesMainThread(buffer);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
// Fallback to main thread
|
|
98
|
+
meshes = await this.collectMeshesMainThread(buffer);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
// Use main thread (faster for total time, but blocks UI)
|
|
103
|
+
meshes = await this.collectMeshesMainThread(buffer);
|
|
104
|
+
}
|
|
105
|
+
// const meshCollectionTime = performance.now() - meshCollectionStart;
|
|
106
|
+
// Handle large coordinates by shifting to origin
|
|
107
|
+
const coordinateInfo = this.coordinateHandler.processMeshes(meshes);
|
|
108
|
+
// Build GPU-ready buffers
|
|
109
|
+
const bufferResult = this.bufferBuilder.processMeshes(meshes);
|
|
110
|
+
// Combine results
|
|
111
|
+
const result = {
|
|
112
|
+
meshes: bufferResult.meshes,
|
|
113
|
+
totalTriangles: bufferResult.totalTriangles,
|
|
114
|
+
totalVertices: bufferResult.totalVertices,
|
|
115
|
+
coordinateInfo,
|
|
116
|
+
};
|
|
117
|
+
return result;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Collect meshes on main thread using IFC-Lite
|
|
121
|
+
*/
|
|
122
|
+
async collectMeshesMainThread(buffer, _entityIndex) {
|
|
123
|
+
// Convert buffer to string (IFC files are text)
|
|
124
|
+
const decoder = new TextDecoder();
|
|
125
|
+
const content = decoder.decode(buffer);
|
|
126
|
+
const collector = new IfcLiteMeshCollector(this.bridge.getApi(), content);
|
|
127
|
+
const meshes = collector.collectMeshes();
|
|
128
|
+
return meshes;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Process IFC file with streaming output for progressive rendering
|
|
132
|
+
* Uses IFC-Lite for native Rust geometry processing (1.9x faster)
|
|
133
|
+
* @param buffer IFC file buffer
|
|
134
|
+
* @param entityIndex Optional entity index for priority-based loading
|
|
135
|
+
* @param batchSize Number of meshes per batch (default: 100)
|
|
136
|
+
*/
|
|
137
|
+
async *processStreaming(buffer, _entityIndex, batchSize = 100) {
|
|
138
|
+
if (!this.bridge.isInitialized()) {
|
|
139
|
+
await this.init();
|
|
140
|
+
}
|
|
141
|
+
// Reset coordinate handler for new file
|
|
142
|
+
this.coordinateHandler.reset();
|
|
143
|
+
yield { type: 'start', totalEstimate: buffer.length / 1000 };
|
|
144
|
+
// Convert buffer to string (IFC files are text)
|
|
145
|
+
const decoder = new TextDecoder();
|
|
146
|
+
const content = decoder.decode(buffer);
|
|
147
|
+
// Use a placeholder model ID (IFC-Lite doesn't use model IDs)
|
|
148
|
+
yield { type: 'model-open', modelID: 0 };
|
|
149
|
+
const collector = new IfcLiteMeshCollector(this.bridge.getApi(), content);
|
|
150
|
+
let totalMeshes = 0;
|
|
151
|
+
for await (const batch of collector.collectMeshesStreaming(batchSize)) {
|
|
152
|
+
// Process coordinate shifts incrementally (will accumulate bounds)
|
|
153
|
+
this.coordinateHandler.processMeshesIncremental(batch);
|
|
154
|
+
totalMeshes += batch.length;
|
|
155
|
+
// Get current coordinate info for this batch (may be null if bounds not yet valid)
|
|
156
|
+
const coordinateInfo = this.coordinateHandler.getCurrentCoordinateInfo();
|
|
157
|
+
yield { type: 'batch', meshes: batch, totalSoFar: totalMeshes, coordinateInfo: coordinateInfo || undefined };
|
|
158
|
+
}
|
|
159
|
+
const coordinateInfo = this.coordinateHandler.getFinalCoordinateInfo();
|
|
160
|
+
yield { type: 'complete', totalMeshes, coordinateInfo };
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Cleanup resources
|
|
164
|
+
*/
|
|
165
|
+
dispose() {
|
|
166
|
+
if (this.workerPool) {
|
|
167
|
+
this.workerPool.terminate();
|
|
168
|
+
this.workerPool = null;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;+DAE+D;AAE/D;;;GAGG;AAEH,6CAA6C;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AAEpE,qBAAqB;AACrB,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAgC,MAAM,UAAU,CAAC;AACtE,cAAc,YAAY,CAAC;AAC3B,cAAc,wBAAwB,CAAC;AAEvC,gDAAgD;AAChD,OAAO,EAAE,aAAa,IAAI,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAErE,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AACpE,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAe9C,MAAM,OAAO,iBAAiB;IACpB,MAAM,CAAgB;IACtB,aAAa,CAAgB;IAC7B,iBAAiB,CAAoB;IACrC,UAAU,GAAsB,IAAI,CAAC;IACrC,QAAQ,GAAW,GAAG,CAAC;IACvB,UAAU,GAAY,KAAK,CAAC;I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C1E,IAAI,WAAW,GAAG,CAAC,CAAC;QAEpB,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,SAAS,CAAC,sBAAsB,CAAC,SAAS,CAAC,EAAE,CAAC;YACtE,mEAAmE;YACnE,IAAI,CAAC,iBAAiB,CAAC,wBAAwB,CAAC,KAAK,CAAC,CAAC;YACvD,WAAW,IAAI,KAAK,CAAC,MAAM,CAAC;YAE5B,mFAAmF;YACnF,MAAM,cAAc,GAAG,IAAI,CAAC,iBAAiB,CAAC,wBAAwB,EAAE,CAAC;YAEzE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,cAAc,EAAE,cAAc,IAAI,SAAS,EAAE,CAAC;QAC/G,CAAC;QAED,MAAM,cAAc,GAAG,IAAI,CAAC,iBAAiB,CAAC,sBAAsB,EAAE,CAAC;QAEvE,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,WAAW,EAAE,cAAc,EAAE,CAAC;IAC1D,CAAC;IAED;;OAEG;IACH,OAAO;QACL,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;YACpB,IAAI,CAAC,UAAU,CAAC,SAAS,EAAE,CAAC;YAC5B,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;QACzB,CAAC;IACH,CAAC;CACF"}
|
package/dist/lod.d.ts
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Level of Detail (LOD) system for geometry optimization
|
|
3
|
+
* Uses screen-space size culling for performance
|
|
4
|
+
*/
|
|
5
|
+
import type { MeshData } from './types.js';
|
|
6
|
+
import type { Vec3 } from './types.js';
|
|
7
|
+
export interface LODConfig {
|
|
8
|
+
/**
|
|
9
|
+
* Minimum screen-space size (in pixels) to render at full detail
|
|
10
|
+
* Objects smaller than this will be culled
|
|
11
|
+
*/
|
|
12
|
+
minScreenSize?: number;
|
|
13
|
+
/**
|
|
14
|
+
* Distance thresholds for LOD levels (in world units)
|
|
15
|
+
* [near, mid, far] - objects beyond far threshold are culled
|
|
16
|
+
*/
|
|
17
|
+
distanceThresholds?: [number, number, number];
|
|
18
|
+
}
|
|
19
|
+
export interface LODMesh {
|
|
20
|
+
lod0: MeshData;
|
|
21
|
+
lod1?: MeshData;
|
|
22
|
+
lod2?: MeshData;
|
|
23
|
+
bounds: {
|
|
24
|
+
min: Vec3;
|
|
25
|
+
max: Vec3;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
export declare class LODGenerator {
|
|
29
|
+
private config;
|
|
30
|
+
constructor(config?: LODConfig);
|
|
31
|
+
/**
|
|
32
|
+
* Calculate screen-space size of a mesh from camera position
|
|
33
|
+
*/
|
|
34
|
+
calculateScreenSize(meshBounds: {
|
|
35
|
+
min: Vec3;
|
|
36
|
+
max: Vec3;
|
|
37
|
+
}, cameraPosition: Vec3, _viewProjMatrix: Float32Array, _viewportWidth: number, viewportHeight: number): number;
|
|
38
|
+
/**
|
|
39
|
+
* Determine if mesh should be rendered based on screen size
|
|
40
|
+
*/
|
|
41
|
+
shouldRender(meshBounds: {
|
|
42
|
+
min: Vec3;
|
|
43
|
+
max: Vec3;
|
|
44
|
+
}, cameraPosition: Vec3, viewProjMatrix: Float32Array, viewportWidth: number, viewportHeight: number): boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Get LOD level based on distance (0 = full detail, 1 = medium, 2 = low, -1 = cull)
|
|
47
|
+
*/
|
|
48
|
+
getLODLevel(meshBounds: {
|
|
49
|
+
min: Vec3;
|
|
50
|
+
max: Vec3;
|
|
51
|
+
}, cameraPosition: Vec3): number;
|
|
52
|
+
/**
|
|
53
|
+
* Compute bounds from mesh data
|
|
54
|
+
*/
|
|
55
|
+
static computeBounds(mesh: MeshData): {
|
|
56
|
+
min: Vec3;
|
|
57
|
+
max: Vec3;
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=lod.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+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