bimatter-viewer-react 0.4.1 → 0.5.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/README.md +65 -34
- package/lib/Loaders/BmtLoader.d.ts +20 -2
- package/lib/Loaders/IFCLoader/IFCLoader.d.ts +35 -6
- package/lib/api/loader.d.ts +16 -0
- package/lib/index.d.ts +5 -3
- package/lib/index.js +838 -439
- package/lib/workers/BMTWorker.d.ts +53 -0
- package/lib/workers/BMTWorkerClient.d.ts +14 -0
- package/lib/workers/IFCWorker.d.ts +62 -0
- package/lib/workers/IFCWorkerClient.d.ts +14 -0
- package/lib/workers/ProgressUtils.d.ts +27 -0
- package/lib/workers/index.d.ts +7 -0
- package/package.json +4 -1
package/README.md
CHANGED
|
@@ -152,6 +152,37 @@ await loader.loadModel(["/models/model.bmt", "/models/model.ifc"]);
|
|
|
152
152
|
await loader.loadModel(files);
|
|
153
153
|
```
|
|
154
154
|
|
|
155
|
+
Use `useWorker` to parse BMT and IFC models outside the main thread:
|
|
156
|
+
|
|
157
|
+
```ts
|
|
158
|
+
const models = await loader.loadModel(["/models/model.ifc"], {
|
|
159
|
+
chunk: 200,
|
|
160
|
+
useIfcSpace: true,
|
|
161
|
+
useWorker: true,
|
|
162
|
+
onProgress: (event) => {
|
|
163
|
+
console.log(event.phase, Math.round(event.progress * 100));
|
|
164
|
+
},
|
|
165
|
+
onChunk: (chunk) => {
|
|
166
|
+
// Optional: add chunk.geometry to your viewer state for progressive render.
|
|
167
|
+
console.log(chunk.modelID, chunk.geometryID);
|
|
168
|
+
},
|
|
169
|
+
});
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
For IFC, `chunk` controls how many geometries are packed before a streamed mesh is emitted. For BMT, chunks are read as they are already stored in the file.
|
|
173
|
+
|
|
174
|
+
When you render chunks yourself in `onChunk`, set `collectWorkerChunks: false` to avoid keeping the same streamed geometry in the loader helper until the final result:
|
|
175
|
+
|
|
176
|
+
```ts
|
|
177
|
+
await loader.loadModel(["/models/model.bmt"], {
|
|
178
|
+
collectWorkerChunks: false,
|
|
179
|
+
useWorker: true,
|
|
180
|
+
onChunk: (chunk) => {
|
|
181
|
+
// Store chunk.geometry in your own model state.
|
|
182
|
+
},
|
|
183
|
+
});
|
|
184
|
+
```
|
|
185
|
+
|
|
155
186
|
## File Upload Example
|
|
156
187
|
|
|
157
188
|
```tsx
|
|
@@ -180,40 +211,6 @@ function App() {
|
|
|
180
211
|
}
|
|
181
212
|
```
|
|
182
213
|
|
|
183
|
-
## HotKeys
|
|
184
|
-
|
|
185
|
-
### Selection
|
|
186
|
-
|
|
187
|
-
`Left Click` - Select element
|
|
188
|
-
|
|
189
|
-
`Shift + Left Click` - Multi-select element
|
|
190
|
-
|
|
191
|
-
`Ctrl + Left Click` - Toggle element selection
|
|
192
|
-
|
|
193
|
-
`Shift + Drag Right` - Select elements fully inside rectangle
|
|
194
|
-
|
|
195
|
-
`Shift + Drag Left` - Select elements intersected by rectangle
|
|
196
|
-
|
|
197
|
-
`Ctrl + Drag Right` - Unselect elements fully inside rectangle
|
|
198
|
-
|
|
199
|
-
`Ctrl + Drag Left` - Unselect elements intersected by rectangle
|
|
200
|
-
|
|
201
|
-
### Visibility
|
|
202
|
-
|
|
203
|
-
`C` - Clear hidden / isolated elements
|
|
204
|
-
|
|
205
|
-
`H` - Hide selected elements
|
|
206
|
-
|
|
207
|
-
`I` - Isolate selected elements
|
|
208
|
-
|
|
209
|
-
### Clipping
|
|
210
|
-
|
|
211
|
-
`P` - Create clipping plane by model intersection
|
|
212
|
-
|
|
213
|
-
### Dimensions
|
|
214
|
-
|
|
215
|
-
`M` - Toggle dimension drawing mode
|
|
216
|
-
|
|
217
214
|
## Viewer API
|
|
218
215
|
|
|
219
216
|
```ts
|
|
@@ -574,3 +571,37 @@ viewerRef.current?.utils.setGridAxesVisibility({
|
|
|
574
571
|
top: false,
|
|
575
572
|
});
|
|
576
573
|
```
|
|
574
|
+
|
|
575
|
+
## HotKeys
|
|
576
|
+
|
|
577
|
+
### Selection
|
|
578
|
+
|
|
579
|
+
`Left Click` - Select element
|
|
580
|
+
|
|
581
|
+
`Shift + Left Click` - Multi-select element
|
|
582
|
+
|
|
583
|
+
`Ctrl + Left Click` - Toggle element selection
|
|
584
|
+
|
|
585
|
+
`Shift + Drag Right` - Select elements fully inside rectangle
|
|
586
|
+
|
|
587
|
+
`Shift + Drag Left` - Select elements intersected by rectangle
|
|
588
|
+
|
|
589
|
+
`Ctrl + Drag Right` - Unselect elements fully inside rectangle
|
|
590
|
+
|
|
591
|
+
`Ctrl + Drag Left` - Unselect elements intersected by rectangle
|
|
592
|
+
|
|
593
|
+
### Visibility
|
|
594
|
+
|
|
595
|
+
`C` - Clear hidden / isolated elements
|
|
596
|
+
|
|
597
|
+
`H` - Hide selected elements
|
|
598
|
+
|
|
599
|
+
`I` - Isolate selected elements
|
|
600
|
+
|
|
601
|
+
### Clipping
|
|
602
|
+
|
|
603
|
+
`P` - Create clipping plane by model intersection
|
|
604
|
+
|
|
605
|
+
### Dimensions
|
|
606
|
+
|
|
607
|
+
`M` - Toggle dimension drawing mode
|
|
@@ -59,6 +59,24 @@ export interface BmtModelData {
|
|
|
59
59
|
props: BmtModelProps;
|
|
60
60
|
structure: BmtModelStructure;
|
|
61
61
|
}
|
|
62
|
+
export type BmtGeometryChunkData = {
|
|
63
|
+
chunkIndex: number;
|
|
64
|
+
geometry: BmtGeomData;
|
|
65
|
+
geometryID: number;
|
|
66
|
+
isIfcSpace: boolean;
|
|
67
|
+
loadedBytes: number;
|
|
68
|
+
totalBytes: number;
|
|
69
|
+
};
|
|
70
|
+
export type BmtParseProgressData = {
|
|
71
|
+
emittedChunks: number;
|
|
72
|
+
loadedBytes: number;
|
|
73
|
+
totalBytes: number;
|
|
74
|
+
};
|
|
75
|
+
export type BmtParseCallbacks = {
|
|
76
|
+
onGeometryChunk?: (chunk: BmtGeometryChunkData) => void;
|
|
77
|
+
onProgress?: (progress: BmtParseProgressData) => void;
|
|
78
|
+
streamGeometryChunks?: boolean;
|
|
79
|
+
};
|
|
62
80
|
type BmtMeshData = {
|
|
63
81
|
colorId: BmtMaterialData;
|
|
64
82
|
ids: Uint8Array;
|
|
@@ -93,7 +111,7 @@ export declare class BMTLoader {
|
|
|
93
111
|
private getExternalMetadataPath;
|
|
94
112
|
private loadExternalMetadata;
|
|
95
113
|
private getModelNameFromPath;
|
|
96
|
-
loadModel(path: string): Promise<BmtModelData>;
|
|
97
|
-
parseBinaryFile(data: ArrayBuffer): BmtModelData;
|
|
114
|
+
loadModel(path: string, callbacks?: BmtParseCallbacks): Promise<BmtModelData>;
|
|
115
|
+
parseBinaryFile(data: ArrayBuffer, callbacks?: BmtParseCallbacks): BmtModelData;
|
|
98
116
|
}
|
|
99
117
|
export {};
|
|
@@ -2,7 +2,7 @@ import { type IfcElementsAssembly } from "./PropertySerializer";
|
|
|
2
2
|
import { Matrix4 } from "three";
|
|
3
3
|
import { IfcAPI, type LocateFileHandlerFn } from "web-ifc";
|
|
4
4
|
import { type GridData } from "./IfcGrid";
|
|
5
|
-
import type { BmtModelData, BmtModelProps, BmtModelStructure } from "../BmtLoader";
|
|
5
|
+
import type { BmtGeomData, BmtModelData, BmtModelProps, BmtModelStructure } from "../BmtLoader";
|
|
6
6
|
type IfcParserOptions = {
|
|
7
7
|
geometryTransformation?: number[];
|
|
8
8
|
maxGeometriesPerMesh: number;
|
|
@@ -18,6 +18,25 @@ type IfcModelDataResult = {
|
|
|
18
18
|
export type IfcModelSource = string | File;
|
|
19
19
|
export type IfcLoadedModels = Record<number, BmtModelData>;
|
|
20
20
|
export type IfcCoordinationMatrixSource = Matrix4 | number[] | string | null | undefined;
|
|
21
|
+
export type IfcGeometryChunkData = {
|
|
22
|
+
chunkIndex: number;
|
|
23
|
+
geometry: BmtGeomData;
|
|
24
|
+
geometryID: number;
|
|
25
|
+
isIfcSpace: boolean;
|
|
26
|
+
totalChunks: number;
|
|
27
|
+
};
|
|
28
|
+
export type IfcGeometryProgressData = {
|
|
29
|
+
emittedChunks: number;
|
|
30
|
+
processed: number;
|
|
31
|
+
total: number;
|
|
32
|
+
};
|
|
33
|
+
export type IfcParsePhase = "opening" | "opened" | "streaming" | "properties" | "metadata";
|
|
34
|
+
export type IfcParseCallbacks = {
|
|
35
|
+
onGeometryChunk?: (chunk: IfcGeometryChunkData) => void;
|
|
36
|
+
onGeometryProgress?: (progress: IfcGeometryProgressData) => void;
|
|
37
|
+
onPhase?: (phase: IfcParsePhase) => void;
|
|
38
|
+
streamGeometryChunks?: boolean;
|
|
39
|
+
};
|
|
21
40
|
export declare class IFCLoader {
|
|
22
41
|
useIfcElemetAssembly: boolean;
|
|
23
42
|
useIfcColors: boolean;
|
|
@@ -31,20 +50,20 @@ export declare class IFCLoader {
|
|
|
31
50
|
chunk: number;
|
|
32
51
|
maxMeshBytes: number;
|
|
33
52
|
constructor();
|
|
34
|
-
getPath
|
|
35
|
-
initParser(func?: LocateFileHandlerFn): Promise<void>;
|
|
53
|
+
getPath: LocateFileHandlerFn;
|
|
54
|
+
initParser(func?: LocateFileHandlerFn, forceSingleThread?: boolean): Promise<void>;
|
|
36
55
|
set wasmPath(path: string);
|
|
37
56
|
get _parser(): IfcAPI;
|
|
38
57
|
set _parser(parser: IfcAPI);
|
|
39
58
|
loadModel(sources: IfcModelSource | IfcModelSource[], coordinationMatrix?: IfcCoordinationMatrixSource): Promise<IfcLoadedModels>;
|
|
40
|
-
parseBinaryFile(file: ArrayBuffer, coordinationMatrix?: IfcCoordinationMatrixSource): Promise<BmtModelData>;
|
|
59
|
+
parseBinaryFile(file: ArrayBuffer, coordinationMatrix?: IfcCoordinationMatrixSource, callbacks?: IfcParseCallbacks): Promise<BmtModelData>;
|
|
41
60
|
private loadSingleModel;
|
|
42
61
|
private parseInitializedBuffer;
|
|
43
62
|
getModelData(path: string): Promise<IfcModelDataResult>;
|
|
44
63
|
setCoordinationMatrix(matrix: IfcCoordinationMatrixSource): void;
|
|
45
64
|
resetCoordinationMatrix(): void;
|
|
46
65
|
get coordinationMatrixData(): string | undefined;
|
|
47
|
-
getModelDataFromBuffer(file: ArrayBuffer, coordinationMatrix?: IfcCoordinationMatrixSource): Promise<IfcModelDataResult | false>;
|
|
66
|
+
getModelDataFromBuffer(file: ArrayBuffer, coordinationMatrix?: IfcCoordinationMatrixSource, callbacks?: IfcParseCallbacks): Promise<IfcModelDataResult | false>;
|
|
48
67
|
private createCoordinationMatrix;
|
|
49
68
|
private getOptionalGridCoordinate;
|
|
50
69
|
private transformGridPoint;
|
|
@@ -59,7 +78,14 @@ export declare class IfcParser {
|
|
|
59
78
|
private readonly meshMatrix;
|
|
60
79
|
private readonly normalMatrix;
|
|
61
80
|
constructor(parser: IfcAPI, ifcModelID: number, options: IfcParserOptions);
|
|
62
|
-
|
|
81
|
+
getGeometryProgressTotal(): number;
|
|
82
|
+
parseData(allIds: Set<number>, elementsAssembly: IfcElementsAssembly | null, includeSpaces?: boolean, callbacks?: IfcParseCallbacks): BmtModelData;
|
|
83
|
+
private parseDataStreaming;
|
|
84
|
+
private streamDynamicGeometryChunks;
|
|
85
|
+
private getDynamicChunkBuilder;
|
|
86
|
+
private writeGeometryPayloadToDynamicBuilder;
|
|
87
|
+
private flushDynamicGeometryChunks;
|
|
88
|
+
private emitDynamicGeometryChunk;
|
|
63
89
|
private streamGeometryChunks;
|
|
64
90
|
private applyGeometryTransformation;
|
|
65
91
|
private planGeometryChunks;
|
|
@@ -75,6 +101,9 @@ export declare class IfcParser {
|
|
|
75
101
|
private getGeometryByteSize;
|
|
76
102
|
private writeGeometryPayload;
|
|
77
103
|
private createModelDataFromChunks;
|
|
104
|
+
private getTotalChunkCount;
|
|
105
|
+
private emitCompletedGeometryChunk;
|
|
106
|
+
private createGeometryDataFromBuilder;
|
|
78
107
|
private getElementId;
|
|
79
108
|
private getFiniteNumber;
|
|
80
109
|
private getDisplayColor;
|
package/lib/api/loader.d.ts
CHANGED
|
@@ -1,8 +1,20 @@
|
|
|
1
1
|
import { type BmtModelData } from "../Loaders/BmtLoader";
|
|
2
|
+
import { type BmtWorkerGeometryChunk, type IfcWorkerGeometryChunk, type WorkerProgressEvent } from "../workers";
|
|
2
3
|
export type ViewerModelSource = string | File;
|
|
3
4
|
export type ViewerLoadedModels = Record<number, BmtModelData>;
|
|
5
|
+
export type ViewerLoaderWorkerChunk = (BmtWorkerGeometryChunk | IfcWorkerGeometryChunk) & {
|
|
6
|
+
modelID: number;
|
|
7
|
+
};
|
|
4
8
|
export type ViewerLoadModelOptions = {
|
|
9
|
+
chunk?: number;
|
|
10
|
+
collectWorkerChunks?: boolean;
|
|
11
|
+
maxMeshBytes?: number;
|
|
12
|
+
onChunk?: (chunk: ViewerLoaderWorkerChunk) => void;
|
|
13
|
+
onProgress?: (progress: WorkerProgressEvent) => void;
|
|
14
|
+
streamGeometryChunks?: boolean;
|
|
5
15
|
useIfcSpace?: boolean;
|
|
16
|
+
useWorker?: boolean;
|
|
17
|
+
wasmPath?: string;
|
|
6
18
|
};
|
|
7
19
|
declare class ViewerLoaderApi {
|
|
8
20
|
coordinationMatrix: string | undefined;
|
|
@@ -17,6 +29,10 @@ declare class ViewerLoaderApi {
|
|
|
17
29
|
private getFileSourceMap;
|
|
18
30
|
private applyBmtMetadata;
|
|
19
31
|
private loadBmtModel;
|
|
32
|
+
private createWorkerProgressHandler;
|
|
33
|
+
private createWorkerChunkHandler;
|
|
34
|
+
private loadIfcModelInWorker;
|
|
35
|
+
private loadBmtModelInWorker;
|
|
20
36
|
private resetCoordinationMatrixState;
|
|
21
37
|
resetCoordinationMatrix(): void;
|
|
22
38
|
loadModel(sources: ViewerModelSource | ViewerModelSource[], options?: ViewerLoadModelOptions): Promise<ViewerLoadedModels>;
|
package/lib/index.d.ts
CHANGED
|
@@ -3,9 +3,9 @@ export type { ViewerModelsData, ViewerProps } from "./Viewer";
|
|
|
3
3
|
export type { ViewerApi, ViewerCameraApi, ViewerCameraGetIntersection, ViewerClippingApi, ViewerColorsApi, ViewerBmtConverterOptions, ViewerConverterApi, ViewerDimensionsApi, ViewerGeometryUtilsApi, ViewerSelection, ViewerSelectorApi, ViewerUtilsApi, } from "./api/ViewerApi";
|
|
4
4
|
export type { ViewerPropertiesApi, ViewerPropertiesExcelOptions, } from "./api/ViewerPropertiesApi";
|
|
5
5
|
export { BMTLoader } from "./Loaders/BmtLoader";
|
|
6
|
-
export type { BmtModelGeometryData, BmtGeomData, BmtIndexArray, BmtMaterialData, BmtElementProps, BmtModelData, BmtModelProps, BmtModelStructure, BmtModelStructureNode, BmtPropertyRecord, BmtPropertySet, BmtPropertyValue, } from "./Loaders/BmtLoader";
|
|
6
|
+
export type { BmtGeometryChunkData, BmtParseCallbacks, BmtParseProgressData, BmtModelGeometryData, BmtGeomData, BmtIndexArray, BmtMaterialData, BmtElementProps, BmtModelData, BmtModelProps, BmtModelStructure, BmtModelStructureNode, BmtPropertyRecord, BmtPropertySet, BmtPropertyValue, } from "./Loaders/BmtLoader";
|
|
7
7
|
export { IFCLoader } from "./Loaders/IFCLoader/IFCLoader";
|
|
8
|
-
export type { IfcLoadedModels, IfcModelSource, } from "./Loaders/IFCLoader/IFCLoader";
|
|
8
|
+
export type { IfcLoadedModels, IfcGeometryChunkData, IfcModelSource, IfcParseCallbacks, } from "./Loaders/IFCLoader/IFCLoader";
|
|
9
9
|
export { BmtConverter, ConvertIfcFileToBmt, ConvertToBmt, bmtConverter, } from "./Loaders/BmtConverter";
|
|
10
10
|
export type { BmtActiveViewFilter, BmtActiveViewFilterParams, BmtConvertibleModels, BmtConversionResult, BmtConvertedFile, BmtConvertedFileType, BmtConverterOptions, BmtConverterSource, BmtVisibleIdsByModel, } from "./Loaders/BmtConverter";
|
|
11
11
|
export { ModelGrids } from "./utils/ModelGrids";
|
|
@@ -13,7 +13,9 @@ export type { ModelGridAxis, ModelGridData, ModelGridPoint, ModelGridsProps, Mod
|
|
|
13
13
|
export { exportExcel, exportModelPropertiesToExcel, } from "./utils/ExportUtils";
|
|
14
14
|
export type { ExportedExcelFile, ExportModelSource, ModelPropertiesExcelOptions, } from "./utils/ExportUtils";
|
|
15
15
|
export { loader } from "./api/loader";
|
|
16
|
-
export type { ViewerLoadedModels, ViewerLoadModelOptions, ViewerModelSource, } from "./api/loader";
|
|
16
|
+
export type { ViewerLoadedModels, ViewerLoadModelOptions, ViewerLoaderWorkerChunk, ViewerModelSource, } from "./api/loader";
|
|
17
|
+
export { createBmtWorker, createIfcWorker, loadBmtModelsInWorker, loadIfcModelsInWorker, } from "./workers";
|
|
18
|
+
export type { BmtWorkerClientOptions, BmtWorkerError, BmtWorkerGeometryChunk, BmtWorkerLoadedModels, BmtWorkerLoadOptions, BmtWorkerLoadRequest, BmtWorkerModelSource, BmtWorkerResponse, BmtWorkerSource, IfcWorkerClientOptions, IfcWorkerError, IfcWorkerGeometryChunk, IfcWorkerLoadedModels, IfcWorkerLoadOptions, IfcWorkerLoadRequest, IfcWorkerModelSource, IfcWorkerResponse, IfcWorkerSource, WorkerProgressEvent, WorkerProgressPhase, } from "./workers";
|
|
17
19
|
export { FilteredElementsCollector } from "./Selector/FilteredElementsCollector";
|
|
18
20
|
export type { FilteredElement, FilteredElementId, FilteredElementIdsResult, FilteredElementPredicate, FilteredElementsResult, FilteredElementsSource, FilteredElementWithModel, IfcClass, IfcClassName, } from "./Selector/FilteredElementsCollector";
|
|
19
21
|
export { NavigationCube } from "./utils/NavigationCube";
|