@shopware-ag/dive 1.0.7 → 1.0.8
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/package.json +6 -3
- package/src/__test__/DIVE.test.ts +244 -0
- package/src/animation/AnimationSystem.ts +14 -0
- package/src/animation/__test__/AnimationSystem.test.ts +19 -0
- package/src/axiscamera/AxisCamera.ts +50 -0
- package/src/axiscamera/__test__/AxisCamera.test.ts +41 -0
- package/src/camera/PerspectiveCamera.ts +43 -0
- package/src/camera/__test__/PerspectiveCamera.test.ts +27 -0
- package/src/com/Communication.ts +382 -0
- package/src/com/__test__/Communication.test.ts +612 -0
- package/src/com/actions/camera/getcameratransform.ts +9 -0
- package/src/com/actions/camera/movecamera.ts +15 -0
- package/src/com/actions/camera/resetcamera.ts +4 -0
- package/src/com/actions/camera/setcameralayer.ts +4 -0
- package/src/com/actions/camera/setcameratransform.ts +9 -0
- package/src/com/actions/camera/zoomcamera.ts +4 -0
- package/src/com/actions/index.ts +41 -0
- package/src/com/actions/media/generatemedia.ts +15 -0
- package/src/com/actions/object/addobject.ts +6 -0
- package/src/com/actions/object/deleteobject.ts +6 -0
- package/src/com/actions/object/getallobjects.ts +6 -0
- package/src/com/actions/object/getobjects.ts +6 -0
- package/src/com/actions/object/model/modelloaded.ts +4 -0
- package/src/com/actions/object/model/placeonfloor.ts +4 -0
- package/src/com/actions/object/selectobject.ts +6 -0
- package/src/com/actions/object/updateobject.ts +6 -0
- package/src/com/actions/scene/getallscenedata.ts +23 -0
- package/src/com/actions/scene/setbackground.ts +4 -0
- package/src/com/actions/scene/updatescene.ts +9 -0
- package/src/com/actions/toolbox/select/setgizmomode.ts +4 -0
- package/src/com/index.ts +4 -0
- package/src/com/types.ts +30 -0
- package/src/constant/AxisHelperColors.ts +7 -0
- package/src/constant/GridColors.ts +2 -0
- package/src/constant/VisibilityLayerMask.ts +5 -0
- package/src/controls/OrbitControls.ts +145 -0
- package/src/controls/__test__/OrbitControls.test.ts +181 -0
- package/src/grid/Grid.ts +22 -0
- package/src/grid/__test__/Grid.test.ts +19 -0
- package/src/helper/applyMixins/__test__/applyMixins.test.ts +27 -0
- package/src/helper/applyMixins/applyMixins.ts +15 -0
- package/src/helper/getObjectDelta/__test__/getObjectDelta.spec.ts +152 -0
- package/src/helper/getObjectDelta/getObjectDelta.ts +101 -0
- package/src/interface/Moveable.ts +13 -0
- package/src/interface/Rotatable.ts +10 -0
- package/src/interface/Scalable.ts +10 -0
- package/src/interface/Selectable.ts +11 -0
- package/src/interface/__test__/Interfaces.test.ts +13 -0
- package/src/light/AmbientLight.ts +29 -0
- package/src/light/PointLight.ts +63 -0
- package/src/light/SceneLight.ts +60 -0
- package/src/light/__test__/AmbientLight.test.ts +44 -0
- package/src/light/__test__/PointLight.test.ts +98 -0
- package/src/light/__test__/SceneLight.test.ts +122 -0
- package/src/loadingmanager/LoadingManager.ts +44 -0
- package/src/loadingmanager/__test__/LoadingManager.test.ts +52 -0
- package/src/math/__test__/DIVEMath.test.ts +12 -0
- package/src/math/ceil/__test__/ceilExp.test.ts +12 -0
- package/src/math/ceil/ceilExp.ts +6 -0
- package/src/math/floor/__test__/floorExp.test.ts +14 -0
- package/src/math/floor/floorExp.ts +6 -0
- package/src/math/helper/__test__/shift.test.ts +12 -0
- package/src/math/helper/shift.ts +4 -0
- package/src/math/index.ts +19 -0
- package/src/math/round/__test__/roundExp.test.ts +14 -0
- package/src/math/round/roundExp.ts +7 -0
- package/src/math/toFixed/__test__/toFixedExp.test.ts +14 -0
- package/src/math/toFixed/toFixedExp.ts +6 -0
- package/src/math/truncate/__test__/truncateExp.test.ts +14 -0
- package/src/math/truncate/truncateExp.ts +6 -0
- package/src/mediacreator/MediaCreator.ts +65 -0
- package/src/mediacreator/__test__/MediaCreator.test.ts +113 -0
- package/src/model/Model.ts +72 -0
- package/src/model/__test__/Model.test.ts +163 -0
- package/src/primitive/floor/Floor.ts +34 -0
- package/src/primitive/floor/__test__/Floor.test.ts +21 -0
- package/src/renderer/Renderer.ts +165 -0
- package/src/renderer/__test__/Renderer.test.ts +169 -0
- package/src/scene/Scene.ts +49 -0
- package/src/scene/__test__/Scene.test.ts +70 -0
- package/src/scene/root/Root.ts +107 -0
- package/src/scene/root/__test__/Root.test.ts +129 -0
- package/src/scene/root/lightroot/LightRoot.ts +84 -0
- package/src/scene/root/lightroot/__test__/LightRoot.test.ts +137 -0
- package/src/scene/root/modelroot/ModelRoot.ts +82 -0
- package/src/scene/root/modelroot/__test__/ModelRoot.test.ts +185 -0
- package/src/toolbox/BaseTool.ts +18 -0
- package/src/toolbox/Toolbox.ts +76 -0
- package/src/toolbox/__test__/Toolbox.test.ts +109 -0
- package/src/toolbox/select/SelectTool.ts +123 -0
- package/src/toolbox/select/__test__/SelectTool.test.ts +190 -0
- package/build/dive.cjs +0 -1551
- package/build/dive.cjs.map +0 -1
- package/build/dive.d.cts +0 -558
- package/build/dive.d.ts +0 -558
- package/build/dive.js +0 -1516
- package/build/dive.js.map +0 -1
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { getObjectDelta } from '../getObjectDelta.ts';
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
describe('dive/helper/getObjectDelta', () => {
|
|
6
|
+
|
|
7
|
+
// NO DELTAS
|
|
8
|
+
it('should not find any deltas with empty objects', () => {
|
|
9
|
+
const obj0 = {};
|
|
10
|
+
const obj1 = {};
|
|
11
|
+
|
|
12
|
+
const delta = getObjectDelta(obj0, obj1);
|
|
13
|
+
|
|
14
|
+
expect(delta).toStrictEqual({});
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it('should not find any deltas with equal references', () => {
|
|
18
|
+
const obj0 = { test0: 'test', value0: 42, array0: [187, 6, 9, 42] };
|
|
19
|
+
const obj1 = obj0;
|
|
20
|
+
|
|
21
|
+
const delta = getObjectDelta(obj0, obj1);
|
|
22
|
+
|
|
23
|
+
expect(delta).toStrictEqual({});
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('should not find any deltas with equal objects', () => {
|
|
27
|
+
const obj0 = { test0: 'test', value0: 42, array0: [187, 6, 9, 42] };
|
|
28
|
+
const obj1 = { ...obj0 };
|
|
29
|
+
|
|
30
|
+
const delta = getObjectDelta(obj0, obj1);
|
|
31
|
+
|
|
32
|
+
expect(delta).toStrictEqual({});
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('should not find any deltas with empty arrays', () => {
|
|
36
|
+
const obj0 = { array0: [] };
|
|
37
|
+
const obj1 = { array0: [] };
|
|
38
|
+
|
|
39
|
+
const delta = getObjectDelta(obj0, obj1);
|
|
40
|
+
|
|
41
|
+
expect(delta).toStrictEqual({});
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
// DELTAS
|
|
45
|
+
it('should find deltas with incorrect types (case a)', () => {
|
|
46
|
+
const obj0 = 'test' as unknown as object;
|
|
47
|
+
const obj1 = { test: 0 };
|
|
48
|
+
|
|
49
|
+
const delta = getObjectDelta(obj0, obj1);
|
|
50
|
+
|
|
51
|
+
expect(delta).toStrictEqual(obj1);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('should find deltas with incorrect types (case b)', () => {
|
|
55
|
+
const obj0 = { test: 0 };
|
|
56
|
+
const obj1 = 'test' as unknown as object;
|
|
57
|
+
|
|
58
|
+
const delta = getObjectDelta(obj0, obj1);
|
|
59
|
+
|
|
60
|
+
expect(delta).toStrictEqual(obj1);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('should find deltas with one empty object', () => {
|
|
64
|
+
const obj0 = {};
|
|
65
|
+
const obj1 = { test: 0 };
|
|
66
|
+
|
|
67
|
+
const delta = getObjectDelta(obj0, obj1);
|
|
68
|
+
|
|
69
|
+
expect(delta).toStrictEqual(obj1);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('should find deltas with different key lengths', () => {
|
|
73
|
+
const obj0 = { test: 0 };
|
|
74
|
+
const obj1 = { test: 0, test0: 0 };
|
|
75
|
+
|
|
76
|
+
const delta = getObjectDelta(obj0, obj1);
|
|
77
|
+
|
|
78
|
+
expect(delta).toStrictEqual({ test0: 0 });
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it('should find deltas with a type delta', () => {
|
|
82
|
+
const obj0 = { test: 'test' };
|
|
83
|
+
const obj1 = { test: 0 as unknown as string };
|
|
84
|
+
|
|
85
|
+
const delta = getObjectDelta(obj0, obj1);
|
|
86
|
+
|
|
87
|
+
expect(delta).toStrictEqual(obj1);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it('should find deltas with a value delta', () => {
|
|
91
|
+
const obj0 = { test: 'test' };
|
|
92
|
+
const obj1 = { test: 'hello world!' };
|
|
93
|
+
|
|
94
|
+
const delta = getObjectDelta(obj0, obj1);
|
|
95
|
+
|
|
96
|
+
expect(delta).toStrictEqual(obj1);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it('should find deltas with array value delta', () => {
|
|
100
|
+
const obj0 = { array0: [187, 6, 9, 42] };
|
|
101
|
+
const obj1 = { array0: [187, 6, 9] };
|
|
102
|
+
|
|
103
|
+
const delta = getObjectDelta(obj0, obj1);
|
|
104
|
+
|
|
105
|
+
expect(delta).toStrictEqual(obj1);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it('should find deltas with array type difference', () => {
|
|
109
|
+
const obj0 = { array0: 'array0' };
|
|
110
|
+
const obj1 = { array0: [187, 6, 9] as unknown as string };
|
|
111
|
+
|
|
112
|
+
const delta = getObjectDelta(obj0, obj1);
|
|
113
|
+
|
|
114
|
+
expect(delta).toStrictEqual(obj1);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it('should find deltas with deltas in objects in array', () => {
|
|
118
|
+
const obj0 = { array0: [{ test: 0 }] };
|
|
119
|
+
const obj1 = { array0: [{ test: 1 }] };
|
|
120
|
+
|
|
121
|
+
const delta = getObjectDelta(obj0, obj1);
|
|
122
|
+
|
|
123
|
+
expect(delta).toStrictEqual(obj1);
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it('should find deltas with undefined value in objects in object', () => {
|
|
127
|
+
const obj0 = { object0: undefined as unknown as object };
|
|
128
|
+
const obj1 = { object0: { test: 1 } };
|
|
129
|
+
|
|
130
|
+
const delta = getObjectDelta(obj0, obj1);
|
|
131
|
+
|
|
132
|
+
expect(delta).toStrictEqual(obj1);
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
it('should find deltas with wrong type in objects in object', () => {
|
|
136
|
+
const obj0 = { object0: 'test' };
|
|
137
|
+
const obj1 = { object0: { test: 1 } as unknown as string };
|
|
138
|
+
|
|
139
|
+
const delta = getObjectDelta(obj0, obj1);
|
|
140
|
+
|
|
141
|
+
expect(delta).toStrictEqual(obj1);
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
it('should find deltas with empty value in objects in object', () => {
|
|
145
|
+
const obj0 = { object0: {} };
|
|
146
|
+
const obj1 = { object0: { test: 1 } };
|
|
147
|
+
|
|
148
|
+
const delta = getObjectDelta(obj0, obj1);
|
|
149
|
+
|
|
150
|
+
expect(delta).toStrictEqual(obj1);
|
|
151
|
+
});
|
|
152
|
+
});
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Find the difference between two objects.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export const getObjectDelta = <T extends object>(a: T, b: Partial<T>): Partial<T> => {
|
|
6
|
+
|
|
7
|
+
// if a and b have no entries we have no delta
|
|
8
|
+
if (Object.keys(a).length === 0 && Object.keys(b).length === 0) {
|
|
9
|
+
return {};
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// if a or b is not an object we have a delta
|
|
13
|
+
if (typeof a !== 'object' || typeof b !== 'object') {
|
|
14
|
+
return b;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
let delta = {};
|
|
18
|
+
|
|
19
|
+
Object.keys(b).forEach((key) => {
|
|
20
|
+
|
|
21
|
+
// if key is not in a we have a delta
|
|
22
|
+
if (!Object.keys(a).includes(key)) {
|
|
23
|
+
delta = { ...delta, [key]: b[key as keyof object] };
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// assumption: b[key] is an array
|
|
28
|
+
if (Array.isArray(b[key as keyof object])) {
|
|
29
|
+
|
|
30
|
+
// if a[key] is not an array we have a delta
|
|
31
|
+
if (!Array.isArray(a[key as keyof object])) {
|
|
32
|
+
delta = { ...delta, [key]: b[key as keyof object] };
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// create arrays (for TS types to be correct)
|
|
37
|
+
const aArray = a[key as keyof object] as [];
|
|
38
|
+
const bArray = b[key as keyof object] as [];
|
|
39
|
+
|
|
40
|
+
// if both arrays are empty we have no delta
|
|
41
|
+
if (aArray.length === 0 && bArray.length === 0) {
|
|
42
|
+
delta = { ...delta };
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// if array length is different we have a delta
|
|
47
|
+
if (aArray.length !== bArray.length) {
|
|
48
|
+
delta = { ...delta, [key]: b[key as keyof object] };
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// create array for deltas
|
|
53
|
+
const arrayDeltas: [] = [];
|
|
54
|
+
|
|
55
|
+
bArray.forEach((entry, index) => {
|
|
56
|
+
// getObjectDelta in array
|
|
57
|
+
const inArrayDelta = getObjectDelta(aArray[index], bArray[index]);
|
|
58
|
+
|
|
59
|
+
// if inArrayDelta has more then 0 entries we have a delta
|
|
60
|
+
if (Object.keys(inArrayDelta).length) {
|
|
61
|
+
arrayDeltas.push(bArray[index]);
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
// if arrayDeltas has more than 0 entries we have a delta
|
|
66
|
+
if (Object.keys(arrayDeltas).length) {
|
|
67
|
+
delta = { ...delta, [key]: arrayDeltas };
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// assumption: b[key] is an object
|
|
76
|
+
if (typeof b[key as keyof object] === 'object') {
|
|
77
|
+
|
|
78
|
+
// if a[key] is not an object we have a delta
|
|
79
|
+
if (typeof a[key as keyof object] !== 'object') {
|
|
80
|
+
delta = { ...delta, [key]: b[key as keyof object] };
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// recursive: find objectDelta in a and b
|
|
85
|
+
const objectDelta = getObjectDelta(a[key as keyof object], b[key as keyof object]);
|
|
86
|
+
|
|
87
|
+
// if objectDelta has more than 0 entries we have a delta
|
|
88
|
+
if (Object.keys(objectDelta).length) {
|
|
89
|
+
delta = { ...delta, [key]: objectDelta };
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// if a[key] is not equal to b[key] we have a delta
|
|
95
|
+
if (a[key as keyof object] !== b[key as keyof object]) {
|
|
96
|
+
delta = { ...delta, [key]: b[key as keyof object] };
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
return delta;
|
|
101
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { TransformControls } from "three/examples/jsm/Addons.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Interface for objects that can be moved in the scene.
|
|
5
|
+
*
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
export interface DIVEMoveable {
|
|
10
|
+
isMoveable: true;
|
|
11
|
+
gizmo: TransformControls | null;
|
|
12
|
+
onMove?: () => void;
|
|
13
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as Moveable_DEF from '../Moveable';
|
|
2
|
+
import * as Rotatable_DEF from '../Rotatable';
|
|
3
|
+
import * as Scalable_DEF from '../Scalable';
|
|
4
|
+
import * as Selectable_DEF from '../Selectable';
|
|
5
|
+
|
|
6
|
+
describe('interfaces', () => {
|
|
7
|
+
it('should be defined', () => {
|
|
8
|
+
expect(Moveable_DEF).toBeDefined();
|
|
9
|
+
expect(Rotatable_DEF).toBeDefined();
|
|
10
|
+
expect(Scalable_DEF).toBeDefined();
|
|
11
|
+
expect(Selectable_DEF).toBeDefined();
|
|
12
|
+
});
|
|
13
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { AmbientLight, Color } from 'three';
|
|
2
|
+
import { PRODUCT_LAYER_MASK } from '../constant/VisibilityLayerMask';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A basic ambient light.
|
|
6
|
+
*
|
|
7
|
+
* Can change the color, intensity, and visibility of the light.
|
|
8
|
+
*
|
|
9
|
+
* @module
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
export default class DIVEAmbientLight extends AmbientLight {
|
|
13
|
+
constructor() {
|
|
14
|
+
super(0xffffff, 1);
|
|
15
|
+
this.layers.mask = PRODUCT_LAYER_MASK;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
public SetColor(color: Color): void {
|
|
19
|
+
this.color = color;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
public SetIntensity(intensity: number): void {
|
|
23
|
+
this.intensity = intensity;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
public SetEnabled(enabled: boolean): void {
|
|
27
|
+
this.visible = enabled;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { PointLight, Color, SphereGeometry, MeshBasicMaterial, Mesh, FrontSide } from 'three';
|
|
2
|
+
import DIVECommunication from '../com/Communication';
|
|
3
|
+
import { HELPER_LAYER_MASK, PRODUCT_LAYER_MASK } from '../constant/VisibilityLayerMask';
|
|
4
|
+
import { DIVEMoveable } from '../interface/Moveable';
|
|
5
|
+
import { DIVESelectable } from '../interface/Selectable';
|
|
6
|
+
import type { TransformControls } from 'three/examples/jsm/Addons.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* A basic point light.
|
|
10
|
+
*
|
|
11
|
+
* Can change the color, intensity, and visibility of the light.
|
|
12
|
+
*
|
|
13
|
+
* Can be moved and selected.
|
|
14
|
+
*
|
|
15
|
+
* @module
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
export default class DIVEPointLight extends PointLight implements DIVESelectable, DIVEMoveable {
|
|
19
|
+
public isMoveable: true = true;
|
|
20
|
+
public isSelectable: true = true;
|
|
21
|
+
public gizmo: TransformControls | null = null;
|
|
22
|
+
|
|
23
|
+
constructor() {
|
|
24
|
+
super(0xffffff, 1);
|
|
25
|
+
|
|
26
|
+
this.layers.mask = PRODUCT_LAYER_MASK;
|
|
27
|
+
|
|
28
|
+
this.castShadow = true;
|
|
29
|
+
this.shadow.mapSize.width = 512;
|
|
30
|
+
this.shadow.mapSize.height = 512;
|
|
31
|
+
|
|
32
|
+
const geoSize = 0.1;
|
|
33
|
+
|
|
34
|
+
const geometry = new SphereGeometry(geoSize, geoSize * 320, geoSize * 320);
|
|
35
|
+
|
|
36
|
+
const material = new MeshBasicMaterial({ color: this.color, transparent: true, opacity: 0.8, side: FrontSide });
|
|
37
|
+
|
|
38
|
+
const mesh = new Mesh(geometry, material);
|
|
39
|
+
mesh.layers.mask = HELPER_LAYER_MASK;
|
|
40
|
+
|
|
41
|
+
this.add(mesh);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
public SetColor(color: Color): void {
|
|
45
|
+
this.color = color;
|
|
46
|
+
|
|
47
|
+
((this.children[0] as Mesh).material as MeshBasicMaterial).color = color;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
public SetIntensity(intensity: number): void {
|
|
51
|
+
this.intensity = intensity;
|
|
52
|
+
|
|
53
|
+
((this.children[0] as Mesh).material as MeshBasicMaterial).opacity = intensity > 0.8 ? 0.8 : intensity * 0.8;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
public SetEnabled(enabled: boolean): void {
|
|
57
|
+
this.visible = enabled;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
public onMove(): void {
|
|
61
|
+
DIVECommunication.get(this.userData.id)?.PerformAction('UPDATE_OBJECT', { id: this.userData.id, position: this.position });
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { PRODUCT_LAYER_MASK } from "../constant/VisibilityLayerMask.ts";
|
|
2
|
+
import { Color, DirectionalLight, HemisphereLight, Object3D } from "three";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A complex scene light.
|
|
6
|
+
*
|
|
7
|
+
* Can change the color, intensity, and visibility of the light.
|
|
8
|
+
*
|
|
9
|
+
* @module
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
export default class DIVESceneLight extends Object3D {
|
|
13
|
+
|
|
14
|
+
private hemiLight: HemisphereLight;
|
|
15
|
+
private dirLight: DirectionalLight;
|
|
16
|
+
|
|
17
|
+
constructor() {
|
|
18
|
+
super();
|
|
19
|
+
|
|
20
|
+
this.name = "SceneLight";
|
|
21
|
+
|
|
22
|
+
this.hemiLight = new HemisphereLight(0xffffff, 0xffffff, 2);
|
|
23
|
+
this.hemiLight.layers.mask = PRODUCT_LAYER_MASK;
|
|
24
|
+
this.hemiLight.position.set(0, 50, 0);
|
|
25
|
+
this.add(this.hemiLight);
|
|
26
|
+
|
|
27
|
+
this.dirLight = new DirectionalLight(0xffffff, 3);
|
|
28
|
+
this.dirLight.layers.mask = PRODUCT_LAYER_MASK;
|
|
29
|
+
this.dirLight.position.set(1, 1.75, 1);
|
|
30
|
+
this.dirLight.position.multiplyScalar(30);
|
|
31
|
+
this.dirLight.castShadow = true;
|
|
32
|
+
|
|
33
|
+
this.dirLight.shadow.mapSize.width = 2048;
|
|
34
|
+
this.dirLight.shadow.mapSize.height = 2048;
|
|
35
|
+
|
|
36
|
+
const d = 5;
|
|
37
|
+
|
|
38
|
+
this.dirLight.shadow.camera.left = - d;
|
|
39
|
+
this.dirLight.shadow.camera.right = d;
|
|
40
|
+
this.dirLight.shadow.camera.top = d;
|
|
41
|
+
this.dirLight.shadow.camera.bottom = - d;
|
|
42
|
+
|
|
43
|
+
this.dirLight.shadow.camera.far = 3500;
|
|
44
|
+
this.add(this.dirLight);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
public SetColor(color: Color): void {
|
|
48
|
+
this.hemiLight.color = color;
|
|
49
|
+
this.dirLight.color = color;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
public SetIntensity(intensity: number): void {
|
|
53
|
+
this.hemiLight.intensity = intensity * 2;
|
|
54
|
+
this.dirLight.intensity = intensity * 3;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
public SetEnabled(enabled: boolean): void {
|
|
58
|
+
this.visible = enabled;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { Color } from 'three';
|
|
2
|
+
import DIVEAmbientLight from '../AmbientLight';
|
|
3
|
+
|
|
4
|
+
jest.mock('three', () => {
|
|
5
|
+
return {
|
|
6
|
+
Color: jest.fn(function () {
|
|
7
|
+
return {};
|
|
8
|
+
}),
|
|
9
|
+
AmbientLight: jest.fn(function () {
|
|
10
|
+
this.color = {};
|
|
11
|
+
this.intensity = 0;
|
|
12
|
+
this.layers = {
|
|
13
|
+
mask: 0,
|
|
14
|
+
};
|
|
15
|
+
return this;
|
|
16
|
+
}),
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
describe('dive/light/DIVEAmbientLight', () => {
|
|
22
|
+
it('should instantiate', () => {
|
|
23
|
+
const testLight = new DIVEAmbientLight();
|
|
24
|
+
expect(testLight).toBeDefined();
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('should set intensity', () => {
|
|
28
|
+
const testLight = new DIVEAmbientLight();
|
|
29
|
+
testLight.SetIntensity(1.0);
|
|
30
|
+
expect(testLight.intensity).toBe(1.0);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('should set color', () => {
|
|
34
|
+
const testLight = new DIVEAmbientLight();
|
|
35
|
+
testLight.SetColor({ test: true } as unknown as Color);
|
|
36
|
+
expect(testLight.color).toEqual({ test: true });
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('should set enabled', () => {
|
|
40
|
+
const testLight = new DIVEAmbientLight();
|
|
41
|
+
testLight.SetEnabled(false);
|
|
42
|
+
expect(testLight.visible).toBe(false);
|
|
43
|
+
});
|
|
44
|
+
});
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import DIVEPointLight from '../PointLight.ts';
|
|
2
|
+
import DIVECommunication from '../../com/Communication.ts';
|
|
3
|
+
import { Color } from 'three';
|
|
4
|
+
|
|
5
|
+
const mockAdd = jest.fn();
|
|
6
|
+
|
|
7
|
+
jest.mock('three', () => {
|
|
8
|
+
return {
|
|
9
|
+
Color: jest.fn(function () {
|
|
10
|
+
return {};
|
|
11
|
+
}),
|
|
12
|
+
PointLight: jest.fn(function () {
|
|
13
|
+
this.color = {};
|
|
14
|
+
this.intensity = 0;
|
|
15
|
+
this.layers = {
|
|
16
|
+
mask: 0,
|
|
17
|
+
};
|
|
18
|
+
this.shadow = {
|
|
19
|
+
radius: 0,
|
|
20
|
+
mapSize: { width: 0, height: 0 },
|
|
21
|
+
bias: 0,
|
|
22
|
+
camera: {
|
|
23
|
+
near: 0,
|
|
24
|
+
far: 0,
|
|
25
|
+
fov: 0,
|
|
26
|
+
},
|
|
27
|
+
}
|
|
28
|
+
this.add = mockAdd;
|
|
29
|
+
this.children = [{
|
|
30
|
+
material: {
|
|
31
|
+
color: {},
|
|
32
|
+
},
|
|
33
|
+
}];
|
|
34
|
+
this.userData = {};
|
|
35
|
+
return this;
|
|
36
|
+
}),
|
|
37
|
+
SphereGeometry: jest.fn(function () {
|
|
38
|
+
return this;
|
|
39
|
+
}),
|
|
40
|
+
MeshBasicMaterial: jest.fn(function () {
|
|
41
|
+
return this;
|
|
42
|
+
}),
|
|
43
|
+
Mesh: jest.fn(function () {
|
|
44
|
+
this.layers = {
|
|
45
|
+
mask: 0,
|
|
46
|
+
};
|
|
47
|
+
return this;
|
|
48
|
+
}),
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
jest.mock('../../com/Communication.ts', () => {
|
|
53
|
+
return {
|
|
54
|
+
get: jest.fn(() => {
|
|
55
|
+
return {
|
|
56
|
+
PerformAction: jest.fn(),
|
|
57
|
+
}
|
|
58
|
+
}),
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
describe('dive/light/DIVEPointLight', () => {
|
|
63
|
+
it('should instantiate', () => {
|
|
64
|
+
const testLight = new DIVEPointLight();
|
|
65
|
+
testLight.userData.id = 'something';
|
|
66
|
+
expect(testLight).toBeDefined();
|
|
67
|
+
expect(mockAdd).toHaveBeenCalledTimes(1);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('should set intensity', () => {
|
|
71
|
+
const testLight = new DIVEPointLight();
|
|
72
|
+
testLight.SetIntensity(1.0);
|
|
73
|
+
expect(testLight.intensity).toBe(1.0);
|
|
74
|
+
testLight.SetIntensity(0.6);
|
|
75
|
+
expect(testLight.intensity).toBe(0.6);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it('should set color', () => {
|
|
79
|
+
const testLight = new DIVEPointLight();
|
|
80
|
+
testLight.SetColor({ test: true } as unknown as Color);
|
|
81
|
+
expect(testLight.color).toEqual({ test: true });
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('should set enabled', () => {
|
|
85
|
+
const testLight = new DIVEPointLight();
|
|
86
|
+
testLight.SetEnabled(false);
|
|
87
|
+
expect(testLight.visible).toBe(false);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it('should onMove', () => {
|
|
91
|
+
const testLight = new DIVEPointLight();
|
|
92
|
+
testLight.userData.id = 'something';
|
|
93
|
+
expect(() => testLight.onMove()).not.toThrow();
|
|
94
|
+
|
|
95
|
+
jest.spyOn(DIVECommunication, 'get').mockReturnValueOnce(undefined);
|
|
96
|
+
expect(() => testLight.onMove()).not.toThrow();
|
|
97
|
+
});
|
|
98
|
+
});
|