@ifc-lite/geometry 1.1.7 → 1.2.1
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/default-materials.d.ts.map +1 -1
- package/dist/default-materials.js +12 -1
- package/dist/default-materials.js.map +1 -1
- package/dist/ifc-lite-bridge.d.ts +1 -0
- package/dist/ifc-lite-bridge.d.ts.map +1 -1
- package/dist/ifc-lite-bridge.js.map +1 -1
- package/dist/ifc-lite-mesh-collector.d.ts +12 -2
- package/dist/ifc-lite-mesh-collector.d.ts.map +1 -1
- package/dist/ifc-lite-mesh-collector.js +63 -7
- package/dist/ifc-lite-mesh-collector.js.map +1 -1
- package/dist/index.d.ts +40 -13
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +167 -85
- package/dist/index.js.map +1 -1
- package/dist/native-bridge.d.ts +24 -0
- package/dist/native-bridge.d.ts.map +1 -0
- package/dist/native-bridge.js +141 -0
- package/dist/native-bridge.js.map +1 -0
- package/dist/platform-bridge.d.ts +96 -0
- package/dist/platform-bridge.d.ts.map +1 -0
- package/dist/platform-bridge.js +26 -0
- package/dist/platform-bridge.js.map +1 -0
- package/dist/types.d.ts +1 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/wasm-bridge.d.ts +21 -0
- package/dist/wasm-bridge.d.ts.map +1 -0
- package/dist/wasm-bridge.js +111 -0
- package/dist/wasm-bridge.js.map +1 -0
- package/dist/wasm-memory-manager.d.ts +178 -0
- package/dist/wasm-memory-manager.d.ts.map +1 -0
- package/dist/wasm-memory-manager.js +86 -0
- package/dist/wasm-memory-manager.js.map +1 -0
- package/dist/zero-copy-collector.d.ts +158 -0
- package/dist/zero-copy-collector.d.ts.map +1 -0
- package/dist/zero-copy-collector.js +224 -0
- package/dist/zero-copy-collector.js.map +1 -0
- package/package.json +12 -8
- package/dist/geometry.worker.d.ts +0 -2
- package/dist/geometry.worker.d.ts.map +0 -1
- package/dist/geometry.worker.js +0 -116
- package/dist/geometry.worker.js.map +0 -1
- package/dist/worker-pool.d.ts +0 -56
- package/dist/worker-pool.d.ts.map +0 -1
- package/dist/worker-pool.js +0 -160
- package/dist/worker-pool.js.map +0 -1
|
@@ -0,0 +1,141 @@
|
|
|
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
|
+
* Native Tauri bridge for desktop apps
|
|
6
|
+
*
|
|
7
|
+
* This uses Tauri's invoke() to call native Rust commands that use
|
|
8
|
+
* ifc-lite-core and ifc-lite-geometry directly (no WASM overhead).
|
|
9
|
+
*/
|
|
10
|
+
export class NativeBridge {
|
|
11
|
+
initialized = false;
|
|
12
|
+
invoke = null;
|
|
13
|
+
listen = null;
|
|
14
|
+
async init() {
|
|
15
|
+
if (this.initialized)
|
|
16
|
+
return;
|
|
17
|
+
// Access Tauri internals directly to avoid bundler issues
|
|
18
|
+
// This is set by Tauri runtime and is always available in Tauri apps
|
|
19
|
+
const win = globalThis;
|
|
20
|
+
if (!win.__TAURI_INTERNALS__?.invoke) {
|
|
21
|
+
throw new Error('Tauri API not available - this bridge should only be used in Tauri apps');
|
|
22
|
+
}
|
|
23
|
+
this.invoke = win.__TAURI_INTERNALS__.invoke;
|
|
24
|
+
// For event listening, we still need the event module
|
|
25
|
+
// Use dynamic import with try-catch for better error handling
|
|
26
|
+
try {
|
|
27
|
+
const event = await import('@tauri-apps/api/event');
|
|
28
|
+
this.listen = event.listen;
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
// Event listening is optional - streaming will fall back to non-streaming
|
|
32
|
+
console.warn('[NativeBridge] Event API not available, streaming will be limited');
|
|
33
|
+
}
|
|
34
|
+
this.initialized = true;
|
|
35
|
+
}
|
|
36
|
+
isInitialized() {
|
|
37
|
+
return this.initialized;
|
|
38
|
+
}
|
|
39
|
+
async processGeometry(content) {
|
|
40
|
+
if (!this.initialized || !this.invoke) {
|
|
41
|
+
await this.init();
|
|
42
|
+
}
|
|
43
|
+
// Convert string to buffer for Tauri command
|
|
44
|
+
const encoder = new TextEncoder();
|
|
45
|
+
const buffer = Array.from(encoder.encode(content));
|
|
46
|
+
// Call native Rust command
|
|
47
|
+
const result = await this.invoke('get_geometry', { buffer });
|
|
48
|
+
// Convert native format to TypeScript format
|
|
49
|
+
const meshes = result.meshes.map(convertNativeMesh);
|
|
50
|
+
const coordinateInfo = convertNativeCoordinateInfo(result.coordinateInfo);
|
|
51
|
+
return {
|
|
52
|
+
meshes,
|
|
53
|
+
totalVertices: result.totalVertices,
|
|
54
|
+
totalTriangles: result.totalTriangles,
|
|
55
|
+
coordinateInfo,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
async processGeometryStreaming(content, options) {
|
|
59
|
+
if (!this.initialized || !this.invoke) {
|
|
60
|
+
await this.init();
|
|
61
|
+
}
|
|
62
|
+
// If event API not available, fall back to non-streaming processing
|
|
63
|
+
if (!this.listen) {
|
|
64
|
+
console.warn('[NativeBridge] Event API unavailable, falling back to non-streaming mode');
|
|
65
|
+
const result = await this.processGeometry(content);
|
|
66
|
+
const stats = {
|
|
67
|
+
totalMeshes: result.meshes.length,
|
|
68
|
+
totalVertices: result.totalVertices,
|
|
69
|
+
totalTriangles: result.totalTriangles,
|
|
70
|
+
parseTimeMs: 0,
|
|
71
|
+
geometryTimeMs: 0,
|
|
72
|
+
};
|
|
73
|
+
// Emit single batch with all meshes
|
|
74
|
+
options.onBatch?.({
|
|
75
|
+
meshes: result.meshes,
|
|
76
|
+
progress: { processed: result.meshes.length, total: result.meshes.length, currentType: 'complete' },
|
|
77
|
+
});
|
|
78
|
+
options.onComplete?.(stats);
|
|
79
|
+
return stats;
|
|
80
|
+
}
|
|
81
|
+
// Convert string to buffer for Tauri command
|
|
82
|
+
const encoder = new TextEncoder();
|
|
83
|
+
const buffer = Array.from(encoder.encode(content));
|
|
84
|
+
// Listen for geometry batch events
|
|
85
|
+
const unlisten = await this.listen('geometry-batch', (event) => {
|
|
86
|
+
const batch = {
|
|
87
|
+
meshes: event.payload.meshes.map(convertNativeMesh),
|
|
88
|
+
progress: {
|
|
89
|
+
processed: event.payload.progress.processed,
|
|
90
|
+
total: event.payload.progress.total,
|
|
91
|
+
currentType: event.payload.progress.currentType,
|
|
92
|
+
},
|
|
93
|
+
};
|
|
94
|
+
options.onBatch?.(batch);
|
|
95
|
+
});
|
|
96
|
+
try {
|
|
97
|
+
// Call native streaming command
|
|
98
|
+
const stats = await this.invoke('get_geometry_streaming', { buffer });
|
|
99
|
+
const result = {
|
|
100
|
+
totalMeshes: stats.totalMeshes,
|
|
101
|
+
totalVertices: stats.totalVertices,
|
|
102
|
+
totalTriangles: stats.totalTriangles,
|
|
103
|
+
parseTimeMs: stats.parseTimeMs,
|
|
104
|
+
geometryTimeMs: stats.geometryTimeMs,
|
|
105
|
+
};
|
|
106
|
+
options.onComplete?.(result);
|
|
107
|
+
return result;
|
|
108
|
+
}
|
|
109
|
+
catch (error) {
|
|
110
|
+
options.onError?.(error instanceof Error ? error : new Error(String(error)));
|
|
111
|
+
throw error;
|
|
112
|
+
}
|
|
113
|
+
finally {
|
|
114
|
+
// Clean up event listener
|
|
115
|
+
unlisten();
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
getApi() {
|
|
119
|
+
// Native bridge doesn't expose an API object
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
// Conversion functions
|
|
124
|
+
function convertNativeMesh(native) {
|
|
125
|
+
return {
|
|
126
|
+
expressId: native.expressId,
|
|
127
|
+
positions: new Float32Array(native.positions),
|
|
128
|
+
normals: new Float32Array(native.normals),
|
|
129
|
+
indices: new Uint32Array(native.indices),
|
|
130
|
+
color: native.color,
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
function convertNativeCoordinateInfo(native) {
|
|
134
|
+
return {
|
|
135
|
+
originShift: native.originShift,
|
|
136
|
+
originalBounds: native.originalBounds,
|
|
137
|
+
shiftedBounds: native.shiftedBounds,
|
|
138
|
+
isGeoReferenced: native.isGeoReferenced,
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
//# sourceMappingURL=native-bridge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"native-bridge.js","sourceRoot":"","sources":["../src/native-bridge.ts"],"names":[],"mappings":"AAAA;;+DAE+D;AA2B/D;;;;;GAKG;AACH,MAAM,OAAO,YAAY;IACf,WAAW,GAAG,KAAK,CAAC;IACpB,MAAM,GAAoB,IAAI,CAAC;IAC/B,MAAM,GAAoB,IAAI,CAAC;IAEvC,KAAK,CAAC,IAAI;QACR,IAAI,IAAI,CAAC,WAAW;YAAE,OAAO;QAE7B,0DAA0D;QAC1D,qEAAqE;QACrE,MAAM,GAAG,GAAG,UAAiE,CAAC;QAC9E,IAAI,CAAC,GAAG,CAAC,mBAAmB,EAAE,MAAM,EAAE,CAAC;YACrC,MAAM,IAAI,KAAK,CAAC,yEAAyE,CAAC,CAAC;QAC7F,CAAC;QAED,IAAI,CAAC,MAAM,GAAG,GAAG,CAAC,mBAAmB,CAAC,MAAM,CAAC;QAE7C,sDAAsD;QACtD,8DAA8D;QAC9D,IAAI,CAAC;YACH,MAAM,KAAK,GAAG,MAAM,MAAM,CAAC,uBAAuB,CAAC,CAAC;YACpD,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC;QAC7B,CAAC;QAAC,MAAM,CAAC;YACP,0EAA0E;YAC1E,OAAO,CAAC,IAAI,CAAC,mEAAmE,CAAC,CAAC;QACpF,CAAC;QAED,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;IAC1B,CAAC;IAED,aAAa;QACX,OAAO,IAAI,CAAC,WAAW,CAAC;IAC1B,CAAC;IAED,KAAK,CAAC,eAAe,CAAC,OAAe;QACnC,IAAI,CAAC,IAAI,CAAC,WAAW,I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form Bridge Abstraction
|
|
3
|
+
*
|
|
4
|
+
* Provides a unified interface for geometry processing that works in both:
|
|
5
|
+
* - Web browsers (using WASM via @ifc-lite/wasm)
|
|
6
|
+
* - Tauri desktop apps (using native Rust via Tauri commands)
|
|
7
|
+
*
|
|
8
|
+
* The appropriate implementation is selected at runtime based on environment detection.
|
|
9
|
+
*/
|
|
10
|
+
import type { MeshData, CoordinateInfo } from './types.js';
|
|
11
|
+
/**
|
|
12
|
+
* Progress information during streaming geometry processing
|
|
13
|
+
*/
|
|
14
|
+
export interface StreamingProgress {
|
|
15
|
+
processed: number;
|
|
16
|
+
total: number;
|
|
17
|
+
currentType: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Batch of meshes emitted during streaming
|
|
21
|
+
*/
|
|
22
|
+
export interface GeometryBatch {
|
|
23
|
+
meshes: MeshData[];
|
|
24
|
+
progress: StreamingProgress;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Statistics returned after geometry processing completes
|
|
28
|
+
*/
|
|
29
|
+
export interface GeometryStats {
|
|
30
|
+
totalMeshes: number;
|
|
31
|
+
totalVertices: number;
|
|
32
|
+
totalTriangles: number;
|
|
33
|
+
parseTimeMs: number;
|
|
34
|
+
geometryTimeMs: number;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Complete geometry result from processing
|
|
38
|
+
*/
|
|
39
|
+
export interface GeometryProcessingResult {
|
|
40
|
+
meshes: MeshData[];
|
|
41
|
+
totalVertices: number;
|
|
42
|
+
totalTriangles: number;
|
|
43
|
+
coordinateInfo: CoordinateInfo;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Options for streaming geometry processing
|
|
47
|
+
*/
|
|
48
|
+
export interface StreamingOptions {
|
|
49
|
+
/** Callback for each batch of meshes */
|
|
50
|
+
onBatch?: (batch: GeometryBatch) => void;
|
|
51
|
+
/** Callback when processing is complete */
|
|
52
|
+
onComplete?: (stats: GeometryStats) => void;
|
|
53
|
+
/** Callback for errors */
|
|
54
|
+
onError?: (error: Error) => void;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Platform bridge interface - abstracts WASM vs native processing
|
|
58
|
+
*/
|
|
59
|
+
export interface IPlatformBridge {
|
|
60
|
+
/**
|
|
61
|
+
* Initialize the bridge (WASM loading for web, no-op for native)
|
|
62
|
+
*/
|
|
63
|
+
init(): Promise<void>;
|
|
64
|
+
/**
|
|
65
|
+
* Check if the bridge is initialized
|
|
66
|
+
*/
|
|
67
|
+
isInitialized(): boolean;
|
|
68
|
+
/**
|
|
69
|
+
* Process IFC content and return all geometry at once
|
|
70
|
+
* @param content IFC file content as string
|
|
71
|
+
*/
|
|
72
|
+
processGeometry(content: string): Promise<GeometryProcessingResult>;
|
|
73
|
+
/**
|
|
74
|
+
* Process IFC content with streaming output
|
|
75
|
+
* @param content IFC file content as string
|
|
76
|
+
* @param options Streaming options with callbacks
|
|
77
|
+
*/
|
|
78
|
+
processGeometryStreaming(content: string, options: StreamingOptions): Promise<GeometryStats>;
|
|
79
|
+
/**
|
|
80
|
+
* Get the underlying API object (for advanced usage)
|
|
81
|
+
* Returns the WASM IfcAPI in web, or null in Tauri
|
|
82
|
+
*/
|
|
83
|
+
getApi(): unknown | null;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Detect if running in Tauri desktop environment
|
|
87
|
+
*/
|
|
88
|
+
export declare function isTauri(): boolean;
|
|
89
|
+
/**
|
|
90
|
+
* Create the appropriate platform bridge based on runtime environment
|
|
91
|
+
*
|
|
92
|
+
* In Tauri: Returns NativeBridge (native Rust processing)
|
|
93
|
+
* In Browser: Returns WasmBridge (WASM processing)
|
|
94
|
+
*/
|
|
95
|
+
export declare function createPlatformBridge(): Promise<IPlatformBridge>;
|
|
96
|
+
//# sourceMappingURL=platform-bridge.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"platform-bridge.d.ts","sourceRoot":"","sources":["../src/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,CAAC,CAAC;IAEpE;;;;OAIG;IACH,wBAAwB,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;IAE7F;;;OAGG;IACH,MAAM,IAAI,OAAO,GAAG,IAAI,CAAC;CAC1B;AAED;;GAEG;AACH,wBAAgB,OAAO,IAAI,OAAO,CAEjC;AAED;;;;;GAKG;AACH,wBAAsB,oBAAoB,IAAI,OAAO,CAAC,eAAe,CAAC,CAQrE"}
|
|
@@ -0,0 +1,26 @@
|
|
|
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
|
+
* Detect if running in Tauri desktop environment
|
|
6
|
+
*/
|
|
7
|
+
export function isTauri() {
|
|
8
|
+
return typeof window !== 'undefined' && '__TAURI_INTERNALS__' in window;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Create the appropriate platform bridge based on runtime environment
|
|
12
|
+
*
|
|
13
|
+
* In Tauri: Returns NativeBridge (native Rust processing)
|
|
14
|
+
* In Browser: Returns WasmBridge (WASM processing)
|
|
15
|
+
*/
|
|
16
|
+
export async function createPlatformBridge() {
|
|
17
|
+
if (isTauri()) {
|
|
18
|
+
const { NativeBridge } = await import('./native-bridge.js');
|
|
19
|
+
return new NativeBridge();
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
const { WasmBridge } = await import('./wasm-bridge.js');
|
|
23
|
+
return new WasmBridge();
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=platform-bridge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"platform-bridge.js","sourceRoot":"","sources":["../src/platform-bridge.ts"],"names":[],"mappings":"AAAA;;+DAE+D;AAkG/D;;GAEG;AACH,MAAM,UAAU,OAAO;IACrB,OAAO,OAAO,MAAM,KAAK,WAAW,IAAI,qBAAqB,IAAI,MAAM,CAAC;AAC1E,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB;IACxC,IAAI,OAAO,EAAE,EAAE,CAAC;QACd,MAAM,EAAE,YAAY,EAAE,GAAG,MAAM,MAAM,CAAC,oBAAoB,CAAC,CAAC;QAC5D,OAAO,IAAI,YAAY,EAAE,CAAC;IAC5B,CAAC;SAAM,CAAC;QACN,MAAM,EAAE,UAAU,EAAE,GAAG,MAAM,MAAM,CAAC,kBAAkB,CAAC,CAAC;QACxD,OAAO,IAAI,UAAU,EAAE,CAAC;IAC1B,CAAC;AACH,CAAC"}
|
package/dist/types.d.ts
CHANGED
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,MAAM,WAAW,QAAQ;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,YAAY,CAAC;IACxB,OAAO,EAAE,YAAY,CAAC;IACtB,OAAO,EAAE,WAAW,CAAC;IACrB,KAAK,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;CACzC;AAED,MAAM,WAAW,IAAI;IACnB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;CACX;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,YAAY,CAAC;IACxB,KAAK,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;CACzC;AAED;;;GAGG;AACH,MAAM,WAAW,iBAAiB;IAChC,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,YAAY,CAAC;IACx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GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,YAAY,CAAC;IACxB,KAAK,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;CACzC;AAED;;;GAGG;AACH,MAAM,WAAW,iBAAiB;IAChC,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,YAAY,CAAC;IACxB,OAAO,EAAE,YAAY,CAAC;IACtB,OAAO,EAAE,WAAW,CAAC;IACrB,cAAc,EAAE,MAAM,CAAC;IACvB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,YAAY,GAAG,IAAI,CAAC;CAClD;AAED;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC,MAAM,EAAE,MAAM,CAAC;IACf,eAAe,EAAE,MAAM,CAAC;IACxB,cAAc,EAAE,MAAM,CAAC;IACvB,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,iBAAiB,GAAG,IAAI,CAAC;CAC9C;AAED,MAAM,WAAW,IAAI;IACnB,GAAG,EAAE,IAAI,CAAC;IACV,GAAG,EAAE,IAAI,CAAC;CACX;AAED,MAAM,WAAW,cAAc;IAC7B,WAAW,EAAE,IAAI,CAAC;IAClB,cAAc,EAAE,IAAI,CAAC;IACrB,aAAa,EAAE,IAAI,CAAC;IACpB,eAAe,EAAE,OAAO,CAAC;CAC1B;AAED,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,QAAQ,EAAE,CAAC;IACnB,cAAc,EAAE,MAAM,CAAC;IACvB,aAAa,EAAE,MAAM,CAAC;IACtB,cAAc,EAAE,cAAc,CAAC;CAChC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WASM Bridge Implementation
|
|
3
|
+
*
|
|
4
|
+
* Uses @ifc-lite/wasm for geometry processing in web browsers.
|
|
5
|
+
* This is the existing implementation wrapped in the IPlatformBridge interface.
|
|
6
|
+
*/
|
|
7
|
+
import type { IPlatformBridge, GeometryProcessingResult, GeometryStats, StreamingOptions } from './platform-bridge.js';
|
|
8
|
+
/**
|
|
9
|
+
* WASM-based platform bridge for web browsers
|
|
10
|
+
*/
|
|
11
|
+
export declare class WasmBridge implements IPlatformBridge {
|
|
12
|
+
private bridge;
|
|
13
|
+
private initialized;
|
|
14
|
+
constructor();
|
|
15
|
+
init(): Promise<void>;
|
|
16
|
+
isInitialized(): boolean;
|
|
17
|
+
processGeometry(content: string): Promise<GeometryProcessingResult>;
|
|
18
|
+
processGeometryStreaming(content: string, options: StreamingOptions): Promise<GeometryStats>;
|
|
19
|
+
getApi(): unknown;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=wasm-bridge.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wasm-bridge.d.ts","sourceRoot":"","sources":["../src/wasm-bridge.ts"],"names":[],"mappings":"AAIA;;;;;GAKG;AAEH,OAAO,KAAK,EACV,eAAe,EACf,wBAAwB,EACxB,aAAa,EACb,gBAAgB,EACjB,MAAM,sBAAsB,CAAC;AAK9B;;GAEG;AACH,qBAAa,UAAW,YAAW,eAAe;IAChD,OAAO,CAAC,MAAM,CAAgB;IAC9B,OAAO,CAAC,WAAW,CAAS;;IAMtB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAM3B,aAAa,IAAI,OAAO;IAIlB,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,wBAAwB,CAAC;IAwCnE,wBAAwB,CAC5B,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,gBAAgB,GACxB,OAAO,CAAC,aAAa,CAAC;IAyDzB,MAAM,IAAI,OAAO;CAGlB"}
|
|
@@ -0,0 +1,111 @@
|
|
|
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
|
+
import { IfcLiteBridge } from './ifc-lite-bridge.js';
|
|
5
|
+
import { IfcLiteMeshCollector } from './ifc-lite-mesh-collector.js';
|
|
6
|
+
/**
|
|
7
|
+
* WASM-based platform bridge for web browsers
|
|
8
|
+
*/
|
|
9
|
+
export class WasmBridge {
|
|
10
|
+
bridge;
|
|
11
|
+
initialized = false;
|
|
12
|
+
constructor() {
|
|
13
|
+
this.bridge = new IfcLiteBridge();
|
|
14
|
+
}
|
|
15
|
+
async init() {
|
|
16
|
+
if (this.initialized)
|
|
17
|
+
return;
|
|
18
|
+
await this.bridge.init();
|
|
19
|
+
this.initialized = true;
|
|
20
|
+
}
|
|
21
|
+
isInitialized() {
|
|
22
|
+
return this.initialized;
|
|
23
|
+
}
|
|
24
|
+
async processGeometry(content) {
|
|
25
|
+
if (!this.initialized) {
|
|
26
|
+
await this.init();
|
|
27
|
+
}
|
|
28
|
+
const startTime = performance.now();
|
|
29
|
+
const collector = new IfcLiteMeshCollector(this.bridge.getApi(), content);
|
|
30
|
+
const meshes = collector.collectMeshes();
|
|
31
|
+
const endTime = performance.now();
|
|
32
|
+
// Calculate totals
|
|
33
|
+
let totalVertices = 0;
|
|
34
|
+
let totalTriangles = 0;
|
|
35
|
+
for (const mesh of meshes) {
|
|
36
|
+
totalVertices += mesh.positions.length / 3;
|
|
37
|
+
totalTriangles += mesh.indices.length / 3;
|
|
38
|
+
}
|
|
39
|
+
// Default coordinate info (coordinate handling is done by GeometryProcessor)
|
|
40
|
+
const coordinateInfo = {
|
|
41
|
+
originShift: { x: 0, y: 0, z: 0 },
|
|
42
|
+
originalBounds: {
|
|
43
|
+
min: { x: 0, y: 0, z: 0 },
|
|
44
|
+
max: { x: 0, y: 0, z: 0 },
|
|
45
|
+
},
|
|
46
|
+
shiftedBounds: {
|
|
47
|
+
min: { x: 0, y: 0, z: 0 },
|
|
48
|
+
max: { x: 0, y: 0, z: 0 },
|
|
49
|
+
},
|
|
50
|
+
isGeoReferenced: false,
|
|
51
|
+
};
|
|
52
|
+
return {
|
|
53
|
+
meshes,
|
|
54
|
+
totalVertices,
|
|
55
|
+
totalTriangles,
|
|
56
|
+
coordinateInfo,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
async processGeometryStreaming(content, options) {
|
|
60
|
+
if (!this.initialized) {
|
|
61
|
+
await this.init();
|
|
62
|
+
}
|
|
63
|
+
const startTime = performance.now();
|
|
64
|
+
const collector = new IfcLiteMeshCollector(this.bridge.getApi(), content);
|
|
65
|
+
let totalMeshes = 0;
|
|
66
|
+
let totalVertices = 0;
|
|
67
|
+
let totalTriangles = 0;
|
|
68
|
+
try {
|
|
69
|
+
for await (const item of collector.collectMeshesStreaming(50)) {
|
|
70
|
+
// Handle color update events (skip them for streaming stats)
|
|
71
|
+
if (item && typeof item === 'object' && 'type' in item && item.type === 'colorUpdate') {
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
// Handle mesh batches
|
|
75
|
+
const batch = item;
|
|
76
|
+
totalMeshes += batch.length;
|
|
77
|
+
for (const mesh of batch) {
|
|
78
|
+
totalVertices += mesh.positions.length / 3;
|
|
79
|
+
totalTriangles += mesh.indices.length / 3;
|
|
80
|
+
}
|
|
81
|
+
options.onBatch?.({
|
|
82
|
+
meshes: batch,
|
|
83
|
+
progress: {
|
|
84
|
+
processed: totalMeshes,
|
|
85
|
+
total: totalMeshes, // We don't know total upfront with WASM
|
|
86
|
+
currentType: 'processing',
|
|
87
|
+
},
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
catch (error) {
|
|
92
|
+
options.onError?.(error instanceof Error ? error : new Error(String(error)));
|
|
93
|
+
throw error;
|
|
94
|
+
}
|
|
95
|
+
const endTime = performance.now();
|
|
96
|
+
const totalTime = endTime - startTime;
|
|
97
|
+
const stats = {
|
|
98
|
+
totalMeshes,
|
|
99
|
+
totalVertices,
|
|
100
|
+
totalTriangles,
|
|
101
|
+
parseTimeMs: totalTime * 0.3, // Estimate
|
|
102
|
+
geometryTimeMs: totalTime * 0.7, // Estimate
|
|
103
|
+
};
|
|
104
|
+
options.onComplete?.(stats);
|
|
105
|
+
return stats;
|
|
106
|
+
}
|
|
107
|
+
getApi() {
|
|
108
|
+
return this.bridge.getApi();
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
//# sourceMappingURL=wasm-bridge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wasm-bridge.js","sourceRoot":"","sources":["../src/wasm-bridge.ts"],"names":[],"mappings":"AAAA;;+DAE+D;AAe/D,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,oBAAoB,EAAkC,MAAM,8BAA8B,CAAC;AAGpG;;GAEG;AACH,MAAM,OAAO,UAAU;IACb,MAAM,CAAgB;IACtB,WAAW,GAAG,KAAK,CAAC;IAE5B;QACE,IAAI,CAAC,MAAM,GAAG,IAAI,aAAa,EAAE,CAAC;IACpC,CAAC;IAED,KAAK,CAAC,IAAI;QACR,IAAI,IAAI,CAAC,WAAW;YAAE,OAAO;QAC7B,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;QACzB,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;IAC1B,CAAC;IAED,aAAa;QACX,OAAO,IAAI,CAAC,WAAW,CAAC;IAC1B,CAAC;IAED,KAAK,CAAC,eAAe,CAAC,OAAe;QACnC,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;YACtB,MAAM,IAAI,CAAC,IAAI,EAAE,CAAC;QACpB,CAAC;QAED,MAAM,SAAS,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC;QACpC,MAAM,SAAS,GAAG,IAAI,oBAAoB,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,EAAE,OAAO,CAAC,CAAC;QAC1E,MAAM,MAAM,GAAG,SAAS,CAAC,aAAa,EAAE,CAAC;QACzC,MAAM,OAAO,GAAG,WAAW,CAAC,GA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AE,CAAC;QAClC,MAAM,SAAS,GAAG,OAAO,GAAG,SAAS,CAAC;QAEtC,MAAM,KAAK,GAAkB;YAC3B,WAAW;YACX,aAAa;YACb,cAAc;YACd,WAAW,EAAE,SAAS,GAAG,GAAG,EAAE,WAAW;YACzC,cAAc,EAAE,SAAS,GAAG,GAAG,EAAE,WAAW;SAC7C,CAAC;QAEF,OAAO,CAAC,UAAU,EAAE,CAAC,KAAK,CAAC,CAAC;QAC5B,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM;QACJ,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;IAC9B,CAAC;CACF"}
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WASM Memory Manager - manages zero-copy views into WASM linear memory
|
|
3
|
+
*
|
|
4
|
+
* This module provides safe access to WASM memory for zero-copy GPU uploads.
|
|
5
|
+
* Views are created directly into WASM linear memory, avoiding data copies.
|
|
6
|
+
*
|
|
7
|
+
* IMPORTANT: Views become INVALID when WASM memory grows (any allocation).
|
|
8
|
+
* Use the "immediate upload" pattern:
|
|
9
|
+
* 1. Create view
|
|
10
|
+
* 2. Upload to GPU immediately
|
|
11
|
+
* 3. Discard view reference
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* const manager = new WasmMemoryManager(api.getMemory());
|
|
16
|
+
*
|
|
17
|
+
* // SAFE: View created and used immediately
|
|
18
|
+
* const vertexView = manager.createFloat32View(ptr, len);
|
|
19
|
+
* device.queue.writeBuffer(gpuBuffer, 0, vertexView);
|
|
20
|
+
* // View may be invalid now, but we're done with it
|
|
21
|
+
*
|
|
22
|
+
* // UNSAFE: Don't store views across async boundaries!
|
|
23
|
+
* const view = manager.createFloat32View(ptr, len);
|
|
24
|
+
* await someAsyncOp(); // WASM could allocate here!
|
|
25
|
+
* // view might be INVALID now - use would crash!
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export interface WasmMemory {
|
|
29
|
+
buffer: ArrayBuffer;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Manages zero-copy TypedArray views into WASM linear memory
|
|
33
|
+
*/
|
|
34
|
+
export declare class WasmMemoryManager {
|
|
35
|
+
private memory;
|
|
36
|
+
private cachedBuffer;
|
|
37
|
+
constructor(memory: WasmMemory);
|
|
38
|
+
/**
|
|
39
|
+
* Get current memory buffer, detecting if it has changed (grown)
|
|
40
|
+
*/
|
|
41
|
+
private getBuffer;
|
|
42
|
+
/**
|
|
43
|
+
* Create a Float32Array view directly into WASM memory (NO COPY!)
|
|
44
|
+
*
|
|
45
|
+
* WARNING: View becomes invalid if WASM memory grows!
|
|
46
|
+
* Use immediately and discard.
|
|
47
|
+
*
|
|
48
|
+
* @param byteOffset Byte offset into WASM memory (ptr value from Rust)
|
|
49
|
+
* @param length Number of f32 elements (not bytes)
|
|
50
|
+
*/
|
|
51
|
+
createFloat32View(byteOffset: number, length: number): Float32Array;
|
|
52
|
+
/**
|
|
53
|
+
* Create a Uint32Array view directly into WASM memory (NO COPY!)
|
|
54
|
+
*
|
|
55
|
+
* @param byteOffset Byte offset into WASM memory
|
|
56
|
+
* @param length Number of u32 elements (not bytes)
|
|
57
|
+
*/
|
|
58
|
+
createUint32View(byteOffset: number, length: number): Uint32Array;
|
|
59
|
+
/**
|
|
60
|
+
* Create a Float64Array view directly into WASM memory (NO COPY!)
|
|
61
|
+
*
|
|
62
|
+
* @param byteOffset Byte offset into WASM memory
|
|
63
|
+
* @param length Number of f64 elements (not bytes)
|
|
64
|
+
*/
|
|
65
|
+
createFloat64View(byteOffset: number, length: number): Float64Array;
|
|
66
|
+
/**
|
|
67
|
+
* Create a Uint8Array view directly into WASM memory (NO COPY!)
|
|
68
|
+
*
|
|
69
|
+
* @param byteOffset Byte offset into WASM memory
|
|
70
|
+
* @param length Number of bytes
|
|
71
|
+
*/
|
|
72
|
+
createUint8View(byteOffset: number, length: number): Uint8Array;
|
|
73
|
+
/**
|
|
74
|
+
* Check if a view is still valid (memory hasn't grown)
|
|
75
|
+
*/
|
|
76
|
+
isViewValid(view: ArrayBufferView): boolean;
|
|
77
|
+
/**
|
|
78
|
+
* Get raw ArrayBuffer (for advanced use cases)
|
|
79
|
+
*/
|
|
80
|
+
getRawBuffer(): ArrayBuffer;
|
|
81
|
+
/**
|
|
82
|
+
* Check if memory has grown since last access
|
|
83
|
+
*/
|
|
84
|
+
hasMemoryGrown(): boolean;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* GPU-ready geometry data with pointer access
|
|
88
|
+
* Wraps the WASM GpuGeometry struct for TypeScript use
|
|
89
|
+
*/
|
|
90
|
+
export interface GpuGeometryHandle {
|
|
91
|
+
/** Pointer to interleaved vertex data [px,py,pz,nx,ny,nz,...] */
|
|
92
|
+
vertexDataPtr: number;
|
|
93
|
+
/** Length of vertex data in f32 elements */
|
|
94
|
+
vertexDataLen: number;
|
|
95
|
+
/** Byte length of vertex data (for GPU buffer creation) */
|
|
96
|
+
vertexDataByteLength: number;
|
|
97
|
+
/** Pointer to index data */
|
|
98
|
+
indicesPtr: number;
|
|
99
|
+
/** Length of indices in u32 elements */
|
|
100
|
+
indicesLen: number;
|
|
101
|
+
/** Byte length of indices */
|
|
102
|
+
indicesByteLength: number;
|
|
103
|
+
/** Number of meshes in this geometry batch */
|
|
104
|
+
meshCount: number;
|
|
105
|
+
/** Total vertex count */
|
|
106
|
+
totalVertexCount: number;
|
|
107
|
+
/** Total triangle count */
|
|
108
|
+
totalTriangleCount: number;
|
|
109
|
+
/** Check if geometry is empty */
|
|
110
|
+
isEmpty: boolean;
|
|
111
|
+
/** Get metadata for a specific mesh */
|
|
112
|
+
getMeshMetadata(index: number): GpuMeshMetadataHandle | undefined;
|
|
113
|
+
/** Free the geometry (allows WASM to reuse memory) */
|
|
114
|
+
free(): void;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Mesh metadata for draw calls and selection
|
|
118
|
+
*/
|
|
119
|
+
export interface GpuMeshMetadataHandle {
|
|
120
|
+
expressId: number;
|
|
121
|
+
ifcTypeIdx: number;
|
|
122
|
+
vertexOffset: number;
|
|
123
|
+
vertexCount: number;
|
|
124
|
+
indexOffset: number;
|
|
125
|
+
indexCount: number;
|
|
126
|
+
color: number[];
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* GPU-ready instanced geometry with pointer access
|
|
130
|
+
*/
|
|
131
|
+
export interface GpuInstancedGeometryHandle {
|
|
132
|
+
/** Geometry ID (hash for deduplication) */
|
|
133
|
+
geometryId: bigint;
|
|
134
|
+
/** Pointer to interleaved vertex data */
|
|
135
|
+
vertexDataPtr: number;
|
|
136
|
+
vertexDataLen: number;
|
|
137
|
+
vertexDataByteLength: number;
|
|
138
|
+
/** Pointer to index data */
|
|
139
|
+
indicesPtr: number;
|
|
140
|
+
indicesLen: number;
|
|
141
|
+
indicesByteLength: number;
|
|
142
|
+
/** Pointer to instance data [transform(16) + color(4)] per instance */
|
|
143
|
+
instanceDataPtr: number;
|
|
144
|
+
instanceDataLen: number;
|
|
145
|
+
instanceDataByteLength: number;
|
|
146
|
+
/** Pointer to express IDs for each instance */
|
|
147
|
+
instanceExpressIdsPtr: number;
|
|
148
|
+
instanceCount: number;
|
|
149
|
+
/** Vertex and triangle counts */
|
|
150
|
+
vertexCount: number;
|
|
151
|
+
triangleCount: number;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Collection of instanced geometries with pointer access
|
|
155
|
+
*/
|
|
156
|
+
export interface GpuInstancedGeometryCollectionHandle {
|
|
157
|
+
length: number;
|
|
158
|
+
get(index: number): GpuInstancedGeometryHandle | undefined;
|
|
159
|
+
getRef(index: number): GpuInstancedGeometryRefHandle | undefined;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Reference to instanced geometry (avoids cloning)
|
|
163
|
+
*/
|
|
164
|
+
export interface GpuInstancedGeometryRefHandle {
|
|
165
|
+
geometryId: bigint;
|
|
166
|
+
vertexDataPtr: number;
|
|
167
|
+
vertexDataLen: number;
|
|
168
|
+
vertexDataByteLength: number;
|
|
169
|
+
indicesPtr: number;
|
|
170
|
+
indicesLen: number;
|
|
171
|
+
indicesByteLength: number;
|
|
172
|
+
instanceDataPtr: number;
|
|
173
|
+
instanceDataLen: number;
|
|
174
|
+
instanceDataByteLength: number;
|
|
175
|
+
instanceExpressIdsPtr: number;
|
|
176
|
+
instanceCount: number;
|
|
177
|
+
}
|
|
178
|
+
//# sourceMappingURL=wasm-memory-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wasm-memory-manager.d.ts","sourceRoot":"","sources":["../src/wasm-memory-manager.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,WAAW,CAAC;CACrB;AAED;;GAEG;AACH,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,MAAM,CAAa;IAC3B,OAAO,CAAC,YAAY,CAA4B;gBAEpC,MAAM,EAAE,UAAU;IAI9B;;OAEG;IACH,OAAO,CAAC,SAAS;IASjB;;;;;;;;OAQG;IACH,iBAAiB,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,YAAY;IAKnE;;;;;OAKG;IACH,gBAAgB,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,WAAW;IAKjE;;;;;OAKG;IACH,iBAAiB,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,YAAY;IAKnE;;;;;OAKG;IACH,eAAe,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,UAAU;IAK/D;;OAEG;IACH,WAAW,CAAC,IAAI,EAAE,eAAe,GAAG,OAAO;IAI3C;;OAEG;IACH,YAAY,IAAI,WAAW;IAI3B;;OAEG;IACH,cAAc,IAAI,OAAO;CAG1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