@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
package/src/dive.ts
DELETED
|
@@ -1,363 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
DIVERenderer,
|
|
3
|
-
DIVERendererDefaultSettings,
|
|
4
|
-
DIVERendererSettings,
|
|
5
|
-
} from './renderer/Renderer.ts';
|
|
6
|
-
import { DIVEScene } from './scene/Scene.ts';
|
|
7
|
-
import DIVEPerspectiveCamera, {
|
|
8
|
-
DIVEPerspectiveCameraDefaultSettings,
|
|
9
|
-
DIVEPerspectiveCameraSettings,
|
|
10
|
-
} from './camera/PerspectiveCamera.ts';
|
|
11
|
-
import DIVEOrbitControls, {
|
|
12
|
-
DIVEOrbitControlsDefaultSettings,
|
|
13
|
-
DIVEOrbitControlsSettings,
|
|
14
|
-
} from './controls/OrbitControls.ts';
|
|
15
|
-
import DIVEToolbox from './toolbox/Toolbox.ts';
|
|
16
|
-
import { DIVECommunication } from './com/Communication.ts';
|
|
17
|
-
import { DIVEAnimationSystem } from './animation/AnimationSystem.ts';
|
|
18
|
-
import DIVEAxisCamera from './axiscamera/AxisCamera.ts';
|
|
19
|
-
import { getObjectDelta } from './helper/getObjectDelta/getObjectDelta.ts';
|
|
20
|
-
import { MathUtils } from 'three';
|
|
21
|
-
import { SystemInfo } from './info/Info.ts';
|
|
22
|
-
import pkgjson from '../package.json';
|
|
23
|
-
|
|
24
|
-
export type DIVESettings = {
|
|
25
|
-
autoResize: boolean;
|
|
26
|
-
autoStart: boolean;
|
|
27
|
-
displayAxes: boolean;
|
|
28
|
-
renderer: Partial<DIVERendererSettings>;
|
|
29
|
-
perspectiveCamera: Partial<DIVEPerspectiveCameraSettings>;
|
|
30
|
-
orbitControls: Partial<DIVEOrbitControlsSettings>;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
export const DIVEDefaultSettings: DIVESettings = {
|
|
34
|
-
autoResize: true,
|
|
35
|
-
autoStart: true,
|
|
36
|
-
displayAxes: false,
|
|
37
|
-
renderer: DIVERendererDefaultSettings,
|
|
38
|
-
perspectiveCamera: DIVEPerspectiveCameraDefaultSettings,
|
|
39
|
-
orbitControls: DIVEOrbitControlsDefaultSettings,
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* #### DIVE
|
|
44
|
-
* is the main class of the DIVE framework.
|
|
45
|
-
*
|
|
46
|
-
* An instance of this class delivers a complete 3D environment with a perspective camera, orbit controls, a toolbox, and a communication system.
|
|
47
|
-
* ```ts
|
|
48
|
-
* import { DIVE } from "@shopware-ag/dive";
|
|
49
|
-
*
|
|
50
|
-
* const myWrapper = document.getElementById('myWrapper');
|
|
51
|
-
*
|
|
52
|
-
* const dive = new DIVE();
|
|
53
|
-
*
|
|
54
|
-
* myWrapper.appendChild(dive.Canvas);
|
|
55
|
-
*
|
|
56
|
-
* dive.Communication.Subscribe('GET_ALL_SCENE_DATA', () => {
|
|
57
|
-
* // do something
|
|
58
|
-
* }));
|
|
59
|
-
*
|
|
60
|
-
* dive.Communication.PerformAction('GET_ALL_SCENE_DATA', {});
|
|
61
|
-
* ```
|
|
62
|
-
* @module
|
|
63
|
-
*/
|
|
64
|
-
|
|
65
|
-
export default class DIVE {
|
|
66
|
-
// static members
|
|
67
|
-
public static QuickView(
|
|
68
|
-
uri: string,
|
|
69
|
-
settings?: Partial<DIVESettings>,
|
|
70
|
-
): DIVE {
|
|
71
|
-
const dive = new DIVE(settings);
|
|
72
|
-
|
|
73
|
-
dive.Communication.PerformAction('SET_CAMERA_TRANSFORM', {
|
|
74
|
-
position: { x: 0, y: 2, z: 2 },
|
|
75
|
-
target: { x: 0, y: 0.5, z: 0 },
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
// generate scene light id
|
|
79
|
-
const lightid = MathUtils.generateUUID();
|
|
80
|
-
|
|
81
|
-
// add scene light
|
|
82
|
-
dive.Communication.PerformAction('ADD_OBJECT', {
|
|
83
|
-
entityType: 'light',
|
|
84
|
-
type: 'scene',
|
|
85
|
-
name: 'light',
|
|
86
|
-
id: lightid,
|
|
87
|
-
enabled: true,
|
|
88
|
-
visible: true,
|
|
89
|
-
intensity: 1,
|
|
90
|
-
color: 0xffffff,
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
// generate model id
|
|
94
|
-
const modelid = MathUtils.generateUUID();
|
|
95
|
-
|
|
96
|
-
// add loaded listener
|
|
97
|
-
dive.Communication.Subscribe('MODEL_LOADED', (data) => {
|
|
98
|
-
if (data.id !== modelid) return;
|
|
99
|
-
|
|
100
|
-
const transform = dive.Communication.PerformAction(
|
|
101
|
-
'COMPUTE_ENCOMPASSING_VIEW',
|
|
102
|
-
{},
|
|
103
|
-
);
|
|
104
|
-
|
|
105
|
-
dive.Communication.PerformAction('SET_CAMERA_TRANSFORM', {
|
|
106
|
-
position: transform.position,
|
|
107
|
-
target: transform.target,
|
|
108
|
-
});
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
// instantiate model
|
|
112
|
-
dive.Communication.PerformAction('ADD_OBJECT', {
|
|
113
|
-
entityType: 'model',
|
|
114
|
-
name: 'object',
|
|
115
|
-
id: modelid,
|
|
116
|
-
position: { x: 0, y: 0, z: 0 },
|
|
117
|
-
rotation: { x: 0, y: 0, z: 0 },
|
|
118
|
-
scale: { x: 1, y: 1, z: 1 },
|
|
119
|
-
uri: uri,
|
|
120
|
-
visible: true,
|
|
121
|
-
loaded: false,
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
// set scene properties
|
|
125
|
-
dive.Communication.PerformAction('UPDATE_SCENE', {
|
|
126
|
-
backgroundColor: 0xffffff,
|
|
127
|
-
gridEnabled: false,
|
|
128
|
-
floorColor: 0xffffff,
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
return dive;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
// descriptive members
|
|
135
|
-
private _settings: DIVESettings;
|
|
136
|
-
private _resizeObserverId: string;
|
|
137
|
-
private _width: number;
|
|
138
|
-
private _height: number;
|
|
139
|
-
|
|
140
|
-
// functional components
|
|
141
|
-
private renderer: DIVERenderer;
|
|
142
|
-
private scene: DIVEScene;
|
|
143
|
-
private perspectiveCamera: DIVEPerspectiveCamera;
|
|
144
|
-
private orbitControls: DIVEOrbitControls;
|
|
145
|
-
private toolbox: DIVEToolbox;
|
|
146
|
-
private communication: DIVECommunication;
|
|
147
|
-
|
|
148
|
-
// additional components
|
|
149
|
-
private animationSystem: DIVEAnimationSystem;
|
|
150
|
-
private axisCamera: DIVEAxisCamera | null;
|
|
151
|
-
|
|
152
|
-
// getters
|
|
153
|
-
public get Communication(): DIVECommunication {
|
|
154
|
-
return this.communication;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
public get Canvas(): HTMLCanvasElement {
|
|
158
|
-
return this.renderer.domElement;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
public get Info(): SystemInfo {
|
|
162
|
-
return SystemInfo;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
// setters
|
|
166
|
-
public set Settings(settings: Partial<DIVESettings>) {
|
|
167
|
-
const settingsDelta = getObjectDelta(this._settings, settings);
|
|
168
|
-
|
|
169
|
-
// apply renderer settings (we have to rebuild the renderer to apply the settings)
|
|
170
|
-
if (settingsDelta.renderer)
|
|
171
|
-
this.renderer = new DIVERenderer(this._settings.renderer);
|
|
172
|
-
|
|
173
|
-
// apply perspective camera settings
|
|
174
|
-
if (settingsDelta.perspectiveCamera) {
|
|
175
|
-
if (settingsDelta.perspectiveCamera.fov !== undefined)
|
|
176
|
-
this.perspectiveCamera.fov =
|
|
177
|
-
settingsDelta.perspectiveCamera.fov;
|
|
178
|
-
if (settingsDelta.perspectiveCamera.near !== undefined)
|
|
179
|
-
this.perspectiveCamera.near =
|
|
180
|
-
settingsDelta.perspectiveCamera.near;
|
|
181
|
-
if (settingsDelta.perspectiveCamera.far !== undefined)
|
|
182
|
-
this.perspectiveCamera.far =
|
|
183
|
-
settingsDelta.perspectiveCamera.far;
|
|
184
|
-
this.perspectiveCamera.OnResize(
|
|
185
|
-
this.renderer.domElement.width,
|
|
186
|
-
this.renderer.domElement.height,
|
|
187
|
-
);
|
|
188
|
-
}
|
|
189
|
-
// apply orbit controls settings
|
|
190
|
-
if (settingsDelta.orbitControls) {
|
|
191
|
-
if (settingsDelta.orbitControls.enableDamping !== undefined)
|
|
192
|
-
this.orbitControls.enableDamping =
|
|
193
|
-
settingsDelta.orbitControls.enableDamping;
|
|
194
|
-
if (settingsDelta.orbitControls.dampingFactor !== undefined)
|
|
195
|
-
this.orbitControls.dampingFactor =
|
|
196
|
-
settingsDelta.orbitControls.dampingFactor;
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
if (settingsDelta.autoResize !== this._settings.autoResize) {
|
|
200
|
-
if (settingsDelta.autoResize) {
|
|
201
|
-
this.addResizeObserver();
|
|
202
|
-
} else {
|
|
203
|
-
this.removeResizeObserver();
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
if (settingsDelta.displayAxes) {
|
|
208
|
-
this.axisCamera = new DIVEAxisCamera(
|
|
209
|
-
this.renderer,
|
|
210
|
-
this.scene,
|
|
211
|
-
this.orbitControls,
|
|
212
|
-
);
|
|
213
|
-
} else {
|
|
214
|
-
this.axisCamera?.Dispose();
|
|
215
|
-
this.axisCamera = null;
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
Object.assign(this._settings, settings);
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
constructor(settings?: Partial<DIVESettings>) {
|
|
222
|
-
this._settings = {
|
|
223
|
-
...DIVEDefaultSettings,
|
|
224
|
-
...(settings !== undefined ? settings : {}),
|
|
225
|
-
};
|
|
226
|
-
|
|
227
|
-
this._resizeObserverId = '';
|
|
228
|
-
this._width = 0;
|
|
229
|
-
this._height = 0;
|
|
230
|
-
|
|
231
|
-
// initialize functional components
|
|
232
|
-
this.renderer = new DIVERenderer(this._settings.renderer);
|
|
233
|
-
this.scene = new DIVEScene();
|
|
234
|
-
this.perspectiveCamera = new DIVEPerspectiveCamera(
|
|
235
|
-
this._settings.perspectiveCamera,
|
|
236
|
-
);
|
|
237
|
-
|
|
238
|
-
// initialize animation system
|
|
239
|
-
this.animationSystem = new DIVEAnimationSystem(this.renderer);
|
|
240
|
-
|
|
241
|
-
this.orbitControls = new DIVEOrbitControls(
|
|
242
|
-
this.perspectiveCamera,
|
|
243
|
-
this.renderer,
|
|
244
|
-
this.animationSystem,
|
|
245
|
-
this._settings.orbitControls,
|
|
246
|
-
);
|
|
247
|
-
this.toolbox = new DIVEToolbox(this.scene, this.orbitControls);
|
|
248
|
-
this.communication = new DIVECommunication(
|
|
249
|
-
this.renderer,
|
|
250
|
-
this.scene,
|
|
251
|
-
this.orbitControls,
|
|
252
|
-
this.toolbox,
|
|
253
|
-
);
|
|
254
|
-
|
|
255
|
-
// initialize axis camera
|
|
256
|
-
if (this._settings.displayAxes) {
|
|
257
|
-
this.axisCamera = new DIVEAxisCamera(
|
|
258
|
-
this.renderer,
|
|
259
|
-
this.scene,
|
|
260
|
-
this.orbitControls,
|
|
261
|
-
);
|
|
262
|
-
} else {
|
|
263
|
-
this.axisCamera = null;
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
// add resize observer if autoResize is enabled
|
|
267
|
-
if (this._settings.autoResize) {
|
|
268
|
-
this.addResizeObserver();
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
272
|
-
(window as any).DIVE = {
|
|
273
|
-
PrintScene: () => {
|
|
274
|
-
console.log(this.scene);
|
|
275
|
-
},
|
|
276
|
-
};
|
|
277
|
-
|
|
278
|
-
console.log(`DIVE ${pkgjson.version} initialized successfully!`);
|
|
279
|
-
console.log(`
|
|
280
|
-
@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@
|
|
281
|
-
@@@@+-:::::::---------------------==------------------------------=#@@@@
|
|
282
|
-
@@%=::::.......::---------------------------------------------------------+@@
|
|
283
|
-
@@+:::...........::-----------------------------------------------------------#@@
|
|
284
|
-
@@=:::.........::::::-------------------------------------------------------------%@
|
|
285
|
-
@%:::.......:::::::-----------------------------------------------------------------#@
|
|
286
|
-
@*:::.....:::::-----------------------------------------------------------------------*@
|
|
287
|
-
@%::::::.::::---------------------------------------------------------------------------@@
|
|
288
|
-
@@-:::::::::-----------------------------------------------------------------------------=@
|
|
289
|
-
@%::::::::--------------------------------------------------------------------------------%@
|
|
290
|
-
@+::::::::--------------------------------=@@@@@%-----------------------------------------%@
|
|
291
|
-
@=:::::::--------------------------------*@@ @@+---------------------------------------#@
|
|
292
|
-
@+:::::::-------------------------------*@ @*--------------------------------------%@
|
|
293
|
-
@#::::::::-----------------------------=@@ @@=-------------------------------------%@
|
|
294
|
-
@@-::::::::----------------------------@@ @@------------------------------------=@
|
|
295
|
-
@%:::::::::--------------------------*@ @*-----------------------------------@@
|
|
296
|
-
@*:::::::::-------------------------@@ @@----------------------------------%@
|
|
297
|
-
@#::::::::::----------------------%@ @%--------------------------------%@
|
|
298
|
-
@#:::::::::::-------------------=@@ @@=------------------------------%@
|
|
299
|
-
@@-::::::::::::----------------%@ @%----------------------------=@@
|
|
300
|
-
@@#::::::::::::::------------*@ @*--------------------------#@@
|
|
301
|
-
@@+::::::::::::::::--------@@ @@------------------------+@@
|
|
302
|
-
@@*:::::::::::::::::----@@ @@---------------------+@@
|
|
303
|
-
@@@-:::::::::::::::--#@ @#-----------------=%@@
|
|
304
|
-
@@%-::::::::::::-%@ @%-------------=%@@
|
|
305
|
-
@@@@+:::::::#@@ @@*-------*@@@@
|
|
306
|
-
@@@@@@@ @@@@@@
|
|
307
|
-
|
|
308
|
-
`);
|
|
309
|
-
|
|
310
|
-
if (this._settings.autoStart) {
|
|
311
|
-
// when everything is done, start the renderer
|
|
312
|
-
this.renderer.StartRenderer(this.scene, this.perspectiveCamera);
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
public Dispose(): void {
|
|
317
|
-
this.removeResizeObserver();
|
|
318
|
-
this.renderer.Dispose();
|
|
319
|
-
this.orbitControls.Dispose();
|
|
320
|
-
this.axisCamera?.Dispose();
|
|
321
|
-
this.animationSystem.Dispose();
|
|
322
|
-
this.toolbox.Dispose();
|
|
323
|
-
this.communication.DestroyInstance();
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
// methods
|
|
327
|
-
public OnResize(width: number, height: number): void {
|
|
328
|
-
// resize renderer
|
|
329
|
-
this.renderer.OnResize(width, height);
|
|
330
|
-
|
|
331
|
-
// resize camera
|
|
332
|
-
this.perspectiveCamera.OnResize(width, height);
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
private addResizeObserver(): void {
|
|
336
|
-
this._resizeObserverId = this.renderer.AddPreRenderCallback(() => {
|
|
337
|
-
// check if the canvas is mounted
|
|
338
|
-
const canvasWrapper = this.renderer.domElement.parentElement;
|
|
339
|
-
if (!canvasWrapper) return;
|
|
340
|
-
|
|
341
|
-
const { clientWidth, clientHeight } = canvasWrapper;
|
|
342
|
-
if (clientWidth === this._width && clientHeight === this._height)
|
|
343
|
-
return;
|
|
344
|
-
|
|
345
|
-
this.OnResize(clientWidth, clientHeight);
|
|
346
|
-
|
|
347
|
-
this._width = clientWidth;
|
|
348
|
-
this._height = clientHeight;
|
|
349
|
-
});
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
private removeResizeObserver(): void {
|
|
353
|
-
this.renderer.RemovePreRenderCallback(this._resizeObserverId);
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
export { DIVE, DIVECommunication };
|
|
358
|
-
|
|
359
|
-
export * from './math/index.ts';
|
|
360
|
-
|
|
361
|
-
export type * from './com/actions/index.ts';
|
|
362
|
-
export type * from './com/types';
|
|
363
|
-
export type * from './types';
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
export class DIVEEventExecutor<T> {
|
|
2
|
-
private _listeners: Map<keyof T, ((payload: T[keyof T]) => void)[]> =
|
|
3
|
-
new Map();
|
|
4
|
-
|
|
5
|
-
public Subscribe<S extends keyof T>(
|
|
6
|
-
type: S,
|
|
7
|
-
listener: (payload: T[S]) => void,
|
|
8
|
-
): () => boolean {
|
|
9
|
-
if (!this._listeners.get(type)) this._listeners.set(type, []);
|
|
10
|
-
|
|
11
|
-
this._listeners
|
|
12
|
-
.get(type)!
|
|
13
|
-
.push(listener as (payload: T[keyof T]) => void);
|
|
14
|
-
|
|
15
|
-
return () => {
|
|
16
|
-
const listenerArray = this._listeners.get(type);
|
|
17
|
-
if (!listenerArray) return false;
|
|
18
|
-
|
|
19
|
-
const existingIndex = listenerArray.findIndex(
|
|
20
|
-
(entry) => entry === listener,
|
|
21
|
-
);
|
|
22
|
-
if (existingIndex === -1) return false;
|
|
23
|
-
|
|
24
|
-
listenerArray.splice(existingIndex, 1);
|
|
25
|
-
return true;
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
protected dispatch<S extends keyof T>(type: S, payload?: T[S]): void {
|
|
30
|
-
const listenerArray = this._listeners.get(type);
|
|
31
|
-
if (!listenerArray) return;
|
|
32
|
-
|
|
33
|
-
listenerArray.forEach((listener) => listener(payload as T[S]));
|
|
34
|
-
}
|
|
35
|
-
}
|
package/src/exporter/Exporter.ts
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { Object3D } from 'three';
|
|
2
|
-
import { GLTFExporter } from 'three/examples/jsm/exporters/GLTFExporter';
|
|
3
|
-
import { USDZExporter } from 'three/examples/jsm/exporters/USDZExporter';
|
|
4
|
-
import {
|
|
5
|
-
type FileType,
|
|
6
|
-
type GLTFExporterOptions,
|
|
7
|
-
type USDZExporterOptions,
|
|
8
|
-
type ExportOptions,
|
|
9
|
-
} from '../types';
|
|
10
|
-
|
|
11
|
-
export class Exporter {
|
|
12
|
-
private _gltfExporter: GLTFExporter;
|
|
13
|
-
private _usdzExporter: USDZExporter;
|
|
14
|
-
|
|
15
|
-
constructor() {
|
|
16
|
-
this._gltfExporter = new GLTFExporter();
|
|
17
|
-
this._usdzExporter = new USDZExporter();
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
public async export<T extends FileType>(
|
|
21
|
-
object: Object3D,
|
|
22
|
-
type: T,
|
|
23
|
-
options?: ExportOptions<T>,
|
|
24
|
-
): Promise<ArrayBuffer> {
|
|
25
|
-
switch (type) {
|
|
26
|
-
case 'glb': {
|
|
27
|
-
return this._exportGlb(object, options);
|
|
28
|
-
}
|
|
29
|
-
case 'gltf': {
|
|
30
|
-
return this._exportGltf(object, options);
|
|
31
|
-
}
|
|
32
|
-
case 'usdz': {
|
|
33
|
-
return this._exportUsdz(object, options);
|
|
34
|
-
}
|
|
35
|
-
default:
|
|
36
|
-
throw new Error(`Unsupported file type: ${type}`);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
private async _exportGlb(
|
|
41
|
-
object: Object3D,
|
|
42
|
-
options?: GLTFExporterOptions,
|
|
43
|
-
): Promise<ArrayBuffer> {
|
|
44
|
-
const result = await this._gltfExporter.parseAsync(object, {
|
|
45
|
-
...options,
|
|
46
|
-
binary: true,
|
|
47
|
-
});
|
|
48
|
-
if (result instanceof ArrayBuffer) {
|
|
49
|
-
return result;
|
|
50
|
-
}
|
|
51
|
-
throw new Error('Failed to export GLB: expected ArrayBuffer');
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
private async _exportGltf(
|
|
55
|
-
object: Object3D,
|
|
56
|
-
options?: GLTFExporterOptions,
|
|
57
|
-
): Promise<ArrayBuffer> {
|
|
58
|
-
const json = await this._gltfExporter.parseAsync(object, {
|
|
59
|
-
...options,
|
|
60
|
-
binary: false,
|
|
61
|
-
});
|
|
62
|
-
const text = JSON.stringify(json);
|
|
63
|
-
const encoder = new TextEncoder();
|
|
64
|
-
const bytes = encoder.encode(text);
|
|
65
|
-
return bytes.buffer as ArrayBuffer;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
private async _exportUsdz(
|
|
69
|
-
object: Object3D,
|
|
70
|
-
options?: USDZExporterOptions,
|
|
71
|
-
): Promise<ArrayBuffer> {
|
|
72
|
-
const result = await this._usdzExporter.parse(object, options);
|
|
73
|
-
return result.buffer as ArrayBuffer;
|
|
74
|
-
}
|
|
75
|
-
}
|
package/src/gizmo/Gizmo.ts
DELETED
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
import { Euler, Object3D, Vector3 } from 'three';
|
|
2
|
-
import { DIVERotateGizmo } from './rotate/RotateGizmo';
|
|
3
|
-
import { DIVETranslateGizmo } from './translate/TranslateGizmo';
|
|
4
|
-
import DIVEOrbitControls from '../controls/OrbitControls';
|
|
5
|
-
import { DIVEScaleGizmo } from './scale/ScaleGizmo';
|
|
6
|
-
import { DIVEGizmoPlane as DIVEGizmoPlane } from './plane/GizmoPlane';
|
|
7
|
-
import { DIVESelectable } from '../interface/Selectable';
|
|
8
|
-
|
|
9
|
-
export type DIVEGizmoMode = 'translate' | 'rotate' | 'scale';
|
|
10
|
-
|
|
11
|
-
export type DIVEGizmoAxis = 'x' | 'y' | 'z';
|
|
12
|
-
|
|
13
|
-
export class DIVEGizmo extends Object3D {
|
|
14
|
-
private _mode: DIVEGizmoMode;
|
|
15
|
-
public get mode(): DIVEGizmoMode {
|
|
16
|
-
return this._mode;
|
|
17
|
-
}
|
|
18
|
-
public set mode(value: DIVEGizmoMode) {
|
|
19
|
-
this._mode = value;
|
|
20
|
-
this.assemble();
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
public set debug(value: boolean) {
|
|
24
|
-
this._translateGizmo.debug = value;
|
|
25
|
-
this._rotateGizmo.debug = value;
|
|
26
|
-
this._scaleGizmo.debug = value;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
private _gizmoNode: Object3D;
|
|
30
|
-
public get gizmoNode(): Object3D {
|
|
31
|
-
return this._gizmoNode;
|
|
32
|
-
}
|
|
33
|
-
private _translateGizmo: DIVETranslateGizmo;
|
|
34
|
-
private _rotateGizmo: DIVERotateGizmo;
|
|
35
|
-
private _scaleGizmo: DIVEScaleGizmo;
|
|
36
|
-
|
|
37
|
-
private _gizmoPlane: DIVEGizmoPlane;
|
|
38
|
-
public get gizmoPlane(): DIVEGizmoPlane {
|
|
39
|
-
return this._gizmoPlane;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// attachment stuff
|
|
43
|
-
private _object: (Object3D & DIVESelectable) | null;
|
|
44
|
-
public get object(): (Object3D & DIVESelectable) | null {
|
|
45
|
-
return this._object;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
constructor(controller: DIVEOrbitControls) {
|
|
49
|
-
super();
|
|
50
|
-
this.name = 'DIVEGizmo';
|
|
51
|
-
|
|
52
|
-
controller.addEventListener('change', () => {
|
|
53
|
-
const size = controller.getDistance() / 2.5;
|
|
54
|
-
this.scale.set(size, size, size);
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
this._mode = 'translate';
|
|
58
|
-
|
|
59
|
-
this._gizmoNode = new Object3D();
|
|
60
|
-
this.add(this._gizmoNode);
|
|
61
|
-
|
|
62
|
-
this._translateGizmo = new DIVETranslateGizmo(controller);
|
|
63
|
-
this._rotateGizmo = new DIVERotateGizmo(controller);
|
|
64
|
-
this._scaleGizmo = new DIVEScaleGizmo(controller);
|
|
65
|
-
|
|
66
|
-
this._gizmoPlane = new DIVEGizmoPlane();
|
|
67
|
-
this._gizmoPlane.visible = false;
|
|
68
|
-
|
|
69
|
-
this._object = null;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
public attach(object: Object3D & DIVESelectable): this {
|
|
73
|
-
this._object = object;
|
|
74
|
-
this.assemble();
|
|
75
|
-
return this;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
public detach(): this {
|
|
79
|
-
this._object = null;
|
|
80
|
-
this.assemble();
|
|
81
|
-
return this;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
public onHover(
|
|
85
|
-
mode: DIVEGizmoMode,
|
|
86
|
-
axis: DIVEGizmoAxis,
|
|
87
|
-
value: boolean,
|
|
88
|
-
): void {
|
|
89
|
-
if (!value) return;
|
|
90
|
-
this._gizmoPlane.assemble(mode, axis);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
public onChange(
|
|
94
|
-
position?: Vector3,
|
|
95
|
-
rotation?: Euler,
|
|
96
|
-
scale?: Vector3,
|
|
97
|
-
): void {
|
|
98
|
-
if (this.object === null) return;
|
|
99
|
-
|
|
100
|
-
if (position) {
|
|
101
|
-
this.position.copy(position);
|
|
102
|
-
this.object.position.copy(position);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
if (rotation) {
|
|
106
|
-
this.object.rotation.copy(rotation);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
if (scale) {
|
|
110
|
-
this.object.scale.copy(scale);
|
|
111
|
-
this._scaleGizmo.update(scale);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
private assemble(): void {
|
|
116
|
-
// clear all children
|
|
117
|
-
this._gizmoNode.clear();
|
|
118
|
-
this._gizmoPlane.clear();
|
|
119
|
-
|
|
120
|
-
// reset all gizmos
|
|
121
|
-
this._translateGizmo.reset();
|
|
122
|
-
this._rotateGizmo.reset();
|
|
123
|
-
this._scaleGizmo.reset();
|
|
124
|
-
|
|
125
|
-
// check for object
|
|
126
|
-
if (this.object === null) return;
|
|
127
|
-
|
|
128
|
-
// add gizmos
|
|
129
|
-
if (this._mode === 'translate') {
|
|
130
|
-
this._gizmoNode.add(this._translateGizmo);
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
if (this._mode === 'rotate') {
|
|
134
|
-
this._gizmoNode.add(this._rotateGizmo);
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
if (this._mode === 'scale') {
|
|
138
|
-
this._gizmoNode.add(this._scaleGizmo);
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
// add plane for raycasting properly while dragging
|
|
142
|
-
this.add(this._gizmoPlane);
|
|
143
|
-
}
|
|
144
|
-
}
|