bimatter-viewer-react 0.1.1 → 0.1.3

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
@@ -30,18 +30,26 @@ Install the viewer:
30
30
  npm install bimatter-viewer-react
31
31
  ```
32
32
 
33
- `react` and `react-dom` come with the Vite React template. Three.js, React Three Fiber, Drei, and BVH support are installed with `bimatter-viewer-react`.
34
-
35
33
  ## Basic Usage
36
34
 
37
35
  Put your `.bmt` or `.ifc` files in `public/models`:
38
36
 
39
37
  ```text
40
38
  public/
41
- models/
39
+ models/
42
40
  architecture.bmt
43
41
  structure.bmt
44
- architecture.ifc
42
+ ```
43
+
44
+ Replace `src/index.css` or add global sizing:
45
+
46
+ ```css
47
+ html,
48
+ body,
49
+ #root {
50
+ height: 100%;
51
+ margin: 0;
52
+ }
45
53
  ```
46
54
 
47
55
  Then replace `src/App.tsx`:
@@ -60,17 +68,6 @@ function App() {
60
68
  export default App;
61
69
  ```
62
70
 
63
- Replace `src/index.css` or add global sizing:
64
-
65
- ```css
66
- html,
67
- body,
68
- #root {
69
- height: 100%;
70
- margin: 0;
71
- }
72
- ```
73
-
74
71
  Run the app:
75
72
 
76
73
  ```bash
@@ -79,16 +76,18 @@ npm run dev
79
76
 
80
77
  ## IFC Models
81
78
 
82
- IFC loading is based on `web-ifc`. The WASM parser file must be available from the public assets folder:
83
-
84
79
  ```text
85
80
  public/
86
- ifc-parser.wasm
87
- models/
81
+ ifc-parser.wasm
82
+ models/
88
83
  architecture.ifc
89
84
  ```
90
85
 
91
- For Vite apps, files in `public` are served from the app root, so `public/ifc-parser.wasm` is available as `/ifc-parser.wasm`. If you copy the file from `web-ifc`, rename `web-ifc.wasm` to `ifc-parser.wasm`.
86
+ For loading ifc files you need to copy ifc parser wasm file into your public folder, you can take it from bimatter-viewer-react/public/ifc-parser.wasm or by command:
87
+
88
+ ```bash
89
+ cp node_modules/bimatter-viewer-react/public/ifc-parser.wasm public/ifc-parser.wasm
90
+ ```
92
91
 
93
92
  After that, IFC models can be loaded the same way as BMT models:
94
93
 
@@ -140,45 +139,61 @@ await loader.loadModel(["/models/model.bmt", "/models/model.ifc"]);
140
139
  await loader.loadModel(files);
141
140
  ```
142
141
 
143
- # Viewer API
144
-
145
- Use `ref` to call viewer actions:
142
+ ## File Upload Example
146
143
 
147
144
  ```tsx
148
- import { useRef } from "react";
149
- import { Viewer, type ViewerApi } from "bimatter-viewer-react";
145
+ import { useState } from "react";
146
+ import { Viewer, loader, type ViewerLoadedModels } from "bimatter-viewer-react";
150
147
 
151
148
  function App() {
152
- const viewerRef = useRef<ViewerApi>(null);
149
+ const [modelsData, setModelsData] = useState<ViewerLoadedModels>();
150
+
151
+ async function onFilesChange(files: FileList | null) {
152
+ if (!files?.length) return;
153
+ setModelsData(await loader.loadModel(Array.from(files)));
154
+ }
153
155
 
154
156
  return (
155
157
  <>
156
- <button onClick={() => viewerRef.current?.camera.fitCamera()}>
157
- Fit
158
- </button>
159
- <button
160
- onClick={() => viewerRef.current?.geometryUtils.hideSelected()}
161
- >
162
- Hide selected
163
- </button>
164
- <button
165
- onClick={() =>
166
- viewerRef.current?.geometryUtils.isolateSelected()
167
- }
168
- >
169
- Isolate selected
170
- </button>
171
- <button onClick={() => viewerRef.current?.geometryUtils.showAll()}>
172
- Show all
173
- </button>
174
-
175
- <Viewer ref={viewerRef} modelUrls={["/models/model.bmt"]} />
158
+ <input
159
+ accept=".bmt,.ifc"
160
+ multiple
161
+ type="file"
162
+ onChange={(event) => onFilesChange(event.target.files)}
163
+ />
164
+ {modelsData && <Viewer modelsData={modelsData} />}
176
165
  </>
177
166
  );
178
167
  }
179
168
  ```
180
169
 
