@shopware-ag/dive 1.19.1-beta.0 → 1.19.1-beta.2
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 +362 -199
- package/build/dive.cjs.map +1 -1
- package/build/dive.js +330 -167
- package/build/dive.js.map +1 -1
- package/build/dive.mjs +10803 -8714
- package/build/dive.mjs.map +1 -1
- package/build/src/converter/Converter.d.ts +3 -12
- package/build/src/dive.d.ts +1 -0
- package/build/src/exporter/Exporter.d.ts +20 -2
- package/build/src/loader/Loader.d.ts +0 -4
- package/build/src/types/error/index.d.ts +12 -0
- package/build/src/types/file/FileTypes.d.ts +17 -0
- package/build/src/types/file/index.d.ts +1 -0
- package/build/src/types/index.d.ts +5 -8
- package/package.json +2 -3
- package/build/src/types/ExporterOptions.d.ts +0 -15
- package/build/src/types/FileTypes.d.ts +0 -27
- 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 -101
- package/src/ar/__test__/AR.test.ts +0 -276
- package/src/ar/arquicklook/ARQuickLook.ts +0 -53
- package/src/ar/arquicklook/__test__/ARQuickLook.test.ts +0 -144
- package/src/ar/sceneviewer/SceneViewer.ts +0 -119
- package/src/ar/sceneviewer/__test__/SceneViewer.test.ts +0 -190
- package/src/ar/webxr/WebXR.ts +0 -177
- 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 -806
- package/src/com/__test__/Communication.test.ts +0 -1030
- 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/converter/Converter.ts +0 -117
- package/src/dive.ts +0 -363
- package/src/events/EventExecutor.ts +0 -35
- package/src/exporter/Exporter.ts +0 -75
- 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 -70
- 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 -178
- package/src/info/__test__/Info.test.ts +0 -346
- 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/loader/Loader.ts +0 -48
- 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 -190
- package/src/model/__test__/Model.test.ts +0 -215
- package/src/module/Module.ts +0 -45
- package/src/module/__test__/Module.test.ts +0 -54
- package/src/node/Node.ts +0 -100
- 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/ExporterOptions.ts +0 -14
- package/src/types/FileTypes.ts +0 -37
- 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 -31
- package/src/types/info/index.ts +0 -76
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { Mesh, MeshBasicMaterial, Object3D, RingGeometry } from 'three';
|
|
2
|
-
|
|
3
|
-
export class DIVEWebXRCrosshair extends Object3D {
|
|
4
|
-
public set mesh(mesh: Mesh | undefined) {
|
|
5
|
-
this.clear();
|
|
6
|
-
|
|
7
|
-
if (mesh) {
|
|
8
|
-
this.add(mesh);
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
constructor(mesh?: Mesh) {
|
|
13
|
-
super();
|
|
14
|
-
|
|
15
|
-
if (mesh) {
|
|
16
|
-
this.mesh = mesh;
|
|
17
|
-
} else {
|
|
18
|
-
this.UseDefaultMesh();
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
this.matrixAutoUpdate = false;
|
|
22
|
-
|
|
23
|
-
return this;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
public UseDefaultMesh(): void {
|
|
27
|
-
const geometry = new RingGeometry(0.08, 0.1, 32).rotateX(-Math.PI / 2);
|
|
28
|
-
const material = new MeshBasicMaterial();
|
|
29
|
-
this.mesh = new Mesh(geometry, material);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
public UpdateFromPose(pose: XRPose): void {
|
|
33
|
-
this.matrix.fromArray(pose.transform.matrix);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
@@ -1,192 +0,0 @@
|
|
|
1
|
-
import { Matrix4, Quaternion, Vector3 } from 'three';
|
|
2
|
-
import { DIVERenderer } from '../../../renderer/Renderer';
|
|
3
|
-
|
|
4
|
-
export class DIVEWebXROrigin {
|
|
5
|
-
private _renderer: DIVERenderer;
|
|
6
|
-
private _session: XRSession;
|
|
7
|
-
|
|
8
|
-
private _requesting: boolean;
|
|
9
|
-
private _initialized: boolean;
|
|
10
|
-
|
|
11
|
-
private _referenceSpaceBuffer: XRReferenceSpace | null;
|
|
12
|
-
private _hitTestSource: XRHitTestSource | null;
|
|
13
|
-
|
|
14
|
-
private _entityTypes: XRHitTestTrackableType[];
|
|
15
|
-
|
|
16
|
-
private _hitTestResultBuffer: XRHitTestResult[];
|
|
17
|
-
private _raycastHitCounter: number = 0;
|
|
18
|
-
|
|
19
|
-
private _originSet: Promise<void>;
|
|
20
|
-
private _originSetResolve: (value: void) => void = () => {};
|
|
21
|
-
public get originSet(): Promise<void> {
|
|
22
|
-
return this._originSet;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
private _matrix: Matrix4;
|
|
26
|
-
public get matrix(): Matrix4 {
|
|
27
|
-
return this._matrix;
|
|
28
|
-
}
|
|
29
|
-
private set matrix(value: Matrix4) {
|
|
30
|
-
this._matrix = value;
|
|
31
|
-
this._matrix.decompose(this._position, this._quaternion, this._scale);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
private _position: Vector3;
|
|
35
|
-
public get position(): Vector3 {
|
|
36
|
-
return this._position;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
private _quaternion: Quaternion;
|
|
40
|
-
public get quaternion(): Quaternion {
|
|
41
|
-
return this._quaternion;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
private _scale: Vector3;
|
|
45
|
-
public get scale(): Vector3 {
|
|
46
|
-
return this._scale;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
constructor(
|
|
50
|
-
session: XRSession,
|
|
51
|
-
renderer: DIVERenderer,
|
|
52
|
-
entityTypes?: XRHitTestTrackableType[],
|
|
53
|
-
) {
|
|
54
|
-
this._renderer = renderer;
|
|
55
|
-
this._session = session;
|
|
56
|
-
|
|
57
|
-
this._originSet = new Promise<void>((resolve) => {
|
|
58
|
-
this._originSetResolve = resolve;
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
this._requesting = false;
|
|
62
|
-
this._initialized = false;
|
|
63
|
-
|
|
64
|
-
this._referenceSpaceBuffer = null;
|
|
65
|
-
this._hitTestSource = null;
|
|
66
|
-
|
|
67
|
-
this._entityTypes = entityTypes || ['plane'];
|
|
68
|
-
|
|
69
|
-
this._hitTestResultBuffer = [];
|
|
70
|
-
|
|
71
|
-
// set up promises and executors
|
|
72
|
-
this._matrix = new Matrix4();
|
|
73
|
-
this._position = new Vector3();
|
|
74
|
-
this._quaternion = new Quaternion();
|
|
75
|
-
this._scale = new Vector3();
|
|
76
|
-
|
|
77
|
-
// when origin is set, decompose matrix into position, quaternion and scale
|
|
78
|
-
this._originSet.then(() => {
|
|
79
|
-
// decompose matrix into position, quaternion and scale
|
|
80
|
-
this._matrix.decompose(
|
|
81
|
-
this._position,
|
|
82
|
-
this._quaternion,
|
|
83
|
-
this._scale,
|
|
84
|
-
);
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
public async Init(): Promise<this> {
|
|
89
|
-
if (this._initialized) {
|
|
90
|
-
return Promise.resolve(this);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
if (!this._session) {
|
|
94
|
-
console.error(
|
|
95
|
-
'DIVEWebXROrigin: No session set in Init()! Aborting initialization...',
|
|
96
|
-
);
|
|
97
|
-
return Promise.reject();
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
if (this._requesting) {
|
|
101
|
-
console.error(
|
|
102
|
-
'DIVEWebXROrigin: Currently initializing! Aborting initialization...',
|
|
103
|
-
);
|
|
104
|
-
return Promise.reject();
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
this._requesting = true;
|
|
108
|
-
const referenceSpace =
|
|
109
|
-
await this._session.requestReferenceSpace('viewer');
|
|
110
|
-
this._hitTestSource =
|
|
111
|
-
(await this._session.requestHitTestSource!({
|
|
112
|
-
space: referenceSpace,
|
|
113
|
-
entityTypes: this._entityTypes,
|
|
114
|
-
})) || null;
|
|
115
|
-
this._requesting = false;
|
|
116
|
-
|
|
117
|
-
if (!this._hitTestSource) {
|
|
118
|
-
return Promise.reject();
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
this._initialized = true;
|
|
122
|
-
|
|
123
|
-
return Promise.resolve(this);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
public Dispose(): void {
|
|
127
|
-
this._initialized = false;
|
|
128
|
-
this._requesting = false;
|
|
129
|
-
|
|
130
|
-
this._hitTestSource?.cancel();
|
|
131
|
-
|
|
132
|
-
this._hitTestSource = null;
|
|
133
|
-
this._hitTestResultBuffer = [];
|
|
134
|
-
|
|
135
|
-
this._matrix = new Matrix4();
|
|
136
|
-
this._position = new Vector3();
|
|
137
|
-
this._quaternion = new Quaternion();
|
|
138
|
-
this._scale = new Vector3();
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
public Update(frame: XRFrame): void {
|
|
142
|
-
if (!this._initialized) return;
|
|
143
|
-
|
|
144
|
-
if (!this._hitTestSource) {
|
|
145
|
-
throw new Error(
|
|
146
|
-
'DIVEWebXRRaycaster: Critical Error: HitTestSource not available but WebXROrigin is initialized!',
|
|
147
|
-
);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
// get hit test results
|
|
151
|
-
this._hitTestResultBuffer = frame.getHitTestResults(
|
|
152
|
-
this._hitTestSource,
|
|
153
|
-
);
|
|
154
|
-
if (this._hitTestResultBuffer.length > 0) {
|
|
155
|
-
// hit found
|
|
156
|
-
this._referenceSpaceBuffer = this._renderer.xr.getReferenceSpace();
|
|
157
|
-
|
|
158
|
-
// if there is no reference space, hit will be counted as lost for this frame
|
|
159
|
-
if (!this._referenceSpaceBuffer) {
|
|
160
|
-
this.onHitLost();
|
|
161
|
-
return;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
const pose = this._hitTestResultBuffer[0].getPose(
|
|
165
|
-
this._referenceSpaceBuffer,
|
|
166
|
-
);
|
|
167
|
-
if (!pose) {
|
|
168
|
-
this.onHitLost();
|
|
169
|
-
return;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
this.onHitFound(pose);
|
|
173
|
-
} else {
|
|
174
|
-
this.onHitLost();
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
private onHitFound(pose: XRPose): void {
|
|
179
|
-
this._raycastHitCounter++;
|
|
180
|
-
|
|
181
|
-
this.matrix.fromArray(pose.transform.matrix);
|
|
182
|
-
|
|
183
|
-
// we have to wait for a certain amount of frames to make sure the origin is set
|
|
184
|
-
if (this._raycastHitCounter > 50) {
|
|
185
|
-
this._originSetResolve();
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
private onHitLost(): void {
|
|
190
|
-
this._raycastHitCounter = 0;
|
|
191
|
-
}
|
|
192
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
export class Overlay {
|
|
2
|
-
private _element: HTMLDivElement;
|
|
3
|
-
public get Element(): HTMLDivElement {
|
|
4
|
-
return this._element;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
private _closeButton: SVGSVGElement;
|
|
8
|
-
public get CloseButton(): SVGSVGElement {
|
|
9
|
-
return this._closeButton;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
constructor() {
|
|
13
|
-
// create div
|
|
14
|
-
this._element = document.createElement('div');
|
|
15
|
-
|
|
16
|
-
// create and append close button to overlay
|
|
17
|
-
this._closeButton = this.createCloseButton();
|
|
18
|
-
this._element.appendChild(this._closeButton);
|
|
19
|
-
|
|
20
|
-
// append overlay to body
|
|
21
|
-
document.body.appendChild(this._element);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
private createCloseButton(): SVGSVGElement {
|
|
25
|
-
// create svg path
|
|
26
|
-
const path = document.createElementNS(
|
|
27
|
-
'http://www.w3.org/2000/svg',
|
|
28
|
-
'path',
|
|
29
|
-
);
|
|
30
|
-
path.setAttribute('d', 'M 12,12 L 28,28 M 28,12 12,28');
|
|
31
|
-
path.setAttribute('stroke', '#fff');
|
|
32
|
-
path.setAttribute('stroke-width', '2');
|
|
33
|
-
|
|
34
|
-
// create svg
|
|
35
|
-
const svg = document.createElementNS(
|
|
36
|
-
'http://www.w3.org/2000/svg',
|
|
37
|
-
'svg',
|
|
38
|
-
);
|
|
39
|
-
svg.setAttribute('width', '38');
|
|
40
|
-
svg.setAttribute('height', '38');
|
|
41
|
-
svg.style.position = 'absolute';
|
|
42
|
-
svg.style.right = '20px';
|
|
43
|
-
svg.style.top = '20px';
|
|
44
|
-
|
|
45
|
-
// append path to svg
|
|
46
|
-
svg.appendChild(path);
|
|
47
|
-
|
|
48
|
-
return svg;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
import { Matrix4, Mesh, Vector3 } from 'three';
|
|
2
|
-
import { DIVERenderer } from '../../../renderer/Renderer';
|
|
3
|
-
import { DIVEWebXRRaycasterAR } from './ar/WebXRRaycasterAR';
|
|
4
|
-
import { DIVEWebXRRaycasterTHREE } from './three/WebXRRaycasterTHREE';
|
|
5
|
-
import { DIVEScene } from '../../../scene/Scene';
|
|
6
|
-
import { DIVEEventExecutor } from '../../../events/EventExecutor';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* object is undefined when AR world is hit.
|
|
10
|
-
*/
|
|
11
|
-
export type DIVEHitResult = {
|
|
12
|
-
point: Vector3;
|
|
13
|
-
matrix: Matrix4;
|
|
14
|
-
object?: Mesh;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export type DIVEWebXRRaycasterEvents = {
|
|
18
|
-
AR_HIT_FOUND: {
|
|
19
|
-
hit: DIVEHitResult;
|
|
20
|
-
};
|
|
21
|
-
AR_HIT_LOST: undefined;
|
|
22
|
-
SCENE_HIT_FOUND: {
|
|
23
|
-
hit: DIVEHitResult;
|
|
24
|
-
};
|
|
25
|
-
SCENE_HIT_LOST: undefined;
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
export class DIVEWebXRRaycaster extends DIVEEventExecutor<DIVEWebXRRaycasterEvents> {
|
|
29
|
-
private _session: XRSession;
|
|
30
|
-
|
|
31
|
-
private _initialized: boolean = false;
|
|
32
|
-
|
|
33
|
-
private _threeRaycaster: DIVEWebXRRaycasterTHREE;
|
|
34
|
-
private _arRaycaster: DIVEWebXRRaycasterAR;
|
|
35
|
-
|
|
36
|
-
private _arHitResultBuffer: DIVEHitResult[] = [];
|
|
37
|
-
private _sceneHitResultBuffer: DIVEHitResult[] = [];
|
|
38
|
-
|
|
39
|
-
// buffers
|
|
40
|
-
private _hasHit: boolean = false;
|
|
41
|
-
|
|
42
|
-
constructor(session: XRSession, renderer: DIVERenderer, scene: DIVEScene) {
|
|
43
|
-
super();
|
|
44
|
-
|
|
45
|
-
this._session = session;
|
|
46
|
-
|
|
47
|
-
this._threeRaycaster = new DIVEWebXRRaycasterTHREE(renderer, scene);
|
|
48
|
-
this._arRaycaster = new DIVEWebXRRaycasterAR(session, renderer);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
public Dispose(): void {
|
|
52
|
-
// dispose code here
|
|
53
|
-
this._initialized = false;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
public async Init(): Promise<this> {
|
|
57
|
-
if (!this._session) {
|
|
58
|
-
console.error(
|
|
59
|
-
'DIVEWebXRRaycaster: No session set in Init()! Aborting initialization...',
|
|
60
|
-
);
|
|
61
|
-
return Promise.reject();
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
if (this._initialized) {
|
|
65
|
-
console.error(
|
|
66
|
-
'DIVEWebXRRaycaster: Already initialized! Aborting initialization...',
|
|
67
|
-
);
|
|
68
|
-
return Promise.reject();
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
await this._threeRaycaster.Init();
|
|
72
|
-
await this._arRaycaster.Init();
|
|
73
|
-
|
|
74
|
-
console.log('DIVEWebXRRaycaster: Initialized');
|
|
75
|
-
|
|
76
|
-
this._initialized = true;
|
|
77
|
-
|
|
78
|
-
return Promise.resolve(this);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
public GetARIntersections(frame: XRFrame): DIVEHitResult[] {
|
|
82
|
-
// check for ar hits
|
|
83
|
-
this._arHitResultBuffer = this._arRaycaster.GetIntersections(frame);
|
|
84
|
-
if (this._arHitResultBuffer.length > 0) {
|
|
85
|
-
// hit found
|
|
86
|
-
this.onARHitFound(this._arHitResultBuffer[0]);
|
|
87
|
-
} else {
|
|
88
|
-
// hit nothing
|
|
89
|
-
this.onARHitLost();
|
|
90
|
-
}
|
|
91
|
-
return this._arHitResultBuffer;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
public GetSceneIntersections(): DIVEHitResult[] {
|
|
95
|
-
// check for scene hits
|
|
96
|
-
this._sceneHitResultBuffer = this._threeRaycaster.GetIntersections();
|
|
97
|
-
if (this._sceneHitResultBuffer.length > 0) {
|
|
98
|
-
// scene hit found
|
|
99
|
-
this.onSceneHitFound(this._sceneHitResultBuffer[0]);
|
|
100
|
-
// early return to prevent ar raycaster from overriding scene hit
|
|
101
|
-
} else {
|
|
102
|
-
// scene hit nothing
|
|
103
|
-
this.onSceneHitLost();
|
|
104
|
-
}
|
|
105
|
-
return this._sceneHitResultBuffer;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
private onARHitFound(hit: DIVEHitResult): void {
|
|
109
|
-
this._hasHit = true;
|
|
110
|
-
this.dispatch('AR_HIT_FOUND', { hit });
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
private onARHitLost(): void {
|
|
114
|
-
if (!this._hasHit) return;
|
|
115
|
-
|
|
116
|
-
this._hasHit = false;
|
|
117
|
-
this.dispatch('AR_HIT_LOST');
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
private onSceneHitFound(hit: DIVEHitResult): void {
|
|
121
|
-
this._hasHit = true;
|
|
122
|
-
this.dispatch('SCENE_HIT_FOUND', { hit });
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
private onSceneHitLost(): void {
|
|
126
|
-
if (!this._hasHit) return;
|
|
127
|
-
|
|
128
|
-
this._hasHit = false;
|
|
129
|
-
this.dispatch('SCENE_HIT_LOST');
|
|
130
|
-
}
|
|
131
|
-
}
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
import { Matrix4, Vector3 } from 'three';
|
|
2
|
-
import { type DIVERenderer } from '../../../../renderer/Renderer';
|
|
3
|
-
import { type DIVEHitResult } from '../WebXRRaycaster';
|
|
4
|
-
|
|
5
|
-
export class DIVEWebXRRaycasterAR {
|
|
6
|
-
private _session: XRSession;
|
|
7
|
-
private _renderer: DIVERenderer;
|
|
8
|
-
|
|
9
|
-
private _transientHitTestSource: XRTransientInputHitTestSource | undefined;
|
|
10
|
-
private _referenceSpaceBuffer: XRReferenceSpace | null = null;
|
|
11
|
-
|
|
12
|
-
private _requesting: boolean = false;
|
|
13
|
-
private _initialized: boolean = false;
|
|
14
|
-
|
|
15
|
-
private _hitMatrixBuffer: Matrix4;
|
|
16
|
-
|
|
17
|
-
constructor(session: XRSession, renderer: DIVERenderer) {
|
|
18
|
-
this._session = session;
|
|
19
|
-
this._renderer = renderer;
|
|
20
|
-
|
|
21
|
-
this._hitMatrixBuffer = new Matrix4();
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
public Dispose(): void {
|
|
25
|
-
this._transientHitTestSource?.cancel();
|
|
26
|
-
this._transientHitTestSource = undefined;
|
|
27
|
-
|
|
28
|
-
this._initialized = false;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
public async Init(): Promise<this> {
|
|
32
|
-
if (!this._session) {
|
|
33
|
-
console.error(
|
|
34
|
-
'DIVEWebXRRaycaster: No session set in Init()! Aborting initialization...',
|
|
35
|
-
);
|
|
36
|
-
return Promise.reject();
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
if (this._requesting) {
|
|
40
|
-
console.error(
|
|
41
|
-
'DIVEWebXRRaycaster: Currently initializing! Aborting initialization...',
|
|
42
|
-
);
|
|
43
|
-
return Promise.reject();
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
if (this._initialized) {
|
|
47
|
-
console.error(
|
|
48
|
-
'DIVEWebXRRaycaster: Already initialized! Aborting initialization...',
|
|
49
|
-
);
|
|
50
|
-
return Promise.reject();
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
this._requesting = true;
|
|
54
|
-
this._transientHitTestSource = await this._session
|
|
55
|
-
.requestHitTestSourceForTransientInput!({
|
|
56
|
-
profile: 'generic-touchscreen',
|
|
57
|
-
});
|
|
58
|
-
this._referenceSpaceBuffer = this._renderer.xr.getReferenceSpace();
|
|
59
|
-
this._requesting = false;
|
|
60
|
-
|
|
61
|
-
if (!this._transientHitTestSource) {
|
|
62
|
-
return Promise.reject();
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
this._initialized = true;
|
|
66
|
-
|
|
67
|
-
console.log('DIVEWebXRRaycasterAR: Initialized');
|
|
68
|
-
|
|
69
|
-
return Promise.resolve(this);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
public GetIntersections(frame: XRFrame): DIVEHitResult[] {
|
|
73
|
-
if (!this._transientHitTestSource) return [];
|
|
74
|
-
|
|
75
|
-
const touches = frame.getHitTestResultsForTransientInput(
|
|
76
|
-
this._transientHitTestSource,
|
|
77
|
-
);
|
|
78
|
-
if (touches.length === 0) return [];
|
|
79
|
-
|
|
80
|
-
const hits = touches.map((touch: XRTransientInputHitTestResult) => {
|
|
81
|
-
if (!this._referenceSpaceBuffer) return undefined;
|
|
82
|
-
if (!touch.results[0]) return undefined;
|
|
83
|
-
if (!touch.results[0].getPose) return undefined;
|
|
84
|
-
|
|
85
|
-
const pose = touch.results[0].getPose(this._referenceSpaceBuffer);
|
|
86
|
-
if (!pose) return undefined;
|
|
87
|
-
|
|
88
|
-
this._hitMatrixBuffer.fromArray(pose.transform.matrix);
|
|
89
|
-
const position = new Vector3().setFromMatrixPosition(
|
|
90
|
-
this._hitMatrixBuffer,
|
|
91
|
-
);
|
|
92
|
-
|
|
93
|
-
return {
|
|
94
|
-
point: position,
|
|
95
|
-
matrix: this._hitMatrixBuffer,
|
|
96
|
-
object: undefined,
|
|
97
|
-
};
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
return hits.filter((hit) => hit !== undefined) as DIVEHitResult[];
|
|
101
|
-
}
|
|
102
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type Intersection,
|
|
3
|
-
type Mesh,
|
|
4
|
-
Raycaster,
|
|
5
|
-
type XRTargetRaySpace,
|
|
6
|
-
} from 'three';
|
|
7
|
-
import { type DIVERenderer } from '../../../../renderer/Renderer';
|
|
8
|
-
import { type DIVEScene } from '../../../../scene/Scene';
|
|
9
|
-
import { type DIVEHitResult } from '../WebXRRaycaster';
|
|
10
|
-
|
|
11
|
-
export class DIVEWebXRRaycasterTHREE {
|
|
12
|
-
private _renderer: DIVERenderer;
|
|
13
|
-
private _scene: DIVEScene;
|
|
14
|
-
|
|
15
|
-
private _controller: XRTargetRaySpace;
|
|
16
|
-
|
|
17
|
-
// internal raycaster
|
|
18
|
-
private _raycaster: Raycaster = new Raycaster();
|
|
19
|
-
|
|
20
|
-
constructor(renderer: DIVERenderer, scene: DIVEScene) {
|
|
21
|
-
this._renderer = renderer;
|
|
22
|
-
this._scene = scene;
|
|
23
|
-
|
|
24
|
-
this._controller = this._renderer.xr.getController(0);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
public async Init(): Promise<this> {
|
|
28
|
-
console.log('DIVEWebXRRaycasterTHREE: Initialized');
|
|
29
|
-
return Promise.resolve(this);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
public GetIntersections(): DIVEHitResult[] {
|
|
33
|
-
this._controller.updateMatrixWorld();
|
|
34
|
-
this._raycaster.setFromXRController(this._controller);
|
|
35
|
-
const intersections = this._raycaster.intersectObjects(
|
|
36
|
-
this._scene.XRRoot.XRModelRoot.children,
|
|
37
|
-
);
|
|
38
|
-
|
|
39
|
-
if (intersections.length === 0) return [];
|
|
40
|
-
|
|
41
|
-
return intersections.map((intersection: Intersection) => {
|
|
42
|
-
return {
|
|
43
|
-
point: intersection.point,
|
|
44
|
-
matrix: intersection.object.matrixWorld,
|
|
45
|
-
object: intersection.object as Mesh,
|
|
46
|
-
};
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
}
|