@shopware-ag/dive 1.12.1 → 1.14.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.
Files changed (77) hide show
  1. package/build/dive.cjs +458 -405
  2. package/build/dive.cjs.map +1 -1
  3. package/build/dive.d.cts +314 -78
  4. package/build/dive.d.ts +314 -78
  5. package/build/dive.js +430 -377
  6. package/build/dive.js.map +1 -1
  7. package/package.json +1 -1
  8. package/src/__test__/DIVE.test.ts +33 -29
  9. package/src/axiscamera/AxisCamera.ts +1 -1
  10. package/src/axiscamera/__test__/AxisCamera.test.ts +1 -1
  11. package/src/com/Communication.ts +59 -14
  12. package/src/com/__test__/Communication.test.ts +111 -31
  13. package/src/com/actions/index.ts +2 -0
  14. package/src/com/actions/object/addobject.ts +1 -1
  15. package/src/com/actions/object/deleteobject.ts +1 -1
  16. package/src/com/actions/object/deselectobject.ts +1 -1
  17. package/src/com/actions/object/getallobjects.ts +1 -1
  18. package/src/com/actions/object/getobjects.ts +1 -1
  19. package/src/com/actions/object/selectobject.ts +1 -1
  20. package/src/com/actions/object/setparent.ts +9 -0
  21. package/src/com/actions/object/updateobject.ts +1 -1
  22. package/src/com/actions/scene/getallscenedata.ts +1 -1
  23. package/src/com/types/COMBaseEntity.ts +9 -0
  24. package/src/com/types/COMEntity.ts +7 -0
  25. package/src/com/types/COMEntityType.ts +1 -0
  26. package/src/com/types/COMGeometry.ts +6 -0
  27. package/src/com/types/COMGroup.ts +9 -0
  28. package/src/com/types/COMLight.ts +10 -0
  29. package/src/com/types/COMMaterial.ts +12 -0
  30. package/src/com/types/COMModel.ts +12 -0
  31. package/src/com/types/COMPov.ts +8 -0
  32. package/src/com/types/COMPrimitive.ts +12 -0
  33. package/src/com/types/index.ts +21 -0
  34. package/src/dive.ts +9 -16
  35. package/src/grid/Grid.ts +1 -1
  36. package/src/grid/__test__/Grid.test.ts +1 -1
  37. package/src/group/Group.ts +126 -0
  38. package/src/group/__test__/Group.test.ts +100 -0
  39. package/src/helper/findSceneRecursive/findSceneRecursive.ts +1 -1
  40. package/src/light/AmbientLight.ts +3 -0
  41. package/src/light/PointLight.ts +6 -3
  42. package/src/light/SceneLight.ts +2 -0
  43. package/src/light/__test__/PointLight.test.ts +8 -6
  44. package/src/light/__test__/SceneLight.test.ts +8 -6
  45. package/src/loadingmanager/LoadingManager.ts +1 -1
  46. package/src/loadingmanager/__test__/LoadingManager.test.ts +1 -1
  47. package/src/mediacreator/MediaCreator.ts +1 -1
  48. package/src/mediacreator/__test__/MediaCreator.test.ts +6 -4
  49. package/src/model/Model.ts +8 -7
  50. package/src/model/__test__/Model.test.ts +13 -10
  51. package/src/primitive/Primitive.ts +4 -3
  52. package/src/primitive/__test__/Primitive.test.ts +9 -7
  53. package/src/primitive/floor/Floor.ts +1 -1
  54. package/src/primitive/floor/__test__/Floor.test.ts +1 -1
  55. package/src/renderer/__test__/Renderer.test.ts +1 -1
  56. package/src/scene/Scene.ts +29 -9
  57. package/src/scene/__test__/Scene.test.ts +33 -19
  58. package/src/scene/root/Root.ts +239 -72
  59. package/src/scene/root/__test__/Root.test.ts +476 -114
  60. package/src/toolbox/BaseTool.ts +1 -1
  61. package/src/toolbox/Toolbox.ts +1 -1
  62. package/src/toolbox/__test__/BaseTool.test.ts +1 -1
  63. package/src/toolbox/__test__/Toolbox.test.ts +1 -1
  64. package/src/toolbox/select/SelectTool.ts +1 -1
  65. package/src/toolbox/select/__test__/SelectTool.test.ts +11 -9
  66. package/src/toolbox/transform/TransformTool.ts +1 -1
  67. package/src/toolbox/transform/__test__/TransformTool.test.ts +12 -10
  68. package/src/types/SceneObjects.ts +14 -0
  69. package/src/types/index.ts +5 -0
  70. package/src/com/index.ts +0 -3
  71. package/src/com/types.ts +0 -58
  72. package/src/scene/root/lightroot/LightRoot.ts +0 -99
  73. package/src/scene/root/lightroot/__test__/LightRoot.test.ts +0 -145
  74. package/src/scene/root/modelroot/ModelRoot.ts +0 -98
  75. package/src/scene/root/modelroot/__test__/ModelRoot.test.ts +0 -189
  76. package/src/scene/root/primitiveroot/PrimitiveRoot.ts +0 -88
  77. package/src/scene/root/primitiveroot/__test__/PrimitiveRoot.test.ts +0 -181