181
- ## Available API groups:
170
+ ## HotKeys
171
+
172
+ ### Selection
173
+
174
+ `Left Click` - Select element
175
+
176
+ `Shift + Left Click` - Multi-select element
177
+
178
+ `Ctrl + Left Click` - Unselect element
179
+
180
+ `Shift + Drag Right` - Select elements fully inside rectangle
181
+
182
+ `Shift + Drag Left` - Select elements intersected by rectangle
183
+
184
+ `Ctrl + Drag Right` - Unselect elements fully inside rectangle
185
+
186
+ `Ctrl + Drag Left` - Unselect elements intersected by rectangle
187
+
188
+ ### Visibility
189
+
190
+ `C` - Clear hidden / isolated elements
191
+
192
+ `H` - Hide selected elements
193
+
194
+ `I` - Isolate selected elements
195
+
196
+ # Viewer API:
182
197
 
183
198
  ```ts
184
199
  viewerRef.current?.camera.fitCamera();
@@ -214,29 +229,39 @@ viewerRef.current?.utils.setGridAxesVisibility({ top: false, bottom: true });
214
229
  viewerRef.current?.utils.setGridAxisVisibility("left", false);
215
230
  ```
216
231
 
217
- ## File Upload Example
232
+ ## Geometry Utils
233
+
234
+ Use `ref` to call viewer actions:
218
235
 
219
236
  ```tsx
220
- import { useState } from "react";
221
- import { Viewer, loader, type ViewerLoadedModels } from "bimatter-viewer-react";
237
+ import { useRef } from "react";
238
+ import { Viewer, type ViewerApi } from "bimatter-viewer-react";
222
239
 
223
240
  function App() {
224
- const [modelsData, setModelsData] = useState<ViewerLoadedModels>();
225
-
226
- async function onFilesChange(files: FileList | null) {
227
- if (!files?.length) return;
228
- setModelsData(await loader.loadModel(Array.from(files)));
229
- }
241
+ const viewerRef = useRef<ViewerApi>(null);
230
242
 
231
243
  return (
232
244
  <>
233
- <input
234
- accept=".bmt,.ifc"
235
- multiple
236
- type="file"
237
- onChange={(event) => onFilesChange(event.target.files)}
238
- />
239
- {modelsData && <Viewer modelsData={modelsData} />}
245
+ <button onClick={() => viewerRef.current?.camera.fitCamera()}>
246
+ Fit
247
+ </button>
248
+ <button
249
+ onClick={() => viewerRef.current?.geometryUtils.hideSelected()}
250
+ >
251
+ Hide selected
252
+ </button>
253
+ <button
254
+ onClick={() =>
255
+ viewerRef.current?.geometryUtils.isolateSelected()
256
+ }
257
+ >
258
+ Isolate selected
259
+ </button>
260
+ <button onClick={() => viewerRef.current?.geometryUtils.showAll()}>
261
+ Show all
262
+ </button>
263
+
264
+ <Viewer ref={viewerRef} modelUrls={["/models/model.bmt"]} />
240
265
  </>
241
266
  );
242
267
  }
@@ -315,29 +340,3 @@ viewerRef.current?.utils.setGridAxesVisibility({
315
340
  top: false,
316
341
  });
317
342
  ```
318
-
319
- ## HotKeys
320
-
321
- ### Selection
322
-
323
- `Left Click` - Select element
324
-
325
- `Shift + Left Click` - Multi-select element
326
-
327
- `Ctrl + Left Click` - Unselect element
328
-
329
- `Shift + Drag Right` - Select elements fully inside rectangle
330
-
331
- `Shift + Drag Left` - Select elements intersected by rectangle
332
-
333
- `Ctrl + Drag Right` - Unselect elements fully inside rectangle
334
-
335
- `Ctrl + Drag Left` - Unselect elements intersected by rectangle
336
-
337
- ### Visibility
338
-
339
- `C` - Clear hidden / isolated elements
340
-
341
- `H` - Hide selected elements
342
-
343
- `I` - Isolate selected elements
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bimatter-viewer-react",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "license": "PolyForm-Noncommercial-1.0.0",
5
5
  "type": "module",
6
6
  "main": "./lib/index.js",
@@ -10,10 +10,12 @@
10
10
  ".": {
11
11
  "types": "./lib/index.d.ts",
12
12
  "import": "./lib/index.js"
13
- }
13
+ },
14
+ "./ifc-parser.wasm": "./public/ifc-parser.wasm"
14
15
  },
15
16
  "files": [
16
- "lib"
17
+ "lib",
18
+ "public/ifc-parser.wasm"
17
19
  ],
18
20
  "scripts": {
19
21
  "dev": "vite",
Binary file