bimatter-viewer-react 0.0.1 → 0.0.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.
Files changed (2) hide show
  1. package/README.md +227 -60
  2. package/package.json +6 -6
package/README.md CHANGED
@@ -1,73 +1,240 @@
1
- # React + TypeScript + Vite
1
+ # bimatter-viewer-react
2
2
 
3
- This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
3
+ React viewer for Bimatter `.bmt` model.
4
4
 
5
- Currently, two official plugins are available:
5
+ All about us you can see on our website [Bimatter](https://bimatter.ru/)
6
6
 
7
- - [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react) uses [Oxc](https://oxc.rs)
8
- - [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react-swc) uses [SWC](https://swc.rs/)
7
+ Vanila js viewer core: [bimatter-viewer](https://www.npmjs.com/package/bimatter-viewer?activeTab=code)
9
8
 
10
- ## React Compiler
9
+ Write your issuse here: [GitHub](https://github.com/rkaeplive/bimatter-viewer/issues)
11
10
 
12
- The React Compiler is not enabled on this template because of its impact on dev & build performances. To add it, see [this documentation](https://react.dev/learn/react-compiler/installation).
11
+ ## Create A New React + Vite + TypeScript Project
13
12
 
14
- ## Expanding the ESLint configuration
13
+ ```bash
14
+ npm create vite@latest bimatter-viewer-demo -- --template react-ts
15
+ cd bimatter-viewer-demo
16
+ npm install
17
+ ```
18
+
19
+ Install the viewer:
20
+
21
+ ```bash
22
+ npm install bimatter-viewer-react
23
+ ```
24
+
25
+ `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`.
26
+
27
+ ## Basic Usage
28
+
29
+ Put your `.bmt` files in `public/models`:
30
+
31
+ ```text
32
+ public/
33
+ models/
34
+ architecture.bmt
35
+ structure.bmt
36
+ ```
37
+
38
+ Then replace `src/App.tsx`:
39
+
40
+ ```tsx
41
+ import { Viewer } from "bimatter-viewer-react";
42
+
43
+ function App() {
44
+ return (
45
+ <Viewer
46
+ modelUrls={["/models/architecture.bmt", "/models/structure.bmt"]}
47
+ />
48
+ );
49
+ }
50
+
51
+ export default App;
52
+ ```
53
+
54
+ Replace `src/index.css` or add global sizing:
55
+
56
+ ```css
57
+ html,
58
+ body,
59
+ #root {
60
+ height: 100%;
61
+ margin: 0;
62
+ }
63
+ ```
64
+
65
+ Run the app:
66
+
67
+ ```bash
68
+ npm run dev
69
+ ```
70
+
71
+ ## Loader API
72
+
73
+ You can load models yourself and pass parsed data to the viewer:
74
+
75
+ ```tsx
76
+ import { useEffect, useState } from "react";
77
+ import { loader, Viewer, type ViewerLoadedModels } from "bimatter-viewer-react";
78
+
79
+ function App() {
80
+ const [modelsData, setModelsData] = useState<ViewerLoadedModels>();
81
+
82
+ useEffect(() => {
83
+ loader
84
+ .loadModel(["/models/architecture.bmt", "/models/structure.bmt"])
85
+ .then(setModelsData);
86
+ }, []);
87
+
88
+ if (!modelsData) return null;
89
+
90
+ return <Viewer modelsData={modelsData} />;
91
+ }
92
+ ```
93
+
94
+ `loader.loadModel` accepts paths or browser `File` objects:
95
+
96
+ ```ts
97
+ await loader.loadModel(["/models/model.bmt"]);
98
+ await loader.loadModel(files);
99
+ ```
15
100
 
16
- If you are developing a production application, we recommend updating the configuration to enable type-aware lint rules:
101
+ `.ifc` files are recognized but not parsed yet.
17
102
 
18
- ```js
19
- export default defineConfig([
20
- globalIgnores(['dist']),
21
- {
22
- files: ['**/*.{ts,tsx}'],
23
- extends: [
24
- // Other configs...
103
+ ## Viewer API
25
104
 
26
- // Remove tseslint.configs.recommended and replace with this
27
- tseslint.configs.recommendedTypeChecked,
28
- // Alternatively, use this for stricter rules
29
- tseslint.configs.strictTypeChecked,
30
- // Optionally, add this for stylistic rules
31
- tseslint.configs.stylisticTypeChecked,
105
+ Use `ref` to call viewer actions:
32
106
 
33
- // Other configs...
34
- ],
35
- languageOptions: {
36
- parserOptions: {
37
- project: ['./tsconfig.node.json', './tsconfig.app.json'],
38
- tsconfigRootDir: import.meta.dirname,
39
- },
40
- // other options...
41
- },
42
- },
43
- ])
107
+ ```tsx
108
+ import { useRef } from "react";
109
+ import { Viewer, type ViewerApi } from "bimatter-viewer-react";
110
+
111
+ function App() {
112
+ const viewerRef = useRef<ViewerApi>(null);
113
+
114
+ return (
115
+ <>
116
+ <button onClick={() => viewerRef.current?.camera.fitCamera()}>
117
+ Fit
118
+ </button>
119
+ <button
120
+ onClick={() => viewerRef.current?.geometryUtils.hideSelected()}
121
+ >
122
+ Hide selected
123
+ </button>
124
+ <button
125
+ onClick={() =>
126
+ viewerRef.current?.geometryUtils.isolateSelected()
127
+ }
128
+ >
129
+ Isolate selected
130
+ </button>
131
+ <button onClick={() => viewerRef.current?.geometryUtils.showAll()}>
132
+ Show all
133
+ </button>
134
+
135
+ <Viewer ref={viewerRef} modelUrls={["/models/model.bmt"]} />
136
+ </>
137
+ );
138
+ }
139
+ ```
140
+
141
+ Available API groups:
142
+
143
+ ```ts
144
+ viewerRef.current?.camera.fitCamera();
145
+
146
+ viewerRef.current?.geometryUtils.showAll();
147
+ viewerRef.current?.geometryUtils.showByIds([1, 2, 3]);
148
+ viewerRef.current?.geometryUtils.hideByIds([1, 2, 3]);
149
+ viewerRef.current?.geometryUtils.hideSelected();
150
+ viewerRef.current?.geometryUtils.isolateByIds([1, 2, 3]);
151
+ viewerRef.current?.geometryUtils.isolateSelected();
152
+ viewerRef.current?.geometryUtils.resetIsolation();
153
+ viewerRef.current?.geometryUtils.getAllIds();
154
+
155
+ viewerRef.current?.selector.setSelected(0, [10, 20], true);
156
+ viewerRef.current?.selector.addSelected(0, [30]);
157
+ viewerRef.current?.selector.removeSelected(0, [10]);
158
+ viewerRef.current?.selector.resetSelection();
159
+ viewerRef.current?.selector.getSelected();
160
+
161
+ viewerRef.current?.utils.getUserDevice();
162
+ viewerRef.current?.utils.getShowStats();
163
+ viewerRef.current?.utils.setShowStats(true);
164
+ ```
165
+
166
+ ## Controlled Selection
167
+
168
+ Selection can be controlled by your app state, including Zustand, Redux, or local React state.
169
+
170
+ ```tsx
171
+ import { useState } from "react";
172
+ import { Viewer, type ViewerSelection } from "bimatter-viewer-react";
173
+
174
+ function App() {
175
+ const [selected, setSelected] = useState<ViewerSelection>({});
176
+
177
+ return (
178
+ <Viewer
179
+ modelUrls={["/models/model.bmt"]}
180
+ selected={selected}
181
+ onSelectedChange={setSelected}
182
+ />
183
+ );
184
+ }
44
185
  ```
45
186
 
46
- You can also install [eslint-plugin-react-x](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-x) and [eslint-plugin-react-dom](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-dom) for React-specific lint rules:
47
-
48
- ```js
49
- // eslint.config.js
50
- import reactX from 'eslint-plugin-react-x'
51
- import reactDom from 'eslint-plugin-react-dom'
52
-
53
- export default defineConfig([
54
- globalIgnores(['dist']),
55
- {
56
- files: ['**/*.{ts,tsx}'],
57
- extends: [
58
- // Other configs...
59
- // Enable lint rules for React
60
- reactX.configs['recommended-typescript'],
61
- // Enable lint rules for React DOM
62
- reactDom.configs.recommended,
63
- ],
64
- languageOptions: {
65
- parserOptions: {
66
- project: ['./tsconfig.node.json', './tsconfig.app.json'],
67
- tsconfigRootDir: import.meta.dirname,
68
- },
69
- // other options...
70
- },
71
- },
72
- ])
187
+ Selection format:
188
+
189
+ ```ts
190
+ const selected = {
191
+ 0: [101, 102],
192
+ 1: [205],
193
+ };
194
+ ```
195
+
196
+ The key is `modelID`; the value is an array of element ids.
197
+
198
+ ## Stats And Profiling
199
+
200
+ Enable FPS stats and console timing logs:
201
+
202
+ ```tsx
203
+ <Viewer modelUrls={["/models/model.bmt"]} showStats />
204
+ ```
205
+
206
+ Or via API:
207
+
208
+ ```ts
209
+ viewerRef.current?.utils.setShowStats(true);
210
+ ```
211
+
212
+ When enabled, the viewer logs timing for selection, hide, isolate, show, and reset actions.
213
+
214
+ ## File Upload Example
215
+
216
+ ```tsx
217
+ import { useState } from "react";
218
+ import { Viewer, loader, type ViewerLoadedModels } from "bimatter-viewer-react";
219
+
220
+ function App() {
221
+ const [modelsData, setModelsData] = useState<ViewerLoadedModels>();
222
+
223
+ async function onFilesChange(files: FileList | null) {
224
+ if (!files?.length) return;
225
+ setModelsData(await loader.loadModel(Array.from(files)));
226
+ }
227
+
228
+ return (
229
+ <>
230
+ <input
231
+ accept=".bmt,.ifc"
232
+ multiple
233
+ type="file"
234
+ onChange={(event) => onFilesChange(event.target.files)}
235
+ />
236
+ {modelsData && <Viewer modelsData={modelsData} />}
237
+ </>
238
+ );
239
+ }
73
240
  ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bimatter-viewer-react",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
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",