@@ -1,6 +1,6 @@
1
1
  import { Intersection, Object3D, Raycaster, Vector2, Vector3 } from "three";
2
2
  import { PRODUCT_LAYER_MASK, UI_LAYER_MASK } from "../constant/VisibilityLayerMask";
3
- import DIVEScene from "../scene/Scene";
3
+ import { DIVEScene } from "../scene/Scene";
4
4
  import DIVEOrbitControls from "../controls/OrbitControls";
5
5
  import { DIVEDraggable, findDraggableInterface } from "../interface/Draggable";
6
6
  import { DIVEHoverable, findHoverableInterface } from "../interface/Hoverable";
@@ -1,5 +1,5 @@
1
1
  import type DIVEOrbitControls from "../controls/OrbitControls.ts";
2
- import type DIVEScene from "../scene/Scene.ts";
2
+ import type { DIVEScene } from "../scene/Scene.ts";
3
3
  import { type DIVEBaseTool } from "./BaseTool.ts";
4
4
  import { type DIVESelectTool } from "./select/SelectTool.ts";
5
5
 
@@ -1,7 +1,7 @@
1
1
 
2
2
  import { DIVEBaseTool } from '../BaseTool';
3
3
  import type DIVEOrbitControls from '../../controls/OrbitControls';
4
- import type DIVEScene from '../../scene/Scene';
4
+ import type { DIVEScene } from '../../scene/Scene';
5
5
  import { type Object3D, type Vector3 } from 'three';
6
6
  import { type DIVEHoverable } from '../../interface/Hoverable';
7
7
  import { type DIVEDraggable } from '../../interface/Draggable';
@@ -1,6 +1,6 @@
1
1
  import DIVEToolbox, { type ToolType } from '../Toolbox';
2
2
  import type DIVEOrbitControls from '../../controls/OrbitControls';
3
- import type DIVEScene from '../../scene/Scene';
3
+ import type { DIVEScene } from '../../scene/Scene';
4
4
 
