bimatter-viewer-react 0.1.3 → 0.2.0

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
@@ -175,7 +175,7 @@ function App() {
175
175
 
176
176
  `Shift + Left Click` - Multi-select element
177
177
 
178
- `Ctrl + Left Click` - Unselect element
178
+ `Ctrl + Left Click` - Toggle element selection
179
179
 
180
180
  `Shift + Drag Right` - Select elements fully inside rectangle
181
181
 
@@ -193,7 +193,7 @@ function App() {
193
193
 
194
194
  `I` - Isolate selected elements
195
195
 
196
- # Viewer API:
196
+ ## Viewer API
197
197
 
198
198
  ```ts
199
199
  viewerRef.current?.camera.fitCamera();
@@ -213,6 +213,11 @@ viewerRef.current?.selector.removeSelected(0, [10]);
213
213
  viewerRef.current?.selector.resetSelection();
214
214
  viewerRef.current?.selector.getSelected();
215
215
 
216
+ viewerRef.current?.colors.setColor(0, [10, 20], "#ff3355");
217
+ viewerRef.current?.colors.clearColor(0, [10]);
218
+ viewerRef.current?.colors.clearModelColors(0);
219
+ viewerRef.current?.colors.clearAllColors();
220
+
216
221
  viewerRef.current?.properties.getModelProps();
217
222
  viewerRef.current?.properties.getModelStructure();
218
223
  viewerRef.current?.utils.getUserDevice();
@@ -267,6 +272,54 @@ function App() {
267
272
  }
268
273
  ```
269
274
 
275
+ ## Colorize Elements
276
+
277
+ Use `viewerRef.current.colors` to apply temporary color overrides to model elements. The color is applied by `modelID` and element ids:
278
+
279
+ ```tsx
280
+ viewerRef.current?.colors.setColor(0, [10, 20, 30], "#ff3355");
281
+ viewerRef.current?.colors.clearColor(0, [10, 20]);
282
+ viewerRef.current?.colors.clearModelColors(0);
283
+ viewerRef.current?.colors.clearAllColors();
284
+ ```
285
+
286
+ Example with current selection:
287
+
288
+ ```tsx
289
+ import { useRef, useState } from "react";
290
+ import {
291
+ Viewer,
292
+ type ViewerApi,
293
+ type ViewerSelection,
294
+ } from "bimatter-viewer-react";
295
+
296
+ function App() {
297
+ const viewerRef = useRef<ViewerApi>(null);
298
+ const [selected, setSelected] = useState<ViewerSelection>({});
299
+
300
+ function colorizeSelected() {
301
+ Object.entries(selected).forEach(([modelID, ids]) => {
302
+ viewerRef.current?.colors.setColor(Number(modelID), ids, "#ff3355");
303
+ });
304
+ }
305
+
306
+ return (
307
+ <>
308
+ <button onClick={colorizeSelected}>Colorize selected</button>
309
+ <button onClick={() => viewerRef.current?.colors.clearAllColors()}>
310
+ Clear colors
311
+ </button>
312
+ <Viewer
313
+ ref={viewerRef}
314
+ modelUrls={["/models/model.bmt"]}
315
+ selected={selected}
316
+ onSelectedChange={setSelected}
317
+ />
318
+ </>
319
+ );
320
+ }
321
+ ```
322
+
270
323
  ## Controlled Selection
271
324
 
272
325
  Selection can be controlled by your app state, including Zustand, Redux, or local React state.
@@ -0,0 +1,15 @@
1
+ import { DataTexture, type ColorRepresentation } from "three";
2
+ import type { GeometryIndexApi } from "../GeometryUtils/useGeometryIndex";
3
+ export declare const MAX_ELEMENT_COLOR_PALETTE_SIZE = 256;
4
+ export type ViewerElementColorsApi = {
5
+ applyStoredColors: () => void;
6
+ clearAllColors: () => void;
7
+ clearColor: (modelID: number, ids: number[]) => void;
8
+ clearModelColors: (modelID: number) => void;
9
+ setColor: (modelID: number, ids: number[], color: ColorRepresentation) => void;
10
+ };
11
+ export type ViewerElementColors = {
12
+ colorPaletteTexture: DataTexture;
13
+ colorUtils: ViewerElementColorsApi;
14
+ };
15
+ export declare function useElementColors(geometryIndex: GeometryIndexApi): ViewerElementColors;
@@ -31,5 +31,6 @@ export type GeometryIndex = {
31
31
  };
32
32
  export type GeometryIndexApi = {
33
33
  buildIndex: () => GeometryIndex;
34
+ resetIndex: () => void;
34
35
  };
35
36
  export default function useGeometryIndex(modelRef: ViewerModelRef): GeometryIndexApi;
package/lib/Model.d.ts CHANGED
@@ -1,10 +1,14 @@
1
1
  import type { BmtModelData } from "./Loaders/BmtLoader";
2
- import { Matrix4 } from "three";
2
+ import { Matrix4, type DataTexture } from "three";
3
3
  type ModelProps = {
4
+ colorPaletteTexture: DataTexture;
4
5
  coordinationMatrix?: Matrix4 | null;
5
6
  modelID: number;
6
7
  data: BmtModelData;
7
8
  };
9
+ export declare function parseModelMatrix(matrix?: string): Matrix4 | null;
8
10
  export declare function getModelCoordinationMatrix(data: BmtModelData): Matrix4 | null;
9
- declare function Model({ coordinationMatrix, modelID, data }: ModelProps): import("react/jsx-runtime").JSX.Element;
10
- export default Model;
11
+ export declare function getModelCoordinationMatrixSource(data: BmtModelData): string | undefined;
12
+ declare function Model({ colorPaletteTexture, coordinationMatrix, modelID, data, }: ModelProps): import("react/jsx-runtime").JSX.Element;
13
+ declare const _default: import("react").MemoExoticComponent<typeof Model>;
14
+ export default _default;
@@ -1,10 +1,11 @@
1
1
  import React from "react";
2
- import { Matrix4 } from "three";
2
+ import { Matrix4, type DataTexture } from "three";
3
3
  import type { BmtGeomData, BmtMaterialData } from "./Loaders/BmtLoader";
4
4
  type SelectableMeshProps = {
5
+ colorPaletteTexture: DataTexture;
5
6
  data: BmtGeomData;
6
7
  material: BmtMaterialData;
7
8
  meshMatrix: Matrix4;
8
9
  };
9
- export declare const SelectableMesh: React.MemoExoticComponent<({ material, data, meshMatrix, }: SelectableMeshProps) => import("react/jsx-runtime").JSX.Element>;
10
+ export declare const SelectableMesh: React.MemoExoticComponent<({ colorPaletteTexture, material, data, meshMatrix, }: SelectableMeshProps) => import("react/jsx-runtime").JSX.Element>;
10
11
  export {};
@@ -1,3 +1,4 @@
1
+ import type { ColorRepresentation } from "three";
1
2
  import type { SelectedStore, UserDevice, ViewerGridAxesVisibility, ViewerGridAxisSide, ViewerStoreApi } from "../store/ViewerStore";
2
3
  import { type ViewerPropertiesApi } from "./ViewerPropertiesApi";
3
4
  export type ViewerSelection = Record<number, number[]>;
@@ -18,6 +19,12 @@ export type ViewerSelectorApi = {
18
19
  resetSelection: (modelID?: number) => void;
19
20
  setSelected: (modelID: number, ids: number[], reset?: boolean) => void;
20
21
  };
22
+ export type ViewerColorsApi = {
23
+ clearAllColors: () => void;
24
+ clearColor: (modelID: number, ids: number[]) => void;
25
+ clearModelColors: (modelID: number) => void;
26
+ setColor: (modelID: number, ids: number[], color: ColorRepresentation) => void;
27
+ };
21
28
  export type ViewerUtilsApi = {
22
29
  getGridAxesVisibility: () => ViewerGridAxesVisibility;
23
30
  getShowNavCube: () => boolean;
@@ -37,6 +44,7 @@ export type ViewerCameraApi = {
37
44
  };
38
45
  export type ViewerApi = {
39
46
  camera: ViewerCameraApi;
47
+ colors: ViewerColorsApi;
40
48
  geometryUtils: ViewerGeometryUtilsApi;
41
49
  properties: ViewerPropertiesApi;
42
50
  selector: ViewerSelectorApi;
@@ -44,6 +52,7 @@ export type ViewerApi = {
44
52
  };
45
53
  export type ViewerSceneApi = {
46
54
  camera: ViewerCameraApi;
55
+ colors: ViewerColorsApi;
47
56
  geometryUtils: ViewerGeometryUtilsApi;
48
57
  };
49
58
  export declare function serializeSelected(selected: SelectedStore): ViewerSelection;
@@ -5,10 +5,13 @@ declare class ViewerLoaderApi {
5
5
  coordinationMatrix: string | undefined;
6
6
  private bmtLoader;
7
7
  private ifcLoader;
8
+ private loadedModelCount;
9
+ private nextModelID;
8
10
  private initLoaders;
9
11
  private getBmtLoader;
10
12
  private getIfcLoader;
11
13
  private loadBmtModel;
14
+ private resetCoordinationMatrixState;
12
15
  resetCoordinationMatrix(): void;
13
16
  loadModel(sources: ViewerModelSource | ViewerModelSource[]): Promise<ViewerLoadedModels>;
14
17
  }
package/lib/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  export { default as Viewer } from "./Viewer";
2
2
  export type { ViewerModelsData, ViewerProps } from "./Viewer";
3
- export type { ViewerApi, ViewerCameraApi, ViewerGeometryUtilsApi, ViewerSelection, ViewerSelectorApi, ViewerUtilsApi, } from "./api/ViewerApi";
3
+ export type { ViewerApi, ViewerCameraApi, ViewerColorsApi, ViewerGeometryUtilsApi, ViewerSelection, ViewerSelectorApi, ViewerUtilsApi, } from "./api/ViewerApi";
4
4
  export type { ViewerPropertiesApi } from "./api/ViewerPropertiesApi";
5
5
  export { BMTLoader } from "./Loaders/BmtLoader";
6
6
  export type { BmtModelGeometryData, BmtGeomData, BmtIndexArray, BmtMaterialData, BmtElementProps, BmtModelData, BmtModelProps, BmtModelStructure, BmtModelStructureNode, BmtPropertyRecord, BmtPropertySet, BmtPropertyValue, } from "./Loaders/BmtLoader";