@shopware-ag/dive 1.7.0 → 1.8.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/README.md +1 -1
- package/build/dive.cjs +28 -17
- package/build/dive.cjs.map +1 -1
- package/build/dive.d.cts +8 -7
- package/build/dive.d.ts +8 -7
- package/build/dive.js +27 -16
- package/build/dive.js.map +1 -1
- package/package.json +1 -1
- package/src/__test__/DIVE.test.ts +2 -1
- package/src/camera/PerspectiveCamera.ts +7 -2
- package/src/camera/__test__/PerspectiveCamera.test.ts +11 -2
- package/src/controls/OrbitControls.ts +9 -4
- package/src/controls/__test__/OrbitControls.test.ts +15 -5
- package/src/dive.ts +10 -8
- package/src/renderer/Renderer.ts +10 -7
- package/src/renderer/__test__/Renderer.test.ts +11 -0
package/package.json
CHANGED
|
@@ -183,6 +183,8 @@ jest.mock('../axiscamera/AxisCamera.ts', () => {
|
|
|
183
183
|
});
|
|
184
184
|
});
|
|
185
185
|
|
|
186
|
+
console.log = jest.fn();
|
|
187
|
+
|
|
186
188
|
describe('dive/DIVE', () => {
|
|
187
189
|
it('should QuickView', () => {
|
|
188
190
|
const dive = DIVE.QuickView('test_uri');
|
|
@@ -193,7 +195,6 @@ describe('dive/DIVE', () => {
|
|
|
193
195
|
const dive = new DIVE();
|
|
194
196
|
expect(dive).toBeDefined();
|
|
195
197
|
expect((window as any).DIVE.PrintScene).toBeDefined();
|
|
196
|
-
console.log = jest.fn();
|
|
197
198
|
expect(() => (window as any).DIVE.PrintScene()).not.toThrow();
|
|
198
199
|
});
|
|
199
200
|
|
|
@@ -25,8 +25,13 @@ export default class DIVEPerspectiveCamera extends PerspectiveCamera {
|
|
|
25
25
|
|
|
26
26
|
public onSetCameraLayer: (mask: number) => void = () => { };
|
|
27
27
|
|
|
28
|
-
constructor(settings: DIVEPerspectiveCameraSettings = DIVEPerspectiveCameraDefaultSettings) {
|
|
29
|
-
super(
|
|
28
|
+
constructor(settings: Partial<DIVEPerspectiveCameraSettings> = DIVEPerspectiveCameraDefaultSettings) {
|
|
29
|
+
super(
|
|
30
|
+
settings.fov || DIVEPerspectiveCameraDefaultSettings.fov,
|
|
31
|
+
1,
|
|
32
|
+
settings.near || DIVEPerspectiveCameraDefaultSettings.near,
|
|
33
|
+
settings.far || DIVEPerspectiveCameraDefaultSettings.far
|
|
34
|
+
);
|
|
30
35
|
|
|
31
36
|
this.layers.mask = DIVEPerspectiveCamera.EDITOR_VIEW_LAYER_MASK;
|
|
32
37
|
}
|
|
@@ -5,11 +5,20 @@ let cam: DIVEPerspectiveCamera;
|
|
|
5
5
|
describe('dive/camera/DIVEPerspectiveCamera', () => {
|
|
6
6
|
beforeEach(() => {
|
|
7
7
|
jest.clearAllMocks();
|
|
8
|
-
cam = new DIVEPerspectiveCamera(
|
|
8
|
+
cam = new DIVEPerspectiveCamera();
|
|
9
9
|
});
|
|
10
10
|
|
|
11
11
|
it('should instantiate', () => {
|
|
12
|
-
cam = new DIVEPerspectiveCamera();
|
|
12
|
+
cam = new DIVEPerspectiveCamera({});
|
|
13
|
+
expect(cam).toBeDefined();
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it('should instantiate with settings', () => {
|
|
17
|
+
cam = new DIVEPerspectiveCamera({
|
|
18
|
+
fov: 45,
|
|
19
|
+
near: 0.1,
|
|
20
|
+
far: 100,
|
|
21
|
+
});
|
|
13
22
|
expect(cam).toBeDefined();
|
|
14
23
|
});
|
|
15
24
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { OrbitControls } from "three/examples/jsm/
|
|
1
|
+
import { OrbitControls } from "three/examples/jsm/controls/OrbitControls";
|
|
2
2
|
import DIVEPerspectiveCamera from "../camera/PerspectiveCamera.ts";
|
|
3
3
|
import { DIVERenderer } from "../renderer/Renderer.ts";
|
|
4
4
|
import { type Box3, MathUtils, Vector3, Vector3Like } from "three";
|
|
@@ -39,7 +39,7 @@ export default class DIVEOrbitControls extends OrbitControls {
|
|
|
39
39
|
|
|
40
40
|
private _removePreRenderCallback: () => void = () => { };
|
|
41
41
|
|
|
42
|
-
constructor(camera: DIVEPerspectiveCamera, renderer: DIVERenderer, animationSystem: DIVEAnimationSystem, settings: DIVEOrbitControlsSettings = DIVEOrbitControlsDefaultSettings) {
|
|
42
|
+
constructor(camera: DIVEPerspectiveCamera, renderer: DIVERenderer, animationSystem: DIVEAnimationSystem, settings: Partial<DIVEOrbitControlsSettings> = DIVEOrbitControlsDefaultSettings) {
|
|
43
43
|
super(camera, renderer.domElement);
|
|
44
44
|
|
|
45
45
|
this._animationSystem = animationSystem;
|
|
@@ -56,8 +56,13 @@ export default class DIVEOrbitControls extends OrbitControls {
|
|
|
56
56
|
renderer.RemovePreRenderCallback(id);
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
this.enableDamping = settings.enableDamping;
|
|
60
|
-
this.dampingFactor = settings.dampingFactor;
|
|
59
|
+
this.enableDamping = settings.enableDamping || DIVEOrbitControlsDefaultSettings.enableDamping;
|
|
60
|
+
this.dampingFactor = settings.dampingFactor || DIVEOrbitControlsDefaultSettings.dampingFactor;
|
|
61
|
+
|
|
62
|
+
// initialize camera transformation
|
|
63
|
+
this.object.position.set(0, 2, 2);
|
|
64
|
+
this.target.copy({ x: 0, y: 0.5, z: 0 });
|
|
65
|
+
this.update();
|
|
61
66
|
}
|
|
62
67
|
|
|
63
68
|
public Dispose(): void {
|
|
@@ -12,7 +12,7 @@ jest.mock('@tweenjs/tween.js', () => {
|
|
|
12
12
|
}
|
|
13
13
|
});
|
|
14
14
|
|
|
15
|
-
jest.mock('three/examples/jsm/
|
|
15
|
+
jest.mock('three/examples/jsm/controls/OrbitControls', () => {
|
|
16
16
|
return {
|
|
17
17
|
OrbitControls: jest.fn(function () {
|
|
18
18
|
this.enableDamping = true;
|
|
@@ -42,14 +42,13 @@ jest.mock('three/examples/jsm/Addons.js', () => {
|
|
|
42
42
|
MIDDLE: 1,
|
|
43
43
|
RIGHT: 2,
|
|
44
44
|
};
|
|
45
|
-
this.target = {
|
|
46
|
-
set: jest.fn(),
|
|
47
|
-
};
|
|
48
45
|
this.update = jest.fn();
|
|
49
46
|
this.dispose = jest.fn();
|
|
50
47
|
this.getDistance = jest.fn();
|
|
51
48
|
this.target = {
|
|
52
49
|
clone: jest.fn(),
|
|
50
|
+
set: jest.fn(),
|
|
51
|
+
copy: jest.fn(),
|
|
53
52
|
};
|
|
54
53
|
return this;
|
|
55
54
|
}),
|
|
@@ -122,6 +121,9 @@ const mockCamera = {
|
|
|
122
121
|
multiplyScalar: jest.fn(() => {
|
|
123
122
|
return mockCamera.position;
|
|
124
123
|
}),
|
|
124
|
+
set: jest.fn(() => {
|
|
125
|
+
return mockCamera.position;
|
|
126
|
+
}),
|
|
125
127
|
},
|
|
126
128
|
lookAt: jest.fn(),
|
|
127
129
|
} as unknown as DIVEPerspectiveCamera;
|
|
@@ -148,7 +150,15 @@ describe('dive/controls/DIVEOrbitControls', () => {
|
|
|
148
150
|
});
|
|
149
151
|
|
|
150
152
|
it('should instantiate', () => {
|
|
151
|
-
const controller = new DIVEOrbitControls(mockCamera, mockRenderer, mockAnimSystem);
|
|
153
|
+
const controller = new DIVEOrbitControls(mockCamera, mockRenderer, mockAnimSystem, {});
|
|
154
|
+
expect(controller).toBeDefined();
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
it('should instantiate with settings', () => {
|
|
158
|
+
const controller = new DIVEOrbitControls(mockCamera, mockRenderer, mockAnimSystem, {
|
|
159
|
+
enableDamping: false,
|
|
160
|
+
dampingFactor: 0.5,
|
|
161
|
+
});
|
|
152
162
|
expect(controller).toBeDefined();
|
|
153
163
|
});
|
|
154
164
|
|
package/src/dive.ts
CHANGED
|
@@ -17,9 +17,9 @@ import { DIVEInfo } from "./info/Info.ts";
|
|
|
17
17
|
export type DIVESettings = {
|
|
18
18
|
autoResize: boolean;
|
|
19
19
|
displayAxes: boolean;
|
|
20
|
-
renderer: DIVERendererSettings
|
|
21
|
-
perspectiveCamera: DIVEPerspectiveCameraSettings
|
|
22
|
-
orbitControls: DIVEOrbitControlsSettings
|
|
20
|
+
renderer: Partial<DIVERendererSettings>;
|
|
21
|
+
perspectiveCamera: Partial<DIVEPerspectiveCameraSettings>;
|
|
22
|
+
orbitControls: Partial<DIVEOrbitControlsSettings>;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
export const DIVEDefaultSettings: DIVESettings = {
|
|
@@ -159,15 +159,15 @@ export default class DIVE {
|
|
|
159
159
|
|
|
160
160
|
// apply perspective camera settings
|
|
161
161
|
if (settingsDelta.perspectiveCamera) {
|
|
162
|
-
this.perspectiveCamera.fov = settingsDelta.perspectiveCamera.fov;
|
|
163
|
-
this.perspectiveCamera.near = settingsDelta.perspectiveCamera.near;
|
|
164
|
-
this.perspectiveCamera.far = settingsDelta.perspectiveCamera.far;
|
|
162
|
+
if (settingsDelta.perspectiveCamera.fov !== undefined) this.perspectiveCamera.fov = settingsDelta.perspectiveCamera.fov;
|
|
163
|
+
if (settingsDelta.perspectiveCamera.near !== undefined) this.perspectiveCamera.near = settingsDelta.perspectiveCamera.near;
|
|
164
|
+
if (settingsDelta.perspectiveCamera.far !== undefined) this.perspectiveCamera.far = settingsDelta.perspectiveCamera.far;
|
|
165
165
|
this.perspectiveCamera.OnResize(this.renderer.domElement.width, this.renderer.domElement.height);
|
|
166
166
|
}
|
|
167
167
|
// apply orbit controls settings
|
|
168
168
|
if (settingsDelta.orbitControls) {
|
|
169
|
-
this.orbitControls.enableDamping = settingsDelta.orbitControls.enableDamping;
|
|
170
|
-
this.orbitControls.dampingFactor = settingsDelta.orbitControls.dampingFactor;
|
|
169
|
+
if (settingsDelta.orbitControls.enableDamping !== undefined) this.orbitControls.enableDamping = settingsDelta.orbitControls.enableDamping;
|
|
170
|
+
if (settingsDelta.orbitControls.dampingFactor !== undefined) this.orbitControls.dampingFactor = settingsDelta.orbitControls.dampingFactor;
|
|
171
171
|
}
|
|
172
172
|
|
|
173
173
|
if (settingsDelta.autoResize !== this._settings.autoResize) {
|
|
@@ -229,6 +229,8 @@ export default class DIVE {
|
|
|
229
229
|
console.log(this.scene);
|
|
230
230
|
},
|
|
231
231
|
}
|
|
232
|
+
|
|
233
|
+
console.log('DIVE initialized');
|
|
232
234
|
}
|
|
233
235
|
|
|
234
236
|
public Dispose(): void {
|
package/src/renderer/Renderer.ts
CHANGED
|
@@ -7,6 +7,7 @@ export type DIVERendererSettings = {
|
|
|
7
7
|
shadowMapEnabled: boolean;
|
|
8
8
|
shadowMapType: ShadowMapType;
|
|
9
9
|
toneMapping: ToneMapping;
|
|
10
|
+
canvas?: HTMLCanvasElement;
|
|
10
11
|
}
|
|
11
12
|
|
|
12
13
|
export const DIVERendererDefaultSettings: DIVERendererSettings = {
|
|
@@ -16,6 +17,7 @@ export const DIVERendererDefaultSettings: DIVERendererSettings = {
|
|
|
16
17
|
shadowMapEnabled: true,
|
|
17
18
|
shadowMapType: PCFSoftShadowMap,
|
|
18
19
|
toneMapping: NoToneMapping,
|
|
20
|
+
canvas: undefined,
|
|
19
21
|
}
|
|
20
22
|
|
|
21
23
|
/**
|
|
@@ -36,18 +38,19 @@ export class DIVERenderer extends WebGLRenderer {
|
|
|
36
38
|
private preRenderCallbacks: Map<string, () => void> = new Map<string, () => void>();
|
|
37
39
|
private postRenderCallbacks: Map<string, () => void> = new Map<string, () => void>();
|
|
38
40
|
|
|
39
|
-
constructor(rendererSettings: DIVERendererSettings = DIVERendererDefaultSettings) {
|
|
41
|
+
constructor(rendererSettings: Partial<DIVERendererSettings> = DIVERendererDefaultSettings) {
|
|
40
42
|
super({
|
|
41
|
-
antialias: rendererSettings.antialias,
|
|
42
|
-
alpha: rendererSettings.alpha,
|
|
43
|
-
preserveDrawingBuffer: true
|
|
43
|
+
antialias: rendererSettings.antialias || DIVERendererDefaultSettings.antialias,
|
|
44
|
+
alpha: rendererSettings.alpha || DIVERendererDefaultSettings.alpha,
|
|
45
|
+
preserveDrawingBuffer: true,
|
|
46
|
+
canvas: rendererSettings.canvas,
|
|
44
47
|
});
|
|
45
48
|
this.setPixelRatio(window.devicePixelRatio);
|
|
46
49
|
|
|
47
|
-
this.shadowMap.enabled = rendererSettings.shadowMapEnabled;
|
|
48
|
-
this.shadowMap.type = rendererSettings.shadowMapType;
|
|
50
|
+
this.shadowMap.enabled = rendererSettings.shadowMapEnabled || DIVERendererDefaultSettings.shadowMapEnabled;
|
|
51
|
+
this.shadowMap.type = rendererSettings.shadowMapType || DIVERendererDefaultSettings.shadowMapType;
|
|
49
52
|
|
|
50
|
-
this.toneMapping = rendererSettings.toneMapping;
|
|
53
|
+
this.toneMapping = rendererSettings.toneMapping || DIVERendererDefaultSettings.toneMapping;
|
|
51
54
|
|
|
52
55
|
this.debug.checkShaderErrors = false;
|
|
53
56
|
}
|
|
@@ -48,9 +48,20 @@ describe('dive/renderer/DIVERenderer', () => {
|
|
|
48
48
|
});
|
|
49
49
|
|
|
50
50
|
it('should instantiate', () => {
|
|
51
|
+
renderer = new DIVERenderer({});
|
|
51
52
|
expect(renderer).toBeDefined();
|
|
52
53
|
});
|
|
53
54
|
|
|
55
|
+
it('should instantiate', () => {
|
|
56
|
+
renderer = new DIVERenderer({
|
|
57
|
+
alpha: true,
|
|
58
|
+
shadowMapEnabled: true,
|
|
59
|
+
shadowMapType: 1,
|
|
60
|
+
toneMapping: 1,
|
|
61
|
+
antialias: true,
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
|
|
54
65
|
it('should instantiate with settings parameter', () => {
|
|
55
66
|
renderer = new DIVERenderer(DIVERendererDefaultSettings);
|
|
56
67
|
expect(renderer).toBeDefined();
|