5
5
  /**
6
6
  * @jest-environment jsdom
@@ -1,5 +1,5 @@
1
1
  import { type Object3D } from "three";
2
- import DIVEScene from "../../scene/Scene.ts";
2
+ import { DIVEScene } from "../../scene/Scene.ts";
3
3
  import DIVETransformTool from "../transform/TransformTool.ts";
4
4
  import type DIVEOrbitControls from "../../controls/OrbitControls.ts";
5
5
  import { type DIVESelectable, findSelectableInterface } from "../../interface/Selectable.ts";
@@ -1,5 +1,5 @@
1
1
  import { DIVESelectTool, isSelectTool } from '../SelectTool';
2
- import DIVEScene from '../../../scene/Scene';
2
+ import { DIVEScene } from '../../../scene/Scene';
3
3
  import DIVEOrbitControls from '../../../controls/OrbitControls';
4
4
  import { DIVERenderer, DIVERendererDefaultSettings } from '../../../renderer/Renderer';
5
5
  import { DIVESelectable } from '../../../interface/Selectable';
@@ -65,14 +65,16 @@ jest.mock('../../../animation/AnimationSystem', () => {
65
65
  });
66
66
 
67
67
  jest.mock('../../../scene/Scene', () => {
68
- return jest.fn(function () {
69
- this.add = jest.fn();
70
- this.children = [];
71
- this.Root = {
72
- children: [],
73
- }
74
- return this;
75
- });
68
+ return {
69
+ DIVEScene: jest.fn(function () {
70
+ this.add = jest.fn();
71
+ this.children = [];
72
+ this.Root = {
73
+ children: [],
74
+ }
75
+ return this;
76
+ })
77
+ };
76
78
  });
77
79
 
78
80
  const mock_intersectObjects = jest.fn().mockReturnValue([]);
@@ -1,5 +1,5 @@
1
1
  import { DIVEBaseTool } from "../BaseTool.ts";
2
- import DIVEScene from "../../scene/Scene.ts";
2
+ import { DIVEScene } from "../../scene/Scene.ts";
3
3
  import DIVEOrbitControls from "../../controls/OrbitControls.ts";
4
4
  import { TransformControls } from "three/examples/jsm/Addons";
5
5
  import { type DIVEMoveable } from "../../interface/Moveable.ts";
@@ -1,5 +1,5 @@
1
1
  import DIVETransformTool, { isTransformTool } from '../TransformTool';
2
- import DIVEScene from '../../../scene/Scene';
2
+ import { DIVEScene } from '../../../scene/Scene';
3
3
  import DIVEOrbitControls from '../../../controls/OrbitControls';
4
4
  import DIVEPerspectiveCamera from '../../../camera/PerspectiveCamera';
5
5
  import { DIVERenderer } from '../../../renderer/Renderer';
@@ -47,15 +47,17 @@ jest.mock('../../../controls/OrbitControls', () => {
47
47
  });
48
48
 
49
49
  jest.mock('../../../scene/Scene', () => {
50
- return jest.fn(function () {
51
- this.add = jest.fn();
52
- this.remove = jest.fn();
53
- this.Root = {
54
- children: [],
55
- }
56
- this.children = [];
57
- return this;
58
- });
50
+ return {
51
+ DIVEScene: jest.fn(function () {
52
+ this.add = jest.fn();
53
+ this.remove = jest.fn();
54
+ this.Root = {
55
+ children: [],
56
+ }
57
+ this.children = [];
58
+ return this;
59
+ })
60
+ };
59
61
  });
60
62
 
61
63
  jest.mock('../../../animation/AnimationSystem', () => {
@@ -0,0 +1,14 @@
1
+ import { DIVEGroup } from "../group/Group";
2
+ import DIVEAmbientLight from "../light/AmbientLight";
3
+ import DIVEPointLight from "../light/PointLight";
4
+ import DIVESceneLight from "../light/SceneLight";
5
+ import { DIVEModel } from "../model/Model";
6
+ import { DIVEPrimitive } from "../primitive/Primitive";
7
+
8
+ export type DIVESceneObject =
9
+ DIVEModel
10
+ | DIVEGroup
11
+ | DIVEPrimitive
12
+ | DIVEAmbientLight
13
+ | DIVEPointLight
14
+ | DIVESceneLight;
@@ -0,0 +1,5 @@
1
+ import { type DIVESceneObject } from "./SceneObjects";
2
+
3
+ export {
4
+ type DIVESceneObject,
5
+ }
package/src/com/index.ts DELETED
@@ -1,3 +0,0 @@
1
- import DIVECommunication from './Communication.ts';
2
- export type { Actions } from './actions/index.ts';
3
- export default DIVECommunication;
package/src/com/types.ts DELETED
@@ -1,58 +0,0 @@
1
- import { type Texture, type Vector3Like } from "three";
2
-
3
- type COMBaseEntity = {
4
- id: string;
5
- name: string;
6
- entityType: 'pov' | 'light' | 'model' | 'primitive';
7
- visible: boolean;
8
- }
9
- export type COMPov = COMBaseEntity & {
10
- position: Vector3Like;
11
- target: Vector3Like;
12
- locked?: boolean;
13
- };
14
-
15
- export type COMLight = COMBaseEntity & {
16
- type: 'ambient' | 'point' | 'scene';
17
- intensity: number;
18
- color: string | number;
19
- enabled: boolean;
20
- position?: Vector3Like;
21
- };
22
-
23
- export type COMModel = COMBaseEntity & {
24
- uri: string;
25
- position: Vector3Like;
26
- rotation: Vector3Like;
27
- scale: Vector3Like;
28
- loaded: boolean;
29
- material?: Partial<COMMaterial>;
30
- };
31
-
32
- export type COMGeometry = {
33
- name: string
34
- width: number;
35
- height: number;
36
- depth: number;
37
- }
38
-
39
- export type COMMaterial = {
40
- vertexColors: boolean;
41
- color: string | number;
42
- map: Texture | null;
43
- normalMap: Texture | null;
44
- roughness: number;
45
- roughnessMap: Texture | null;
46
- metalness: number;
47
- metalnessMap: Texture | null;
48
- }
49
-
50
- export type COMPrimitive = COMBaseEntity & {
51
- position: Vector3Like;
52
- rotation: Vector3Like;
53
- scale: Vector3Like;
54
- geometry: COMGeometry;
55
- material?: Partial<COMMaterial>;
56
- };
57
-
58
- export type COMEntity = COMPov | COMLight | COMModel | COMPrimitive;
@@ -1,99 +0,0 @@
1
- import { Color, Object3D } from "three";
2
- import { type COMLight } from "../../../com/types.ts";
3
- import DIVEAmbientLight from "../../../light/AmbientLight.ts";
4
- import DIVEPointLight from "../../../light/PointLight.ts";
5
- import DIVESceneLight from "../../../light/SceneLight.ts";
6
- import { type TransformControls } from "three/examples/jsm/Addons";
7
- import type DIVEScene from "../../Scene.ts";
8
-
9
- /**
10
- * A basic scene node to hold all lights.
11
- *
12
- * @module
13
- */
14
-
15
- export default class DIVELightRoot extends Object3D {
16
- constructor() {
17
- super();
18
- this.name = "LightRoot";
19
- }
20
-
21
- public GetLight(object: Partial<COMLight>): Object3D | undefined {
22
- if (object.id === undefined) {
23
- console.warn('LightRoot.GetLight: object.id is undefined')
24
- return undefined;
25
- }
26
- return this.children.find(object3D => object3D.userData.id === object.id);
27
- }
28
-
29
- public UpdateLight(light: Partial<COMLight>): void {
30
- // update scene here for light
31
- if (light.id === undefined) {
32
- console.warn(`LightRoot.UpdateLight: light.id is undefined`)
33
- return;
34
- }
35
-
36
- let sceneObject = this.children.find(object3D => object3D.userData.id === light.id);
37
- if (!sceneObject) {
38
- switch (light.type) {
39
- case 'scene': {
40
- sceneObject = new DIVESceneLight();
41
- break;
42
- }
43
- case 'ambient': {
44
- sceneObject = new DIVEAmbientLight();
45
- break;
46
- }
47
- case 'point': {
48
- sceneObject = new DIVEPointLight();
49
- break;
50
- }
51
- default: {
52
- console.warn(`LightRoot.UpdateLight: Unknown light type: ${light.type}`);
53
- return;
54
- }
55
- }
56
- sceneObject.userData.id = light.id;
57
- this.add(sceneObject);
58
- }
59
-
60
- if (light.name !== undefined && light.name !== null) sceneObject.name = light.name;
61
- if (light.position !== undefined && light.position !== null) sceneObject.position.set(light.position.x, light.position.y, light.position.z);
62
- if (light.intensity !== undefined && light.intensity !== null) (sceneObject as (DIVEAmbientLight | DIVEPointLight)).SetIntensity(light.intensity);
63
- if (light.enabled !== undefined && light.enabled !== null) (sceneObject as (DIVEAmbientLight | DIVEPointLight)).SetEnabled(light.enabled);
64
- if (light.color !== undefined && light.color !== null) (sceneObject as (DIVEAmbientLight | DIVEPointLight)).SetColor(new Color(light.color));
65
- if (light.visible !== undefined && light.visible !== null) (sceneObject as (DIVEAmbientLight | DIVEPointLight)).visible = light.visible;
66
- }
67
-
68
- public DeleteLight(light: Partial<COMLight>): void {
69
- if (light.id === undefined) {
70
- console.warn('LightRoot.DeleteLight: light.id is undefined')
71
- return;
72
- }
73
-
74
- const sceneObject = this.children.find(object3D => object3D.userData.id === light.id);
75
- if (!sceneObject) {
76
- console.warn(`LightRoot.DeleteLight: Light with id ${light.id} not found`);
77
- return;
78
- }
79
-
80
- // _______________________________________________________
81
- // this is only neccessary due to using the old TransformControls instead of the new DIVEGizmo
82
- const findScene = (object: Object3D): DIVEScene => {
83
- if (object.parent !== null) {
84
- return findScene(object.parent);
85
- };
86
- return object as DIVEScene;
87
- }
88
-
89
- const scene = findScene(sceneObject);
90
- scene.children.find((object) => {
91
- if ('isTransformControls' in object) {
92
- (object as TransformControls).detach();
93
- }
94
- });
95
- // _______________________________________________________
96
-
97
- this.remove(sceneObject);
98
- }
99
- }
@@ -1,145 +0,0 @@
1
- import DIVELightRoot from '../LightRoot';
2
- import type DIVEScene from '../../../Scene';
3
- import { type COMLight } from '../../../../com/types';
4
- import { type DIVEMoveable } from '../../../../interface/Moveable';
5
-
6
- const mock_SetPosition = jest.fn();
7
- const mock_SetIntensity = jest.fn();
8
- const mock_SetEnabled = jest.fn();
9
- const mock_SetColor = jest.fn();
10
-
11
- jest.mock('../../../../light/AmbientLight.ts', () => {
12
- return jest.fn(function () {
13
- this.isObject3D = true;
14
- this.parent = null;
15
- this.dispatchEvent = jest.fn();
16
- this.position = {
17
- set: mock_SetPosition,
18
- }
19
- this.SetIntensity = mock_SetIntensity;
20
- this.SetEnabled = mock_SetEnabled;
21
- this.SetColor = mock_SetColor;
22
- this.userData = {
23
- id: undefined,
24
- }
25
- this.removeFromParent = jest.fn();
26
- return this;
27
- });
28
- });
29
-
30
- jest.mock('../../../../light/PointLight.ts', () => {
31
- return jest.fn(function () {
32
- this.isObject3D = true;
33
- this.parent = null;
34
- this.dispatchEvent = jest.fn();
35
- this.position = {
36
- set: mock_SetPosition,
37
- }
38
- this.SetIntensity = mock_SetIntensity;
39
- this.SetEnabled = mock_SetEnabled;
40
- this.SetColor = mock_SetColor;
41
- this.userData = {
42
- id: undefined,
43
- }
44
- this.removeFromParent = jest.fn();
45
- return this;
46
- });
47
- });
48
-
49
- const consoleWarnSpy = jest.spyOn(console, 'warn').mockImplementation(() => { });
50
-
51
- describe('dive/scene/root/lightroot/DIVELightRoot', () => {
52
- beforeEach(() => {
53
- consoleWarnSpy.mockClear();
54
- });
55
-
56
- it('should instantiate', () => {
57
- const lightRoot = new DIVELightRoot();
58
- expect(lightRoot).toBeDefined();
59
- });
60
-
61
- it('should not add incorrect light without id', () => {
62
- const lightRoot = new DIVELightRoot();
63
- expect(() => lightRoot.UpdateLight({ id: undefined })).not.toThrow();
64
- expect(consoleWarnSpy).toHaveBeenCalled();
65
- expect(lightRoot.children).toHaveLength(0);
66
- });
67
-
68
- it('should not add incorrect light', () => {
69
- const lightRoot = new DIVELightRoot();
70
- expect(() => lightRoot.UpdateLight(({ id: 'test_id', name: 'test', type: 'this not a real light type' }) as unknown as COMLight)).not.toThrow();
71
- expect(consoleWarnSpy).toHaveBeenCalled();
72
- expect(lightRoot.children).toHaveLength(0);
73
- });
74
-
75
- it('should update basic scene light', () => {
76
- const lightRoot = new DIVELightRoot();
77
- lightRoot.UpdateLight({ id: 'test_id', type: 'scene', name: 'test', position: undefined, enabled: true, visible: false });
78
- expect(lightRoot.children).toHaveLength(1);
79
- expect(lightRoot.children[0].userData.id).toBe('test_id');
80
- });
81
-
82
- it('should update basic ambient light', () => {
83
- const lightRoot = new DIVELightRoot();
84
- lightRoot.UpdateLight({ id: 'test_id', type: 'ambient', position: undefined });
85
- expect(lightRoot.children).toHaveLength(1);
86
- expect(lightRoot.children[0].userData.id).toBe('test_id');
87
- });
88
-
89
- it('should update basic point light', () => {
90
- const lightRoot = new DIVELightRoot();
91
- lightRoot.UpdateLight({ id: 'test_id', type: 'point', position: undefined });
92
- expect(lightRoot.children).toHaveLength(1);
93
- expect(lightRoot.children[0].userData.id).toBe('test_id');
94
- });
95
-
96
- it('should update configured light', () => {
97
- const lightRoot = new DIVELightRoot();
98
- lightRoot.UpdateLight({ id: 'test_id', type: 'point', position: { x: 1, y: 2, z: 3 }, intensity: 0.5, color: 0x123456 });
99
- expect(consoleWarnSpy).not.toHaveBeenCalled();
100
- expect(lightRoot.children).toHaveLength(1);
101
- expect(lightRoot.children[0].userData.id).toBe('test_id');
102
- expect(mock_SetIntensity).toHaveBeenCalledTimes(1);
103
- expect(mock_SetColor).toHaveBeenCalledTimes(1);
104
- expect(mock_SetPosition).toHaveBeenCalledTimes(1);
105
- });
106
-
107
- it('should get light', () => {
108
- const lightRoot = new DIVELightRoot();
109
- expect(() => lightRoot.GetLight({ id: undefined })).not.toThrow();
110
- expect(lightRoot.GetLight({ id: 'test_id' })).toBeUndefined();
111
- lightRoot.UpdateLight({ id: 'test_id', type: 'point', position: { x: 1, y: 2, z: 3 }, intensity: 0.5, color: 0x123456 });
112
- expect(consoleWarnSpy).toHaveBeenCalled();
113
- expect(lightRoot.GetLight({ id: 'test_id' })).toBeDefined();
114
- });
115
-
116
- it('should delete light', () => {
117
- const lightRoot = new DIVELightRoot();
118
-
119
- const sceneParent = {
120
- parent: null,
121
- children: [
122
- {
123
- isTransformControls: true,
124
- detach: jest.fn(),
125
- }
126
- ],
127
- }
128
- lightRoot.parent = sceneParent as unknown as DIVEScene;
129
- expect(() => lightRoot.DeleteLight({ id: undefined })).not.toThrow();
130
-
131
- expect(() => lightRoot.DeleteLight({ id: 'test_id' })).not.toThrow();
132
-
133
- lightRoot.UpdateLight({ id: 'test_id', type: 'point', position: { x: 1, y: 2, z: 3 }, intensity: 0.5, color: 0x123456 });
134
- expect(() => lightRoot.DeleteLight({ id: 'test_id' })).not.toThrow();
135
-
136
- lightRoot.UpdateLight({ id: 'test_id', type: 'point', position: { x: 1, y: 2, z: 3 }, intensity: 0.5, color: 0x123456 });
137
- (lightRoot.children[0] as unknown as DIVEMoveable).isMoveable = true;
138
- expect(() => lightRoot.DeleteLight({ id: 'test_id' })).not.toThrow();
139
-
140
- lightRoot.UpdateLight({ id: 'test_id', type: 'point', position: { x: 1, y: 2, z: 3 }, intensity: 0.5, color: 0x123456 });
141
- (lightRoot.children[0] as unknown as DIVEMoveable).isMoveable = true;
142
- expect(() => lightRoot.DeleteLight({ id: 'test_id' })).not.toThrow();
143
- expect(lightRoot.children).toHaveLength(0);
144
- });
145
- });
@@ -1,98 +0,0 @@
1
- import { Object3D } from "three";
2
- import { COMModel } from "../../../com/types.ts";
3
- import Model from "../../../model/Model.ts";
4
- import DIVELoadingManager from "../../../loadingmanager/LoadingManager.ts";
5
- import DIVECommunication from "../../../com/Communication.ts";
6
- import { type TransformControls } from "three/examples/jsm/Addons";
7
- import type DIVEScene from "../../Scene.ts";
8
-
9
- /**
10
- * A basic scene node to hold all models.
11
- *
12
- * @module
13
- */
14
- export default class DIVEModelRoot extends Object3D {
15
- private loadingManager: DIVELoadingManager;
16
-
17
- constructor() {
18
- super();
19
- this.name = "ModelRoot";
20
-
21
- this.loadingManager = new DIVELoadingManager();
22
- }
23
-
24
- public GetModel(object: Partial<COMModel>): Object3D | undefined {
25
- if (object.id === undefined) {
26
- console.warn('ModelRoot.GetModel: object.id is undefined')
27
- return undefined;
28
- }
29
- return this.children.find(object3D => object3D.userData.id === object.id);
30
- }
31
-
32
- public UpdateModel(object: Partial<COMModel>): void {
33
- if (object.id === undefined) {
34
- console.warn('ModelRoot.UpdateModel: object.id is undefined')
35
- return;
36
- }
37
-
38
- let sceneObject = this.children.find(object3D => object3D.userData.id === object.id);
39
- if (!sceneObject && object.uri !== undefined) {
40
- const model = new Model();
41
- sceneObject = model;
42
- sceneObject.userData.id = object.id;
43
- this.add(sceneObject);
44
-
45
- this.loadingManager.LoadGLTF(object.uri).then((gltf) => {
46
- model.SetModel(gltf);
47
- DIVECommunication.get(object.id!)?.PerformAction('MODEL_LOADED', { id: object.id! });
48
- });
49
- }
50
-
51
- if (object.position !== undefined) (sceneObject as Model).SetPosition(object.position);
52
- if (object.rotation !== undefined) (sceneObject as Model).SetRotation(object.rotation);
53
- if (object.scale !== undefined) (sceneObject as Model).SetScale(object.scale);
54
- if (object.visible !== undefined) (sceneObject as Model).SetVisibility(object.visible);
55
- if (object.material !== undefined) (sceneObject as Model).SetMaterial(object.material);
56
- }
57
-
58
- public DeleteModel(object: Partial<COMModel>): void {
59
- if (object.id === undefined) {
60
- console.warn(`ModelRoot.DeleteModel: object.id is undefined`)
61
- return;
62
- }
63
-
64
- const sceneObject = this.children.find(object3D => object3D.userData.id === object.id);
65
- if (!sceneObject) {
66
- console.warn(`ModelRoot.DeleteModel: Model with id ${object.id} not found`);
67
- return;
68
- }
69
-
70
- // _______________________________________________________
71
- // this is only neccessary due to using the old TransformControls instead of the new DIVEGizmo
72
- const findScene = (object: Object3D): DIVEScene => {
73
- if (object.parent !== null) {
74
- return findScene(object.parent);
75
- };
76
- return object as DIVEScene;
77
- }
78
-
79
- const scene = findScene(sceneObject);
80
- scene.children.find((object) => {
81
- if ('isTransformControls' in object) {
82
- (object as TransformControls).detach();
83
- }
84
- });
85
- // _______________________________________________________
86
-
87
- this.remove(sceneObject);
88
- }
89
-
90
- public PlaceOnFloor(object: Partial<COMModel>): void {
91
- if (object.id === undefined) console.warn('ModelRoot.PlaceOnFloor: object.id is undefined');
92
-
93
- const sceneObject = this.children.find(object3D => object3D.userData.id === object.id);
94
- if (!sceneObject) return;
95
-
96
- (sceneObject as Model).PlaceOnFloor();
97
- }
98
- }