bimatter-viewer-react 0.0.1 → 0.0.2
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 +246 -72
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -1,73 +1,247 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
## React
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
1
|
+
# bimatter-viewer-react
|
|
2
|
+
|
|
3
|
+
React viewer for Bimatter `.bmt` model.
|
|
4
|
+
|
|
5
|
+
All about us you can see on our website [Bimatter](https://bimatter.ru/)
|
|
6
|
+
|
|
7
|
+
Vanila js viewer core: [bimatter-viewer](https://www.npmjs.com/package/bimatter-viewer?activeTab=code)
|
|
8
|
+
Write your issuse here: [GitHub](https://github.com/rkaeplive/bimatter-viewer/issues)
|
|
9
|
+
|
|
10
|
+
## Create A New React + Vite + TypeScript Project
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npm create vite@latest bimatter-viewer-demo -- --template react-ts
|
|
14
|
+
cd bimatter-viewer-demo
|
|
15
|
+
npm install
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Install the viewer:
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
npm install bimatter-viewer-react
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
`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`.
|
|
25
|
+
|
|
26
|
+
## Basic Usage
|
|
27
|
+
|
|
28
|
+
Put your `.bmt` files in `public/models`:
|
|
29
|
+
|
|
30
|
+
```text
|
|
31
|
+
public/
|
|
32
|
+
models/
|
|
33
|
+
architecture.bmt
|
|
34
|
+
structure.bmt
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Then replace `src/App.tsx`:
|
|
38
|
+
|
|
39
|
+
```tsx
|
|
40
|
+
import { Viewer } from "bimatter-viewer-react";
|
|
41
|
+
|
|
42
|
+
function App() {
|
|
43
|
+
return (
|
|
44
|
+
<Viewer
|
|
45
|
+
modelUrls={["/models/architecture.bmt", "/models/structure.bmt"]}
|
|
46
|
+
/>
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export default App;
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Replace `src/index.css` or add global sizing:
|
|
54
|
+
|
|
55
|
+
```css
|
|
56
|
+
html,
|
|
57
|
+
body,
|
|
58
|
+
#root {
|
|
59
|
+
height: 100%;
|
|
60
|
+
margin: 0;
|
|
61
|
+
}
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Run the app:
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
npm run dev
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## Loader API
|
|
71
|
+
|
|
72
|
+
You can load models yourself and pass parsed data to the viewer:
|
|
73
|
+
|
|
74
|
+
```tsx
|
|
75
|
+
import { useEffect, useState } from "react";
|
|
76
|
+
import { loader, Viewer, type ViewerLoadedModels } from "bimatter-viewer-react";
|
|
77
|
+
|
|
78
|
+
function App() {
|
|
79
|
+
const [modelsData, setModelsData] = useState<ViewerLoadedModels>();
|
|
80
|
+
|
|
81
|
+
useEffect(() => {
|
|
82
|
+
loader
|
|
83
|
+
.loadModel(["/models/architecture.bmt", "/models/structure.bmt"])
|
|
84
|
+
.then(setModelsData);
|
|
85
|
+
}, []);
|
|
86
|
+
|
|
87
|
+
if (!modelsData) return null;
|
|
88
|
+
|
|
89
|
+
return <Viewer modelsData={modelsData} />;
|
|
90
|
+
}
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
`loader.loadModel` accepts paths or browser `File` objects:
|
|
94
|
+
|
|
95
|
+
```ts
|
|
96
|
+
await loader.loadModel(["/models/model.bmt"]);
|
|
97
|
+
await loader.loadModel(files);
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
`.ifc` files are recognized but not parsed yet.
|
|
101
|
+
|
|
102
|
+
## Viewer API
|
|
103
|
+
|
|
104
|
+
Use `ref` to call viewer actions:
|
|
105
|
+
|
|
106
|
+
```tsx
|
|
107
|
+
import { useRef } from "react";
|
|
108
|
+
import { Viewer, type ViewerApi } from "bimatter-viewer-react";
|
|
109
|
+
|
|
110
|
+
function App() {
|
|
111
|
+
const viewerRef = useRef<ViewerApi>(null);
|
|
112
|
+
|
|
113
|
+
return (
|
|
114
|
+
<>
|
|
115
|
+
<button onClick={() => viewerRef.current?.camera.fitCamera()}>
|
|
116
|
+
Fit
|
|
117
|
+
</button>
|
|
118
|
+
<button
|
|
119
|
+
onClick={() => viewerRef.current?.geometryUtils.hideSelected()}
|
|
120
|
+
>
|
|
121
|
+
Hide selected
|
|
122
|
+
</button>
|
|
123
|
+
<button
|
|
124
|
+
onClick={() =>
|
|
125
|
+
viewerRef.current?.geometryUtils.isolateSelected()
|
|
126
|
+
}
|
|
127
|
+
>
|
|
128
|
+
Isolate selected
|
|
129
|
+
</button>
|
|
130
|
+
<button onClick={() => viewerRef.current?.geometryUtils.showAll()}>
|
|
131
|
+
Show all
|
|
132
|
+
</button>
|
|
133
|
+
|
|
134
|
+
<Viewer ref={viewerRef} modelUrls={["/models/model.bmt"]} />
|
|
135
|
+
</>
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
Available API groups:
|
|
141
|
+
|
|
142
|
+
```ts
|
|
143
|
+
viewerRef.current?.camera.fitCamera();
|
|
144
|
+
|
|
145
|
+
viewerRef.current?.geometryUtils.showAll();
|
|
146
|
+
viewerRef.current?.geometryUtils.showByIds([1, 2, 3]);
|
|
147
|
+
viewerRef.current?.geometryUtils.hideByIds([1, 2, 3]);
|
|
148
|
+
viewerRef.current?.geometryUtils.hideSelected();
|
|
149
|
+
viewerRef.current?.geometryUtils.isolateByIds([1, 2, 3]);
|
|
150
|
+
viewerRef.current?.geometryUtils.isolateSelected();
|
|
151
|
+
viewerRef.current?.geometryUtils.resetIsolation();
|
|
152
|
+
viewerRef.current?.geometryUtils.getAllIds();
|
|
153
|
+
|
|
154
|
+
viewerRef.current?.selector.setSelected(0, [10, 20], true);
|
|
155
|
+
viewerRef.current?.selector.addSelected(0, [30]);
|
|
156
|
+
viewerRef.current?.selector.removeSelected(0, [10]);
|
|
157
|
+
viewerRef.current?.selector.resetSelection();
|
|
158
|
+
viewerRef.current?.selector.getSelected();
|
|
159
|
+
|
|
160
|
+
viewerRef.current?.utils.getUserDevice();
|
|
161
|
+
viewerRef.current?.utils.getShowStats();
|
|
162
|
+
viewerRef.current?.utils.setShowStats(true);
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
## Controlled Selection
|
|
166
|
+
|
|
167
|
+
Selection can be controlled by your app state, including Zustand, Redux, or local React state.
|
|
168
|
+
|
|
169
|
+
```tsx
|
|
170
|
+
import { useState } from "react";
|
|
171
|
+
import { Viewer, type ViewerSelection } from "bimatter-viewer-react";
|
|
172
|
+
|
|
173
|
+
function App() {
|
|
174
|
+
const [selected, setSelected] = useState<ViewerSelection>({});
|
|
175
|
+
|
|
176
|
+
return (
|
|
177
|
+
<Viewer
|
|
178
|
+
modelUrls={["/models/model.bmt"]}
|
|
179
|
+
selected={selected}
|
|
180
|
+
onSelectedChange={setSelected}
|
|
181
|
+
/>
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
Selection format:
|
|
187
|
+
|
|
188
|
+
```ts
|
|
189
|
+
const selected = {
|
|
190
|
+
0: [101, 102],
|
|
191
|
+
1: [205],
|
|
192
|
+
};
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
The key is `modelID`; the value is an array of element ids.
|
|
196
|
+
|
|
197
|
+
## Stats And Profiling
|
|
198
|
+
|
|
199
|
+
Enable FPS stats and console timing logs:
|
|
200
|
+
|
|
201
|
+
```tsx
|
|
202
|
+
<Viewer modelUrls={["/models/model.bmt"]} showStats />
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
Or via API:
|
|
206
|
+
|
|
207
|
+
```ts
|
|
208
|
+
viewerRef.current?.utils.setShowStats(true);
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
When enabled, the viewer logs timing for selection, hide, isolate, show, and reset actions.
|
|
212
|
+
|
|
213
|
+
## File Upload Example
|
|
214
|
+
|
|
215
|
+
```tsx
|
|
216
|
+
import { useState } from "react";
|
|
217
|
+
import { Viewer, loader, type ViewerLoadedModels } from "bimatter-viewer-react";
|
|
218
|
+
|
|
219
|
+
function App() {
|
|
220
|
+
const [modelsData, setModelsData] = useState<ViewerLoadedModels>();
|
|
221
|
+
|
|
222
|
+
async function onFilesChange(files: FileList | null) {
|
|
223
|
+
if (!files?.length) return;
|
|
224
|
+
setModelsData(await loader.loadModel(Array.from(files)));
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
return (
|
|
228
|
+
<>
|
|
229
|
+
<input
|
|
230
|
+
accept=".bmt,.ifc"
|
|
231
|
+
multiple
|
|
232
|
+
type="file"
|
|
233
|
+
onChange={(event) => onFilesChange(event.target.files)}
|
|
234
|
+
/>
|
|
235
|
+
{modelsData && <Viewer modelsData={modelsData} />}
|
|
236
|
+
</>
|
|
237
|
+
);
|
|
238
|
+
}
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
## Publish
|
|
242
|
+
|
|
243
|
+
```bash
|
|
244
|
+
npm run build:lib
|
|
245
|
+
npm pack --dry-run
|
|
246
|
+
npm publish
|
|
73
247
|
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bimatter-viewer-react",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"module": "./lib/index.js",
|
|
@@ -23,16 +23,16 @@
|
|
|
23
23
|
"preview": "vite preview"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
+
"@react-three/drei": "^10.7.7",
|
|
27
|
+
"@react-three/fiber": "^9.6.1",
|
|
26
28
|
"pako": "^2.1.0",
|
|
29
|
+
"three": "^0.184.0",
|
|
30
|
+
"three-mesh-bvh": "^0.9.9",
|
|
27
31
|
"zustand": "^5.0.13"
|
|
28
32
|
},
|
|
29
33
|
"peerDependencies": {
|
|
30
|
-
"@react-three/drei": "^10.7.7",
|
|
31
|
-
"@react-three/fiber": "^9.6.1",
|
|
32
34
|
"react": "^19.2.5",
|
|
33
|
-
"react-dom": "^19.2.5"
|
|
34
|
-
"three": "^0.184.0",
|
|
35
|
-
"three-mesh-bvh": "^0.9.9"
|
|
35
|
+
"react-dom": "^19.2.5"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@react-three/drei": "^10.7.7",
|