bimatter-viewer-react 0.2.0 → 0.3.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.
@@ -1,5 +1,7 @@
1
1
  import { type StoreApi } from "zustand/vanilla";
2
+ import type { ColorRepresentation } from "three";
2
3
  import type { BmtModelProps, BmtModelStructure } from "../Loaders/BmtLoader";
4
+ import type { ViewerApi } from "../api/ViewerApi";
3
5
  export type UserDevice = "pc" | "mobile";
4
6
  export type ViewerGridAxisSide = "bottom" | "left" | "right" | "top";
5
7
  export type ViewerGridAxesVisibility = Record<ViewerGridAxisSide, boolean> & {
@@ -10,19 +12,31 @@ export interface SelectedStore {
10
12
  }
11
13
  export type ViewerModelPropsStore = Record<number, BmtModelProps>;
12
14
  export type ViewerModelStructureStore = Record<number, BmtModelStructure>;
15
+ export declare const DEFAULT_SELECTION_COLOR = "rgb(17, 148, 189)";
16
+ export declare const DEFAULT_PRESELECTION_COLOR = "rgb(104, 198, 227)";
13
17
  export type ViewerStore = {
18
+ api: ViewerApi | null;
19
+ defaultHotkeysEnabled: boolean;
14
20
  modelProps: ViewerModelPropsStore;
15
21
  modelStructure: ViewerModelStructureStore;
16
22
  gridAxesVisibility: ViewerGridAxesVisibility;
23
+ preselectionColor: ColorRepresentation;
17
24
  selected: SelectedStore;
25
+ selectionColor: ColorRepresentation;
26
+ selectionInteractionDisabled: boolean;
18
27
  showNavCube: boolean;
19
28
  showStats: boolean;
20
29
  userDevice: UserDevice;
30
+ setApi: (api: ViewerApi | null) => void;
31
+ setDefaultHotkeysEnabled: (enabled: boolean) => void;
21
32
  setGridAxesVisibility: (gridAxesVisibility: Partial<ViewerGridAxesVisibility>) => void;
22
33
  setGridAxisVisibility: (side: ViewerGridAxisSide, visible: boolean) => void;
23
34
  setShowGridAxes: (visible: boolean) => void;
24
35
  setModelProps: (modelProps: ViewerModelPropsStore) => void;
25
36
  setModelStructure: (modelStructure: ViewerModelStructureStore) => void;
37
+ setPreselectionColor: (color: ColorRepresentation) => void;
38
+ setSelectionColor: (color: ColorRepresentation) => void;
39
+ setSelectionInteractionDisabled: (disabled: boolean) => void;
26
40
  setShowNavCube: (showNavCube: boolean) => void;
27
41
  setShowStats: (showStats: boolean) => void;
28
42
  setSelection: (selected: SelectedStore) => void;
@@ -0,0 +1,23 @@
1
+ import { BufferGeometry, LineBasicMaterial, LineSegments, Plane } from "three";
2
+ import type { ClippingUtils } from "./ClippingUtils";
3
+ export declare class ClippingEdges {
4
+ active: boolean;
5
+ readonly material: LineBasicMaterial;
6
+ readonly plane: Plane;
7
+ private readonly context;
8
+ private readonly lines;
9
+ private readonly inverseMatrix;
10
+ private readonly localPlane;
11
+ private readonly tempLine;
12
+ private readonly tempVector;
13
+ private readonly tempVector1;
14
+ private readonly tempVector2;
15
+ private readonly tempVector3;
16
+ constructor(context: ClippingUtils, plane: Plane);
17
+ create(): LineSegments<BufferGeometry<import("three").NormalBufferAttributes, import("three").BufferGeometryEventMap>, import("three").Material<import("three").MaterialEventMap> | import("three").Material<import("three").MaterialEventMap>[], import("three").Object3DEventMap>[];
18
+ syncMeshes(): void;
19
+ dispose(): void;
20
+ setVisible(visible: boolean): void;
21
+ toggle(): void;
22
+ update(): void;
23
+ }
@@ -0,0 +1,87 @@
1
+ import { Camera, Material, Mesh, Plane, Raycaster, Scene, Vector3, WebGLRenderer } from "three";
2
+ import type { CameraUtilsApi } from "../../Camera/useCameraUtils";
3
+ import type { ViewerStoreApi } from "../../store/ViewerStore";
4
+ import type { ViewerControlsRef, ViewerModelRef } from "../../types";
5
+ import { ClippingEdges } from "./ClippingEdges";
6
+ import { PlaneHelper } from "./PlaneHelper";
7
+ type ClippingContext = {
8
+ camera: Camera;
9
+ cameraUtils: CameraUtilsApi;
10
+ controlRef: ViewerControlsRef;
11
+ domElement: HTMLCanvasElement;
12
+ modelRef: ViewerModelRef;
13
+ raycaster: Raycaster;
14
+ renderer: WebGLRenderer;
15
+ scene: Scene;
16
+ viewerStore: ViewerStoreApi;
17
+ };
18
+ export type ViewerClippingApi = {
19
+ createClippingRectangle: () => Plane[];
20
+ createPlane: (event?: MouseEvent | PointerEvent) => Plane | null;
21
+ deleteAllPlanes: () => void;
22
+ getEdgesActive: () => boolean;
23
+ getHelpersActive: () => boolean;
24
+ getPlanes: () => Plane[];
25
+ getActive: () => boolean;
26
+ setActive: (active: boolean) => void;
27
+ setEdgesActive: (active: boolean) => void;
28
+ setHelpersActive: (active: boolean) => void;
29
+ toggle: () => void;
30
+ updateEdges: () => void;
31
+ updateMaterials: () => void;
32
+ };
33
+ export declare class ClippingUtils {
34
+ planes: Plane[];
35
+ edges: ClippingEdges[];
36
+ helpers: PlaneHelper[];
37
+ private active;
38
+ private context;
39
+ private edgesActive;
40
+ private helperDragActive;
41
+ private helpersActive;
42
+ private helperHoverMoveState;
43
+ private updateEdgesFrame;
44
+ private updateHelpersFrame;
45
+ constructor(context: ClippingContext);
46
+ setContext(context: ClippingContext): void;
47
+ getActive(): boolean;
48
+ getEdgesActive(): boolean;
49
+ getHelpersActive(): boolean;
50
+ getPlanes(): Plane[];
51
+ getScene(): Scene<import("three").Object3DEventMap>;
52
+ getCamera(): Camera;
53
+ getCameraUtils(): CameraUtilsApi;
54
+ getDomElement(): HTMLCanvasElement;
55
+ getRaycaster(): Raycaster;
56
+ getControlRef(): ViewerControlsRef;
57
+ getMeshes(): Mesh<import("three").BufferGeometry<import("three").NormalBufferAttributes, import("three").BufferGeometryEventMap>, Material<import("three").MaterialEventMap> | Material<import("three").MaterialEventMap>[], import("three").Object3DEventMap>[];
58
+ getHelperHoverIsMoving(): boolean;
59
+ getHelperDragActive(): boolean;
60
+ setHelperDragActive(active: boolean): void;
61
+ clearHelpersHover(except?: PlaneHelper): void;
62
+ setHelperHoverMoveStart: () => void;
63
+ setHelperHoverMoveEnd: () => void;
64
+ setHelperHoverMoving: () => void;
65
+ private getModelWorldBox;
66
+ setControlsEnabled(enabled: boolean): void;
67
+ setSelectionInteractionDisabled(disabled: boolean): void;
68
+ updateMaterials(): void;
69
+ setActive(active: boolean): void;
70
+ toggle(): void;
71
+ createPlane(event?: MouseEvent | PointerEvent): Plane | null;
72
+ createClippingRectangle(): Plane[];
73
+ addPlane(plane: Plane, location: Vector3, normal: Vector3): void;
74
+ deleteAllPlanes(): void;
75
+ setHelpersActive(active: boolean): void;
76
+ setEdgesActive(active: boolean): void;
77
+ updateEdges(): void;
78
+ updateHelpers(): void;
79
+ requestEdgesUpdate(): void;
80
+ requestHelpersUpdate(): void;
81
+ syncWithModel(): void;
82
+ dispose(): void;
83
+ }
84
+ export declare function useClippingUtils(modelRef: ViewerModelRef, controlRef: ViewerControlsRef, cameraUtils: CameraUtilsApi): ViewerClippingApi & {
85
+ syncWithModel: () => void;
86
+ };
87
+ export {};
@@ -0,0 +1,54 @@
1
+ import { Box3, Group, LineDashedMaterial, MeshBasicMaterial, Object3D, Plane, Vector3 } from "three";
2
+ import type { ClippingUtils } from "./ClippingUtils";
3
+ export declare function getClippingHelperBoundsOffset(box: Box3): number;
4
+ export declare class PlaneHelper extends Object3D {
5
+ readonly helper: Group<import("three").Object3DEventMap>;
6
+ readonly borderMaterial: LineDashedMaterial;
7
+ readonly material: MeshBasicMaterial;
8
+ readonly plane: Plane;
9
+ private active;
10
+ private readonly border;
11
+ private readonly context;
12
+ private readonly location;
13
+ private readonly normal;
14
+ private readonly planeMesh;
15
+ private readonly pointer;
16
+ private layout;
17
+ private dragState;
18
+ private hovered;
19
+ private listenersActive;
20
+ constructor(context: ClippingUtils, plane: Plane, location: Vector3, normal: Vector3);
21
+ setVisible(visible: boolean): void;
22
+ toggle(): void;
23
+ clearHover(): void;
24
+ dispose(): void;
25
+ private addToView;
26
+ private removeFromView;
27
+ updateClipping(): void;
28
+ private updateBorderDash;
29
+ private addEventListeners;
30
+ private removeEventListeners;
31
+ private getPointerIntersection;
32
+ private getNearestHelperIntersection;
33
+ private hasModelIntersection;
34
+ private getPointerPointOnPlane;
35
+ private onPointerDown;
36
+ private onPointerMove;
37
+ private onPointerUp;
38
+ private updateHoverState;
39
+ private setHovered;
40
+ private createPlaneMesh;
41
+ private createBorder;
42
+ private replaceGeometry;
43
+ private createFillGeometry;
44
+ private createBorderGeometry;
45
+ private getClippedPolygon;
46
+ private clipPolygonByPlane;
47
+ private getLocalPointDistanceToPlane;
48
+ private getPlaneIntersectionPoint;
49
+ private getHelperLayout;
50
+ private getPlaneBasis;
51
+ private applyPlaneOrientation;
52
+ private getModelWorldBox;
53
+ private getBoxCorners;
54
+ }
@@ -0,0 +1,2 @@
1
+ export { useClippingUtils } from "./ClippingUtils";
2
+ export type { ViewerClippingApi } from "./ClippingUtils";
@@ -1,6 +1,7 @@
1
1
  import { DataTexture, type ColorRepresentation } from "three";
2
2
  import type { GeometryIndexApi } from "../GeometryUtils/useGeometryIndex";
3
3
  export declare const MAX_ELEMENT_COLOR_PALETTE_SIZE = 256;
4
+ export declare const SELECTION_COLOR_INDEX = 1;
4
5
  export type ViewerElementColorsApi = {
5
6
  applyStoredColors: () => void;
6
7
  clearAllColors: () => void;
@@ -1,6 +1,6 @@
1
1
  import { Mesh, Object3D } from "three";
2
2
  import type { MeshBVH } from "three-mesh-bvh";
3
- import type { ViewerModelRef } from "../types";
3
+ import type { ViewerModelRef } from "../../types";
4
4
  export type IndexArray = Uint16Array | Uint32Array;
5
5
  export type IndexRange = {
6
6
  count: number;
@@ -0,0 +1 @@
1
+ export default function useHotkeys(): void;
@@ -1,4 +1,4 @@
1
- import type { ViewerCameraRef, ViewerControlsRef, ViewerModelRef } from "../types";
1
+ import type { ViewerCameraRef, ViewerControlsRef, ViewerModelRef } from "../../types";
2
2
  type NavigationCubeProps = {
3
3
  active?: boolean;
4
4
  cameraRef: ViewerCameraRef;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bimatter-viewer-react",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "license": "PolyForm-Noncommercial-1.0.0",
5
5
  "type": "module",
6
6
  "main": "./lib/index.js",
@@ -53,6 +53,7 @@
53
53
  "eslint-plugin-react-hooks": "^7.1.1",
54
54
  "eslint-plugin-react-refresh": "^0.5.2",
55
55
  "globals": "^17.5.0",
56
+ "lil-gui": "^0.21.0",
56
57
  "react": "^19.2.5",
57
58
  "react-dom": "^19.2.5",
58
59
  "three": "^0.184.0",
@@ -1,2 +0,0 @@
1
- import type { GeometryUtilsApi } from "../GeometryUtils/useGeometryUtils";
2
- export default function useHotkeys(geometryUtils: GeometryUtilsApi): void;
@@ -1,61 +0,0 @@
1
- import { Color, Group, LineBasicMaterial, Texture, Vector3, type Matrix4 } from "three";
2
- import { CSS2DObject } from "three/examples/jsm/renderers/CSS2DRenderer.js";
3
- import type { GridData } from "../Loaders/IFCLoader/IfcGrid";
4
- import type { ModelGridAxis, ModelGridPoint } from "../ModelGrids";
5
- type LegacyViewerContext = {
6
- boundingBox: {
7
- min: Vector3;
8
- };
9
- context: {
10
- container: {
11
- style: {
12
- background: string;
13
- };
14
- };
15
- context: {
16
- scene: {
17
- threeScene: {
18
- add: (object: Group) => void;
19
- background: Color | Texture | null;
20
- };
21
- };
22
- };
23
- loaders: {
24
- coordinationMatrix?: Matrix4 | null;
25
- };
26
- };
27
- };
28
- type LegacyGridAxisType = "u" | "v";
29
- type RgbColor = {
30
- b: number;
31
- g: number;
32
- r: number;
33
- };
34
- export declare class ModelGrids {
35
- topTags: CSS2DObject[];
36
- botTags: CSS2DObject[];
37
- leftTags: CSS2DObject[];
38
- rightTags: CSS2DObject[];
39
- _active: boolean;
40
- grids: GridData[];
41
- color: string;
42
- material: LineBasicMaterial;
43
- mesh: Group;
44
- readonly context: LegacyViewerContext;
45
- constructor(context: LegacyViewerContext, grids: {
46
- [key: string]: GridData;
47
- });
48
- init(): Promise<void>;
49
- addGrid(gridGroup: Group, data: ModelGridAxis, locCoordinates: ModelGridPoint, type: LegacyGridAxisType, lowY: Vector3): void;
50
- viewTop(bool: boolean): void;
51
- viewBot(bool: boolean): void;
52
- viewLeft(bool: boolean): void;
53
- viewRight(bool: boolean): void;
54
- get active(): boolean;
55
- set active(active: boolean);
56
- hexToRgb(hex: string): RgbColor;
57
- hex2hsl(hex: string): number[];
58
- rgb2hsl(r: number, g: number, b: number): number[];
59
- changeColor(color: Color | string): "#000000" | "#FFFFFF";
60
- }
61
- export {};
File without changes
File without changes