@shopware-ag/dive 1.19.0 → 1.19.1-beta.1
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/dive.cjs +388 -220
- package/build/dive.cjs.map +1 -1
- package/build/dive.js +395 -21946
- package/build/dive.js.map +1 -1
- package/build/dive.mjs +28206 -0
- package/build/dive.mjs.map +1 -0
- package/build/src/ar/AR.d.ts +37 -14
- package/build/src/ar/arquicklook/ARQuickLook.d.ts +5 -6
- package/build/src/ar/sceneviewer/SceneViewer.d.ts +42 -6
- package/build/src/com/actions/scene/launchar.d.ts +5 -2
- package/build/src/converter/Converter.d.ts +21 -0
- package/build/src/dive.d.ts +3 -2
- package/build/src/exporter/Exporter.d.ts +11 -0
- package/build/src/helper/applyMixins/applyMixins.d.ts +22 -6
- package/build/src/info/Info.d.ts +37 -13
- package/build/src/interface/Movable.d.ts +5 -5
- package/build/src/interface/Selectable.d.ts +4 -4
- package/build/src/loader/Loader.d.ts +11 -0
- package/build/src/model/Model.d.ts +2 -2
- package/build/src/node/Node.d.ts +3 -3
- package/build/src/scene/root/Root.d.ts +1 -1
- package/build/src/types/ExporterOptions.d.ts +15 -0
- package/build/src/types/FileTypes.d.ts +27 -0
- package/build/src/types/index.d.ts +4 -0
- package/build/src/types/info/index.d.ts +66 -0
- package/package.json +17 -3
- package/build/src/exporters/usdz/USDZExporter.d.ts +0 -15
- package/build/src/loadingmanager/LoadingManager.d.ts +0 -14
- package/src/__test__/DIVE.test.ts +0 -274
- package/src/animation/AnimationSystem.ts +0 -34
- package/src/animation/__test__/AnimationSystem.test.ts +0 -40
- package/src/ar/AR.ts +0 -98
- package/src/ar/__test__/AR.test.ts +0 -187
- package/src/ar/arquicklook/ARQuickLook.ts +0 -93
- package/src/ar/arquicklook/__test__/ARQuickLook.test.ts +0 -93
- package/src/ar/sceneviewer/SceneViewer.ts +0 -74
- package/src/ar/sceneviewer/__test__/SceneViewer.test.ts +0 -93
- package/src/ar/webxr/WebXR.ts +0 -176
- package/src/ar/webxr/controller/WebXRController.ts +0 -340
- package/src/ar/webxr/crosshair/WebXRCrosshair.ts +0 -35
- package/src/ar/webxr/origin/WebXROrigin.ts +0 -192
- package/src/ar/webxr/overlay/Overlay.ts +0 -50
- package/src/ar/webxr/raycaster/WebXRRaycaster.ts +0 -131
- package/src/ar/webxr/raycaster/ar/WebXRRaycasterAR.ts +0 -102
- package/src/ar/webxr/raycaster/three/WebXRRaycasterTHREE.ts +0 -49
- package/src/ar/webxr/touchscreencontrols/WebXRTouchscreenControls.ts +0 -356
- package/src/axiscamera/AxisCamera.ts +0 -108
- package/src/axiscamera/__test__/AxisCamera.test.ts +0 -150
- package/src/camera/PerspectiveCamera.ts +0 -63
- package/src/camera/__test__/PerspectiveCamera.test.ts +0 -36
- package/src/com/Communication.ts +0 -808
- package/src/com/__test__/Communication.test.ts +0 -1024
- package/src/com/actions/camera/computeencompassingview.ts +0 -10
- package/src/com/actions/camera/getcameratransform.ts +0 -10
- package/src/com/actions/camera/movecamera.ts +0 -18
- package/src/com/actions/camera/resetcamera.ts +0 -5
- package/src/com/actions/camera/setcameralayer.ts +0 -5
- package/src/com/actions/camera/setcameratransform.ts +0 -10
- package/src/com/actions/camera/zoomcamera.ts +0 -5
- package/src/com/actions/index.ts +0 -61
- package/src/com/actions/media/generatemedia.ts +0 -18
- package/src/com/actions/object/addobject.ts +0 -7
- package/src/com/actions/object/deleteobject.ts +0 -7
- package/src/com/actions/object/deselectobject.ts +0 -7
- package/src/com/actions/object/getallobjects.ts +0 -7
- package/src/com/actions/object/getobjects.ts +0 -7
- package/src/com/actions/object/model/dropit.ts +0 -5
- package/src/com/actions/object/model/modelloaded.ts +0 -5
- package/src/com/actions/object/model/placeonfloor.ts +0 -5
- package/src/com/actions/object/selectobject.ts +0 -7
- package/src/com/actions/object/setparent.ts +0 -10
- package/src/com/actions/object/updateobject.ts +0 -7
- package/src/com/actions/renderer/startrender.ts +0 -5
- package/src/com/actions/scene/exportscene.ts +0 -7
- package/src/com/actions/scene/getallscenedata.ts +0 -7
- package/src/com/actions/scene/launchar.ts +0 -7
- package/src/com/actions/scene/setbackground.ts +0 -5
- package/src/com/actions/scene/updatescene.ts +0 -11
- package/src/com/actions/toolbox/select/setgizmomode.ts +0 -5
- package/src/com/actions/toolbox/transform/setgizmoscalelinked.ts +0 -5
- package/src/com/actions/toolbox/transform/setgizmovisible.ts +0 -5
- package/src/com/actions/toolbox/usetool.ts +0 -7
- package/src/com/types/COMBaseEntity.ts +0 -9
- package/src/com/types/COMEntity.ts +0 -7
- package/src/com/types/COMEntityType.ts +0 -1
- package/src/com/types/COMGeometry.ts +0 -8
- package/src/com/types/COMGeometryType.ts +0 -9
- package/src/com/types/COMGroup.ts +0 -9
- package/src/com/types/COMLight.ts +0 -11
- package/src/com/types/COMMaterial.ts +0 -12
- package/src/com/types/COMModel.ts +0 -12
- package/src/com/types/COMPov.ts +0 -8
- package/src/com/types/COMPrimitive.ts +0 -12
- package/src/com/types/index.ts +0 -23
- package/src/constant/AxisHelperColors.ts +0 -7
- package/src/constant/GridColors.ts +0 -2
- package/src/constant/VisibilityLayerMask.ts +0 -5
- package/src/controls/OrbitControls.ts +0 -211
- package/src/controls/__test__/OrbitControls.test.ts +0 -256
- package/src/dive.ts +0 -363
- package/src/events/EventExecutor.ts +0 -35
- package/src/exporters/usdz/USDZExporter.ts +0 -21
- package/src/exporters/usdz/__test__/USDZExporter.test.ts +0 -57
- package/src/gizmo/Gizmo.ts +0 -144
- package/src/gizmo/handles/AxisHandle.ts +0 -153
- package/src/gizmo/handles/RadialHandle.ts +0 -149
- package/src/gizmo/handles/ScaleHandle.ts +0 -195
- package/src/gizmo/plane/GizmoPlane.ts +0 -84
- package/src/gizmo/rotate/RotateGizmo.ts +0 -143
- package/src/gizmo/scale/ScaleGizmo.ts +0 -125
- package/src/gizmo/translate/TranslateGizmo.ts +0 -114
- package/src/grid/Grid.ts +0 -34
- package/src/grid/__test__/Grid.test.ts +0 -28
- package/src/group/Group.ts +0 -184
- package/src/group/__test__/Group.test.ts +0 -212
- package/src/helper/applyMixins/__test__/applyMixins.test.ts +0 -30
- package/src/helper/applyMixins/applyMixins.ts +0 -18
- package/src/helper/findInterface/__test__/findInterface.test.ts +0 -63
- package/src/helper/findInterface/findInterface.ts +0 -13
- package/src/helper/findSceneRecursive/__test__/findSceneRecursive.test.ts +0 -40
- package/src/helper/findSceneRecursive/findSceneRecursive.ts +0 -16
- package/src/helper/getObjectDelta/__test__/getObjectDelta.test.ts +0 -186
- package/src/helper/getObjectDelta/getObjectDelta.ts +0 -105
- package/src/helper/isInterface/__test__/implementsInterface.test.ts +0 -19
- package/src/helper/isInterface/implementsInterface.ts +0 -9
- package/src/info/Info.ts +0 -154
- package/src/info/__test__/Info.test.ts +0 -338
- package/src/interface/Draggable.ts +0 -14
- package/src/interface/Hoverable.ts +0 -14
- package/src/interface/Movable.ts +0 -12
- package/src/interface/Rotatable.ts +0 -10
- package/src/interface/Scalable.ts +0 -10
- package/src/interface/Selectable.ts +0 -11
- package/src/io/IO.ts +0 -62
- package/src/io/__test__/IO.test.ts +0 -116
- package/src/io/gltf/GLTFIO.ts +0 -56
- package/src/io/gltf/__test__/GLTFIO.test.ts +0 -108
- package/src/light/AmbientLight.ts +0 -39
- package/src/light/PointLight.ts +0 -115
- package/src/light/SceneLight.ts +0 -63
- package/src/light/__test__/AmbientLight.test.ts +0 -29
- package/src/light/__test__/PointLight.test.ts +0 -74
- package/src/light/__test__/SceneLight.test.ts +0 -47
- package/src/loadingmanager/LoadingManager.ts +0 -50
- package/src/loadingmanager/__test__/LoadingManager.test.ts +0 -27
- package/src/math/__test__/DIVEMath.test.ts +0 -12
- package/src/math/ceil/__test__/ceilExp.test.ts +0 -12
- package/src/math/ceil/ceilExp.ts +0 -6
- package/src/math/degToRad/__test__/degToRad.test.ts +0 -172
- package/src/math/degToRad/degToRad.ts +0 -5
- package/src/math/floor/__test__/floorExp.test.ts +0 -14
- package/src/math/floor/floorExp.ts +0 -6
- package/src/math/helper/__test__/shift.test.ts +0 -12
- package/src/math/helper/shift.ts +0 -4
- package/src/math/index.ts +0 -28
- package/src/math/radToDeg/__test__/radToDeg.test.ts +0 -155
- package/src/math/radToDeg/radToDeg.ts +0 -5
- package/src/math/round/__test__/roundExp.test.ts +0 -14
- package/src/math/round/roundExp.ts +0 -10
- package/src/math/signedAngleTo/__test__/signedAngleTo.test.ts +0 -20
- package/src/math/signedAngleTo/signedAngleTo.ts +0 -20
- package/src/math/toFixed/__test__/toFixedExp.test.ts +0 -14
- package/src/math/toFixed/toFixedExp.ts +0 -9
- package/src/math/truncate/__test__/truncateExp.test.ts +0 -14
- package/src/math/truncate/truncateExp.ts +0 -9
- package/src/mediacreator/MediaCreator.ts +0 -75
- package/src/mediacreator/__test__/MediaCreator.test.ts +0 -155
- package/src/model/Model.ts +0 -185
- package/src/model/__test__/Model.test.ts +0 -222
- package/src/module/Module.ts +0 -45
- package/src/module/__test__/Module.test.ts +0 -54
- package/src/node/Node.ts +0 -98
- package/src/node/__test__/Node.test.ts +0 -120
- package/src/primitive/Primitive.ts +0 -299
- package/src/primitive/__test__/Primitive.test.ts +0 -281
- package/src/primitive/floor/Floor.ts +0 -45
- package/src/primitive/floor/__test__/Floor.test.ts +0 -24
- package/src/renderer/Renderer.ts +0 -215
- package/src/renderer/__test__/Renderer.test.ts +0 -228
- package/src/scene/Scene.ts +0 -106
- package/src/scene/__test__/Scene.test.ts +0 -124
- package/src/scene/root/Root.ts +0 -426
- package/src/scene/root/__test__/Root.test.ts +0 -903
- package/src/scene/xrroot/XRRoot.ts +0 -56
- package/src/scene/xrroot/xrlightroot/XRLightRoot.ts +0 -80
- package/src/toolbox/BaseTool.ts +0 -319
- package/src/toolbox/Toolbox.ts +0 -129
- package/src/toolbox/__test__/BaseTool.test.ts +0 -627
- package/src/toolbox/__test__/Toolbox.test.ts +0 -143
- package/src/toolbox/select/SelectTool.ts +0 -92
- package/src/toolbox/select/__test__/SelectTool.test.ts +0 -237
- package/src/toolbox/transform/TransformTool.ts +0 -166
- package/src/toolbox/transform/__test__/TransformTool.test.ts +0 -147
- package/src/types/SceneData.ts +0 -26
- package/src/types/SceneObjects.ts +0 -14
- package/src/types/SceneType.ts +0 -14
- package/src/types/index.ts +0 -5
package/src/node/Node.ts
DELETED
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
import { Box3, Object3D, Vector3, type Vector3Like } from 'three';
|
|
2
|
-
import { PRODUCT_LAYER_MASK } from '../constant/VisibilityLayerMask';
|
|
3
|
-
import { DIVECommunication } from '../com/Communication';
|
|
4
|
-
|
|
5
|
-
import { type DIVEMovable } from '../interface/Movable';
|
|
6
|
-
import { type DIVESelectable } from '../interface/Selectable';
|
|
7
|
-
import { type TransformControls } from 'three/examples/jsm/controls/TransformControls';
|
|
8
|
-
import { type DIVEGroup } from '../group/Group';
|
|
9
|
-
|
|
10
|
-
export class DIVENode extends Object3D implements DIVESelectable, DIVEMovable {
|
|
11
|
-
readonly isDIVENode: true = true;
|
|
12
|
-
readonly isSelectable: true = true;
|
|
13
|
-
readonly isMovable: true = true;
|
|
14
|
-
|
|
15
|
-
public gizmo: TransformControls | null = null;
|
|
16
|
-
|
|
17
|
-
protected _positionWorldBuffer: Vector3;
|
|
18
|
-
protected _boundingBox: Box3;
|
|
19
|
-
|
|
20
|
-
constructor() {
|
|
21
|
-
super();
|
|
22
|
-
|
|
23
|
-
this.layers.mask = PRODUCT_LAYER_MASK;
|
|
24
|
-
|
|
25
|
-
this._positionWorldBuffer = new Vector3();
|
|
26
|
-
this._boundingBox = new Box3();
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
public SetPosition(position: Vector3Like): void {
|
|
30
|
-
// if there is no parent, the object will be attached later and keep it's world position
|
|
31
|
-
if (!this.parent) {
|
|
32
|
-
this.position.set(position.x, position.y, position.z);
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// if we have a parent, we have to calculate the position in the parent's coordinate system to keep the world position
|
|
37
|
-
const newPosition = new Vector3(position.x, position.y, position.z);
|
|
38
|
-
this.position.copy(this.parent.worldToLocal(newPosition));
|
|
39
|
-
|
|
40
|
-
if ('isDIVEGroup' in this.parent) {
|
|
41
|
-
(this.parent as unknown as DIVEGroup).UpdateLineTo(this);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
public SetRotation(rotation: Vector3Like): void {
|
|
46
|
-
this.rotation.set(rotation.x, rotation.y, rotation.z);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
public SetScale(scale: Vector3Like): void {
|
|
50
|
-
this.scale.set(scale.x, scale.y, scale.z);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
public SetVisibility(visible: boolean): void {
|
|
54
|
-
this.visible = visible;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
public SetToWorldOrigin(): void {
|
|
58
|
-
this.position.set(0, 0, 0);
|
|
59
|
-
DIVECommunication.get(this.userData.id)?.PerformAction(
|
|
60
|
-
'UPDATE_OBJECT',
|
|
61
|
-
{
|
|
62
|
-
id: this.userData.id,
|
|
63
|
-
position: this.getWorldPosition(this._positionWorldBuffer),
|
|
64
|
-
rotation: this.rotation,
|
|
65
|
-
scale: this.scale,
|
|
66
|
-
},
|
|
67
|
-
);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Can be called when the object is moved from a foreign object (gizmo, parent, etc.) to update the object's position.
|
|
72
|
-
*/
|
|
73
|
-
public onMove(): void {
|
|
74
|
-
DIVECommunication.get(this.userData.id)?.PerformAction(
|
|
75
|
-
'UPDATE_OBJECT',
|
|
76
|
-
{
|
|
77
|
-
id: this.userData.id,
|
|
78
|
-
position: this.getWorldPosition(this._positionWorldBuffer),
|
|
79
|
-
rotation: this.rotation,
|
|
80
|
-
scale: this.scale,
|
|
81
|
-
},
|
|
82
|
-
);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
public onSelect(): void {
|
|
86
|
-
DIVECommunication.get(this.userData.id)?.PerformAction(
|
|
87
|
-
'SELECT_OBJECT',
|
|
88
|
-
{ id: this.userData.id },
|
|
89
|
-
);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
public onDeselect(): void {
|
|
93
|
-
DIVECommunication.get(this.userData.id)?.PerformAction(
|
|
94
|
-
'DESELECT_OBJECT',
|
|
95
|
-
{ id: this.userData.id },
|
|
96
|
-
);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
import { DIVENode } from '../Node';
|
|
2
|
-
import { DIVECommunication } from '../../com/Communication';
|
|
3
|
-
import { Vector3, Box3, Mesh, Color, Euler } from 'three';
|
|
4
|
-
import { type DIVEGroup } from '../../group/Group';
|
|
5
|
-
|
|
6
|
-
jest.mock('../../com/Communication.ts', () => {
|
|
7
|
-
return {
|
|
8
|
-
DIVECommunication: {
|
|
9
|
-
get: jest.fn(() => {
|
|
10
|
-
return {
|
|
11
|
-
PerformAction: jest.fn(),
|
|
12
|
-
};
|
|
13
|
-
}),
|
|
14
|
-
},
|
|
15
|
-
};
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
jest.spyOn(DIVECommunication, 'get').mockReturnValue({
|
|
19
|
-
PerformAction: jest.fn(),
|
|
20
|
-
} as unknown as DIVECommunication);
|
|
21
|
-
|
|
22
|
-
let node: DIVENode;
|
|
23
|
-
|
|
24
|
-
describe('dive/node/DIVENode', () => {
|
|
25
|
-
beforeEach(() => {
|
|
26
|
-
node = new DIVENode();
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
afterEach(() => {
|
|
30
|
-
jest.clearAllMocks();
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it('should instantiate', () => {
|
|
34
|
-
expect(node).toBeDefined();
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it('should set position', () => {
|
|
38
|
-
const spySet = jest.spyOn(node.position, 'set');
|
|
39
|
-
const spyCopy = jest.spyOn(node.position, 'copy');
|
|
40
|
-
|
|
41
|
-
// without a parent, the node should only set it's local position
|
|
42
|
-
node.parent = null;
|
|
43
|
-
expect(() => node.SetPosition({ x: 1, y: 2, z: 3 })).not.toThrow();
|
|
44
|
-
expect(spySet).toHaveBeenCalledWith(1, 2, 3);
|
|
45
|
-
expect(spyCopy).not.toHaveBeenCalled();
|
|
46
|
-
|
|
47
|
-
// with a parent, the node should set it's position relative to the parent
|
|
48
|
-
spySet.mockClear();
|
|
49
|
-
spyCopy.mockClear();
|
|
50
|
-
node.parent = {
|
|
51
|
-
worldToLocal: jest.fn(() => new Vector3(4, 5, 6)),
|
|
52
|
-
isDIVEGroup: true,
|
|
53
|
-
UpdateLineTo: jest.fn(),
|
|
54
|
-
} as unknown as DIVENode;
|
|
55
|
-
const spyUpdateLineTo = jest.spyOn(
|
|
56
|
-
node.parent as DIVEGroup,
|
|
57
|
-
'UpdateLineTo',
|
|
58
|
-
);
|
|
59
|
-
expect(() => node.SetPosition({ x: 4, y: 5, z: 6 })).not.toThrow();
|
|
60
|
-
expect(spySet).not.toHaveBeenCalled();
|
|
61
|
-
expect(spyCopy).toHaveBeenCalledWith(
|
|
62
|
-
expect.objectContaining({ x: 4, y: 5, z: 6 }),
|
|
63
|
-
);
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
it('should set rotation', () => {
|
|
67
|
-
expect(() => node.SetRotation({ x: 0, y: 0, z: 0 })).not.toThrow();
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
it('should set scale', () => {
|
|
71
|
-
expect(() => node.SetScale({ x: 1, y: 1, z: 1 })).not.toThrow();
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
it('should set visibility', () => {
|
|
75
|
-
expect(() => node.SetVisibility(true)).not.toThrow();
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
it('should set to world origin', () => {
|
|
79
|
-
node.userData.id = 'something';
|
|
80
|
-
|
|
81
|
-
expect(() => node.SetToWorldOrigin()).not.toThrow();
|
|
82
|
-
expect(node.position.x).toBe(0);
|
|
83
|
-
expect(node.position.y).toBe(0);
|
|
84
|
-
expect(node.position.z).toBe(0);
|
|
85
|
-
|
|
86
|
-
jest.spyOn(DIVECommunication, 'get').mockReturnValueOnce(undefined);
|
|
87
|
-
expect(() => node.SetToWorldOrigin()).not.toThrow();
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
it('should onMove', () => {
|
|
91
|
-
node.userData.id = 'something';
|
|
92
|
-
node.parent = {
|
|
93
|
-
isDIVEGroup: true,
|
|
94
|
-
UpdateLineTo: jest.fn(),
|
|
95
|
-
} as unknown as DIVENode;
|
|
96
|
-
|
|
97
|
-
expect(() => node.onMove()).not.toThrow();
|
|
98
|
-
|
|
99
|
-
jest.spyOn(DIVECommunication, 'get').mockReturnValueOnce(undefined);
|
|
100
|
-
expect(() => node.onMove()).not.toThrow();
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
it('should onSelect', () => {
|
|
104
|
-
node.userData.id = 'something';
|
|
105
|
-
|
|
106
|
-
expect(() => node.onSelect()).not.toThrow();
|
|
107
|
-
|
|
108
|
-
jest.spyOn(DIVECommunication, 'get').mockReturnValueOnce(undefined);
|
|
109
|
-
expect(() => node.onSelect()).not.toThrow();
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
it('should onDeselect', () => {
|
|
113
|
-
node.userData.id = 'something';
|
|
114
|
-
|
|
115
|
-
expect(() => node.onDeselect()).not.toThrow();
|
|
116
|
-
|
|
117
|
-
jest.spyOn(DIVECommunication, 'get').mockReturnValueOnce(undefined);
|
|
118
|
-
expect(() => node.onDeselect()).not.toThrow();
|
|
119
|
-
});
|
|
120
|
-
});
|
|
@@ -1,299 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
BoxGeometry,
|
|
3
|
-
BufferAttribute,
|
|
4
|
-
BufferGeometry,
|
|
5
|
-
Color,
|
|
6
|
-
ConeGeometry,
|
|
7
|
-
CylinderGeometry,
|
|
8
|
-
Mesh,
|
|
9
|
-
MeshStandardMaterial,
|
|
10
|
-
Raycaster,
|
|
11
|
-
SphereGeometry,
|
|
12
|
-
Vector3,
|
|
13
|
-
} from 'three';
|
|
14
|
-
import { PRODUCT_LAYER_MASK } from '../constant/VisibilityLayerMask';
|
|
15
|
-
import { findSceneRecursive } from '../helper/findSceneRecursive/findSceneRecursive';
|
|
16
|
-
import { DIVENode } from '../node/Node';
|
|
17
|
-
import { type COMGeometry, type COMMaterial } from '../com/types';
|
|
18
|
-
import { DIVECommunication } from '../com/Communication';
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* A basic model class.
|
|
22
|
-
*
|
|
23
|
-
* It does calculate it's own bounding box which is used for positioning on the floor.
|
|
24
|
-
*
|
|
25
|
-
* Can be moved and selected.
|
|
26
|
-
*
|
|
27
|
-
* @module
|
|
28
|
-
*/
|
|
29
|
-
export class DIVEPrimitive extends DIVENode {
|
|
30
|
-
readonly isDIVEPrimitive: true = true;
|
|
31
|
-
|
|
32
|
-
private _mesh: Mesh;
|
|
33
|
-
|
|
34
|
-
constructor() {
|
|
35
|
-
super();
|
|
36
|
-
|
|
37
|
-
this._mesh = new Mesh();
|
|
38
|
-
this._mesh.layers.mask = PRODUCT_LAYER_MASK;
|
|
39
|
-
this._mesh.castShadow = true;
|
|
40
|
-
this._mesh.receiveShadow = true;
|
|
41
|
-
this._mesh.material = new MeshStandardMaterial();
|
|
42
|
-
this.add(this._mesh);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
public SetGeometry(geometry: COMGeometry): void {
|
|
46
|
-
const geo = this.assembleGeometry(geometry);
|
|
47
|
-
if (!geo) return;
|
|
48
|
-
|
|
49
|
-
this._mesh.geometry = geo;
|
|
50
|
-
this._boundingBox.setFromObject(this._mesh);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
public SetMaterial(material: Partial<COMMaterial>): void {
|
|
54
|
-
const primitiveMaterial = this._mesh.material as MeshStandardMaterial;
|
|
55
|
-
|
|
56
|
-
if (material.vertexColors !== undefined) {
|
|
57
|
-
primitiveMaterial.vertexColors = material.vertexColors;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
// apply color if supplied
|
|
61
|
-
if (material.color !== undefined) {
|
|
62
|
-
primitiveMaterial.color = new Color(material.color);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// apply albedo map if supplied
|
|
66
|
-
if (material.map !== undefined) {
|
|
67
|
-
primitiveMaterial.map = material.map;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// apply normal map
|
|
71
|
-
if (material.normalMap !== undefined) {
|
|
72
|
-
primitiveMaterial.normalMap = material.normalMap;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
// set roughness value
|
|
76
|
-
// if supplied, apply roughness map
|
|
77
|
-
// if we applied a roughness map, set roughness to 1.0
|
|
78
|
-
if (material.roughness !== undefined) {
|
|
79
|
-
primitiveMaterial.roughness = material.roughness;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
if (material.roughnessMap !== undefined) {
|
|
83
|
-
primitiveMaterial.roughnessMap = material.roughnessMap;
|
|
84
|
-
|
|
85
|
-
if (primitiveMaterial.roughnessMap) {
|
|
86
|
-
primitiveMaterial.roughness = 1.0;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// set metalness value
|
|
91
|
-
// if supplied, apply metalness map
|
|
92
|
-
// if we applied a metalness map, set metalness to 1.0
|
|
93
|
-
if (material.metalness !== undefined) {
|
|
94
|
-
primitiveMaterial.metalness = material.metalness;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
if (material.metalnessMap !== undefined) {
|
|
98
|
-
primitiveMaterial.metalnessMap = material.metalnessMap;
|
|
99
|
-
|
|
100
|
-
if (primitiveMaterial.metalnessMap) {
|
|
101
|
-
primitiveMaterial.metalness = 0.0;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
// if the mesh is already set, update the material
|
|
106
|
-
if (this._mesh) this._mesh.material = primitiveMaterial;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
public PlaceOnFloor(): void {
|
|
110
|
-
// calculate and temporary save world position
|
|
111
|
-
const worldPos = this.getWorldPosition(this._positionWorldBuffer);
|
|
112
|
-
const oldWorldPos = worldPos.clone();
|
|
113
|
-
|
|
114
|
-
// compute the bounding box
|
|
115
|
-
this._mesh?.geometry?.computeBoundingBox();
|
|
116
|
-
const meshBB = this._mesh?.geometry?.boundingBox;
|
|
117
|
-
|
|
118
|
-
// subtract the bounding box min y axis value from the world position y value
|
|
119
|
-
if (!meshBB || !this._mesh) return;
|
|
120
|
-
worldPos.y = worldPos.y - this._mesh.localToWorld(meshBB.min.clone()).y;
|
|
121
|
-
|
|
122
|
-
// skip any action when the position did not change
|
|
123
|
-
if (worldPos.y === oldWorldPos.y) return;
|
|
124
|
-
|
|
125
|
-
DIVECommunication.get(this.userData.id)?.PerformAction(
|
|
126
|
-
'UPDATE_OBJECT',
|
|
127
|
-
{
|
|
128
|
-
id: this.userData.id,
|
|
129
|
-
position: worldPos,
|
|
130
|
-
rotation: this.rotation,
|
|
131
|
-
scale: this.scale,
|
|
132
|
-
},
|
|
133
|
-
);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
public DropIt(): void {
|
|
137
|
-
if (!this.parent) {
|
|
138
|
-
console.warn(
|
|
139
|
-
'DIVEPrimitive: DropIt() called on a model that is not in the scene.',
|
|
140
|
-
this,
|
|
141
|
-
);
|
|
142
|
-
return;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
// calculate the bottom center of the bounding box
|
|
146
|
-
const bottomY = this._boundingBox.min.y * this.scale.y;
|
|
147
|
-
const bbBottomCenter = this.localToWorld(
|
|
148
|
-
this._boundingBox.getCenter(new Vector3()).multiply(this.scale),
|
|
149
|
-
);
|
|
150
|
-
bbBottomCenter.y = bottomY + this.position.y;
|
|
151
|
-
|
|
152
|
-
// set up raycaster and raycast all scene objects (product layer)
|
|
153
|
-
const raycaster = new Raycaster(bbBottomCenter, new Vector3(0, -1, 0));
|
|
154
|
-
raycaster.layers.mask = PRODUCT_LAYER_MASK;
|
|
155
|
-
const intersections = raycaster.intersectObjects(
|
|
156
|
-
findSceneRecursive(this).Root.children,
|
|
157
|
-
true,
|
|
158
|
-
);
|
|
159
|
-
|
|
160
|
-
// if we hit something, move the model to the top on the hit object's bounding box
|
|
161
|
-
if (intersections.length > 0) {
|
|
162
|
-
const mesh = intersections[0].object as Mesh;
|
|
163
|
-
mesh.geometry.computeBoundingBox();
|
|
164
|
-
const meshBB = mesh.geometry.boundingBox!;
|
|
165
|
-
const worldPos = mesh.localToWorld(meshBB.max.clone());
|
|
166
|
-
|
|
167
|
-
const oldPos = this.position.clone();
|
|
168
|
-
const newPos = this.position
|
|
169
|
-
.clone()
|
|
170
|
-
.setY(worldPos.y)
|
|
171
|
-
.sub(new Vector3(0, bottomY, 0));
|
|
172
|
-
this.position.copy(newPos);
|
|
173
|
-
|
|
174
|
-
// if the position changed, update the object in communication
|
|
175
|
-
if (this.position.y === oldPos.y) return;
|
|
176
|
-
|
|
177
|
-
this.onMove();
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
private assembleGeometry(geometry: COMGeometry): BufferGeometry | null {
|
|
182
|
-
// reset material to smooth shading
|
|
183
|
-
(this._mesh.material as MeshStandardMaterial).flatShading = false;
|
|
184
|
-
|
|
185
|
-
switch (geometry.name.toLowerCase()) {
|
|
186
|
-
case 'cylinder':
|
|
187
|
-
return this.createCylinderGeometry(geometry);
|
|
188
|
-
case 'sphere':
|
|
189
|
-
return this.createSphereGeometry(geometry);
|
|
190
|
-
case 'pyramid':
|
|
191
|
-
// set material to flat shading for pyramid
|
|
192
|
-
(this._mesh.material as MeshStandardMaterial).flatShading =
|
|
193
|
-
true;
|
|
194
|
-
return this.createPyramidGeometry(geometry);
|
|
195
|
-
case 'cube':
|
|
196
|
-
case 'box':
|
|
197
|
-
return this.createBoxGeometry(geometry);
|
|
198
|
-
case 'cone':
|
|
199
|
-
return this.createConeGeometry(geometry);
|
|
200
|
-
case 'wall':
|
|
201
|
-
return this.createWallGeometry(geometry);
|
|
202
|
-
case 'plane':
|
|
203
|
-
return this.createPlaneGeometry(geometry);
|
|
204
|
-
default: {
|
|
205
|
-
console.warn(
|
|
206
|
-
'DIVEPrimitive.assembleGeometry: Invalid geometry type:',
|
|
207
|
-
geometry.name.toLowerCase(),
|
|
208
|
-
);
|
|
209
|
-
return null;
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
private createCylinderGeometry(geometry: COMGeometry): BufferGeometry {
|
|
215
|
-
const geo = new CylinderGeometry(
|
|
216
|
-
geometry.width / 2,
|
|
217
|
-
geometry.width / 2,
|
|
218
|
-
geometry.height,
|
|
219
|
-
64,
|
|
220
|
-
);
|
|
221
|
-
geo.translate(0, geometry.height / 2, 0);
|
|
222
|
-
return geo;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
private createSphereGeometry(geometry: COMGeometry): BufferGeometry {
|
|
226
|
-
const geo = new SphereGeometry(geometry.width / 2, 256, 256);
|
|
227
|
-
return geo;
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
private createPyramidGeometry(geometry: COMGeometry): BufferGeometry {
|
|
231
|
-
// prettier-multiline-arrays-next-line-pattern: 3
|
|
232
|
-
const vertices = new Float32Array([
|
|
233
|
-
-geometry.width / 2, 0, -geometry.depth / 2, // 0
|
|
234
|
-
geometry.width / 2, 0, -geometry.depth / 2, // 1
|
|
235
|
-
geometry.width / 2, 0, geometry.depth / 2, // 2
|
|
236
|
-
-geometry.width / 2, 0, geometry.depth / 2, // 3
|
|
237
|
-
0, geometry.height, 0,
|
|
238
|
-
]);
|
|
239
|
-
|
|
240
|
-
// prettier-multiline-arrays-next-line-pattern: 3
|
|
241
|
-
const indices = new Uint16Array([
|
|
242
|
-
0, 1, 2,
|
|
243
|
-
0, 2, 3,
|
|
244
|
-
0, 4, 1,
|
|
245
|
-
1, 4, 2,
|
|
246
|
-
2, 4, 3,
|
|
247
|
-
3, 4, 0,
|
|
248
|
-
]);
|
|
249
|
-
|
|
250
|
-
const geometryBuffer = new BufferGeometry();
|
|
251
|
-
geometryBuffer.setAttribute(
|
|
252
|
-
'position',
|
|
253
|
-
new BufferAttribute(vertices, 3),
|
|
254
|
-
);
|
|
255
|
-
geometryBuffer.setIndex(new BufferAttribute(indices, 1));
|
|
256
|
-
geometryBuffer.computeVertexNormals();
|
|
257
|
-
|
|
258
|
-
geometryBuffer.computeBoundingBox();
|
|
259
|
-
geometryBuffer.computeBoundingSphere();
|
|
260
|
-
return geometryBuffer;
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
private createBoxGeometry(geometry: COMGeometry): BufferGeometry {
|
|
264
|
-
const geo = new BoxGeometry(
|
|
265
|
-
geometry.width,
|
|
266
|
-
geometry.height,
|
|
267
|
-
geometry.depth,
|
|
268
|
-
);
|
|
269
|
-
geo.translate(0, geometry.height / 2, 0);
|
|
270
|
-
return geo;
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
private createConeGeometry(geometry: COMGeometry): BufferGeometry {
|
|
274
|
-
const geo = new ConeGeometry(geometry.width / 2, geometry.height, 256);
|
|
275
|
-
geo.translate(0, geometry.height / 2, 0);
|
|
276
|
-
return geo;
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
private createWallGeometry(geometry: COMGeometry): BufferGeometry {
|
|
280
|
-
const geo = new BoxGeometry(
|
|
281
|
-
geometry.width,
|
|
282
|
-
geometry.height,
|
|
283
|
-
geometry.depth || 0.05,
|
|
284
|
-
16,
|
|
285
|
-
);
|
|
286
|
-
geo.translate(0, geometry.height / 2, 0);
|
|
287
|
-
return geo;
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
private createPlaneGeometry(geometry: COMGeometry): BufferGeometry {
|
|
291
|
-
const geo = new BoxGeometry(
|
|
292
|
-
geometry.width,
|
|
293
|
-
geometry.height,
|
|
294
|
-
geometry.depth,
|
|
295
|
-
);
|
|
296
|
-
geo.translate(0, geometry.height / 2, 0);
|
|
297
|
-
return geo;
|
|
298
|
-
}
|
|
299
|
-
}
|