@shopware-ag/dive 1.12.1 → 1.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/dive.cjs +458 -405
- package/build/dive.cjs.map +1 -1
- package/build/dive.d.cts +314 -78
- package/build/dive.d.ts +314 -78
- package/build/dive.js +430 -377
- package/build/dive.js.map +1 -1
- package/package.json +1 -1
- package/src/__test__/DIVE.test.ts +33 -29
- package/src/axiscamera/AxisCamera.ts +1 -1
- package/src/axiscamera/__test__/AxisCamera.test.ts +1 -1
- package/src/com/Communication.ts +59 -14
- package/src/com/__test__/Communication.test.ts +111 -31
- package/src/com/actions/index.ts +2 -0
- package/src/com/actions/object/addobject.ts +1 -1
- package/src/com/actions/object/deleteobject.ts +1 -1
- package/src/com/actions/object/deselectobject.ts +1 -1
- package/src/com/actions/object/getallobjects.ts +1 -1
- package/src/com/actions/object/getobjects.ts +1 -1
- package/src/com/actions/object/selectobject.ts +1 -1
- package/src/com/actions/object/setparent.ts +9 -0
- package/src/com/actions/object/updateobject.ts +1 -1
- package/src/com/actions/scene/getallscenedata.ts +1 -1
- package/src/com/types/COMBaseEntity.ts +9 -0
- package/src/com/types/COMEntity.ts +7 -0
- package/src/com/types/COMEntityType.ts +1 -0
- package/src/com/types/COMGeometry.ts +6 -0
- package/src/com/types/COMGroup.ts +9 -0
- package/src/com/types/COMLight.ts +10 -0
- package/src/com/types/COMMaterial.ts +12 -0
- package/src/com/types/COMModel.ts +12 -0
- package/src/com/types/COMPov.ts +8 -0
- package/src/com/types/COMPrimitive.ts +12 -0
- package/src/com/types/index.ts +21 -0
- package/src/dive.ts +9 -16
- package/src/grid/Grid.ts +1 -1
- package/src/grid/__test__/Grid.test.ts +1 -1
- package/src/group/Group.ts +126 -0
- package/src/group/__test__/Group.test.ts +100 -0
- package/src/helper/findSceneRecursive/findSceneRecursive.ts +1 -1
- package/src/light/AmbientLight.ts +3 -0
- package/src/light/PointLight.ts +6 -3
- package/src/light/SceneLight.ts +2 -0
- package/src/light/__test__/PointLight.test.ts +8 -6
- package/src/light/__test__/SceneLight.test.ts +8 -6
- package/src/loadingmanager/LoadingManager.ts +1 -1
- package/src/loadingmanager/__test__/LoadingManager.test.ts +1 -1
- package/src/mediacreator/MediaCreator.ts +1 -1
- package/src/mediacreator/__test__/MediaCreator.test.ts +6 -4
- package/src/model/Model.ts +8 -7
- package/src/model/__test__/Model.test.ts +13 -10
- package/src/primitive/Primitive.ts +4 -3
- package/src/primitive/__test__/Primitive.test.ts +9 -7
- package/src/primitive/floor/Floor.ts +1 -1
- package/src/primitive/floor/__test__/Floor.test.ts +1 -1
- package/src/renderer/__test__/Renderer.test.ts +1 -1
- package/src/scene/Scene.ts +29 -9
- package/src/scene/__test__/Scene.test.ts +33 -19
- package/src/scene/root/Root.ts +239 -72
- package/src/scene/root/__test__/Root.test.ts +476 -114
- package/src/toolbox/BaseTool.ts +1 -1
- package/src/toolbox/Toolbox.ts +1 -1
- package/src/toolbox/__test__/BaseTool.test.ts +1 -1
- package/src/toolbox/__test__/Toolbox.test.ts +1 -1
- package/src/toolbox/select/SelectTool.ts +1 -1
- package/src/toolbox/select/__test__/SelectTool.test.ts +11 -9
- package/src/toolbox/transform/TransformTool.ts +1 -1
- package/src/toolbox/transform/__test__/TransformTool.test.ts +12 -10
- package/src/types/SceneObjects.ts +14 -0
- package/src/types/index.ts +5 -0
- package/src/com/index.ts +0 -3
- package/src/com/types.ts +0 -58
- package/src/scene/root/lightroot/LightRoot.ts +0 -99
- package/src/scene/root/lightroot/__test__/LightRoot.test.ts +0 -145
- package/src/scene/root/modelroot/ModelRoot.ts +0 -98
- package/src/scene/root/modelroot/__test__/ModelRoot.test.ts +0 -189
- package/src/scene/root/primitiveroot/PrimitiveRoot.ts +0 -88
- package/src/scene/root/primitiveroot/__test__/PrimitiveRoot.test.ts +0 -181
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type Vector3Like } from "three";
|
|
2
|
+
import { type COMBaseEntity } from "./COMBaseEntity";
|
|
3
|
+
import { type COMGeometry } from "./COMGeometry";
|
|
4
|
+
import { type COMMaterial } from "./COMMaterial";
|
|
5
|
+
|
|
6
|
+
export type COMPrimitive = COMBaseEntity & {
|
|
7
|
+
position: Vector3Like;
|
|
8
|
+
rotation: Vector3Like;
|
|
9
|
+
scale: Vector3Like;
|
|
10
|
+
geometry: COMGeometry;
|
|
11
|
+
material?: Partial<COMMaterial>;
|
|
12
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type COMEntity } from "./COMEntity";
|
|
2
|
+
import { type COMPrimitive } from "./COMPrimitive";
|
|
3
|
+
import { type COMModel } from "./COMModel";
|
|
4
|
+
import { type COMLight } from "./COMLight";
|
|
5
|
+
import { type COMPov } from "./COMPov";
|
|
6
|
+
import { type COMGeometry } from "./COMGeometry";
|
|
7
|
+
import { type COMMaterial } from "./COMMaterial";
|
|
8
|
+
import { type COMGroup } from "./COMGroup";
|
|
9
|
+
import { type COMEntityType } from "./COMEntityType";
|
|
10
|
+
|
|
11
|
+
export type {
|
|
12
|
+
COMEntity,
|
|
13
|
+
COMPrimitive,
|
|
14
|
+
COMModel,
|
|
15
|
+
COMLight,
|
|
16
|
+
COMPov,
|
|
17
|
+
COMGeometry,
|
|
18
|
+
COMMaterial,
|
|
19
|
+
COMGroup,
|
|
20
|
+
COMEntityType,
|
|
21
|
+
}
|
package/src/dive.ts
CHANGED
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
import { DIVERenderer, DIVERendererDefaultSettings, DIVERendererSettings } from "./renderer/Renderer.ts";
|
|
2
|
-
import DIVEScene from "./scene/Scene.ts";
|
|
2
|
+
import { DIVEScene } from "./scene/Scene.ts";
|
|
3
3
|
import DIVEPerspectiveCamera, { DIVEPerspectiveCameraDefaultSettings, DIVEPerspectiveCameraSettings } from "./camera/PerspectiveCamera.ts";
|
|
4
4
|
import DIVEOrbitControls, { DIVEOrbitControlsDefaultSettings, DIVEOrbitControlsSettings } from "./controls/OrbitControls.ts";
|
|
5
5
|
import DIVEToolbox from "./toolbox/Toolbox.ts";
|
|
6
|
-
import DIVECommunication from "./com/Communication.ts";
|
|
6
|
+
import { DIVECommunication } from "./com/Communication.ts";
|
|
7
7
|
import { DIVEAnimationSystem } from "./animation/AnimationSystem.ts";
|
|
8
8
|
import DIVEAxisCamera from "./axiscamera/AxisCamera.ts";
|
|
9
9
|
import { getObjectDelta } from "./helper/getObjectDelta/getObjectDelta.ts";
|
|
10
10
|
|
|
11
|
-
import type { Actions } from './com/actions/index.ts';
|
|
12
|
-
import type { COMPov, COMLight, COMModel, COMEntity, COMPrimitive } from './com/types.ts';
|
|
13
|
-
import { DIVEMath } from './math/index.ts';
|
|
14
11
|
import { generateUUID } from "three/src/math/MathUtils";
|
|
15
12
|
import { DIVEInfo } from "./info/Info.ts";
|
|
16
13
|
|
|
@@ -273,17 +270,13 @@ export default class DIVE {
|
|
|
273
270
|
}
|
|
274
271
|
}
|
|
275
272
|
|
|
276
|
-
export type {
|
|
277
|
-
Actions,
|
|
278
|
-
COMPov,
|
|
279
|
-
COMLight,
|
|
280
|
-
COMModel,
|
|
281
|
-
COMPrimitive,
|
|
282
|
-
COMEntity,
|
|
283
|
-
};
|
|
284
|
-
|
|
285
273
|
export {
|
|
286
274
|
DIVE,
|
|
287
275
|
DIVECommunication,
|
|
288
|
-
|
|
289
|
-
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
export * from './math/index.ts';
|
|
279
|
+
|
|
280
|
+
export type * from './com/actions/index.ts';
|
|
281
|
+
export type * from './com/types';
|
|
282
|
+
|
package/src/grid/Grid.ts
CHANGED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { Box3, BoxGeometry, Mesh, MeshBasicMaterial, Object3D, Vector3, type Vector3Like } from "three";
|
|
2
|
+
import { type DIVEMoveable } from "../interface/Moveable";
|
|
3
|
+
import { type DIVESelectable } from "../interface/Selectable";
|
|
4
|
+
import { type DIVESceneObject } from "../types";
|
|
5
|
+
import { DIVECommunication } from "../com/Communication";
|
|
6
|
+
|
|
7
|
+
export class DIVEGroup extends Object3D implements DIVESelectable, DIVEMoveable {
|
|
8
|
+
readonly isDIVEGroup: true = true;
|
|
9
|
+
readonly isSelectable: true = true;
|
|
10
|
+
readonly isMoveable: true = true;
|
|
11
|
+
|
|
12
|
+
private _bb: Box3;
|
|
13
|
+
private _boxMesh: Mesh;
|
|
14
|
+
|
|
15
|
+
constructor() {
|
|
16
|
+
super();
|
|
17
|
+
|
|
18
|
+
this.name = 'DIVEGroup';
|
|
19
|
+
|
|
20
|
+
this._bb = new Box3();
|
|
21
|
+
|
|
22
|
+
this._boxMesh = new Mesh(new BoxGeometry(0, 0, 0), new MeshBasicMaterial({ color: 0xff0000, wireframe: true }));
|
|
23
|
+
this._boxMesh.visible = false;
|
|
24
|
+
this.add(this._boxMesh);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
public SetPosition(position: Vector3Like): void {
|
|
28
|
+
this.position.set(position.x, position.y, position.z);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
public SetRotation(rotation: Vector3Like): void {
|
|
32
|
+
this.rotation.setFromVector3(new Vector3(rotation.x, rotation.y, rotation.z));
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
public SetScale(scale: Vector3Like): void {
|
|
36
|
+
this.scale.set(scale.x, scale.y, scale.z);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
public SetVisibility(visible: boolean): void {
|
|
40
|
+
this.traverse((child) => {
|
|
41
|
+
if (child.uuid === this._boxMesh.uuid) return;
|
|
42
|
+
child.visible = visible;
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
public SetBoundingBoxVisibility(visible: boolean): void {
|
|
47
|
+
this._boxMesh.visible = visible;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
public attach(object: DIVESceneObject): this {
|
|
51
|
+
// attach (insted of add) object to keep it's world position
|
|
52
|
+
super.attach(object);
|
|
53
|
+
|
|
54
|
+
// set position to it's bb's center
|
|
55
|
+
this.recalculatePosition();
|
|
56
|
+
|
|
57
|
+
// update box mesh
|
|
58
|
+
this.updateBoxMesh();
|
|
59
|
+
|
|
60
|
+
return this;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
public remove(object: DIVESceneObject): this {
|
|
64
|
+
// removes object from group while keeping it's world position
|
|
65
|
+
super.remove(object);
|
|
66
|
+
|
|
67
|
+
// set position to it's bb's center
|
|
68
|
+
this.recalculatePosition();
|
|
69
|
+
|
|
70
|
+
// update box mesh
|
|
71
|
+
this.updateBoxMesh();
|
|
72
|
+
|
|
73
|
+
return this;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Recalculates the position of the group based on it's bounding box.
|
|
78
|
+
* Children's world positions are kept.
|
|
79
|
+
*/
|
|
80
|
+
private recalculatePosition(): void {
|
|
81
|
+
// store all children's world positions
|
|
82
|
+
const childrensWorldPositions: Vector3[] = this.children.map((child) => child.getWorldPosition(new Vector3()));
|
|
83
|
+
|
|
84
|
+
// calculate new center and set it as the group's position
|
|
85
|
+
const bbcenter = this.updateBB();
|
|
86
|
+
this.position.copy(bbcenter);
|
|
87
|
+
|
|
88
|
+
// set childrens's positions so their world positions are kept
|
|
89
|
+
this.children.forEach((child, i) => {
|
|
90
|
+
if (child.uuid === this._boxMesh.uuid) return;
|
|
91
|
+
child.position.copy(this.worldToLocal(childrensWorldPositions[i]));
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
DIVECommunication.get(this.userData.id)?.PerformAction('UPDATE_OBJECT', { id: this.userData.id, position: this.position });
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Updates the bounding box of the group.
|
|
99
|
+
* @returns {Vector3} The new center of the bounding box.
|
|
100
|
+
*/
|
|
101
|
+
private updateBB(): Vector3 {
|
|
102
|
+
this._bb.makeEmpty();
|
|
103
|
+
this.children.forEach((child) => {
|
|
104
|
+
if (child.uuid === this._boxMesh.uuid) return;
|
|
105
|
+
this._bb.expandByObject(child);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
return this._bb.getCenter(new Vector3());
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
private updateBoxMesh(): void {
|
|
112
|
+
this._boxMesh.geometry = new BoxGeometry(this._bb.max.x - this._bb.min.x, this._bb.max.y - this._bb.min.y, this._bb.max.z - this._bb.min.z);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
public onMove(): void {
|
|
116
|
+
DIVECommunication.get(this.userData.id)?.PerformAction('UPDATE_OBJECT', { id: this.userData.id, position: this.position, rotation: this.rotation, scale: this.scale });
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
public onSelect(): void {
|
|
120
|
+
DIVECommunication.get(this.userData.id)?.PerformAction('SELECT_OBJECT', { id: this.userData.id });
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
public onDeselect(): void {
|
|
124
|
+
DIVECommunication.get(this.userData.id)?.PerformAction('DESELECT_OBJECT', { id: this.userData.id });
|
|
125
|
+
}
|
|
126
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { type GLTF } from "three/examples/jsm/loaders/GLTFLoader";
|
|
2
|
+
import { DIVECommunication } from "../../com/Communication";
|
|
3
|
+
import { DIVEGroup } from "../Group";
|
|
4
|
+
|
|
5
|
+
jest.mock('../../com/Communication.ts', () => {
|
|
6
|
+
return {
|
|
7
|
+
DIVECommunication: {
|
|
8
|
+
get: jest.fn(() => {
|
|
9
|
+
return {
|
|
10
|
+
PerformAction: jest.fn(),
|
|
11
|
+
}
|
|
12
|
+
}),
|
|
13
|
+
},
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
jest.spyOn(DIVECommunication, 'get').mockReturnValue({ PerformAction: jest.fn() } as unknown as DIVECommunication);
|
|
18
|
+
|
|
19
|
+
let group: DIVEGroup;
|
|
20
|
+
|
|
21
|
+
describe('dive/group/DIVEGroup', () => {
|
|
22
|
+
beforeEach(() => {
|
|
23
|
+
group = new DIVEGroup();
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
afterEach(() => {
|
|
27
|
+
jest.clearAllMocks();
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('should instantiate', () => {
|
|
31
|
+
expect(group).toBeDefined();
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('should set position', () => {
|
|
35
|
+
expect(() => group.SetPosition({ x: 0, y: 0, z: 0 })).not.toThrow();
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('should set rotation', () => {
|
|
39
|
+
expect(() => group.SetRotation({ x: 0, y: 0, z: 0 })).not.toThrow();
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('should set scale', () => {
|
|
43
|
+
expect(() => group.SetScale({ x: 1, y: 1, z: 1 })).not.toThrow();
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('should set visibility', () => {
|
|
47
|
+
expect(() => group.SetVisibility(true)).not.toThrow();
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('should set bounding box visibility', () => {
|
|
51
|
+
expect(() => group.SetBoundingBoxVisibility(true)).not.toThrow();
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('should add an object', () => {
|
|
55
|
+
const mockObject = new DIVEGroup();
|
|
56
|
+
|
|
57
|
+
expect(() => group.attach(mockObject)).not.toThrow();
|
|
58
|
+
expect(group.children).toContain(mockObject);
|
|
59
|
+
|
|
60
|
+
jest.spyOn(DIVECommunication, 'get').mockReturnValueOnce(undefined);
|
|
61
|
+
expect(() => group.attach(mockObject)).not.toThrow();
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('should remove an object', () => {
|
|
65
|
+
const mockObject = new DIVEGroup();
|
|
66
|
+
|
|
67
|
+
expect(() => group.remove(mockObject)).not.toThrow();
|
|
68
|
+
expect(group.children).not.toContain(mockObject);
|
|
69
|
+
|
|
70
|
+
jest.spyOn(DIVECommunication, 'get').mockReturnValueOnce(undefined);
|
|
71
|
+
expect(() => group.remove(mockObject)).not.toThrow();
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it('should onMove', () => {
|
|
75
|
+
group.userData.id = 'something';
|
|
76
|
+
|
|
77
|
+
expect(() => group.onMove()).not.toThrow();
|
|
78
|
+
|
|
79
|
+
jest.spyOn(DIVECommunication, 'get').mockReturnValueOnce(undefined);
|
|
80
|
+
expect(() => group.onMove()).not.toThrow();
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it('should onSelect', () => {
|
|
84
|
+
group.userData.id = 'something';
|
|
85
|
+
|
|
86
|
+
expect(() => group.onSelect()).not.toThrow();
|
|
87
|
+
|
|
88
|
+
jest.spyOn(DIVECommunication, 'get').mockReturnValueOnce(undefined);
|
|
89
|
+
expect(() => group.onSelect()).not.toThrow();
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it('should onDeselect', () => {
|
|
93
|
+
group.userData.id = 'something';
|
|
94
|
+
|
|
95
|
+
expect(() => group.onDeselect()).not.toThrow();
|
|
96
|
+
|
|
97
|
+
jest.spyOn(DIVECommunication, 'get').mockReturnValueOnce(undefined);
|
|
98
|
+
expect(() => group.onDeselect()).not.toThrow();
|
|
99
|
+
});
|
|
100
|
+
});
|
|
@@ -10,6 +10,9 @@ import { PRODUCT_LAYER_MASK } from '../constant/VisibilityLayerMask';
|
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
export default class DIVEAmbientLight extends Object3D {
|
|
13
|
+
readonly isDIVELight: true = true;
|
|
14
|
+
readonly isDIVEAmbientLight: true = true;
|
|
15
|
+
|
|
13
16
|
private _light: AmbientLight;
|
|
14
17
|
|
|
15
18
|
constructor() {
|
package/src/light/PointLight.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PointLight, Color, SphereGeometry, MeshBasicMaterial, Mesh, FrontSide, Object3D } from 'three';
|
|
2
|
-
import DIVECommunication from '../com/Communication';
|
|
2
|
+
import { DIVECommunication } from '../com/Communication';
|
|
3
3
|
import { PRODUCT_LAYER_MASK, UI_LAYER_MASK } from '../constant/VisibilityLayerMask';
|
|
4
4
|
import { DIVEMoveable } from '../interface/Moveable';
|
|
5
5
|
import { DIVESelectable } from '../interface/Selectable';
|
|
@@ -16,8 +16,11 @@ import type { TransformControls } from 'three/examples/jsm/Addons.js';
|
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
18
|
export default class DIVEPointLight extends Object3D implements DIVESelectable, DIVEMoveable {
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
readonly isDIVELight: true = true;
|
|
20
|
+
readonly isDIVEPointLight: true = true;
|
|
21
|
+
readonly isMoveable: true = true;
|
|
22
|
+
readonly isSelectable: true = true;
|
|
23
|
+
|
|
21
24
|
public gizmo: TransformControls | null = null;
|
|
22
25
|
|
|
23
26
|
private light: PointLight;
|
package/src/light/SceneLight.ts
CHANGED
|
@@ -10,6 +10,8 @@ import { Color, DirectionalLight, HemisphereLight, Object3D } from "three";
|
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
export default class DIVESceneLight extends Object3D {
|
|
13
|
+
readonly isDIVELight: true = true;
|
|
14
|
+
readonly isDIVESceneLight: true = true;
|
|
13
15
|
|
|
14
16
|
private _hemiLight: HemisphereLight;
|
|
15
17
|
private _dirLight: DirectionalLight;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import DIVEPointLight from '../PointLight.ts';
|
|
2
|
-
import DIVECommunication from '../../com/Communication.ts';
|
|
2
|
+
import { DIVECommunication } from '../../com/Communication.ts';
|
|
3
3
|
import { Color, MeshBasicMaterial, Object3D, PointLight } from 'three';
|
|
4
4
|
|
|
5
5
|
const mockAdd = jest.fn();
|
|
@@ -63,11 +63,13 @@ jest.mock('three', () => {
|
|
|
63
63
|
|
|
64
64
|
jest.mock('../../com/Communication.ts', () => {
|
|
65
65
|
return {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
66
|
+
DIVECommunication: {
|
|
67
|
+
get: jest.fn(() => {
|
|
68
|
+
return {
|
|
69
|
+
PerformAction: jest.fn(),
|
|
70
|
+
}
|
|
71
|
+
}),
|
|
72
|
+
},
|
|
71
73
|
}
|
|
72
74
|
});
|
|
73
75
|
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import DIVESceneLight from '../SceneLight';
|
|
2
|
-
import DIVECommunication from '../../com/Communication';
|
|
2
|
+
import { DIVECommunication } from '../../com/Communication';
|
|
3
3
|
import { Color, HemisphereLight as THREEHemisphereLight, DirectionalLight as THREEDirectionalLight, Object3D } from 'three';
|
|
4
4
|
|
|
5
5
|
jest.mock('../../com/Communication.ts', () => {
|
|
6
6
|
return {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
DIVECommunication: {
|
|
8
|
+
get: jest.fn(() => {
|
|
9
|
+
return {
|
|
10
|
+
PerformAction: jest.fn(),
|
|
11
|
+
}
|
|
12
|
+
}),
|
|
13
|
+
},
|
|
12
14
|
}
|
|
13
15
|
});
|
|
14
16
|
|
|
@@ -6,7 +6,7 @@ import { DRACOLoader, GLTF, GLTFLoader } from "three/examples/jsm/Addons.js";
|
|
|
6
6
|
* @module
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
export
|
|
9
|
+
export class DIVELoadingManager {
|
|
10
10
|
private gltfloader: GLTFLoader;
|
|
11
11
|
private dracoloader: DRACOLoader;
|
|
12
12
|
// ... maybe extend with other loaders later
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import DIVEPerspectiveCamera from "../camera/PerspectiveCamera.ts";
|
|
2
|
-
import DIVEScene from "../scene/Scene.ts";
|
|
2
|
+
import { DIVEScene } from "../scene/Scene.ts";
|
|
3
3
|
import { DIVERenderer } from "../renderer/Renderer.ts";
|
|
4
4
|
import DIVEOrbitControls from "../controls/OrbitControls.ts";
|
|
5
5
|
import { Vector3Like } from "three";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DIVEMediaCreator } from '../MediaCreator';
|
|
2
2
|
import { DIVERenderer } from '../../renderer/Renderer';
|
|
3
|
-
import DIVEScene from '../../scene/Scene';
|
|
3
|
+
import { DIVEScene } from '../../scene/Scene';
|
|
4
4
|
import DIVEPerspectiveCamera, { DIVEPerspectiveCameraDefaultSettings } from '../../camera/PerspectiveCamera';
|
|
5
5
|
import { type COMPov } from '../../com/types';
|
|
6
6
|
import DIVEOrbitControls from '../../controls/OrbitControls';
|
|
@@ -14,9 +14,11 @@ const mock_render = jest.fn();
|
|
|
14
14
|
const mock_toDataURL = jest.fn();
|
|
15
15
|
|
|
16
16
|
jest.mock('../../scene/Scene', () => {
|
|
17
|
-
return
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
return {
|
|
18
|
+
DIVEScene: jest.fn(() => {
|
|
19
|
+
return {};
|
|
20
|
+
})
|
|
21
|
+
};
|
|
20
22
|
});
|
|
21
23
|
|
|
22
24
|
jest.mock('../../camera/PerspectiveCamera', () => {
|
package/src/model/Model.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Box3,
|
|
1
|
+
import { Box3, Mesh, MeshStandardMaterial, Object3D, Raycaster, Vector3, Vector3Like } from 'three';
|
|
2
2
|
import { DIVESelectable } from '../interface/Selectable';
|
|
3
3
|
import { PRODUCT_LAYER_MASK } from '../constant/VisibilityLayerMask';
|
|
4
4
|
import { DIVEMoveable } from '../interface/Moveable';
|
|
5
|
-
import DIVECommunication from '../com/Communication';
|
|
5
|
+
import { DIVECommunication } from '../com/Communication';
|
|
6
6
|
import type { GLTF, TransformControls } from 'three/examples/jsm/Addons.js';
|
|
7
7
|
import { findSceneRecursive } from '../helper/findSceneRecursive/findSceneRecursive';
|
|
8
8
|
import { type COMMaterial } from '../com/types';
|
|
@@ -17,9 +17,11 @@ import { type COMMaterial } from '../com/types';
|
|
|
17
17
|
* @module
|
|
18
18
|
*/
|
|
19
19
|
|
|
20
|
-
export
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
export class DIVEModel extends Object3D implements DIVESelectable, DIVEMoveable {
|
|
21
|
+
readonly isDIVEModel: true = true;
|
|
22
|
+
readonly isSelectable: true = true;
|
|
23
|
+
readonly isMoveable: true = true;
|
|
24
|
+
|
|
23
25
|
public gizmo: TransformControls | null = null;
|
|
24
26
|
|
|
25
27
|
private boundingBox: Box3;
|
|
@@ -91,7 +93,7 @@ export default class DIVEModel extends Object3D implements DIVESelectable, DIVEM
|
|
|
91
93
|
|
|
92
94
|
// apply color if supplied
|
|
93
95
|
if (material.color !== undefined) {
|
|
94
|
-
this._material.color
|
|
96
|
+
this._material.color.set(material.color);
|
|
95
97
|
}
|
|
96
98
|
|
|
97
99
|
// apply albedo map if supplied
|
|
@@ -137,7 +139,6 @@ export default class DIVEModel extends Object3D implements DIVESelectable, DIVEM
|
|
|
137
139
|
// if the mesh is already set, update the material
|
|
138
140
|
if (this._mesh) {
|
|
139
141
|
this._mesh.material = this._material;
|
|
140
|
-
this._mesh.material.needsUpdate = true;
|
|
141
142
|
}
|
|
142
143
|
}
|
|
143
144
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
import DIVECommunication from '../../com/Communication';
|
|
1
|
+
import { DIVEModel } from '../Model';
|
|
2
|
+
import { DIVECommunication } from '../../com/Communication';
|
|
3
3
|
import { GLTF } from 'three/examples/jsm/Addons';
|
|
4
|
-
import DIVEScene from '../../scene/Scene';
|
|
4
|
+
import { DIVEScene } from '../../scene/Scene';
|
|
5
5
|
import { Vector3, Box3, Mesh, MeshStandardMaterial, type Texture, Color } from 'three';
|
|
6
6
|
import { type COMMaterial } from '../../com/types';
|
|
7
7
|
|
|
@@ -145,6 +145,7 @@ jest.mock('three', () => {
|
|
|
145
145
|
return this;
|
|
146
146
|
}),
|
|
147
147
|
Color: jest.fn(function () {
|
|
148
|
+
this.set = jest.fn();
|
|
148
149
|
return this;
|
|
149
150
|
}),
|
|
150
151
|
}
|
|
@@ -152,11 +153,13 @@ jest.mock('three', () => {
|
|
|
152
153
|
|
|
153
154
|
jest.mock('../../com/Communication.ts', () => {
|
|
154
155
|
return {
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
156
|
+
DIVECommunication: {
|
|
157
|
+
get: jest.fn(() => {
|
|
158
|
+
return {
|
|
159
|
+
PerformAction: jest.fn(),
|
|
160
|
+
}
|
|
161
|
+
}),
|
|
162
|
+
},
|
|
160
163
|
}
|
|
161
164
|
});
|
|
162
165
|
|
|
@@ -192,11 +195,11 @@ const gltf = {
|
|
|
192
195
|
|
|
193
196
|
jest.spyOn(DIVECommunication, 'get').mockReturnValue({ PerformAction: jest.fn() } as unknown as DIVECommunication);
|
|
194
197
|
|
|
195
|
-
let model:
|
|
198
|
+
let model: DIVEModel;
|
|
196
199
|
|
|
197
200
|
describe('dive/model/DIVEModel', () => {
|
|
198
201
|
beforeEach(() => {
|
|
199
|
-
model = new
|
|
202
|
+
model = new DIVEModel();
|
|
200
203
|
});
|
|
201
204
|
|
|
202
205
|
afterEach(() => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Box3, BoxGeometry, BufferGeometry, Color, ConeGeometry, CylinderGeometry, Mesh, MeshStandardMaterial, Object3D, Raycaster, SphereGeometry, Vector3, Vector3Like } from 'three';
|
|
2
|
-
import DIVECommunication from '../com/Communication';
|
|
2
|
+
import { DIVECommunication } from '../com/Communication';
|
|
3
3
|
import { PRODUCT_LAYER_MASK } from '../constant/VisibilityLayerMask';
|
|
4
4
|
import { findSceneRecursive } from '../helper/findSceneRecursive/findSceneRecursive';
|
|
5
5
|
import { type DIVESelectable } from '../interface/Selectable';
|
|
@@ -18,8 +18,9 @@ import { type COMGeometry, type COMMaterial } from '../com/types';
|
|
|
18
18
|
*/
|
|
19
19
|
|
|
20
20
|
export class DIVEPrimitive extends Object3D implements DIVESelectable, DIVEMoveable {
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
readonly isDIVEPrimitive: true = true;
|
|
22
|
+
readonly isSelectable: true = true;
|
|
23
|
+
readonly isMoveable: true = true;
|
|
23
24
|
|
|
24
25
|
public gizmo: TransformControls | null = null;
|
|
25
26
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { DIVEPrimitive } from '../Primitive';
|
|
2
|
-
import DIVECommunication from '../../com/Communication';
|
|
2
|
+
import { DIVECommunication } from '../../com/Communication';
|
|
3
3
|
import { Vector3, Box3, Mesh, type Texture, type MeshStandardMaterial } from 'three';
|
|
4
|
-
import type DIVEScene from '../../scene/Scene';
|
|
4
|
+
import type { DIVEScene } from '../../scene/Scene';
|
|
5
5
|
import { type COMMaterial, type COMGeometry } from '../../com/types';
|
|
6
6
|
|
|
7
7
|
const intersectObjectsMock = jest.fn();
|
|
@@ -181,11 +181,13 @@ jest.mock('three', () => {
|
|
|
181
181
|
|
|
182
182
|
jest.mock('../../com/Communication.ts', () => {
|
|
183
183
|
return {
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
184
|
+
DIVECommunication: {
|
|
185
|
+
get: jest.fn(() => {
|
|
186
|
+
return {
|
|
187
|
+
PerformAction: jest.fn(),
|
|
188
|
+
}
|
|
189
|
+
}),
|
|
190
|
+
},
|
|
189
191
|
}
|
|
190
192
|
});
|
|
191
193
|
|