@shopware-ag/dive 2.2.24 → 2.2.25
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/build/chunks/{AssetCache-CT7yQAu0.mjs → AssetCache-CBkOQjYz.mjs} +1 -1
- package/build/chunks/{AssetCache-BvteEWMc.cjs → AssetCache-CCgznm_D.cjs} +1 -1
- package/build/chunks/{AssetLoader-CIsnnlqu.mjs → AssetLoader-BwdDTxfU.mjs} +2 -2
- package/build/chunks/{AssetLoader-C8es4ZuG.cjs → AssetLoader-CF4Pwvca.cjs} +1 -1
- package/build/chunks/{FileTypes-D_r2gn3i.mjs → FileTypes-CNbj06o_.mjs} +1 -1
- package/build/chunks/{FileTypes-CjUNNEmP.cjs → FileTypes-OPeKBpnU.cjs} +1 -1
- package/build/dive.cjs +1 -1
- package/build/dive.mjs +1 -1
- package/build/plugins/ar/index.cjs +1 -1
- package/build/plugins/ar/index.mjs +1 -1
- package/build/plugins/assetcache/index.cjs +1 -1
- package/build/plugins/assetcache/index.mjs +1 -1
- package/build/plugins/assetloader/index.cjs +1 -1
- package/build/plugins/assetloader/index.mjs +1 -1
- package/build/plugins/orbitcontroller/index.cjs +1 -1
- package/build/plugins/orbitcontroller/index.mjs +1 -1
- package/build/plugins/orientationdisplay/index.cjs +1 -1
- package/build/plugins/orientationdisplay/index.mjs +1 -1
- package/build/plugins/quickview/index.cjs +1 -1
- package/build/plugins/quickview/index.mjs +1 -1
- package/build/plugins/state/index.cjs +8 -8
- package/build/plugins/state/index.mjs +978 -979
- package/build/plugins/toolbox/index.cjs +1 -1
- package/build/plugins/toolbox/index.d.ts +9 -1
- package/build/plugins/toolbox/index.mjs +1166 -88
- package/build/plugins/toolbox/src/BaseTool.d.ts +13 -0
- package/build/plugins/toolbox/src/PointerContext.d.ts +46 -0
- package/build/plugins/toolbox/src/SelectionState.d.ts +43 -0
- package/build/plugins/toolbox/src/Tool.d.ts +44 -0
- package/build/plugins/toolbox/src/Toolbox.d.ts +73 -17
- package/build/plugins/toolbox/src/drag/DragTool.d.ts +53 -0
- package/build/plugins/toolbox/src/drag/DraggableEvent.d.ts +16 -0
- package/build/plugins/toolbox/src/hover/HoverTool.d.ts +24 -0
- package/build/plugins/toolbox/src/select/SelectTool.d.ts +32 -16
- package/build/plugins/toolbox/src/transform/TransformTool.d.ts +48 -10
- package/build/plugins/toolbox/types/ToolType.d.ts +14 -1
- package/package.json +1 -1
- package/build/chunks/SelectTool-C-G8iiqX.cjs +0 -1
- package/build/chunks/SelectTool-CP-RUr3R.mjs +0 -718
|
@@ -1,12 +1,25 @@
|
|
|
1
1
|
import { Intersection, Object3D, Raycaster, Vector2, Vector3 } from 'three';
|
|
2
2
|
import { DIVEScene, DIVEDraggable, DIVEHoverable } from '../../../index.ts';
|
|
3
3
|
import { OrbitController } from '../../orbitcontroller/index.ts';
|
|
4
|
+
/**
|
|
5
|
+
* @deprecated Use DraggableEvent from './drag/DraggableEvent.ts' instead.
|
|
6
|
+
* This type will be removed in a future version.
|
|
7
|
+
*/
|
|
4
8
|
export type DraggableEvent = {
|
|
5
9
|
dragStart: Vector3;
|
|
6
10
|
dragCurrent: Vector3;
|
|
7
11
|
dragEnd: Vector3;
|
|
8
12
|
dragDelta: Vector3;
|
|
9
13
|
};
|
|
14
|
+
/**
|
|
15
|
+
* @deprecated Use the new Tool interface and individual tools (HoverTool, SelectTool, TransformTool, DragTool) instead.
|
|
16
|
+
* This class will be removed in a future version.
|
|
17
|
+
*
|
|
18
|
+
* The new architecture uses composition over inheritance:
|
|
19
|
+
* - Tool interface for lightweight event handlers
|
|
20
|
+
* - Toolbox as event dispatcher supporting multiple active tools
|
|
21
|
+
* - Individual tools: HoverTool, SelectTool, TransformTool, DragTool
|
|
22
|
+
*/
|
|
10
23
|
export declare abstract class DIVEBaseTool {
|
|
11
24
|
readonly POINTER_DRAG_THRESHOLD: number;
|
|
12
25
|
name: string;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Intersection, Vector2 } from 'three';
|
|
2
|
+
/**
|
|
3
|
+
* Context object passed to tools on pointer events.
|
|
4
|
+
*
|
|
5
|
+
* Contains pre-computed raycast results and pointer state,
|
|
6
|
+
* shared across all active tools to avoid redundant calculations.
|
|
7
|
+
*
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
export interface PointerContext {
|
|
11
|
+
/** The original DOM pointer event */
|
|
12
|
+
readonly event: PointerEvent;
|
|
13
|
+
/** Normalized device coordinates (-1 to 1) */
|
|
14
|
+
readonly pointer: Vector2;
|
|
15
|
+
/** All raycast intersections */
|
|
16
|
+
readonly intersects: Intersection[];
|
|
17
|
+
/** Intersections filtered to PRODUCT_LAYER (models only) */
|
|
18
|
+
readonly modelIntersects: Intersection[];
|
|
19
|
+
/** Intersections filtered to UI_LAYER (gizmo, UI elements) */
|
|
20
|
+
readonly uiIntersects: Intersection[];
|
|
21
|
+
/** Whether primary mouse button (left) is pressed */
|
|
22
|
+
readonly pointerPrimaryDown: boolean;
|
|
23
|
+
/** Whether middle mouse button is pressed */
|
|
24
|
+
readonly pointerMiddleDown: boolean;
|
|
25
|
+
/** Whether secondary mouse button (right) is pressed */
|
|
26
|
+
readonly pointerSecondaryDown: boolean;
|
|
27
|
+
/** Last pointer position when a button was pressed down */
|
|
28
|
+
readonly lastPointerDown: Vector2;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Context object passed to tools on wheel events.
|
|
32
|
+
*
|
|
33
|
+
* @module
|
|
34
|
+
*/
|
|
35
|
+
export interface WheelContext {
|
|
36
|
+
/** The original DOM wheel event */
|
|
37
|
+
readonly event: WheelEvent;
|
|
38
|
+
/** Normalized device coordinates (-1 to 1) */
|
|
39
|
+
readonly pointer: Vector2;
|
|
40
|
+
/** All raycast intersections at current pointer position */
|
|
41
|
+
readonly intersects: Intersection[];
|
|
42
|
+
/** Intersections filtered to PRODUCT_LAYER (models only) */
|
|
43
|
+
readonly modelIntersects: Intersection[];
|
|
44
|
+
/** Intersections filtered to UI_LAYER (gizmo, UI elements) */
|
|
45
|
+
readonly uiIntersects: Intersection[];
|
|
46
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Object3D } from 'three';
|
|
2
|
+
import { DIVESelectable } from '../../../index.ts';
|
|
3
|
+
type SelectionChangeCallback = (selected: (Object3D & DIVESelectable) | null) => void;
|
|
4
|
+
/**
|
|
5
|
+
* Manages selection state and notifies listeners on changes.
|
|
6
|
+
*
|
|
7
|
+
* Provides a centralized way to track what object is currently selected
|
|
8
|
+
* and allows tools like TransformTool to react to selection changes.
|
|
9
|
+
*
|
|
10
|
+
* @module
|
|
11
|
+
*/
|
|
12
|
+
export declare class SelectionState {
|
|
13
|
+
private _selected;
|
|
14
|
+
private _listeners;
|
|
15
|
+
/**
|
|
16
|
+
* Currently selected object, or null if nothing is selected.
|
|
17
|
+
*/
|
|
18
|
+
get selected(): (Object3D & DIVESelectable) | null;
|
|
19
|
+
/**
|
|
20
|
+
* Select an object. Deselects any previously selected object.
|
|
21
|
+
* Calls onSelect on the new object and onDeselect on the previous.
|
|
22
|
+
*/
|
|
23
|
+
select(obj: Object3D & DIVESelectable): void;
|
|
24
|
+
/**
|
|
25
|
+
* Deselect the currently selected object.
|
|
26
|
+
* Calls onDeselect on the object.
|
|
27
|
+
*/
|
|
28
|
+
deselect(): void;
|
|
29
|
+
/**
|
|
30
|
+
* Register a callback to be notified when selection changes.
|
|
31
|
+
*/
|
|
32
|
+
onChange(callback: SelectionChangeCallback): void;
|
|
33
|
+
/**
|
|
34
|
+
* Unregister a previously registered callback.
|
|
35
|
+
*/
|
|
36
|
+
offChange(callback: SelectionChangeCallback): void;
|
|
37
|
+
/**
|
|
38
|
+
* Dispose of the selection state and clear all listeners.
|
|
39
|
+
*/
|
|
40
|
+
dispose(): void;
|
|
41
|
+
private notifyListeners;
|
|
42
|
+
}
|
|
43
|
+
export {};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { PointerContext, WheelContext } from './PointerContext.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Interface for tools that handle pointer events in the scene.
|
|
4
|
+
*
|
|
5
|
+
* Tools are lightweight event routers that delegate logic to scene objects.
|
|
6
|
+
* Multiple tools can be active simultaneously, processed by priority order.
|
|
7
|
+
*
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
export interface Tool {
|
|
11
|
+
/** Unique identifier for the tool */
|
|
12
|
+
readonly name: string;
|
|
13
|
+
/** Processing priority - lower number runs first */
|
|
14
|
+
readonly priority: number;
|
|
15
|
+
/** Called when tool is activated */
|
|
16
|
+
onActivate?(): void;
|
|
17
|
+
/** Called when tool is deactivated */
|
|
18
|
+
onDeactivate?(): void;
|
|
19
|
+
/**
|
|
20
|
+
* Called on pointer move events
|
|
21
|
+
* @returns true to stop event propagation to lower-priority tools
|
|
22
|
+
*/
|
|
23
|
+
onPointerMove?(ctx: PointerContext): void | boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Called on pointer down events
|
|
26
|
+
* @returns true to stop event propagation to lower-priority tools
|
|
27
|
+
*/
|
|
28
|
+
onPointerDown?(ctx: PointerContext): void | boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Called on pointer up events
|
|
31
|
+
* @returns true to stop event propagation to lower-priority tools
|
|
32
|
+
*/
|
|
33
|
+
onPointerUp?(ctx: PointerContext): void | boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Called on click events (pointer down + up without drag)
|
|
36
|
+
* @returns true to stop event propagation to lower-priority tools
|
|
37
|
+
*/
|
|
38
|
+
onClick?(ctx: PointerContext): void | boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Called on wheel events
|
|
41
|
+
* @returns true to stop event propagation to lower-priority tools
|
|
42
|
+
*/
|
|
43
|
+
onWheel?(ctx: WheelContext): void | boolean;
|
|
44
|
+
}
|
|
@@ -1,26 +1,82 @@
|
|
|
1
1
|
import { DIVEScene } from '../../../index.ts';
|
|
2
|
-
import { DIVEBaseTool } from './BaseTool.ts';
|
|
3
|
-
import { DIVESelectTool } from './select/SelectTool.ts';
|
|
4
2
|
import { OrbitController } from '../../orbitcontroller/index.ts';
|
|
5
|
-
import {
|
|
3
|
+
import { Tool } from './Tool.ts';
|
|
4
|
+
import { SelectionState } from './SelectionState.ts';
|
|
5
|
+
import { ToolType, ToolTypeMap } from '../types/index.ts';
|
|
6
|
+
/**
|
|
7
|
+
* Toolbox manages multiple tools and dispatches pointer events to them.
|
|
8
|
+
*
|
|
9
|
+
* Tools are processed in priority order (lower number = higher priority).
|
|
10
|
+
* Each tool can stop event propagation by returning true from its handler.
|
|
11
|
+
*
|
|
12
|
+
* @module
|
|
13
|
+
*/
|
|
6
14
|
export declare class Toolbox {
|
|
7
|
-
static readonly DefaultTool = "select";
|
|
8
15
|
private _scene;
|
|
9
16
|
private _controller;
|
|
10
|
-
private
|
|
11
|
-
private
|
|
12
|
-
|
|
17
|
+
private _canvas;
|
|
18
|
+
private _tools;
|
|
19
|
+
private _activeTools;
|
|
20
|
+
private _sortedActiveTools;
|
|
21
|
+
private _selectionState;
|
|
22
|
+
get selectionState(): SelectionState;
|
|
23
|
+
private _raycaster;
|
|
24
|
+
private _pointer;
|
|
25
|
+
private _productLayerMask;
|
|
26
|
+
private _uiLayerMask;
|
|
27
|
+
private _pointerPrimaryDown;
|
|
28
|
+
private _pointerMiddleDown;
|
|
29
|
+
private _pointerSecondaryDown;
|
|
30
|
+
private _lastPointerDown;
|
|
31
|
+
private _boundPointerMove;
|
|
32
|
+
private _boundPointerDown;
|
|
33
|
+
private _boundPointerUp;
|
|
34
|
+
private _boundWheel;
|
|
13
35
|
constructor(scene: DIVEScene, controller: OrbitController);
|
|
36
|
+
/**
|
|
37
|
+
* Enable a tool by type.
|
|
38
|
+
*/
|
|
39
|
+
enableTool(type: ToolType): void;
|
|
40
|
+
/**
|
|
41
|
+
* Disable an active tool by type.
|
|
42
|
+
*/
|
|
43
|
+
disableTool(type: ToolType): void;
|
|
44
|
+
/**
|
|
45
|
+
* Check if a tool is currently enabled.
|
|
46
|
+
*/
|
|
47
|
+
isToolEnabled(type: ToolType): boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Get a tool by type.
|
|
50
|
+
*/
|
|
51
|
+
getTool<T extends ToolType>(type: T): ToolTypeMap[T];
|
|
52
|
+
/**
|
|
53
|
+
* Get all currently active tools.
|
|
54
|
+
*/
|
|
55
|
+
getActiveTools(): Tool[];
|
|
56
|
+
/**
|
|
57
|
+
* Dispose of the toolbox and clean up resources.
|
|
58
|
+
*/
|
|
14
59
|
dispose(): void;
|
|
15
|
-
|
|
60
|
+
private onPointerMove;
|
|
61
|
+
private onPointerDown;
|
|
62
|
+
private onPointerUp;
|
|
63
|
+
private onWheel;
|
|
64
|
+
private createPointerContext;
|
|
65
|
+
private createWheelContext;
|
|
66
|
+
private updatePointer;
|
|
67
|
+
private updatePointerState;
|
|
68
|
+
private raycast;
|
|
69
|
+
private filterIntersectsByLayer;
|
|
70
|
+
private updateSortedTools;
|
|
71
|
+
private pointerWasDragged;
|
|
72
|
+
/**
|
|
73
|
+
* @deprecated Use enableTool/disableTool instead.
|
|
74
|
+
* Enable or disable a tool by type.
|
|
75
|
+
*/
|
|
16
76
|
useTool(tool: ToolType): void;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
onPointerUp(e: PointerEvent): void;
|
|
23
|
-
onWheel(e: WheelEvent): void;
|
|
24
|
-
private addEventListeners;
|
|
25
|
-
private removeEventListeners;
|
|
77
|
+
/**
|
|
78
|
+
* @deprecated Use getActiveTools instead.
|
|
79
|
+
* Get the first active tool (for legacy compatibility).
|
|
80
|
+
*/
|
|
81
|
+
getActiveTool(): Tool | null;
|
|
26
82
|
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { Object3D } from 'three';
|
|
2
|
+
import { DIVEDraggable } from '../../../../index.ts';
|
|
3
|
+
import { OrbitController } from '../../../orbitcontroller/index.ts';
|
|
4
|
+
import { Tool } from '../Tool.ts';
|
|
5
|
+
import { PointerContext } from '../PointerContext.ts';
|
|
6
|
+
/**
|
|
7
|
+
* Tool for handling drag operations on objects.
|
|
8
|
+
*
|
|
9
|
+
* Detects DIVEDraggable objects and triggers their drag callbacks.
|
|
10
|
+
* Blocks other tools while a drag operation is in progress.
|
|
11
|
+
*
|
|
12
|
+
* @module
|
|
13
|
+
*/
|
|
14
|
+
export declare class DragTool implements Tool {
|
|
15
|
+
readonly name = "drag";
|
|
16
|
+
readonly priority = 10;
|
|
17
|
+
private _controller;
|
|
18
|
+
private _raycaster;
|
|
19
|
+
private _dragging;
|
|
20
|
+
private _draggable;
|
|
21
|
+
private _dragStart;
|
|
22
|
+
private _dragCurrent;
|
|
23
|
+
private _dragEnd;
|
|
24
|
+
private _dragDelta;
|
|
25
|
+
private _dragRaycastTargets;
|
|
26
|
+
constructor(controller: OrbitController);
|
|
27
|
+
/**
|
|
28
|
+
* Whether a drag operation is currently in progress.
|
|
29
|
+
*/
|
|
30
|
+
get isDragging(): boolean;
|
|
31
|
+
/**
|
|
32
|
+
* The object currently being dragged, or null.
|
|
33
|
+
*/
|
|
34
|
+
get draggable(): (Object3D & DIVEDraggable) | null;
|
|
35
|
+
onActivate(): void;
|
|
36
|
+
onDeactivate(): void;
|
|
37
|
+
onPointerDown(ctx: PointerContext): void;
|
|
38
|
+
onPointerMove(ctx: PointerContext): boolean | void;
|
|
39
|
+
onPointerUp(ctx: PointerContext): void;
|
|
40
|
+
/**
|
|
41
|
+
* Set custom objects to raycast against during drag.
|
|
42
|
+
* Useful for constraining drag to a floor plane.
|
|
43
|
+
*
|
|
44
|
+
* @param targets Objects to raycast against, or null to use scene objects
|
|
45
|
+
*/
|
|
46
|
+
setDragRaycastTargets(targets: Object3D[] | null): void;
|
|
47
|
+
private startDrag;
|
|
48
|
+
private updateDrag;
|
|
49
|
+
private endDrag;
|
|
50
|
+
private getDragIntersect;
|
|
51
|
+
private createDragEvent;
|
|
52
|
+
private resetDragState;
|
|
53
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Vector3 } from 'three';
|
|
2
|
+
/**
|
|
3
|
+
* Event data passed to DIVEDraggable callbacks during drag operations.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
export type DraggableEvent = {
|
|
8
|
+
/** World position where the drag started */
|
|
9
|
+
dragStart: Vector3;
|
|
10
|
+
/** Current world position during drag */
|
|
11
|
+
dragCurrent: Vector3;
|
|
12
|
+
/** World position where the drag ended (same as dragCurrent during drag) */
|
|
13
|
+
dragEnd: Vector3;
|
|
14
|
+
/** Vector from dragStart to dragCurrent */
|
|
15
|
+
dragDelta: Vector3;
|
|
16
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Object3D } from 'three';
|
|
2
|
+
import { DIVEHoverable } from '../../../../index.ts';
|
|
3
|
+
import { Tool } from '../Tool.ts';
|
|
4
|
+
import { PointerContext } from '../PointerContext.ts';
|
|
5
|
+
/**
|
|
6
|
+
* Tool for handling hover events on models.
|
|
7
|
+
*
|
|
8
|
+
* Only processes objects on PRODUCT_LAYER (models), ignoring UI elements like gizmos.
|
|
9
|
+
* Triggers DIVEHoverable callbacks: onPointerEnter, onPointerOver, onPointerLeave.
|
|
10
|
+
*
|
|
11
|
+
* @module
|
|
12
|
+
*/
|
|
13
|
+
export declare class HoverTool implements Tool {
|
|
14
|
+
readonly name = "hover";
|
|
15
|
+
readonly priority = 20;
|
|
16
|
+
private _hovered;
|
|
17
|
+
/**
|
|
18
|
+
* Currently hovered object, or null if nothing is hovered.
|
|
19
|
+
*/
|
|
20
|
+
get hovered(): (Object3D & DIVEHoverable) | null;
|
|
21
|
+
onActivate(): void;
|
|
22
|
+
onDeactivate(): void;
|
|
23
|
+
onPointerMove(ctx: PointerContext): void;
|
|
24
|
+
}
|
|
@@ -1,22 +1,38 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
1
|
+
import { Object3D } from 'three';
|
|
2
|
+
import { DIVESelectable } from '../../../../index.ts';
|
|
3
|
+
import { Tool } from '../Tool.ts';
|
|
4
|
+
import { PointerContext } from '../PointerContext.ts';
|
|
5
|
+
import { SelectionState } from '../SelectionState.ts';
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
7
|
+
* Type guard to check if a tool is a SelectTool.
|
|
8
|
+
*/
|
|
9
|
+
export declare const isSelectTool: (tool: Tool) => tool is SelectTool;
|
|
10
|
+
/**
|
|
11
|
+
* Tool for selecting objects via click.
|
|
8
12
|
*
|
|
9
|
-
*
|
|
13
|
+
* Only processes objects on PRODUCT_LAYER (models), ignoring UI elements like gizmos.
|
|
14
|
+
* Uses SelectionState to manage selection and notify other tools (like TransformTool).
|
|
10
15
|
*
|
|
11
16
|
* @module
|
|
12
17
|
*/
|
|
13
|
-
export declare class
|
|
14
|
-
readonly
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
export declare class SelectTool implements Tool {
|
|
19
|
+
readonly name = "select";
|
|
20
|
+
readonly priority = 30;
|
|
21
|
+
private _selectionState;
|
|
22
|
+
constructor(selectionState: SelectionState);
|
|
23
|
+
/**
|
|
24
|
+
* Get the currently selected object.
|
|
25
|
+
*/
|
|
26
|
+
get selected(): (Object3D & DIVESelectable) | null;
|
|
27
|
+
onActivate(): void;
|
|
28
|
+
onDeactivate(): void;
|
|
29
|
+
onClick(ctx: PointerContext): void;
|
|
30
|
+
/**
|
|
31
|
+
* Programmatically select an object.
|
|
32
|
+
*/
|
|
33
|
+
select(obj: Object3D & DIVESelectable): void;
|
|
34
|
+
/**
|
|
35
|
+
* Programmatically deselect the current selection.
|
|
36
|
+
*/
|
|
37
|
+
deselect(): void;
|
|
22
38
|
}
|
|
@@ -1,23 +1,61 @@
|
|
|
1
1
|
import { TransformControls } from 'three/examples/jsm/controls/TransformControls.js';
|
|
2
|
-
import {
|
|
3
|
-
import { DIVEGizmo, DIVEScene } from '../../../../index.ts';
|
|
2
|
+
import { DIVEScene } from '../../../../index.ts';
|
|
4
3
|
import { OrbitController } from '../../../orbitcontroller/index.ts';
|
|
5
|
-
|
|
4
|
+
import { Tool } from '../Tool.ts';
|
|
5
|
+
import { PointerContext } from '../PointerContext.ts';
|
|
6
|
+
import { SelectionState } from '../SelectionState.ts';
|
|
6
7
|
/**
|
|
7
|
-
*
|
|
8
|
+
* Type guard to check if a tool is a TransformTool.
|
|
9
|
+
*/
|
|
10
|
+
export declare const isTransformTool: (tool: Tool) => tool is TransformTool;
|
|
11
|
+
/**
|
|
12
|
+
* Tool for transforming objects with a gizmo.
|
|
8
13
|
*
|
|
9
|
-
*
|
|
14
|
+
* Manages TransformControls gizmo and reacts to selection changes.
|
|
15
|
+
* Has highest priority to block model-hover when gizmo is being interacted with.
|
|
10
16
|
*
|
|
11
17
|
* @module
|
|
12
18
|
*/
|
|
13
|
-
export declare class
|
|
14
|
-
readonly
|
|
19
|
+
export declare class TransformTool implements Tool {
|
|
20
|
+
readonly name = "transform";
|
|
21
|
+
readonly priority = 5;
|
|
22
|
+
private _scene;
|
|
23
|
+
private _controller;
|
|
24
|
+
private _selectionState;
|
|
25
|
+
private _gizmo;
|
|
15
26
|
private _scaleLinked;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
27
|
+
private _gizmoVisible;
|
|
28
|
+
private _selectionChangeHandler;
|
|
29
|
+
constructor(scene: DIVEScene, controller: OrbitController, selectionState: SelectionState);
|
|
30
|
+
/**
|
|
31
|
+
* Get the TransformControls gizmo.
|
|
32
|
+
*/
|
|
33
|
+
get gizmo(): TransformControls;
|
|
34
|
+
/**
|
|
35
|
+
* Whether a drag operation is currently in progress.
|
|
36
|
+
*/
|
|
37
|
+
get isDragging(): boolean;
|
|
38
|
+
onActivate(): void;
|
|
39
|
+
onDeactivate(): void;
|
|
40
|
+
onPointerMove(ctx: PointerContext): boolean | void;
|
|
41
|
+
/**
|
|
42
|
+
* Set the gizmo transformation mode.
|
|
43
|
+
*/
|
|
19
44
|
setGizmoMode(mode: 'translate' | 'rotate' | 'scale'): void;
|
|
45
|
+
/**
|
|
46
|
+
* Set whether the gizmo is visible.
|
|
47
|
+
*/
|
|
20
48
|
setGizmoVisible(visible: boolean): void;
|
|
49
|
+
/**
|
|
50
|
+
* Set whether scale operations are linked (uniform scaling).
|
|
51
|
+
*/
|
|
21
52
|
setGizmoScaleLinked(linked: boolean): void;
|
|
53
|
+
/**
|
|
54
|
+
* Dispose of the tool and clean up resources.
|
|
55
|
+
*/
|
|
56
|
+
dispose(): void;
|
|
57
|
+
private onSelectionChange;
|
|
58
|
+
private attachGizmo;
|
|
59
|
+
private isGizmoChild;
|
|
22
60
|
private initGizmo;
|
|
23
61
|
}
|
|
@@ -1 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
import { HoverTool } from '../src/hover/HoverTool.ts';
|
|
2
|
+
import { SelectTool } from '../src/select/SelectTool.ts';
|
|
3
|
+
import { TransformTool } from '../src/transform/TransformTool.ts';
|
|
4
|
+
import { DragTool } from '../src/drag/DragTool.ts';
|
|
5
|
+
export type ToolType = 'hover' | 'select' | 'transform' | 'drag';
|
|
6
|
+
/**
|
|
7
|
+
* Maps ToolType to the corresponding Tool class.
|
|
8
|
+
*/
|
|
9
|
+
export interface ToolTypeMap {
|
|
10
|
+
hover: HoverTool;
|
|
11
|
+
select: SelectTool;
|
|
12
|
+
transform: TransformTool;
|
|
13
|
+
drag: DragTool;
|
|
14
|
+
}
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var wt=Object.defineProperty;var gt=(r,n,e)=>n in r?wt(r,n,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[n]=e;var h=(r,n,e)=>gt(r,typeof n!="symbol"?n+"":n,e);require("./FileTypes-CjUNNEmP.cjs");const t=require("three"),j=require("./findInterface-C6mrvf_t.cjs"),$=require("./PerspectiveCamera-iAsZqrnY.cjs"),Q=require("./AxisHelperColors-BrGqktN5.cjs"),D=new t.Raycaster,p=new t.Vector3,P=new t.Vector3,c=new t.Quaternion,tt={X:new t.Vector3(1,0,0),Y:new t.Vector3(0,1,0),Z:new t.Vector3(0,0,1)},U={type:"change"},et={type:"mouseDown"},it={type:"mouseUp",mode:null},nt={type:"objectChange"};class bt extends t.Object3D{constructor(n,e){super(),e===void 0&&(console.warn('THREE.TransformControls: The second parameter "domElement" is now mandatory.'),e=document),this.isTransformControls=!0,this.visible=!1,this.domElement=e,this.domElement.style.touchAction="none";const o=new xt;this._gizmo=o,this.add(o);const s=new Dt;this._plane=s,this.add(s);const a=this;function i(m,y){let A=y;Object.defineProperty(a,m,{get:function(){return A!==void 0?A:y},set:function(x){A!==x&&(A=x,s[m]=x,o[m]=x,a.dispatchEvent({type:m+"-changed",value:x}),a.dispatchEvent(U))}}),a[m]=y,s[m]=y,o[m]=y}i("camera",n),i("object",void 0),i("enabled",!0),i("axis",null),i("mode","translate"),i("translationSnap",null),i("rotationSnap",null),i("scaleSnap",null),i("space","world"),i("size",1),i("dragging",!1),i("showX",!0),i("showY",!0),i("showZ",!0);const d=new t.Vector3,f=new t.Vector3,E=new t.Quaternion,T=new t.Quaternion,z=new t.Vector3,C=new t.Quaternion,K=new t.Vector3,H=new t.Vector3,M=new t.Vector3,S=0,g=new t.Vector3;i("worldPosition",d),i("worldPositionStart",f),i("worldQuaternion",E),i("worldQuaternionStart",T),i("cameraPosition",z),i("cameraQuaternion",C),i("pointStart",K),i("pointEnd",H),i("rotationAxis",M),i("rotationAngle",S),i("eye",g),this._offset=new t.Vector3,this._startNorm=new t.Vector3,this._endNorm=new t.Vector3,this._cameraScale=new t.Vector3,this._parentPosition=new t.Vector3,this._parentQuaternion=new t.Quaternion,this._parentQuaternionInv=new t.Quaternion,this._parentScale=new t.Vector3,this._worldScaleStart=new t.Vector3,this._worldQuaternionInv=new t.Quaternion,this._worldScale=new t.Vector3,this._positionStart=new t.Vector3,this._quaternionStart=new t.Quaternion,this._scaleStart=new t.Vector3,this._getPointer=Mt.bind(this),this._onPointerDown=vt.bind(this),this._onPointerHover=St.bind(this),this._onPointerMove=Pt.bind(this),this._onPointerUp=Et.bind(this),this.domElement.addEventListener("pointerdown",this._onPointerDown),this.domElement.addEventListener("pointermove",this._onPointerHover),this.domElement.addEventListener("pointerup",this._onPointerUp)}updateMatrixWorld(n){this.object!==void 0&&(this.object.updateMatrixWorld(),this.object.parent===null?console.error("TransformControls: The attached 3D object must be a part of the scene graph."):this.object.parent.matrixWorld.decompose(this._parentPosition,this._parentQuaternion,this._parentScale),this.object.matrixWorld.decompose(this.worldPosition,this.worldQuaternion,this._worldScale),this._parentQuaternionInv.copy(this._parentQuaternion).invert(),this._worldQuaternionInv.copy(this.worldQuaternion).invert()),this.camera.updateMatrixWorld(),this.camera.matrixWorld.decompose(this.cameraPosition,this.cameraQuaternion,this._cameraScale),this.camera.isOrthographicCamera?this.camera.getWorldDirection(this.eye).negate():this.eye.copy(this.cameraPosition).sub(this.worldPosition).normalize(),super.updateMatrixWorld(n)}pointerHover(n){if(this.object===void 0||this.dragging===!0)return;n!==null&&D.setFromCamera(n,this.camera);const e=N(this._gizmo.picker[this.mode],D);e?this.axis=e.object.name:this.axis=null}pointerDown(n){if(!(this.object===void 0||this.dragging===!0||n!=null&&n.button!==0)&&this.axis!==null){n!==null&&D.setFromCamera(n,this.camera);const e=N(this._plane,D,!0);e&&(this.object.updateMatrixWorld(),this.object.parent.updateMatrixWorld(),this._positionStart.copy(this.object.position),this._quaternionStart.copy(this.object.quaternion),this._scaleStart.copy(this.object.scale),this.object.matrixWorld.decompose(this.worldPositionStart,this.worldQuaternionStart,this._worldScaleStart),this.pointStart.copy(e.point).sub(this.worldPositionStart)),this.dragging=!0,et.mode=this.mode,this.dispatchEvent(et)}}pointerMove(n){const e=this.axis,o=this.mode,s=this.object;let a=this.space;if(o==="scale"?a="local":(e==="E"||e==="XYZE"||e==="XYZ")&&(a="world"),s===void 0||e===null||this.dragging===!1||n!==null&&n.button!==-1)return;n!==null&&D.setFromCamera(n,this.camera);const i=N(this._plane,D,!0);if(i){if(this.pointEnd.copy(i.point).sub(this.worldPositionStart),o==="translate")this._offset.copy(this.pointEnd).sub(this.pointStart),a==="local"&&e!=="XYZ"&&this._offset.applyQuaternion(this._worldQuaternionInv),e.indexOf("X")===-1&&(this._offset.x=0),e.indexOf("Y")===-1&&(this._offset.y=0),e.indexOf("Z")===-1&&(this._offset.z=0),a==="local"&&e!=="XYZ"?this._offset.applyQuaternion(this._quaternionStart).divide(this._parentScale):this._offset.applyQuaternion(this._parentQuaternionInv).divide(this._parentScale),s.position.copy(this._offset).add(this._positionStart),this.translationSnap&&(a==="local"&&(s.position.applyQuaternion(c.copy(this._quaternionStart).invert()),e.search("X")!==-1&&(s.position.x=Math.round(s.position.x/this.translationSnap)*this.translationSnap),e.search("Y")!==-1&&(s.position.y=Math.round(s.position.y/this.translationSnap)*this.translationSnap),e.search("Z")!==-1&&(s.position.z=Math.round(s.position.z/this.translationSnap)*this.translationSnap),s.position.applyQuaternion(this._quaternionStart)),a==="world"&&(s.parent&&s.position.add(p.setFromMatrixPosition(s.parent.matrixWorld)),e.search("X")!==-1&&(s.position.x=Math.round(s.position.x/this.translationSnap)*this.translationSnap),e.search("Y")!==-1&&(s.position.y=Math.round(s.position.y/this.translationSnap)*this.translationSnap),e.search("Z")!==-1&&(s.position.z=Math.round(s.position.z/this.translationSnap)*this.translationSnap),s.parent&&s.position.sub(p.setFromMatrixPosition(s.parent.matrixWorld))));else if(o==="scale"){if(e.search("XYZ")!==-1){let d=this.pointEnd.length()/this.pointStart.length();this.pointEnd.dot(this.pointStart)<0&&(d*=-1),P.set(d,d,d)}else p.copy(this.pointStart),P.copy(this.pointEnd),p.applyQuaternion(this._worldQuaternionInv),P.applyQuaternion(this._worldQuaternionInv),P.divide(p),e.search("X")===-1&&(P.x=1),e.search("Y")===-1&&(P.y=1),e.search("Z")===-1&&(P.z=1);s.scale.copy(this._scaleStart).multiply(P),this.scaleSnap&&(e.search("X")!==-1&&(s.scale.x=Math.round(s.scale.x/this.scaleSnap)*this.scaleSnap||this.scaleSnap),e.search("Y")!==-1&&(s.scale.y=Math.round(s.scale.y/this.scaleSnap)*this.scaleSnap||this.scaleSnap),e.search("Z")!==-1&&(s.scale.z=Math.round(s.scale.z/this.scaleSnap)*this.scaleSnap||this.scaleSnap))}else if(o==="rotate"){this._offset.copy(this.pointEnd).sub(this.pointStart);const d=20/this.worldPosition.distanceTo(p.setFromMatrixPosition(this.camera.matrixWorld));let f=!1;e==="XYZE"?(this.rotationAxis.copy(this._offset).cross(this.eye).normalize(),this.rotationAngle=this._offset.dot(p.copy(this.rotationAxis).cross(this.eye))*d):(e==="X"||e==="Y"||e==="Z")&&(this.rotationAxis.copy(tt[e]),p.copy(tt[e]),a==="local"&&p.applyQuaternion(this.worldQuaternion),p.cross(this.eye),p.length()===0?f=!0:this.rotationAngle=this._offset.dot(p.normalize())*d),(e==="E"||f)&&(this.rotationAxis.copy(this.eye),this.rotationAngle=this.pointEnd.angleTo(this.pointStart),this._startNorm.copy(this.pointStart).normalize(),this._endNorm.copy(this.pointEnd).normalize(),this.rotationAngle*=this._endNorm.cross(this._startNorm).dot(this.eye)<0?1:-1),this.rotationSnap&&(this.rotationAngle=Math.round(this.rotationAngle/this.rotationSnap)*this.rotationSnap),a==="local"&&e!=="E"&&e!=="XYZE"?(s.quaternion.copy(this._quaternionStart),s.quaternion.multiply(c.setFromAxisAngle(this.rotationAxis,this.rotationAngle)).normalize()):(this.rotationAxis.applyQuaternion(this._parentQuaternionInv),s.quaternion.copy(c.setFromAxisAngle(this.rotationAxis,this.rotationAngle)),s.quaternion.multiply(this._quaternionStart).normalize())}this.dispatchEvent(U),this.dispatchEvent(nt)}}pointerUp(n){n!==null&&n.button!==0||(this.dragging&&this.axis!==null&&(it.mode=this.mode,this.dispatchEvent(it)),this.dragging=!1,this.axis=null)}dispose(){this.domElement.removeEventListener("pointerdown",this._onPointerDown),this.domElement.removeEventListener("pointermove",this._onPointerHover),this.domElement.removeEventListener("pointermove",this._onPointerMove),this.domElement.removeEventListener("pointerup",this._onPointerUp),this.traverse(function(n){n.geometry&&n.geometry.dispose(),n.material&&n.material.dispose()})}attach(n){return this.object=n,this.visible=!0,this}detach(){return this.object=void 0,this.visible=!1,this.axis=null,this}reset(){this.enabled&&this.dragging&&(this.object.position.copy(this._positionStart),this.object.quaternion.copy(this._quaternionStart),this.object.scale.copy(this._scaleStart),this.dispatchEvent(U),this.dispatchEvent(nt),this.pointStart.copy(this.pointEnd))}getRaycaster(){return D}getMode(){return this.mode}setMode(n){this.mode=n}setTranslationSnap(n){this.translationSnap=n}setRotationSnap(n){this.rotationSnap=n}setScaleSnap(n){this.scaleSnap=n}setSize(n){this.size=n}setSpace(n){this.space=n}}function Mt(r){if(this.domElement.ownerDocument.pointerLockElement)return{x:0,y:0,button:r.button};{const n=this.domElement.getBoundingClientRect();return{x:(r.clientX-n.left)/n.width*2-1,y:-(r.clientY-n.top)/n.height*2+1,button:r.button}}}function St(r){if(this.enabled)switch(r.pointerType){case"mouse":case"pen":this.pointerHover(this._getPointer(r));break}}function vt(r){this.enabled&&(document.pointerLockElement||this.domElement.setPointerCapture(r.pointerId),this.domElement.addEventListener("pointermove",this._onPointerMove),this.pointerHover(this._getPointer(r)),this.pointerDown(this._getPointer(r)))}function Pt(r){this.enabled&&this.pointerMove(this._getPointer(r))}function Et(r){this.enabled&&(this.domElement.releasePointerCapture(r.pointerId),this.domElement.removeEventListener("pointermove",this._onPointerMove),this.pointerUp(this._getPointer(r)))}function N(r,n,e){const o=n.intersectObject(r,!0);for(let s=0;s<o.length;s++)if(o[s].object.visible||e)return o[s];return!1}const q=new t.Euler,l=new t.Vector3(0,1,0),ot=new t.Vector3(0,0,0),st=new t.Matrix4,B=new t.Quaternion,F=new t.Quaternion,b=new t.Vector3,rt=new t.Matrix4,O=new t.Vector3(1,0,0),I=new t.Vector3(0,1,0),Z=new t.Vector3(0,0,1),W=new t.Vector3,X=new t.Vector3,Y=new t.Vector3;class xt extends t.Object3D{constructor(){super(),this.isTransformControlsGizmo=!0,this.type="TransformControlsGizmo";const n=new t.MeshBasicMaterial({depthTest:!1,depthWrite:!1,fog:!1,toneMapped:!1,transparent:!0}),e=new t.LineBasicMaterial({depthTest:!1,depthWrite:!1,fog:!1,toneMapped:!1,transparent:!0}),o=n.clone();o.opacity=.15;const s=e.clone();s.opacity=.5;const a=n.clone();a.color.setHex(16711680);const i=n.clone();i.color.setHex(65280);const d=n.clone();d.color.setHex(255);const f=n.clone();f.color.setHex(16711680),f.opacity=.5;const E=n.clone();E.color.setHex(65280),E.opacity=.5;const T=n.clone();T.color.setHex(255),T.opacity=.5;const z=n.clone();z.opacity=.25;const C=n.clone();C.color.setHex(16776960),C.opacity=.25,n.clone().color.setHex(16776960);const H=n.clone();H.color.setHex(7895160);const M=new t.CylinderGeometry(0,.04,.1,12);M.translate(0,.05,0);const S=new t.BoxGeometry(.08,.08,.08);S.translate(0,.04,0);const g=new t.BufferGeometry;g.setAttribute("position",new t.Float32BufferAttribute([0,0,0,1,0,0],3));const m=new t.CylinderGeometry(.0075,.0075,.5,3);m.translate(0,.25,0);function y(_,V){const w=new t.TorusGeometry(_,.0075,3,64,V*Math.PI*2);return w.rotateY(Math.PI/2),w.rotateX(Math.PI/2),w}function A(){const _=new t.BufferGeometry;return _.setAttribute("position",new t.Float32BufferAttribute([0,0,0,1,1,1],3)),_}const x={X:[[new t.Mesh(M,a),[.5,0,0],[0,0,-Math.PI/2]],[new t.Mesh(M,a),[-.5,0,0],[0,0,Math.PI/2]],[new t.Mesh(m,a),[0,0,0],[0,0,-Math.PI/2]]],Y:[[new t.Mesh(M,i),[0,.5,0]],[new t.Mesh(M,i),[0,-.5,0],[Math.PI,0,0]],[new t.Mesh(m,i)]],Z:[[new t.Mesh(M,d),[0,0,.5],[Math.PI/2,0,0]],[new t.Mesh(M,d),[0,0,-.5],[-Math.PI/2,0,0]],[new t.Mesh(m,d),null,[Math.PI/2,0,0]]],XYZ:[[new t.Mesh(new t.OctahedronGeometry(.1,0),z.clone()),[0,0,0]]],XY:[[new t.Mesh(new t.BoxGeometry(.15,.15,.01),T.clone()),[.15,.15,0]]],YZ:[[new t.Mesh(new t.BoxGeometry(.15,.15,.01),f.clone()),[0,.15,.15],[0,Math.PI/2,0]]],XZ:[[new t.Mesh(new t.BoxGeometry(.15,.15,.01),E.clone()),[.15,0,.15],[-Math.PI/2,0,0]]]},ht={X:[[new t.Mesh(new t.CylinderGeometry(.2,0,.6,4),o),[.3,0,0],[0,0,-Math.PI/2]],[new t.Mesh(new t.CylinderGeometry(.2,0,.6,4),o),[-.3,0,0],[0,0,Math.PI/2]]],Y:[[new t.Mesh(new t.CylinderGeometry(.2,0,.6,4),o),[0,.3,0]],[new t.Mesh(new t.CylinderGeometry(.2,0,.6,4),o),[0,-.3,0],[0,0,Math.PI]]],Z:[[new t.Mesh(new t.CylinderGeometry(.2,0,.6,4),o),[0,0,.3],[Math.PI/2,0,0]],[new t.Mesh(new t.CylinderGeometry(.2,0,.6,4),o),[0,0,-.3],[-Math.PI/2,0,0]]],XYZ:[[new t.Mesh(new t.OctahedronGeometry(.2,0),o)]],XY:[[new t.Mesh(new t.BoxGeometry(.2,.2,.01),o),[.15,.15,0]]],YZ:[[new t.Mesh(new t.BoxGeometry(.2,.2,.01),o),[0,.15,.15],[0,Math.PI/2,0]]],XZ:[[new t.Mesh(new t.BoxGeometry(.2,.2,.01),o),[.15,0,.15],[-Math.PI/2,0,0]]]},ct={START:[[new t.Mesh(new t.OctahedronGeometry(.01,2),s),null,null,null,"helper"]],END:[[new t.Mesh(new t.OctahedronGeometry(.01,2),s),null,null,null,"helper"]],DELTA:[[new t.Line(A(),s),null,null,null,"helper"]],X:[[new t.Line(g,s.clone()),[-1e3,0,0],null,[1e6,1,1],"helper"]],Y:[[new t.Line(g,s.clone()),[0,-1e3,0],[0,0,Math.PI/2],[1e6,1,1],"helper"]],Z:[[new t.Line(g,s.clone()),[0,0,-1e3],[0,-Math.PI/2,0],[1e6,1,1],"helper"]]},dt={XYZE:[[new t.Mesh(y(.5,1),H),null,[0,Math.PI/2,0]]],X:[[new t.Mesh(y(.5,.5),a)]],Y:[[new t.Mesh(y(.5,.5),i),null,[0,0,-Math.PI/2]]],Z:[[new t.Mesh(y(.5,.5),d),null,[0,Math.PI/2,0]]],E:[[new t.Mesh(y(.75,1),C),null,[0,Math.PI/2,0]]]},pt={AXIS:[[new t.Line(g,s.clone()),[-1e3,0,0],null,[1e6,1,1],"helper"]]},mt={XYZE:[[new t.Mesh(new t.SphereGeometry(.25,10,8),o)]],X:[[new t.Mesh(new t.TorusGeometry(.5,.1,4,24),o),[0,0,0],[0,-Math.PI/2,-Math.PI/2]]],Y:[[new t.Mesh(new t.TorusGeometry(.5,.1,4,24),o),[0,0,0],[Math.PI/2,0,0]]],Z:[[new t.Mesh(new t.TorusGeometry(.5,.1,4,24),o),[0,0,0],[0,0,-Math.PI/2]]],E:[[new t.Mesh(new t.TorusGeometry(.75,.1,2,24),o)]]},ut={X:[[new t.Mesh(S,a),[.5,0,0],[0,0,-Math.PI/2]],[new t.Mesh(m,a),[0,0,0],[0,0,-Math.PI/2]],[new t.Mesh(S,a),[-.5,0,0],[0,0,Math.PI/2]]],Y:[[new t.Mesh(S,i),[0,.5,0]],[new t.Mesh(m,i)],[new t.Mesh(S,i),[0,-.5,0],[0,0,Math.PI]]],Z:[[new t.Mesh(S,d),[0,0,.5],[Math.PI/2,0,0]],[new t.Mesh(m,d),[0,0,0],[Math.PI/2,0,0]],[new t.Mesh(S,d),[0,0,-.5],[-Math.PI/2,0,0]]],XY:[[new t.Mesh(new t.BoxGeometry(.15,.15,.01),T),[.15,.15,0]]],YZ:[[new t.Mesh(new t.BoxGeometry(.15,.15,.01),f),[0,.15,.15],[0,Math.PI/2,0]]],XZ:[[new t.Mesh(new t.BoxGeometry(.15,.15,.01),E),[.15,0,.15],[-Math.PI/2,0,0]]],XYZ:[[new t.Mesh(new t.BoxGeometry(.1,.1,.1),z.clone())]]},ft={X:[[new t.Mesh(new t.CylinderGeometry(.2,0,.6,4),o),[.3,0,0],[0,0,-Math.PI/2]],[new t.Mesh(new t.CylinderGeometry(.2,0,.6,4),o),[-.3,0,0],[0,0,Math.PI/2]]],Y:[[new t.Mesh(new t.CylinderGeometry(.2,0,.6,4),o),[0,.3,0]],[new t.Mesh(new t.CylinderGeometry(.2,0,.6,4),o),[0,-.3,0],[0,0,Math.PI]]],Z:[[new t.Mesh(new t.CylinderGeometry(.2,0,.6,4),o),[0,0,.3],[Math.PI/2,0,0]],[new t.Mesh(new t.CylinderGeometry(.2,0,.6,4),o),[0,0,-.3],[-Math.PI/2,0,0]]],XY:[[new t.Mesh(new t.BoxGeometry(.2,.2,.01),o),[.15,.15,0]]],YZ:[[new t.Mesh(new t.BoxGeometry(.2,.2,.01),o),[0,.15,.15],[0,Math.PI/2,0]]],XZ:[[new t.Mesh(new t.BoxGeometry(.2,.2,.01),o),[.15,0,.15],[-Math.PI/2,0,0]]],XYZ:[[new t.Mesh(new t.BoxGeometry(.2,.2,.2),o),[0,0,0]]]},_t={X:[[new t.Line(g,s.clone()),[-1e3,0,0],null,[1e6,1,1],"helper"]],Y:[[new t.Line(g,s.clone()),[0,-1e3,0],[0,0,Math.PI/2],[1e6,1,1],"helper"]],Z:[[new t.Line(g,s.clone()),[0,0,-1e3],[0,-Math.PI/2,0],[1e6,1,1],"helper"]]};function v(_){const V=new t.Object3D;for(const w in _)for(let G=_[w].length;G--;){const u=_[w][G][0].clone(),L=_[w][G][1],R=_[w][G][2],k=_[w][G][3],yt=_[w][G][4];u.name=w,u.tag=yt,L&&u.position.set(L[0],L[1],L[2]),R&&u.rotation.set(R[0],R[1],R[2]),k&&u.scale.set(k[0],k[1],k[2]),u.updateMatrix();const J=u.geometry.clone();J.applyMatrix4(u.matrix),u.geometry=J,u.renderOrder=1/0,u.position.set(0,0,0),u.rotation.set(0,0,0),u.scale.set(1,1,1),V.add(u)}return V}this.gizmo={},this.picker={},this.helper={},this.add(this.gizmo.translate=v(x)),this.add(this.gizmo.rotate=v(dt)),this.add(this.gizmo.scale=v(ut)),this.add(this.picker.translate=v(ht)),this.add(this.picker.rotate=v(mt)),this.add(this.picker.scale=v(ft)),this.add(this.helper.translate=v(ct)),this.add(this.helper.rotate=v(pt)),this.add(this.helper.scale=v(_t)),this.picker.translate.visible=!1,this.picker.rotate.visible=!1,this.picker.scale.visible=!1}updateMatrixWorld(n){const o=(this.mode==="scale"?"local":this.space)==="local"?this.worldQuaternion:F;this.gizmo.translate.visible=this.mode==="translate",this.gizmo.rotate.visible=this.mode==="rotate",this.gizmo.scale.visible=this.mode==="scale",this.helper.translate.visible=this.mode==="translate",this.helper.rotate.visible=this.mode==="rotate",this.helper.scale.visible=this.mode==="scale";let s=[];s=s.concat(this.picker[this.mode].children),s=s.concat(this.gizmo[this.mode].children),s=s.concat(this.helper[this.mode].children);for(let a=0;a<s.length;a++){const i=s[a];i.visible=!0,i.rotation.set(0,0,0),i.position.copy(this.worldPosition);let d;if(this.camera.isOrthographicCamera?d=(this.camera.top-this.camera.bottom)/this.camera.zoom:d=this.worldPosition.distanceTo(this.cameraPosition)*Math.min(1.9*Math.tan(Math.PI*this.camera.fov/360)/this.camera.zoom,7),i.scale.set(1,1,1).multiplyScalar(d*this.size/4),i.tag==="helper"){i.visible=!1,i.name==="AXIS"?(i.visible=!!this.axis,this.axis==="X"&&(c.setFromEuler(q.set(0,0,0)),i.quaternion.copy(o).multiply(c),Math.abs(l.copy(O).applyQuaternion(o).dot(this.eye))>.9&&(i.visible=!1)),this.axis==="Y"&&(c.setFromEuler(q.set(0,0,Math.PI/2)),i.quaternion.copy(o).multiply(c),Math.abs(l.copy(I).applyQuaternion(o).dot(this.eye))>.9&&(i.visible=!1)),this.axis==="Z"&&(c.setFromEuler(q.set(0,Math.PI/2,0)),i.quaternion.copy(o).multiply(c),Math.abs(l.copy(Z).applyQuaternion(o).dot(this.eye))>.9&&(i.visible=!1)),this.axis==="XYZE"&&(c.setFromEuler(q.set(0,Math.PI/2,0)),l.copy(this.rotationAxis),i.quaternion.setFromRotationMatrix(st.lookAt(ot,l,I)),i.quaternion.multiply(c),i.visible=this.dragging),this.axis==="E"&&(i.visible=!1)):i.name==="START"?(i.position.copy(this.worldPositionStart),i.visible=this.dragging):i.name==="END"?(i.position.copy(this.worldPosition),i.visible=this.dragging):i.name==="DELTA"?(i.position.copy(this.worldPositionStart),i.quaternion.copy(this.worldQuaternionStart),p.set(1e-10,1e-10,1e-10).add(this.worldPositionStart).sub(this.worldPosition).multiplyScalar(-1),p.applyQuaternion(this.worldQuaternionStart.clone().invert()),i.scale.copy(p),i.visible=this.dragging):(i.quaternion.copy(o),this.dragging?i.position.copy(this.worldPositionStart):i.position.copy(this.worldPosition),this.axis&&(i.visible=this.axis.search(i.name)!==-1));continue}i.quaternion.copy(o),this.mode==="translate"||this.mode==="scale"?(i.name==="X"&&Math.abs(l.copy(O).applyQuaternion(o).dot(this.eye))>.99&&(i.scale.set(1e-10,1e-10,1e-10),i.visible=!1),i.name==="Y"&&Math.abs(l.copy(I).applyQuaternion(o).dot(this.eye))>.99&&(i.scale.set(1e-10,1e-10,1e-10),i.visible=!1),i.name==="Z"&&Math.abs(l.copy(Z).applyQuaternion(o).dot(this.eye))>.99&&(i.scale.set(1e-10,1e-10,1e-10),i.visible=!1),i.name==="XY"&&Math.abs(l.copy(Z).applyQuaternion(o).dot(this.eye))<.2&&(i.scale.set(1e-10,1e-10,1e-10),i.visible=!1),i.name==="YZ"&&Math.abs(l.copy(O).applyQuaternion(o).dot(this.eye))<.2&&(i.scale.set(1e-10,1e-10,1e-10),i.visible=!1),i.name==="XZ"&&Math.abs(l.copy(I).applyQuaternion(o).dot(this.eye))<.2&&(i.scale.set(1e-10,1e-10,1e-10),i.visible=!1)):this.mode==="rotate"&&(B.copy(o),l.copy(this.eye).applyQuaternion(c.copy(o).invert()),i.name.search("E")!==-1&&i.quaternion.setFromRotationMatrix(st.lookAt(this.eye,ot,I)),i.name==="X"&&(c.setFromAxisAngle(O,Math.atan2(-l.y,l.z)),c.multiplyQuaternions(B,c),i.quaternion.copy(c)),i.name==="Y"&&(c.setFromAxisAngle(I,Math.atan2(l.x,l.z)),c.multiplyQuaternions(B,c),i.quaternion.copy(c)),i.name==="Z"&&(c.setFromAxisAngle(Z,Math.atan2(l.y,l.x)),c.multiplyQuaternions(B,c),i.quaternion.copy(c))),i.visible=i.visible&&(i.name.indexOf("X")===-1||this.showX),i.visible=i.visible&&(i.name.indexOf("Y")===-1||this.showY),i.visible=i.visible&&(i.name.indexOf("Z")===-1||this.showZ),i.visible=i.visible&&(i.name.indexOf("E")===-1||this.showX&&this.showY&&this.showZ),i.material._color=i.material._color||i.material.color.clone(),i.material._opacity=i.material._opacity||i.material.opacity,i.material.color.copy(i.material._color),i.material.opacity=i.material._opacity,this.enabled&&this.axis&&(i.name===this.axis||this.axis.split("").some(function(f){return i.name===f}))&&(i.material.color.setHex(16776960),i.material.opacity=1)}super.updateMatrixWorld(n)}}class Dt extends t.Mesh{constructor(){super(new t.PlaneGeometry(1e5,1e5,2,2),new t.MeshBasicMaterial({visible:!1,wireframe:!0,side:t.DoubleSide,transparent:!0,opacity:.1,toneMapped:!1})),this.isTransformControlsPlane=!0,this.type="TransformControlsPlane"}updateMatrixWorld(n){let e=this.space;switch(this.position.copy(this.worldPosition),this.mode==="scale"&&(e="local"),W.copy(O).applyQuaternion(e==="local"?this.worldQuaternion:F),X.copy(I).applyQuaternion(e==="local"?this.worldQuaternion:F),Y.copy(Z).applyQuaternion(e==="local"?this.worldQuaternion:F),l.copy(X),this.mode){case"translate":case"scale":switch(this.axis){case"X":l.copy(this.eye).cross(W),b.copy(W).cross(l);break;case"Y":l.copy(this.eye).cross(X),b.copy(X).cross(l);break;case"Z":l.copy(this.eye).cross(Y),b.copy(Y).cross(l);break;case"XY":b.copy(Y);break;case"YZ":b.copy(W);break;case"XZ":l.copy(Y),b.copy(X);break;case"XYZ":case"E":b.set(0,0,0);break}break;case"rotate":default:b.set(0,0,0)}b.length()===0?this.quaternion.copy(this.cameraQuaternion):(rt.lookAt(p.set(0,0,0),b,l),this.quaternion.setFromRotationMatrix(rt)),super.updateMatrixWorld(n)}}class at{constructor(n,e){h(this,"POINTER_DRAG_THRESHOLD",.001);h(this,"name");h(this,"_canvas");h(this,"_scene");h(this,"_controller");h(this,"_pointer");h(this,"_pointerPrimaryDown");h(this,"_pointerMiddleDown");h(this,"_pointerSecondaryDown");h(this,"_lastPointerDown");h(this,"_lastPointerUp");h(this,"_raycaster");h(this,"_intersects");h(this,"_hovered");h(this,"_dragging");h(this,"_dragStart");h(this,"_dragCurrent");h(this,"_dragEnd");h(this,"_dragDelta");h(this,"_draggable");h(this,"_dragRaycastOnObjects");this.name="BaseTool",this._canvas=e.domElement,this._scene=n,this._controller=e,this._pointer=new t.Vector2,this._pointerPrimaryDown=!1,this._pointerMiddleDown=!1,this._pointerSecondaryDown=!1,this._lastPointerDown=new t.Vector2,this._lastPointerUp=new t.Vector2,this._raycaster=new t.Raycaster,this._raycaster.layers.mask=$.PRODUCT_LAYER_MASK|$.UI_LAYER_MASK,this._intersects=[],this._hovered=null,this._dragging=!1,this._dragStart=new t.Vector3,this._dragCurrent=new t.Vector3,this._dragEnd=new t.Vector3,this._dragDelta=new t.Vector3,this._draggable=null,this._dragRaycastOnObjects=null}get _pointerAnyDown(){return this._pointerPrimaryDown||this._pointerMiddleDown||this._pointerSecondaryDown}activate(){}deactivate(){}onPointerDown(n){var e;switch(n.button){case 0:{this._pointerPrimaryDown=!0;break}case 1:{this._pointerMiddleDown=!0;break}case 2:{this._pointerSecondaryDown=!0;break}default:console.warn("DIVEBaseTool.onPointerDown: Unknown button: "+n.button)}this._lastPointerDown.copy(this._pointer),this._draggable=j.findInterface((e=this._intersects[0])==null?void 0:e.object,"isDraggable")||null}onDragStart(n){this._draggable&&(this._dragRaycastOnObjects!==null&&(this._intersects=this._raycaster.intersectObjects(this._dragRaycastOnObjects,!0)),this._intersects.length!==0&&(this._dragStart.copy(this._intersects[0].point.clone()),this._dragCurrent.copy(this._intersects[0].point.clone()),this._dragEnd.copy(this._dragStart.clone()),this._dragDelta.set(0,0,0),this._draggable&&this._draggable.onDragStart&&(this._draggable.onDragStart({dragStart:this._dragStart,dragCurrent:this._dragCurrent,dragEnd:this._dragEnd,dragDelta:this._dragDelta}),this._dragging=!0,this._controller.enabled=!1)))}onPointerMove(n){var o;this._pointer.x=n.offsetX/this._canvas.clientWidth*2-1,this._pointer.y=-(n.offsetY/this._canvas.clientHeight)*2+1,this._raycaster.setFromCamera(this._pointer,this._controller.object),this._intersects=this.raycast(this._scene.children);const e=j.findInterface((o=this._intersects[0])==null?void 0:o.object,"isHoverable");if(this._intersects[0]&&e){if(!this._hovered){e.onPointerEnter&&e.onPointerEnter(this._intersects[0]),this._hovered=e;return}if(this._hovered.uuid!==e.uuid){this._hovered.onPointerLeave&&this._hovered.onPointerLeave(),e.onPointerEnter&&e.onPointerEnter(this._intersects[0]),this._hovered=e;return}e.onPointerOver&&e.onPointerOver(this._intersects[0]),this._hovered=e}else this._hovered&&this._hovered.onPointerLeave&&this._hovered.onPointerLeave(),this._hovered=null;this._pointerAnyDown&&(this._dragging||this.onDragStart(n),this.onDrag(n))}onDrag(n){this._dragRaycastOnObjects!==null&&(this._intersects=this._raycaster.intersectObjects(this._dragRaycastOnObjects,!0));const e=this._intersects[0];e&&(this._dragCurrent.copy(e.point.clone()),this._dragEnd.copy(e.point.clone()),this._dragDelta.subVectors(this._dragCurrent.clone(),this._dragStart.clone()),this._draggable&&this._draggable.onDrag&&this._draggable.onDrag({dragStart:this._dragStart,dragCurrent:this._dragCurrent,dragEnd:this._dragEnd,dragDelta:this._dragDelta}))}onPointerUp(n){switch(this.pointerWasDragged()||this._dragging?this._draggable&&this.onDragEnd(n):this.onClick(n),n.button){case 0:this._pointerPrimaryDown=!1;break;case 1:this._pointerMiddleDown=!1;break;case 2:this._pointerSecondaryDown=!1;break}this._lastPointerUp.copy(this._pointer)}onClick(n){}onDragEnd(n){const e=this._intersects[0];e&&(this._dragEnd.copy(e.point.clone()),this._dragCurrent.copy(e.point.clone()),this._dragDelta.subVectors(this._dragCurrent.clone(),this._dragStart.clone())),this._draggable&&this._draggable.onDragEnd&&this._draggable.onDragEnd({dragStart:this._dragStart,dragCurrent:this._dragCurrent,dragEnd:this._dragEnd,dragDelta:this._dragDelta}),this._draggable=null,this._dragging=!1,this._dragStart.set(0,0,0),this._dragCurrent.set(0,0,0),this._dragEnd.set(0,0,0),this._dragDelta.set(0,0,0),this._controller.enabled=!0}onWheel(n){}raycast(n){return n!==void 0?this._raycaster.intersectObjects(n,!0).filter(e=>e.object.visible):this._raycaster.intersectObjects(this._scene.children,!0).filter(e=>e.object.visible)}pointerWasDragged(){return this._lastPointerDown.distanceTo(this._pointer)>this.POINTER_DRAG_THRESHOLD}}const It=r=>r.isTransformTool!==void 0;class lt extends at{constructor(e,o){super(e,o);h(this,"isTransformTool",!0);h(this,"_scaleLinked");h(this,"_gizmo");this.name="DIVETransformTool",this._scaleLinked=!1,this._gizmo=this.initGizmo(),this._scene.add(this._gizmo)}activate(){}setGizmoMode(e){this._gizmo.mode=e}setGizmoVisible(e){const o=this._scene.children.includes(this._gizmo);e&&!o?(this._scene.add(this._gizmo),"isTransformControls"in this._gizmo&&this._gizmo.getRaycaster().layers.enableAll()):!e&&o&&(this._scene.remove(this._gizmo),"isTransformControls"in this._gizmo&&this._gizmo.getRaycaster().layers.disableAll())}setGizmoScaleLinked(e){this._scaleLinked=e}initGizmo(){const e=new bt(this._controller.object,this._controller.domElement);return e.mode="translate",e.traverse(o=>{if(!("isMesh"in o))return;const s=o.material;o.name==="X"&&s.color.set(Q.AxesColorRed),o.name==="Y"&&s.color.set(Q.AxesColorGreen),o.name==="Z"&&s.color.set(Q.AxesColorBlue),o.name==="XY"&&s.color.set(Q.AxesColorBlue),o.name==="YZ"&&s.color.set(Q.AxesColorRed),o.name==="XZ"&&s.color.set(Q.AxesColorGreen)}),e.addEventListener("mouseDown",()=>{this._controller.enabled=!1,j.implementsInterface(e.object,"isMovable")&&e.object.onMoveStart&&e.object.onMoveStart()}),e.addEventListener("objectChange",()=>{if(j.implementsInterface(e.object,"isMovable")&&e.object.onMove&&(e.object.onMove(),this._scaleLinked)){const o=e.object.scale,s=(o.x+o.y+o.z)/3;e.object.scale.set(s,s,s)}}),e.addEventListener("mouseUp",()=>{this._controller.enabled=!0,j.implementsInterface(e.object,"isMovable")&&e.object.onMoveEnd&&e.object.onMoveEnd()}),e}}const Tt=r=>r.isSelectTool!==void 0;class At extends lt{constructor(e,o){super(e,o);h(this,"isSelectTool",!0);this.name="SelectTool"}activate(){}select(e){this.attachGizmo(e),e.onSelect&&e.onSelect()}deselect(e){this.detachGizmo(),e.onDeselect&&e.onDeselect()}attachGizmo(e){if("isMovable"in e){const o=e;this._gizmo.attach(o),this.setGizmoVisible(o.visible)}}detachGizmo(){this._gizmo.detach()}onClick(e){super.onClick(e);const o=this._raycaster.intersectObjects(this._scene.root.children,!0).filter(a=>a.object.visible)[0],s=j.findInterface(o==null?void 0:o.object,"isSelectable");if(!o||!s){this._gizmo.object&&this.deselect(this._gizmo.object);return}if(this._gizmo.object){if(this._gizmo.object.uuid===s.uuid)return;this.deselect(this._gizmo.object)}this.select(s)}}exports.DIVEBaseTool=at;exports.DIVESelectTool=At;exports.DIVETransformTool=lt;exports.isSelectTool=Tt;exports.isTransformTool=It;
|