@shopware-ag/dive 1.18.5 → 1.19.1-beta.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 +8 -0
- package/build/dive.cjs +220 -215
- package/build/dive.cjs.map +1 -1
- package/build/dive.js +233 -21102
- package/build/dive.js.map +1 -1
- package/build/dive.mjs +26111 -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/index.d.ts +2 -0
- package/build/src/com/actions/renderer/startrender.d.ts +5 -0
- 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 +16 -1
- package/src/ar/AR.ts +72 -69
- package/src/ar/__test__/AR.test.ts +194 -105
- package/src/ar/arquicklook/ARQuickLook.ts +32 -72
- package/src/ar/arquicklook/__test__/ARQuickLook.test.ts +89 -38
- package/src/ar/sceneviewer/SceneViewer.ts +96 -51
- package/src/ar/sceneviewer/__test__/SceneViewer.test.ts +144 -47
- package/src/ar/webxr/WebXR.ts +5 -4
- package/src/com/Communication.ts +10 -7
- package/src/com/__test__/Communication.test.ts +16 -3
- package/src/com/actions/index.ts +2 -0
- package/src/com/actions/renderer/startrender.ts +5 -0
- package/src/com/actions/scene/launchar.ts +2 -2
- package/src/converter/Converter.ts +117 -0
- package/src/dive.ts +10 -6
- package/src/exporter/Exporter.ts +75 -0
- package/src/helper/applyMixins/applyMixins.ts +59 -7
- package/src/info/Info.ts +99 -75
- package/src/info/__test__/Info.test.ts +162 -154
- package/src/interface/Movable.ts +5 -5
- package/src/interface/Selectable.ts +4 -4
- package/src/loader/Loader.ts +48 -0
- package/src/model/Model.ts +10 -5
- package/src/model/__test__/Model.test.ts +4 -11
- package/src/node/Node.ts +7 -5
- package/src/scene/root/Root.ts +4 -4
- package/src/scene/root/__test__/Root.test.ts +4 -4
- package/src/toolbox/Toolbox.ts +1 -3
- package/src/types/ExporterOptions.ts +14 -0
- package/src/types/FileTypes.ts +37 -0
- package/src/types/index.ts +26 -0
- package/src/types/info/index.ts +76 -0
- package/build/src/exporters/usdz/USDZExporter.d.ts +0 -15
- package/build/src/loadingmanager/LoadingManager.d.ts +0 -14
- package/src/exporters/usdz/USDZExporter.ts +0 -21
- package/src/exporters/usdz/__test__/USDZExporter.test.ts +0 -57
- package/src/loadingmanager/LoadingManager.ts +0 -50
- package/src/loadingmanager/__test__/LoadingManager.test.ts +0 -27
package/src/node/Node.ts
CHANGED
|
@@ -2,15 +2,17 @@ import { Box3, Object3D, Vector3, type Vector3Like } from 'three';
|
|
|
2
2
|
import { PRODUCT_LAYER_MASK } from '../constant/VisibilityLayerMask';
|
|
3
3
|
import { DIVECommunication } from '../com/Communication';
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
5
|
+
import { DIVEMovable } from '../interface/Movable';
|
|
6
|
+
import { DIVESelectable } from '../interface/Selectable';
|
|
7
7
|
import { type TransformControls } from 'three/examples/jsm/controls/TransformControls';
|
|
8
8
|
import { type DIVEGroup } from '../group/Group';
|
|
9
|
+
import { applyMixins } from '../helper/applyMixins/applyMixins';
|
|
9
10
|
|
|
10
|
-
export class DIVENode extends Object3D
|
|
11
|
+
export class DIVENode extends applyMixins(Object3D, [
|
|
12
|
+
DIVESelectable,
|
|
13
|
+
DIVEMovable,
|
|
14
|
+
]) {
|
|
11
15
|
readonly isDIVENode: true = true;
|
|
12
|
-
readonly isSelectable: true = true;
|
|
13
|
-
readonly isMovable: true = true;
|
|
14
16
|
|
|
15
17
|
public gizmo: TransformControls | null = null;
|
|
16
18
|
|
package/src/scene/root/Root.ts
CHANGED
|
@@ -3,7 +3,6 @@ import DIVEAmbientLight from '../../light/AmbientLight.ts';
|
|
|
3
3
|
import DIVEPointLight from '../../light/PointLight.ts';
|
|
4
4
|
import DIVESceneLight from '../../light/SceneLight.ts';
|
|
5
5
|
import { DIVEModel } from '../../model/Model.ts';
|
|
6
|
-
import { DIVELoadingManager } from '../../loadingmanager/LoadingManager.ts';
|
|
7
6
|
import { DIVECommunication } from '../../com/Communication.ts';
|
|
8
7
|
import { DIVEPrimitive } from '../../primitive/Primitive.ts';
|
|
9
8
|
|
|
@@ -18,6 +17,7 @@ import {
|
|
|
18
17
|
} from '../../com/types';
|
|
19
18
|
import { type DIVESceneObject } from '../../types';
|
|
20
19
|
import { DIVEGroup } from '../../group/Group.ts';
|
|
20
|
+
import { Loader } from '../../loader/Loader.ts';
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
23
|
* A basic scene node to hold grid, floor and all lower level roots.
|
|
@@ -28,13 +28,13 @@ import { DIVEGroup } from '../../group/Group.ts';
|
|
|
28
28
|
export class DIVERoot extends Object3D {
|
|
29
29
|
readonly isDIVERoot: true = true;
|
|
30
30
|
|
|
31
|
-
private
|
|
31
|
+
private loader: Loader;
|
|
32
32
|
|
|
33
33
|
constructor() {
|
|
34
34
|
super();
|
|
35
35
|
this.name = 'Root';
|
|
36
36
|
|
|
37
|
-
this.
|
|
37
|
+
this.loader = new Loader();
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
public ComputeSceneBB(): Box3 {
|
|
@@ -243,7 +243,7 @@ export class DIVERoot extends Object3D {
|
|
|
243
243
|
}
|
|
244
244
|
|
|
245
245
|
if (model.uri !== undefined) {
|
|
246
|
-
this.
|
|
246
|
+
this.loader.load(model.uri).then((gltf) => {
|
|
247
247
|
(sceneObject as DIVEModel).SetModel(gltf);
|
|
248
248
|
DIVECommunication.get(model.id!)?.PerformAction(
|
|
249
249
|
'MODEL_LOADED',
|
|
@@ -26,11 +26,11 @@ jest.mock('../../../com/Communication.ts', () => {
|
|
|
26
26
|
};
|
|
27
27
|
});
|
|
28
28
|
|
|
29
|
-
const
|
|
30
|
-
jest.mock('../../../
|
|
29
|
+
const mock_Load = jest.fn().mockResolvedValue({});
|
|
30
|
+
jest.mock('../../../loader/Loader.ts', () => {
|
|
31
31
|
return {
|
|
32
|
-
|
|
33
|
-
this.
|
|
32
|
+
Loader: jest.fn(function () {
|
|
33
|
+
this.load = mock_Load;
|
|
34
34
|
return this;
|
|
35
35
|
}),
|
|
36
36
|
};
|
package/src/toolbox/Toolbox.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type DIVEOrbitControls from '../controls/OrbitControls.ts';
|
|
2
2
|
import { type DIVEScene } from '../scene/Scene.ts';
|
|
3
3
|
import { type DIVEBaseTool } from './BaseTool.ts';
|
|
4
|
-
import {
|
|
4
|
+
import { DIVESelectTool } from './select/SelectTool.ts';
|
|
5
5
|
|
|
6
6
|
export type ToolType = 'select' | 'none';
|
|
7
7
|
|
|
@@ -22,8 +22,6 @@ export default class DIVEToolbox {
|
|
|
22
22
|
private _selectTool: DIVESelectTool | null;
|
|
23
23
|
public get selectTool(): DIVESelectTool {
|
|
24
24
|
if (!this._selectTool) {
|
|
25
|
-
const DIVESelectTool = require('./select/SelectTool.ts')
|
|
26
|
-
.DIVESelectTool as typeof import('./select/SelectTool.ts').DIVESelectTool;
|
|
27
25
|
this._selectTool = new DIVESelectTool(
|
|
28
26
|
this._scene,
|
|
29
27
|
this._controller,
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { GLTFExporterOptions as THREEGLTFExporterOptions } from 'three/examples/jsm/exporters/GLTFExporter';
|
|
2
|
+
import { USDZExporterOptions as THREEUSDZExporterOptions } from 'three/examples/jsm/exporters/USDZExporter';
|
|
3
|
+
import { type FileType, type FileTypeOptions } from './FileTypes';
|
|
4
|
+
|
|
5
|
+
export type USDZExporterOptions = THREEUSDZExporterOptions & {
|
|
6
|
+
ar?: {
|
|
7
|
+
anchoring: { type: 'plane' | 'image' | 'face' | 'none' }; // source: https://developer.apple.com/documentation/realitykit/preliminary-anchoring-type
|
|
8
|
+
planeAnchoring: { alignment: 'horizontal' | 'vertical' | 'any' }; // source: https://developer.apple.com/documentation/realitykit/preliminary-planeanchoring-alignment
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export type GLTFExporterOptions = THREEGLTFExporterOptions;
|
|
13
|
+
|
|
14
|
+
export type ExportOptions<T extends FileType> = FileTypeOptions<T>;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type GLTFExporterOptions,
|
|
3
|
+
type USDZExporterOptions,
|
|
4
|
+
} from './ExporterOptions';
|
|
5
|
+
|
|
6
|
+
export type FileTypeDefinition<T extends string, O> = {
|
|
7
|
+
key: T;
|
|
8
|
+
extension: string;
|
|
9
|
+
options: O;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export const FILE_TYPES = {
|
|
13
|
+
glb: {
|
|
14
|
+
key: 'glb' as const,
|
|
15
|
+
extension: '.glb',
|
|
16
|
+
options: {} as GLTFExporterOptions,
|
|
17
|
+
},
|
|
18
|
+
gltf: {
|
|
19
|
+
key: 'gltf' as const,
|
|
20
|
+
extension: '.gltf',
|
|
21
|
+
options: {} as GLTFExporterOptions,
|
|
22
|
+
},
|
|
23
|
+
usdz: {
|
|
24
|
+
key: 'usdz' as const,
|
|
25
|
+
extension: '.usdz',
|
|
26
|
+
options: {} as USDZExporterOptions,
|
|
27
|
+
},
|
|
28
|
+
} as const;
|
|
29
|
+
|
|
30
|
+
export type FileType = keyof typeof FILE_TYPES;
|
|
31
|
+
export type FileTypeKey = (typeof FILE_TYPES)[FileType]['key'];
|
|
32
|
+
export type FileTypeOptions<T extends FileType> =
|
|
33
|
+
(typeof FILE_TYPES)[T]['options'];
|
|
34
|
+
|
|
35
|
+
export const SUPPORTED_FILE_TYPES = Object.values(FILE_TYPES).map(
|
|
36
|
+
(type) => type.extension,
|
|
37
|
+
) as readonly string[];
|
package/src/types/index.ts
CHANGED
|
@@ -1,5 +1,31 @@
|
|
|
1
1
|
import { type DIVESceneObject } from './SceneObjects';
|
|
2
2
|
import { type DIVESceneFileType } from './SceneType';
|
|
3
3
|
import { type DIVESceneData } from './SceneData';
|
|
4
|
+
import {
|
|
5
|
+
type FileType,
|
|
6
|
+
type FileTypeKey,
|
|
7
|
+
type FileTypeOptions,
|
|
8
|
+
type FileTypeDefinition,
|
|
9
|
+
FILE_TYPES,
|
|
10
|
+
SUPPORTED_FILE_TYPES,
|
|
11
|
+
} from './FileTypes';
|
|
12
|
+
import {
|
|
13
|
+
type GLTFExporterOptions,
|
|
14
|
+
type USDZExporterOptions,
|
|
15
|
+
type ExportOptions,
|
|
16
|
+
} from './ExporterOptions';
|
|
4
17
|
|
|
5
18
|
export { type DIVESceneObject, type DIVESceneFileType, type DIVESceneData };
|
|
19
|
+
export {
|
|
20
|
+
type FileType,
|
|
21
|
+
type FileTypeKey,
|
|
22
|
+
type FileTypeOptions,
|
|
23
|
+
type FileTypeDefinition,
|
|
24
|
+
FILE_TYPES,
|
|
25
|
+
SUPPORTED_FILE_TYPES,
|
|
26
|
+
};
|
|
27
|
+
export {
|
|
28
|
+
type GLTFExporterOptions,
|
|
29
|
+
type USDZExporterOptions,
|
|
30
|
+
type ExportOptions,
|
|
31
|
+
};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Enum representing supported operating systems
|
|
3
|
+
*/
|
|
4
|
+
export enum ESystem {
|
|
5
|
+
/**
|
|
6
|
+
* iOS devices (iPhone, iPad)
|
|
7
|
+
*/
|
|
8
|
+
IOS = 'iOS',
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Android devices
|
|
12
|
+
*/
|
|
13
|
+
ANDROID = 'Android',
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Windows operating system
|
|
17
|
+
*/
|
|
18
|
+
WINDOWS = 'Windows',
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* macOS operating system
|
|
22
|
+
*/
|
|
23
|
+
MACOS = 'MacOS',
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Linux operating system
|
|
27
|
+
*/
|
|
28
|
+
LINUX = 'Linux',
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Unknown or unsupported system
|
|
32
|
+
*/
|
|
33
|
+
UNKNOWN = 'Unknown',
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Enum representing reasons why WebXR AR might not be supported
|
|
38
|
+
*/
|
|
39
|
+
export enum EWebXRUnsupportedReason {
|
|
40
|
+
/**
|
|
41
|
+
* The browser doesn't implement the WebXR API at all.
|
|
42
|
+
* This typically means the browser is outdated or doesn't support WebXR.
|
|
43
|
+
*/
|
|
44
|
+
NO_WEBXR_API = 'NO_WEBXR_API',
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* The page is not served over HTTPS.
|
|
48
|
+
* WebXR requires a secure context (HTTPS) to work.
|
|
49
|
+
*/
|
|
50
|
+
NO_HTTPS = 'NO_HTTPS',
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* The device doesn't support immersive AR sessions.
|
|
54
|
+
* This could be because:
|
|
55
|
+
* - The device doesn't have AR capabilities
|
|
56
|
+
* - The browser doesn't support AR features
|
|
57
|
+
* - The device's AR features are disabled
|
|
58
|
+
*/
|
|
59
|
+
IMMERSIVE_AR_NOT_SUPPORTED_BY_DEVICE = 'IMMERSIVE_AR_NOT_SUPPORTED_BY_DEVICE',
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Access to AR features has been denied by the system or browser.
|
|
63
|
+
* This could be due to:
|
|
64
|
+
* - Privacy settings
|
|
65
|
+
* - System restrictions
|
|
66
|
+
* - Browser policies
|
|
67
|
+
* - Hardware limitations
|
|
68
|
+
*/
|
|
69
|
+
AR_PERMISSION_DENIED = 'AR_PERMISSION_DENIED',
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* An unexpected error occurred while checking for WebXR support.
|
|
73
|
+
* This is a fallback for any unhandled cases.
|
|
74
|
+
*/
|
|
75
|
+
UNKNOWN_ERROR = 'UNKNOWN_ERROR',
|
|
76
|
+
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { Object3D } from 'three';
|
|
2
|
-
import { USDZExporter, USDZExporterOptions } from 'three/examples/jsm/exporters/USDZExporter';
|
|
3
|
-
export type DIVEUSDZExporterOptions = USDZExporterOptions & {
|
|
4
|
-
ar?: {
|
|
5
|
-
anchoring: {
|
|
6
|
-
type: 'plane' | 'image' | 'face' | 'none';
|
|
7
|
-
};
|
|
8
|
-
planeAnchoring: {
|
|
9
|
-
alignment: 'horizontal' | 'vertical' | 'any';
|
|
10
|
-
};
|
|
11
|
-
};
|
|
12
|
-
};
|
|
13
|
-
export declare class DIVEUSDZExporter extends USDZExporter {
|
|
14
|
-
parse(scene: Object3D, options?: DIVEUSDZExporterOptions): Promise<Uint8Array>;
|
|
15
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { GLTF } from 'three/examples/jsm/loaders/GLTFLoader';
|
|
2
|
-
/**
|
|
3
|
-
* A basic loading manager.
|
|
4
|
-
*
|
|
5
|
-
* @module
|
|
6
|
-
*/
|
|
7
|
-
export declare class DIVELoadingManager {
|
|
8
|
-
private gltfloader;
|
|
9
|
-
private dracoloader;
|
|
10
|
-
constructor();
|
|
11
|
-
private progress;
|
|
12
|
-
LoadGLTF(uri: string): Promise<GLTF>;
|
|
13
|
-
PollProgress(): number;
|
|
14
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { Object3D } from 'three';
|
|
2
|
-
import {
|
|
3
|
-
USDZExporter,
|
|
4
|
-
USDZExporterOptions,
|
|
5
|
-
} from 'three/examples/jsm/exporters/USDZExporter';
|
|
6
|
-
|
|
7
|
-
export type DIVEUSDZExporterOptions = USDZExporterOptions & {
|
|
8
|
-
ar?: {
|
|
9
|
-
anchoring: { type: 'plane' | 'image' | 'face' | 'none' }; // source: https://developer.apple.com/documentation/realitykit/preliminary-anchoring-type
|
|
10
|
-
planeAnchoring: { alignment: 'horizontal' | 'vertical' | 'any' }; // source: https://developer.apple.com/documentation/realitykit/preliminary-planeanchoring-alignment
|
|
11
|
-
};
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export class DIVEUSDZExporter extends USDZExporter {
|
|
15
|
-
public parse(
|
|
16
|
-
scene: Object3D,
|
|
17
|
-
options?: DIVEUSDZExporterOptions,
|
|
18
|
-
): Promise<Uint8Array> {
|
|
19
|
-
return super.parse(scene, options);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { Object3D } from 'three';
|
|
2
|
-
import { DIVEUSDZExporter, DIVEUSDZExporterOptions } from '../USDZExporter';
|
|
3
|
-
|
|
4
|
-
describe('DIVEUSDZExporter', () => {
|
|
5
|
-
let exporter: DIVEUSDZExporter;
|
|
6
|
-
let scene: Object3D;
|
|
7
|
-
|
|
8
|
-
beforeEach(() => {
|
|
9
|
-
exporter = new DIVEUSDZExporter();
|
|
10
|
-
scene = new Object3D();
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
test('should create an instance of DIVEUSDZExporter', () => {
|
|
14
|
-
expect(exporter).toBeInstanceOf(DIVEUSDZExporter);
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
test('should call parse method with scene and options', async () => {
|
|
18
|
-
const options: DIVEUSDZExporterOptions = {
|
|
19
|
-
ar: {
|
|
20
|
-
anchoring: { type: 'plane' },
|
|
21
|
-
planeAnchoring: { alignment: 'horizontal' },
|
|
22
|
-
},
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
const result = await exporter.parse(scene, options);
|
|
26
|
-
expect(result).toBeInstanceOf(Uint8Array);
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
test('should call parse method without options', async () => {
|
|
30
|
-
const result = await exporter.parse(scene);
|
|
31
|
-
expect(result).toBeInstanceOf(Uint8Array);
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
test('should handle parse method with different anchoring types', async () => {
|
|
35
|
-
const options: DIVEUSDZExporterOptions = {
|
|
36
|
-
ar: {
|
|
37
|
-
anchoring: { type: 'image' },
|
|
38
|
-
planeAnchoring: { alignment: 'vertical' },
|
|
39
|
-
},
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
const result = await exporter.parse(scene, options);
|
|
43
|
-
expect(result).toBeInstanceOf(Uint8Array);
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
test('should handle parse method with different plane anchoring alignments', async () => {
|
|
47
|
-
const options: DIVEUSDZExporterOptions = {
|
|
48
|
-
ar: {
|
|
49
|
-
anchoring: { type: 'face' },
|
|
50
|
-
planeAnchoring: { alignment: 'any' },
|
|
51
|
-
},
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
const result = await exporter.parse(scene, options);
|
|
55
|
-
expect(result).toBeInstanceOf(Uint8Array);
|
|
56
|
-
});
|
|
57
|
-
});
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { DRACOLoader } from 'three/examples/jsm/loaders/DRACOLoader';
|
|
2
|
-
import { GLTF, GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* A basic loading manager.
|
|
6
|
-
*
|
|
7
|
-
* @module
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
export class DIVELoadingManager {
|
|
11
|
-
private gltfloader: GLTFLoader;
|
|
12
|
-
private dracoloader: DRACOLoader;
|
|
13
|
-
// ... maybe extend with other loaders later
|
|
14
|
-
|
|
15
|
-
constructor() {
|
|
16
|
-
this.gltfloader = new GLTFLoader();
|
|
17
|
-
this.dracoloader = new DRACOLoader();
|
|
18
|
-
this.dracoloader.setDecoderPath(
|
|
19
|
-
'https://www.gstatic.com/draco/v1/decoders/',
|
|
20
|
-
);
|
|
21
|
-
this.gltfloader.setDRACOLoader(this.dracoloader);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
private progress: Map<string, number> = new Map<string, number>();
|
|
25
|
-
|
|
26
|
-
public async LoadGLTF(uri: string): Promise<GLTF> {
|
|
27
|
-
const progEvent = (p: ProgressEvent<EventTarget>): void => {
|
|
28
|
-
this.progress.set(uri, p.loaded / p.total);
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
this.progress.set(uri, 0);
|
|
32
|
-
|
|
33
|
-
return new Promise<GLTF>((resolve, reject) => {
|
|
34
|
-
this.gltfloader
|
|
35
|
-
.loadAsync(uri, progEvent)
|
|
36
|
-
.then(resolve)
|
|
37
|
-
.catch(reject);
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
public PollProgress(): number {
|
|
42
|
-
let total = 0;
|
|
43
|
-
this.progress.forEach((progress: number) => {
|
|
44
|
-
total += progress;
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
if (this.progress.size === 0) return 1;
|
|
48
|
-
return total / this.progress.size;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { DIVELoadingManager } from '../LoadingManager';
|
|
2
|
-
|
|
3
|
-
describe('dive/loadingmanager/DIVELoadingManager', () => {
|
|
4
|
-
it('should instantiate', () => {
|
|
5
|
-
const testLight = new DIVELoadingManager();
|
|
6
|
-
expect(testLight).toBeDefined();
|
|
7
|
-
});
|
|
8
|
-
|
|
9
|
-
it('should return GLTF promise', () => {
|
|
10
|
-
const testLight = new DIVELoadingManager();
|
|
11
|
-
const promise = testLight.LoadGLTF('test.gltf');
|
|
12
|
-
expect(promise).toBeDefined();
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
it('should return progress', () => {
|
|
16
|
-
const testLight = new DIVELoadingManager();
|
|
17
|
-
testLight.LoadGLTF('test.gltf');
|
|
18
|
-
const progress = testLight.PollProgress();
|
|
19
|
-
expect(progress).toBe(0);
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
it('should return done progress without load', () => {
|
|
23
|
-
const testLight = new DIVELoadingManager();
|
|
24
|
-
const progress = testLight.PollProgress();
|
|
25
|
-
expect(progress).toBe(1);
|
|
26
|
-
});
|
|
27
|
-
});
|