@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
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import { type DIVEScene } from '../../scene/Scene';
|
|
2
|
-
import { type DIVEAROptions } from '../AR';
|
|
3
|
-
|
|
4
|
-
export class DIVEARQuickLook {
|
|
5
|
-
public static Launch(
|
|
6
|
-
scene: DIVEScene,
|
|
7
|
-
options?: DIVEAROptions,
|
|
8
|
-
): Promise<void> {
|
|
9
|
-
const url = this.findARQuickLookSrc(scene);
|
|
10
|
-
|
|
11
|
-
// launch ARQuickLook
|
|
12
|
-
return this.launchARQuickLook(url, options);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
private static launchARQuickLook(
|
|
16
|
-
uri: string,
|
|
17
|
-
options?: DIVEAROptions,
|
|
18
|
-
): Promise<void> {
|
|
19
|
-
return new Promise((resolve) => {
|
|
20
|
-
if (options?.arScale === 'fixed') {
|
|
21
|
-
uri = uri.concat('#allowsContentScaling=0');
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// launch ARQuickLook
|
|
25
|
-
const a = document.createElement('a');
|
|
26
|
-
a.innerHTML = '<picture></picture>'; // This is actually needed so the viewer opens instantly
|
|
27
|
-
a.rel = 'ar';
|
|
28
|
-
a.href = uri;
|
|
29
|
-
a.download = 'scene.usdz';
|
|
30
|
-
resolve();
|
|
31
|
-
a.click();
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
private static findARQuickLookSrc(scene: DIVEScene): string {
|
|
36
|
-
let uri: string | null = null;
|
|
37
|
-
|
|
38
|
-
scene.traverse((object) => {
|
|
39
|
-
if (uri) return;
|
|
40
|
-
if (object.userData.uri) {
|
|
41
|
-
uri = object.userData.uri;
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
if (!uri) {
|
|
46
|
-
throw new Error('No model found in scene');
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return uri;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// private static extractModels(scene: DIVEScene): Object3D[] {
|
|
53
|
-
// // extract models
|
|
54
|
-
// return scene.Root.children;
|
|
55
|
-
// }
|
|
56
|
-
|
|
57
|
-
// private static launchARFromNode(
|
|
58
|
-
// node: Object3D,
|
|
59
|
-
// options?: DIVEAROptions,
|
|
60
|
-
// ): Promise<void> {
|
|
61
|
-
// // bundle USDZ
|
|
62
|
-
// return this._usdzExporter
|
|
63
|
-
// .parse(node, {
|
|
64
|
-
// quickLookCompatible: true,
|
|
65
|
-
// ar: {
|
|
66
|
-
// anchoring: { type: 'plane' },
|
|
67
|
-
// planeAnchoring: {
|
|
68
|
-
// alignment:
|
|
69
|
-
// options?.arPlacement === 'vertical'
|
|
70
|
-
// ? 'vertical'
|
|
71
|
-
// : 'horizontal',
|
|
72
|
-
// },
|
|
73
|
-
// },
|
|
74
|
-
// })
|
|
75
|
-
// .then((usdz: Uint8Array) => {
|
|
76
|
-
// // create blob
|
|
77
|
-
// const blob = new Blob([usdz], { type: 'model/vnd.usdz+zip' });
|
|
78
|
-
// let url = URL.createObjectURL(blob);
|
|
79
|
-
|
|
80
|
-
// if (options?.arScale === 'fixed') {
|
|
81
|
-
// url = url.concat('#allowsContentScaling=0');
|
|
82
|
-
// }
|
|
83
|
-
|
|
84
|
-
// // launch ARQuickLook
|
|
85
|
-
// const a = document.createElement('a');
|
|
86
|
-
// a.innerHTML = '<picture></picture>'; // This is actually needed so the viewer opens instantly
|
|
87
|
-
// a.rel = 'ar';
|
|
88
|
-
// a.href = url;
|
|
89
|
-
// a.download = 'scene.usdz';
|
|
90
|
-
// a.click();
|
|
91
|
-
// });
|
|
92
|
-
// }
|
|
93
|
-
}
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import { Box3, Color, Euler, Mesh, Object3D, Vector3 } from 'three';
|
|
2
|
-
import { DIVEScene } from '../../../scene/Scene';
|
|
3
|
-
import { DIVEAROptions } from '../../AR';
|
|
4
|
-
import { DIVEARQuickLook } from '../ARQuickLook';
|
|
5
|
-
|
|
6
|
-
jest.mock('../../../scene/Scene', () => {
|
|
7
|
-
return {
|
|
8
|
-
DIVEScene: jest.fn(function () {
|
|
9
|
-
this.add = jest.fn();
|
|
10
|
-
this.children = [];
|
|
11
|
-
this.Root = {
|
|
12
|
-
children: [],
|
|
13
|
-
};
|
|
14
|
-
this.traverse = jest.fn((callback) => {
|
|
15
|
-
this.Root.children.forEach((child: Object3D) => {
|
|
16
|
-
callback(child);
|
|
17
|
-
});
|
|
18
|
-
});
|
|
19
|
-
return this;
|
|
20
|
-
}),
|
|
21
|
-
};
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
URL.createObjectURL = jest.fn(() => 'blob:http://localhost:8080/');
|
|
25
|
-
|
|
26
|
-
describe('DIVEARQuickLook', () => {
|
|
27
|
-
let mockScene: DIVEScene;
|
|
28
|
-
let mockOptions: DIVEAROptions;
|
|
29
|
-
let mockModels: Object3D[];
|
|
30
|
-
|
|
31
|
-
beforeEach(() => {
|
|
32
|
-
mockModels = [
|
|
33
|
-
new Object3D(),
|
|
34
|
-
new Object3D(),
|
|
35
|
-
new Object3D(),
|
|
36
|
-
];
|
|
37
|
-
mockModels[1].userData = {
|
|
38
|
-
uri: 'https://example.com',
|
|
39
|
-
};
|
|
40
|
-
mockScene = new DIVEScene();
|
|
41
|
-
mockOptions = {
|
|
42
|
-
arPlacement: 'horizontal',
|
|
43
|
-
arScale: 'auto',
|
|
44
|
-
} as DIVEAROptions;
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
describe('Launch', () => {
|
|
48
|
-
it('should be a function', () => {
|
|
49
|
-
expect(DIVEARQuickLook.Launch).toBeInstanceOf(Function);
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
it('should not throw without options', () => {
|
|
53
|
-
mockScene.Root.children = mockModels;
|
|
54
|
-
|
|
55
|
-
expect(() => {
|
|
56
|
-
DIVEARQuickLook.Launch(mockScene);
|
|
57
|
-
}).not.toThrow();
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it('should not throw with options', () => {
|
|
61
|
-
mockScene.Root.children = mockModels;
|
|
62
|
-
|
|
63
|
-
expect(() => {
|
|
64
|
-
DIVEARQuickLook.Launch(mockScene, mockOptions);
|
|
65
|
-
}).not.toThrow();
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
it('should not throw with alternated options', () => {
|
|
69
|
-
mockScene.Root.children = mockModels;
|
|
70
|
-
|
|
71
|
-
mockOptions = {
|
|
72
|
-
arPlacement: 'vertical',
|
|
73
|
-
arScale: 'fixed',
|
|
74
|
-
} as DIVEAROptions;
|
|
75
|
-
|
|
76
|
-
expect(() => {
|
|
77
|
-
DIVEARQuickLook.Launch(mockScene, mockOptions);
|
|
78
|
-
}).not.toThrow();
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
it('should throw if no url is found', () => {
|
|
82
|
-
mockScene.Root.children = [
|
|
83
|
-
new Object3D(),
|
|
84
|
-
new Object3D(),
|
|
85
|
-
new Object3D(),
|
|
86
|
-
];
|
|
87
|
-
|
|
88
|
-
expect(() => {
|
|
89
|
-
DIVEARQuickLook.Launch(mockScene, mockOptions);
|
|
90
|
-
}).toThrow();
|
|
91
|
-
});
|
|
92
|
-
});
|
|
93
|
-
});
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { type DIVEScene } from '../../scene/Scene';
|
|
2
|
-
import { type DIVEAROptions } from '../AR';
|
|
3
|
-
|
|
4
|
-
export class DIVESceneViewer {
|
|
5
|
-
public static Launch(scene: DIVEScene, options?: DIVEAROptions): void {
|
|
6
|
-
// find url in scene (first object found that has a set uri)
|
|
7
|
-
const url = this.findSceneViewerSrc(scene);
|
|
8
|
-
|
|
9
|
-
// launch SceneViewer
|
|
10
|
-
this.launchSceneViewer(url, options);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
private static launchSceneViewer(
|
|
14
|
-
url: string,
|
|
15
|
-
options?: DIVEAROptions,
|
|
16
|
-
): void {
|
|
17
|
-
const anchor = document.createElement('a');
|
|
18
|
-
const noArViewerSigil = '#model-viewer-no-ar-fallback';
|
|
19
|
-
|
|
20
|
-
const location = self.location.toString();
|
|
21
|
-
const locationUrl = new URL(location);
|
|
22
|
-
const modelUrl = new URL(url, location);
|
|
23
|
-
const params = new URLSearchParams(modelUrl.search);
|
|
24
|
-
|
|
25
|
-
locationUrl.hash = noArViewerSigil;
|
|
26
|
-
|
|
27
|
-
// modelUrl can contain title/link/sound etc.
|
|
28
|
-
params.set('mode', 'ar_only');
|
|
29
|
-
|
|
30
|
-
if (options?.arScale === 'fixed') {
|
|
31
|
-
params.set('resizable', 'false');
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
if (options?.arPlacement === 'vertical') {
|
|
35
|
-
params.set('enable_vertical_placement', 'true');
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// will be added later if needed
|
|
39
|
-
// if (params.has('sound')) {
|
|
40
|
-
// const soundUrl = new URL(params.get('sound')!, location);
|
|
41
|
-
// params.set('sound', soundUrl.toString());
|
|
42
|
-
// }
|
|
43
|
-
// if (params.has('link')) {
|
|
44
|
-
// const linkUrl = new URL(params.get('link')!, location);
|
|
45
|
-
// params.set('link', linkUrl.toString());
|
|
46
|
-
// }
|
|
47
|
-
|
|
48
|
-
const intent = `intent://arvr.google.com/scene-viewer/1.2?${
|
|
49
|
-
params.toString() + '&file=' + modelUrl.toString()
|
|
50
|
-
}#Intent;scheme=https;package=com.google.android.googlequicksearchbox;action=android.intent.action.VIEW;S.browser_fallback_url=${encodeURIComponent(
|
|
51
|
-
locationUrl.toString(),
|
|
52
|
-
)};end;`;
|
|
53
|
-
|
|
54
|
-
anchor.setAttribute('href', intent);
|
|
55
|
-
anchor.click();
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
private static findSceneViewerSrc(scene: DIVEScene): string {
|
|
59
|
-
let uri: string | null = null;
|
|
60
|
-
|
|
61
|
-
scene.traverse((object) => {
|
|
62
|
-
if (uri) return;
|
|
63
|
-
if (object.userData.uri) {
|
|
64
|
-
uri = object.userData.uri;
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
if (!uri) {
|
|
69
|
-
throw new Error('No model found in scene');
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
return uri;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import { Box3, Color, Euler, Mesh, Object3D, Vector3 } from 'three';
|
|
2
|
-
import { DIVEScene } from '../../../scene/Scene';
|
|
3
|
-
import { DIVEAROptions } from '../../AR';
|
|
4
|
-
import { DIVESceneViewer } from '../SceneViewer';
|
|
5
|
-
|
|
6
|
-
jest.mock('../../../scene/Scene', () => {
|
|
7
|
-
return {
|
|
8
|
-
DIVEScene: jest.fn(function () {
|
|
9
|
-
this.add = jest.fn();
|
|
10
|
-
this.children = [];
|
|
11
|
-
this.Root = {
|
|
12
|
-
children: [],
|
|
13
|
-
};
|
|
14
|
-
this.traverse = jest.fn((callback) => {
|
|
15
|
-
this.Root.children.forEach((child: Object3D) => {
|
|
16
|
-
callback(child);
|
|
17
|
-
});
|
|
18
|
-
});
|
|
19
|
-
return this;
|
|
20
|
-
}),
|
|
21
|
-
};
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
URL.createObjectURL = jest.fn(() => 'blob:http://localhost:8080/');
|
|
25
|
-
|
|
26
|
-
describe('DIVESceneViewer', () => {
|
|
27
|
-
let mockScene: DIVEScene;
|
|
28
|
-
let mockOptions: DIVEAROptions;
|
|
29
|
-
let mockModels: Object3D[];
|
|
30
|
-
|
|
31
|
-
beforeEach(() => {
|
|
32
|
-
mockModels = [
|
|
33
|
-
new Object3D(),
|
|
34
|
-
new Object3D(),
|
|
35
|
-
new Object3D(),
|
|
36
|
-
];
|
|
37
|
-
mockModels[1].userData = {
|
|
38
|
-
uri: 'https://example.com',
|
|
39
|
-
};
|
|
40
|
-
mockScene = new DIVEScene();
|
|
41
|
-
mockOptions = {
|
|
42
|
-
arPlacement: 'horizontal',
|
|
43
|
-
arScale: 'auto',
|
|
44
|
-
} as DIVEAROptions;
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
describe('Launch', () => {
|
|
48
|
-
it('should be a function', () => {
|
|
49
|
-
expect(DIVESceneViewer.Launch).toBeInstanceOf(Function);
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
it('should not throw without options', () => {
|
|
53
|
-
mockScene.Root.children = mockModels;
|
|
54
|
-
|
|
55
|
-
expect(() => {
|
|
56
|
-
DIVESceneViewer.Launch(mockScene);
|
|
57
|
-
}).not.toThrow();
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it('should not throw with options', () => {
|
|
61
|
-
mockScene.Root.children = mockModels;
|
|
62
|
-
|
|
63
|
-
expect(() => {
|
|
64
|
-
DIVESceneViewer.Launch(mockScene, mockOptions);
|
|
65
|
-
}).not.toThrow();
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
it('should not throw with alternated options', () => {
|
|
69
|
-
mockScene.Root.children = mockModels;
|
|
70
|
-
|
|
71
|
-
mockOptions = {
|
|
72
|
-
arPlacement: 'vertical',
|
|
73
|
-
arScale: 'fixed',
|
|
74
|
-
} as DIVEAROptions;
|
|
75
|
-
|
|
76
|
-
expect(() => {
|
|
77
|
-
DIVESceneViewer.Launch(mockScene, mockOptions);
|
|
78
|
-
}).not.toThrow();
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
it('should throw if no url is found', () => {
|
|
82
|
-
mockScene.Root.children = [
|
|
83
|
-
new Object3D(),
|
|
84
|
-
new Object3D(),
|
|
85
|
-
new Object3D(),
|
|
86
|
-
];
|
|
87
|
-
|
|
88
|
-
expect(() => {
|
|
89
|
-
DIVESceneViewer.Launch(mockScene, mockOptions);
|
|
90
|
-
}).toThrow();
|
|
91
|
-
});
|
|
92
|
-
});
|
|
93
|
-
});
|
package/src/ar/webxr/WebXR.ts
DELETED
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
import { Vector3 } from 'three';
|
|
2
|
-
import DIVEOrbitControls from '../../controls/OrbitControls';
|
|
3
|
-
import { type DIVERenderer } from '../../renderer/Renderer';
|
|
4
|
-
import { type DIVEScene } from '../../scene/Scene';
|
|
5
|
-
import { Overlay } from './overlay/Overlay';
|
|
6
|
-
import { DIVEWebXRController } from './controller/WebXRController';
|
|
7
|
-
|
|
8
|
-
export class DIVEWebXR {
|
|
9
|
-
// general members
|
|
10
|
-
private static _renderer: DIVERenderer;
|
|
11
|
-
private static _scene: DIVEScene;
|
|
12
|
-
private static _controller: DIVEOrbitControls;
|
|
13
|
-
|
|
14
|
-
// camera reset members
|
|
15
|
-
private static _cameraPosition: Vector3;
|
|
16
|
-
private static _cameraTarget: Vector3;
|
|
17
|
-
|
|
18
|
-
// render loop members
|
|
19
|
-
private static _renderCallbackId: string | null = null;
|
|
20
|
-
|
|
21
|
-
// setup members
|
|
22
|
-
private static _session: XRSession | null = null;
|
|
23
|
-
private static _referenceSpaceType: XRReferenceSpaceType = 'local';
|
|
24
|
-
private static _overlay: Overlay | null = null;
|
|
25
|
-
private static _options = {
|
|
26
|
-
requiredFeatures: [
|
|
27
|
-
'local',
|
|
28
|
-
'hit-test',
|
|
29
|
-
],
|
|
30
|
-
optionalFeatures: [
|
|
31
|
-
'light-estimation',
|
|
32
|
-
'local-floor',
|
|
33
|
-
'dom-overlay',
|
|
34
|
-
'depth-sensing',
|
|
35
|
-
],
|
|
36
|
-
depthSensing: {
|
|
37
|
-
usagePreference: ['gpu-optimized'],
|
|
38
|
-
dataFormatPreference: [],
|
|
39
|
-
},
|
|
40
|
-
domOverlay: { root: {} as HTMLElement },
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
private static _xrController: DIVEWebXRController | null = null;
|
|
44
|
-
|
|
45
|
-
public static async Launch(
|
|
46
|
-
renderer: DIVERenderer,
|
|
47
|
-
scene: DIVEScene,
|
|
48
|
-
controller: DIVEOrbitControls,
|
|
49
|
-
): Promise<void> {
|
|
50
|
-
this._renderer = renderer;
|
|
51
|
-
this._scene = scene;
|
|
52
|
-
this._controller = controller;
|
|
53
|
-
|
|
54
|
-
// setting camera reset values
|
|
55
|
-
this._cameraPosition = this._controller.object.position.clone();
|
|
56
|
-
this._cameraTarget = this._controller.target.clone();
|
|
57
|
-
|
|
58
|
-
if (!navigator.xr) {
|
|
59
|
-
console.error('WebXR not supported');
|
|
60
|
-
return Promise.reject();
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// setup current instance
|
|
64
|
-
this._renderer.xr.enabled = true;
|
|
65
|
-
this._scene.InitXR(renderer);
|
|
66
|
-
|
|
67
|
-
// creating overlay
|
|
68
|
-
if (!DIVEWebXR._overlay) {
|
|
69
|
-
const overlay = new Overlay();
|
|
70
|
-
DIVEWebXR._overlay = overlay;
|
|
71
|
-
}
|
|
72
|
-
DIVEWebXR._options.domOverlay = { root: DIVEWebXR._overlay.Element };
|
|
73
|
-
|
|
74
|
-
// request session
|
|
75
|
-
const session = await navigator.xr.requestSession(
|
|
76
|
-
'immersive-ar',
|
|
77
|
-
this._options,
|
|
78
|
-
);
|
|
79
|
-
session.addEventListener('end', () => {
|
|
80
|
-
this._onSessionEnded();
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
// build up session
|
|
84
|
-
renderer.xr.setReferenceSpaceType(this._referenceSpaceType);
|
|
85
|
-
await renderer.xr.setSession(session);
|
|
86
|
-
DIVEWebXR._overlay.Element.style.display = '';
|
|
87
|
-
this._session = session;
|
|
88
|
-
|
|
89
|
-
// add end session event listener
|
|
90
|
-
DIVEWebXR._overlay.CloseButton.addEventListener('click', () =>
|
|
91
|
-
this.End(),
|
|
92
|
-
);
|
|
93
|
-
|
|
94
|
-
// start session
|
|
95
|
-
await this._onSessionStarted();
|
|
96
|
-
|
|
97
|
-
return Promise.resolve();
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
public static Update(_time: DOMHighResTimeStamp, frame: XRFrame): void {
|
|
101
|
-
if (!this._session) return;
|
|
102
|
-
|
|
103
|
-
if (this._xrController) {
|
|
104
|
-
this._xrController.Update(frame);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
public static End(): void {
|
|
109
|
-
if (!this._session) return;
|
|
110
|
-
this._session.end();
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
private static async _onSessionStarted(): Promise<void> {
|
|
114
|
-
if (!this._session) return;
|
|
115
|
-
|
|
116
|
-
// add update callback to render loop
|
|
117
|
-
this._renderCallbackId = this._renderer.AddPreRenderCallback(
|
|
118
|
-
(time: DOMHighResTimeStamp, frame: XRFrame) => {
|
|
119
|
-
this.Update(time, frame);
|
|
120
|
-
},
|
|
121
|
-
);
|
|
122
|
-
|
|
123
|
-
this._xrController = new DIVEWebXRController(
|
|
124
|
-
this._session,
|
|
125
|
-
this._renderer,
|
|
126
|
-
this._scene,
|
|
127
|
-
);
|
|
128
|
-
await this._xrController.Init().catch(() => {
|
|
129
|
-
this.End();
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
return Promise.resolve();
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
private static _onSessionEnded(): void {
|
|
136
|
-
if (!this._session) return;
|
|
137
|
-
|
|
138
|
-
if (this._xrController) {
|
|
139
|
-
this._xrController.Dispose();
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
// remove Update() callback
|
|
143
|
-
if (this._renderCallbackId) {
|
|
144
|
-
this._renderer.RemovePreRenderCallback(this._renderCallbackId);
|
|
145
|
-
this._renderCallbackId = null;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
// disable XR on renderer to restore canvas rendering
|
|
149
|
-
this._renderer.xr.enabled = false;
|
|
150
|
-
|
|
151
|
-
// resize renderer
|
|
152
|
-
const canvasWrapper = this._renderer.domElement.parentElement;
|
|
153
|
-
if (canvasWrapper) {
|
|
154
|
-
const { clientWidth, clientHeight } = canvasWrapper;
|
|
155
|
-
this._renderer.OnResize(clientWidth, clientHeight);
|
|
156
|
-
|
|
157
|
-
// resize camera
|
|
158
|
-
this._controller.object.OnResize(clientWidth, clientHeight);
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
// reset camera
|
|
162
|
-
this._controller.object.position.copy(this._cameraPosition);
|
|
163
|
-
this._controller.target.copy(this._cameraTarget);
|
|
164
|
-
|
|
165
|
-
// reset camera values
|
|
166
|
-
this._cameraPosition.set(0, 0, 0);
|
|
167
|
-
this._cameraTarget.set(0, 0, 0);
|
|
168
|
-
|
|
169
|
-
// dispose xr scene
|
|
170
|
-
this._scene.DisposeXR();
|
|
171
|
-
|
|
172
|
-
this._session.removeEventListener('end', this._onSessionEnded);
|
|
173
|
-
DIVEWebXR._overlay!.Element.style.display = 'none';
|
|
174
|
-
this._session = null;
|
|
175
|
-
}
|
|
176
|
-
}
|