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.
Files changed (2) hide show
  1. package/README.md +246 -72
  2. package/package.json +6 -6
package/README.md CHANGED
@@ -1,73 +1,247 @@
1
- # React + TypeScript + Vite
2
-
3
- This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
4
-
5
- Currently, two official plugins are available:
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/)
9
-
10
- ## React Compiler
11
-
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).
13
-
14
- ## Expanding the ESLint configuration
15
-
16
- If you are developing a production application, we recommend updating the configuration to enable type-aware lint rules:
17
-
18
- ```js
19
- export default defineConfig([
20
- globalIgnores(['dist']),
21
- {
22
- files: ['**/*.{ts,tsx}'],
23
- extends: [
24
- // Other configs...
25
-
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,
32
-
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
- ])
44
- ```
45
-
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
- ])
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.1",
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",