@shopware-ag/dive 1.16.14-beta.0 → 1.16.14
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 +3280 -0
- package/build/dive.cjs.map +1 -0
- package/build/dive.d.cts +1083 -0
- package/build/dive.d.ts +1083 -0
- package/build/dive.js +3298 -0
- package/build/dive.js.map +1 -0
- package/package.json +1 -1
package/build/dive.cjs
ADDED
|
@@ -0,0 +1,3280 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __defProps = Object.defineProperties;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
7
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
9
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
10
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
11
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
12
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
13
|
+
var __spreadValues = (a, b) => {
|
|
14
|
+
for (var prop in b || (b = {}))
|
|
15
|
+
if (__hasOwnProp.call(b, prop))
|
|
16
|
+
__defNormalProp(a, prop, b[prop]);
|
|
17
|
+
if (__getOwnPropSymbols)
|
|
18
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
19
|
+
if (__propIsEnum.call(b, prop))
|
|
20
|
+
__defNormalProp(a, prop, b[prop]);
|
|
21
|
+
}
|
|
22
|
+
return a;
|
|
23
|
+
};
|
|
24
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
25
|
+
var __esm = (fn, res) => function __init() {
|
|
26
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
27
|
+
};
|
|
28
|
+
var __export = (target, all) => {
|
|
29
|
+
for (var name in all)
|
|
30
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
31
|
+
};
|
|
32
|
+
var __copyProps = (to, from, except, desc) => {
|
|
33
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
34
|
+
for (let key of __getOwnPropNames(from))
|
|
35
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
36
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
37
|
+
}
|
|
38
|
+
return to;
|
|
39
|
+
};
|
|
40
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
41
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
42
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
43
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
44
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
45
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
46
|
+
mod
|
|
47
|
+
));
|
|
48
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
49
|
+
var __async = (__this, __arguments, generator) => {
|
|
50
|
+
return new Promise((resolve, reject) => {
|
|
51
|
+
var fulfilled = (value) => {
|
|
52
|
+
try {
|
|
53
|
+
step(generator.next(value));
|
|
54
|
+
} catch (e) {
|
|
55
|
+
reject(e);
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
var rejected = (value) => {
|
|
59
|
+
try {
|
|
60
|
+
step(generator.throw(value));
|
|
61
|
+
} catch (e) {
|
|
62
|
+
reject(e);
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
66
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
67
|
+
});
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
// src/constant/VisibilityLayerMask.ts
|
|
71
|
+
var DEFAULT_LAYER_MASK, COORDINATE_LAYER_MASK, UI_LAYER_MASK, HELPER_LAYER_MASK, PRODUCT_LAYER_MASK;
|
|
72
|
+
var init_VisibilityLayerMask = __esm({
|
|
73
|
+
"src/constant/VisibilityLayerMask.ts"() {
|
|
74
|
+
"use strict";
|
|
75
|
+
DEFAULT_LAYER_MASK = 1;
|
|
76
|
+
COORDINATE_LAYER_MASK = 2;
|
|
77
|
+
UI_LAYER_MASK = 4;
|
|
78
|
+
HELPER_LAYER_MASK = 8;
|
|
79
|
+
PRODUCT_LAYER_MASK = 16;
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
// src/helper/isInterface/implementsInterface.ts
|
|
84
|
+
function implementsInterface(object, discriminator) {
|
|
85
|
+
if (!object) return false;
|
|
86
|
+
return discriminator in object;
|
|
87
|
+
}
|
|
88
|
+
var init_implementsInterface = __esm({
|
|
89
|
+
"src/helper/isInterface/implementsInterface.ts"() {
|
|
90
|
+
"use strict";
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
// src/helper/findInterface/findInterface.ts
|
|
95
|
+
function findInterface(object, discriminator) {
|
|
96
|
+
if (!object) return void 0;
|
|
97
|
+
if (implementsInterface(object, discriminator)) return object;
|
|
98
|
+
return findInterface(object.parent, discriminator);
|
|
99
|
+
}
|
|
100
|
+
var init_findInterface = __esm({
|
|
101
|
+
"src/helper/findInterface/findInterface.ts"() {
|
|
102
|
+
"use strict";
|
|
103
|
+
init_implementsInterface();
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
// src/toolbox/BaseTool.ts
|
|
108
|
+
var import_three3, DIVEBaseTool;
|
|
109
|
+
var init_BaseTool = __esm({
|
|
110
|
+
"src/toolbox/BaseTool.ts"() {
|
|
111
|
+
"use strict";
|
|
112
|
+
import_three3 = require("three");
|
|
113
|
+
init_VisibilityLayerMask();
|
|
114
|
+
init_findInterface();
|
|
115
|
+
DIVEBaseTool = class {
|
|
116
|
+
constructor(scene, controller) {
|
|
117
|
+
this.POINTER_DRAG_THRESHOLD = 1e-3;
|
|
118
|
+
this.name = "BaseTool";
|
|
119
|
+
this._canvas = controller.domElement;
|
|
120
|
+
this._scene = scene;
|
|
121
|
+
this._controller = controller;
|
|
122
|
+
this._pointer = new import_three3.Vector2();
|
|
123
|
+
this._pointerPrimaryDown = false;
|
|
124
|
+
this._pointerMiddleDown = false;
|
|
125
|
+
this._pointerSecondaryDown = false;
|
|
126
|
+
this._lastPointerDown = new import_three3.Vector2();
|
|
127
|
+
this._lastPointerUp = new import_three3.Vector2();
|
|
128
|
+
this._raycaster = new import_three3.Raycaster();
|
|
129
|
+
this._raycaster.layers.mask = PRODUCT_LAYER_MASK | UI_LAYER_MASK;
|
|
130
|
+
this._intersects = [];
|
|
131
|
+
this._hovered = null;
|
|
132
|
+
this._dragging = false;
|
|
133
|
+
this._dragStart = new import_three3.Vector3();
|
|
134
|
+
this._dragCurrent = new import_three3.Vector3();
|
|
135
|
+
this._dragEnd = new import_three3.Vector3();
|
|
136
|
+
this._dragDelta = new import_three3.Vector3();
|
|
137
|
+
this._draggable = null;
|
|
138
|
+
this._dragRaycastOnObjects = null;
|
|
139
|
+
}
|
|
140
|
+
get _pointerAnyDown() {
|
|
141
|
+
return this._pointerPrimaryDown || this._pointerMiddleDown || this._pointerSecondaryDown;
|
|
142
|
+
}
|
|
143
|
+
Activate() {
|
|
144
|
+
}
|
|
145
|
+
Deactivate() {
|
|
146
|
+
}
|
|
147
|
+
onPointerDown(e) {
|
|
148
|
+
var _a;
|
|
149
|
+
switch (e.button) {
|
|
150
|
+
case 0: {
|
|
151
|
+
this._pointerPrimaryDown = true;
|
|
152
|
+
break;
|
|
153
|
+
}
|
|
154
|
+
case 1: {
|
|
155
|
+
this._pointerMiddleDown = true;
|
|
156
|
+
break;
|
|
157
|
+
}
|
|
158
|
+
case 2: {
|
|
159
|
+
this._pointerSecondaryDown = true;
|
|
160
|
+
break;
|
|
161
|
+
}
|
|
162
|
+
default: {
|
|
163
|
+
console.warn(
|
|
164
|
+
"DIVEBaseTool.onPointerDown: Unknown button: " + e.button
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
this._lastPointerDown.copy(this._pointer);
|
|
169
|
+
this._draggable = findInterface(
|
|
170
|
+
(_a = this._intersects[0]) == null ? void 0 : _a.object,
|
|
171
|
+
"isDraggable"
|
|
172
|
+
) || null;
|
|
173
|
+
}
|
|
174
|
+
onDragStart(e) {
|
|
175
|
+
if (!this._draggable) return;
|
|
176
|
+
if (this._dragRaycastOnObjects !== null) {
|
|
177
|
+
this._intersects = this._raycaster.intersectObjects(
|
|
178
|
+
this._dragRaycastOnObjects,
|
|
179
|
+
true
|
|
180
|
+
);
|
|
181
|
+
}
|
|
182
|
+
if (this._intersects.length === 0) return;
|
|
183
|
+
this._dragStart.copy(this._intersects[0].point.clone());
|
|
184
|
+
this._dragCurrent.copy(this._intersects[0].point.clone());
|
|
185
|
+
this._dragEnd.copy(this._dragStart.clone());
|
|
186
|
+
this._dragDelta.set(0, 0, 0);
|
|
187
|
+
if (this._draggable && this._draggable.onDragStart) {
|
|
188
|
+
this._draggable.onDragStart({
|
|
189
|
+
dragStart: this._dragStart,
|
|
190
|
+
dragCurrent: this._dragCurrent,
|
|
191
|
+
dragEnd: this._dragEnd,
|
|
192
|
+
dragDelta: this._dragDelta
|
|
193
|
+
});
|
|
194
|
+
this._dragging = true;
|
|
195
|
+
this._controller.enabled = false;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
onPointerMove(e) {
|
|
199
|
+
var _a;
|
|
200
|
+
this._pointer.x = e.offsetX / this._canvas.clientWidth * 2 - 1;
|
|
201
|
+
this._pointer.y = -(e.offsetY / this._canvas.clientHeight) * 2 + 1;
|
|
202
|
+
this._raycaster.setFromCamera(this._pointer, this._controller.object);
|
|
203
|
+
this._intersects = this.raycast(this._scene.children);
|
|
204
|
+
const hoverable = findInterface(
|
|
205
|
+
(_a = this._intersects[0]) == null ? void 0 : _a.object,
|
|
206
|
+
"isHoverable"
|
|
207
|
+
);
|
|
208
|
+
if (this._intersects[0] && hoverable) {
|
|
209
|
+
if (!this._hovered) {
|
|
210
|
+
if (hoverable.onPointerEnter)
|
|
211
|
+
hoverable.onPointerEnter(this._intersects[0]);
|
|
212
|
+
this._hovered = hoverable;
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
if (this._hovered.uuid !== hoverable.uuid) {
|
|
216
|
+
if (this._hovered.onPointerLeave)
|
|
217
|
+
this._hovered.onPointerLeave();
|
|
218
|
+
if (hoverable.onPointerEnter)
|
|
219
|
+
hoverable.onPointerEnter(this._intersects[0]);
|
|
220
|
+
this._hovered = hoverable;
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
if (hoverable.onPointerOver)
|
|
224
|
+
hoverable.onPointerOver(this._intersects[0]);
|
|
225
|
+
this._hovered = hoverable;
|
|
226
|
+
} else {
|
|
227
|
+
if (this._hovered) {
|
|
228
|
+
if (this._hovered.onPointerLeave)
|
|
229
|
+
this._hovered.onPointerLeave();
|
|
230
|
+
}
|
|
231
|
+
this._hovered = null;
|
|
232
|
+
}
|
|
233
|
+
if (this._pointerAnyDown) {
|
|
234
|
+
if (!this._dragging) {
|
|
235
|
+
this.onDragStart(e);
|
|
236
|
+
}
|
|
237
|
+
this.onDrag(e);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
onDrag(e) {
|
|
241
|
+
if (this._dragRaycastOnObjects !== null) {
|
|
242
|
+
this._intersects = this._raycaster.intersectObjects(
|
|
243
|
+
this._dragRaycastOnObjects,
|
|
244
|
+
true
|
|
245
|
+
);
|
|
246
|
+
}
|
|
247
|
+
const intersect = this._intersects[0];
|
|
248
|
+
if (!intersect) return;
|
|
249
|
+
this._dragCurrent.copy(intersect.point.clone());
|
|
250
|
+
this._dragEnd.copy(intersect.point.clone());
|
|
251
|
+
this._dragDelta.subVectors(
|
|
252
|
+
this._dragCurrent.clone(),
|
|
253
|
+
this._dragStart.clone()
|
|
254
|
+
);
|
|
255
|
+
if (this._draggable && this._draggable.onDrag) {
|
|
256
|
+
this._draggable.onDrag({
|
|
257
|
+
dragStart: this._dragStart,
|
|
258
|
+
dragCurrent: this._dragCurrent,
|
|
259
|
+
dragEnd: this._dragEnd,
|
|
260
|
+
dragDelta: this._dragDelta
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
onPointerUp(e) {
|
|
265
|
+
if (this.pointerWasDragged() || this._dragging) {
|
|
266
|
+
if (this._draggable) {
|
|
267
|
+
this.onDragEnd(e);
|
|
268
|
+
}
|
|
269
|
+
} else {
|
|
270
|
+
this.onClick(e);
|
|
271
|
+
}
|
|
272
|
+
switch (e.button) {
|
|
273
|
+
case 0:
|
|
274
|
+
this._pointerPrimaryDown = false;
|
|
275
|
+
break;
|
|
276
|
+
case 1:
|
|
277
|
+
this._pointerMiddleDown = false;
|
|
278
|
+
break;
|
|
279
|
+
case 2:
|
|
280
|
+
this._pointerSecondaryDown = false;
|
|
281
|
+
break;
|
|
282
|
+
}
|
|
283
|
+
this._lastPointerUp.copy(this._pointer);
|
|
284
|
+
}
|
|
285
|
+
onClick(e) {
|
|
286
|
+
}
|
|
287
|
+
onDragEnd(e) {
|
|
288
|
+
const intersect = this._intersects[0];
|
|
289
|
+
if (intersect) {
|
|
290
|
+
this._dragEnd.copy(intersect.point.clone());
|
|
291
|
+
this._dragCurrent.copy(intersect.point.clone());
|
|
292
|
+
this._dragDelta.subVectors(
|
|
293
|
+
this._dragCurrent.clone(),
|
|
294
|
+
this._dragStart.clone()
|
|
295
|
+
);
|
|
296
|
+
}
|
|
297
|
+
if (this._draggable && this._draggable.onDragEnd) {
|
|
298
|
+
this._draggable.onDragEnd({
|
|
299
|
+
dragStart: this._dragStart,
|
|
300
|
+
dragCurrent: this._dragCurrent,
|
|
301
|
+
dragEnd: this._dragEnd,
|
|
302
|
+
dragDelta: this._dragDelta
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
this._draggable = null;
|
|
306
|
+
this._dragging = false;
|
|
307
|
+
this._dragStart.set(0, 0, 0);
|
|
308
|
+
this._dragCurrent.set(0, 0, 0);
|
|
309
|
+
this._dragEnd.set(0, 0, 0);
|
|
310
|
+
this._dragDelta.set(0, 0, 0);
|
|
311
|
+
this._controller.enabled = true;
|
|
312
|
+
}
|
|
313
|
+
onWheel(e) {
|
|
314
|
+
}
|
|
315
|
+
raycast(objects) {
|
|
316
|
+
if (objects !== void 0)
|
|
317
|
+
return this._raycaster.intersectObjects(objects, true).filter((i) => i.object.visible);
|
|
318
|
+
return this._raycaster.intersectObjects(this._scene.children, true).filter((i) => i.object.visible);
|
|
319
|
+
}
|
|
320
|
+
pointerWasDragged() {
|
|
321
|
+
return this._lastPointerDown.distanceTo(this._pointer) > this.POINTER_DRAG_THRESHOLD;
|
|
322
|
+
}
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
// src/toolbox/transform/TransformTool.ts
|
|
328
|
+
var import_Addons, DIVETransformTool;
|
|
329
|
+
var init_TransformTool = __esm({
|
|
330
|
+
"src/toolbox/transform/TransformTool.ts"() {
|
|
331
|
+
"use strict";
|
|
332
|
+
init_BaseTool();
|
|
333
|
+
import_Addons = require("three/examples/jsm/Addons");
|
|
334
|
+
init_implementsInterface();
|
|
335
|
+
DIVETransformTool = class extends DIVEBaseTool {
|
|
336
|
+
constructor(scene, controller) {
|
|
337
|
+
super(scene, controller);
|
|
338
|
+
this.isTransformTool = true;
|
|
339
|
+
this.name = "DIVETransformTool";
|
|
340
|
+
this._gizmo = new import_Addons.TransformControls(
|
|
341
|
+
this._controller.object,
|
|
342
|
+
this._controller.domElement
|
|
343
|
+
);
|
|
344
|
+
this._gizmo.mode = "translate";
|
|
345
|
+
this._gizmo.addEventListener("mouseDown", () => {
|
|
346
|
+
controller.enabled = false;
|
|
347
|
+
if (!implementsInterface(
|
|
348
|
+
this._gizmo.object,
|
|
349
|
+
"isMovable"
|
|
350
|
+
))
|
|
351
|
+
return;
|
|
352
|
+
if (!this._gizmo.object.onMoveStart) return;
|
|
353
|
+
this._gizmo.object.onMoveStart();
|
|
354
|
+
});
|
|
355
|
+
this._gizmo.addEventListener("objectChange", () => {
|
|
356
|
+
if (!implementsInterface(
|
|
357
|
+
this._gizmo.object,
|
|
358
|
+
"isMovable"
|
|
359
|
+
))
|
|
360
|
+
return;
|
|
361
|
+
if (!this._gizmo.object.onMove) return;
|
|
362
|
+
this._gizmo.object.onMove();
|
|
363
|
+
});
|
|
364
|
+
this._gizmo.addEventListener("mouseUp", () => {
|
|
365
|
+
controller.enabled = true;
|
|
366
|
+
if (!implementsInterface(
|
|
367
|
+
this._gizmo.object,
|
|
368
|
+
"isMovable"
|
|
369
|
+
))
|
|
370
|
+
return;
|
|
371
|
+
if (!this._gizmo.object.onMoveEnd) return;
|
|
372
|
+
this._gizmo.object.onMoveEnd();
|
|
373
|
+
});
|
|
374
|
+
scene.add(this._gizmo);
|
|
375
|
+
}
|
|
376
|
+
Activate() {
|
|
377
|
+
}
|
|
378
|
+
SetGizmoMode(mode) {
|
|
379
|
+
this._gizmo.mode = mode;
|
|
380
|
+
}
|
|
381
|
+
SetGizmoVisibility(active) {
|
|
382
|
+
const contains = this._scene.children.includes(this._gizmo);
|
|
383
|
+
if (active && !contains) {
|
|
384
|
+
this._scene.add(this._gizmo);
|
|
385
|
+
} else if (!active && contains) {
|
|
386
|
+
this._scene.remove(this._gizmo);
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
// public onPointerDown(e: PointerEvent): void {
|
|
390
|
+
// super.onPointerDown(e);
|
|
391
|
+
// // if (this._hovered) {
|
|
392
|
+
// // this._dragRaycastOnObjects = this._gizmo.gizmoPlane.children;
|
|
393
|
+
// // }
|
|
394
|
+
// }
|
|
395
|
+
// protected raycast(): Intersection[] {
|
|
396
|
+
// return super.raycast(this._gizmo.gizmoNode.children);
|
|
397
|
+
// }
|
|
398
|
+
};
|
|
399
|
+
}
|
|
400
|
+
});
|
|
401
|
+
|
|
402
|
+
// src/toolbox/select/SelectTool.ts
|
|
403
|
+
var SelectTool_exports = {};
|
|
404
|
+
__export(SelectTool_exports, {
|
|
405
|
+
DIVESelectTool: () => DIVESelectTool,
|
|
406
|
+
isSelectTool: () => isSelectTool
|
|
407
|
+
});
|
|
408
|
+
var isSelectTool, DIVESelectTool;
|
|
409
|
+
var init_SelectTool = __esm({
|
|
410
|
+
"src/toolbox/select/SelectTool.ts"() {
|
|
411
|
+
"use strict";
|
|
412
|
+
init_TransformTool();
|
|
413
|
+
init_findInterface();
|
|
414
|
+
isSelectTool = (tool) => {
|
|
415
|
+
return tool.isSelectTool !== void 0;
|
|
416
|
+
};
|
|
417
|
+
DIVESelectTool = class extends DIVETransformTool {
|
|
418
|
+
constructor(scene, controller) {
|
|
419
|
+
super(scene, controller);
|
|
420
|
+
this.isSelectTool = true;
|
|
421
|
+
this.name = "SelectTool";
|
|
422
|
+
}
|
|
423
|
+
Activate() {
|
|
424
|
+
}
|
|
425
|
+
Select(selectable) {
|
|
426
|
+
this.AttachGizmo(selectable);
|
|
427
|
+
if (selectable.onSelect) selectable.onSelect();
|
|
428
|
+
}
|
|
429
|
+
Deselect(selectable) {
|
|
430
|
+
this.DetachGizmo();
|
|
431
|
+
if (selectable.onDeselect) selectable.onDeselect();
|
|
432
|
+
}
|
|
433
|
+
AttachGizmo(selectable) {
|
|
434
|
+
if ("isMovable" in selectable) {
|
|
435
|
+
const movable = selectable;
|
|
436
|
+
this._gizmo.attach(movable);
|
|
437
|
+
this.SetGizmoVisibility(movable.visible);
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
DetachGizmo() {
|
|
441
|
+
this._gizmo.detach();
|
|
442
|
+
}
|
|
443
|
+
onClick(e) {
|
|
444
|
+
super.onClick(e);
|
|
445
|
+
const first = this._raycaster.intersectObjects(this._scene.Root.children, true).filter((intersect) => intersect.object.visible)[0];
|
|
446
|
+
const selectable = findInterface(
|
|
447
|
+
first == null ? void 0 : first.object,
|
|
448
|
+
"isSelectable"
|
|
449
|
+
);
|
|
450
|
+
if (!first || !selectable) {
|
|
451
|
+
if (this._gizmo.object) {
|
|
452
|
+
this.Deselect(this._gizmo.object);
|
|
453
|
+
}
|
|
454
|
+
return;
|
|
455
|
+
}
|
|
456
|
+
if (this._gizmo.object) {
|
|
457
|
+
if (this._gizmo.object.uuid === selectable.uuid) return;
|
|
458
|
+
this.Deselect(this._gizmo.object);
|
|
459
|
+
}
|
|
460
|
+
this.Select(selectable);
|
|
461
|
+
}
|
|
462
|
+
};
|
|
463
|
+
}
|
|
464
|
+
});
|
|
465
|
+
|
|
466
|
+
// src/camera/PerspectiveCamera.ts
|
|
467
|
+
var import_three4, DIVEPerspectiveCameraDefaultSettings, _DIVEPerspectiveCamera, DIVEPerspectiveCamera;
|
|
468
|
+
var init_PerspectiveCamera = __esm({
|
|
469
|
+
"src/camera/PerspectiveCamera.ts"() {
|
|
470
|
+
"use strict";
|
|
471
|
+
import_three4 = require("three");
|
|
472
|
+
init_VisibilityLayerMask();
|
|
473
|
+
DIVEPerspectiveCameraDefaultSettings = {
|
|
474
|
+
fov: 80,
|
|
475
|
+
near: 0.1,
|
|
476
|
+
far: 1e3
|
|
477
|
+
};
|
|
478
|
+
_DIVEPerspectiveCamera = class _DIVEPerspectiveCamera extends import_three4.PerspectiveCamera {
|
|
479
|
+
constructor(settings = DIVEPerspectiveCameraDefaultSettings) {
|
|
480
|
+
super(
|
|
481
|
+
settings.fov || DIVEPerspectiveCameraDefaultSettings.fov,
|
|
482
|
+
1,
|
|
483
|
+
settings.near || DIVEPerspectiveCameraDefaultSettings.near,
|
|
484
|
+
settings.far || DIVEPerspectiveCameraDefaultSettings.far
|
|
485
|
+
);
|
|
486
|
+
this.onSetCameraLayer = () => {
|
|
487
|
+
};
|
|
488
|
+
this.layers.mask = _DIVEPerspectiveCamera.EDITOR_VIEW_LAYER_MASK;
|
|
489
|
+
}
|
|
490
|
+
OnResize(width, height) {
|
|
491
|
+
this.aspect = width / height;
|
|
492
|
+
this.updateProjectionMatrix();
|
|
493
|
+
}
|
|
494
|
+
SetCameraLayer(layer) {
|
|
495
|
+
this.layers.mask = layer === "LIVE" ? _DIVEPerspectiveCamera.LIVE_VIEW_LAYER_MASK : _DIVEPerspectiveCamera.EDITOR_VIEW_LAYER_MASK;
|
|
496
|
+
this.onSetCameraLayer(this.layers.mask);
|
|
497
|
+
}
|
|
498
|
+
};
|
|
499
|
+
_DIVEPerspectiveCamera.EDITOR_VIEW_LAYER_MASK = DEFAULT_LAYER_MASK | UI_LAYER_MASK | HELPER_LAYER_MASK | PRODUCT_LAYER_MASK;
|
|
500
|
+
_DIVEPerspectiveCamera.LIVE_VIEW_LAYER_MASK = PRODUCT_LAYER_MASK;
|
|
501
|
+
DIVEPerspectiveCamera = _DIVEPerspectiveCamera;
|
|
502
|
+
}
|
|
503
|
+
});
|
|
504
|
+
|
|
505
|
+
// src/mediacreator/MediaCreator.ts
|
|
506
|
+
var MediaCreator_exports = {};
|
|
507
|
+
__export(MediaCreator_exports, {
|
|
508
|
+
DIVEMediaCreator: () => DIVEMediaCreator
|
|
509
|
+
});
|
|
510
|
+
var DIVEMediaCreator;
|
|
511
|
+
var init_MediaCreator = __esm({
|
|
512
|
+
"src/mediacreator/MediaCreator.ts"() {
|
|
513
|
+
"use strict";
|
|
514
|
+
init_PerspectiveCamera();
|
|
515
|
+
DIVEMediaCreator = class {
|
|
516
|
+
constructor(renderer, scene, controller) {
|
|
517
|
+
this.renderer = renderer;
|
|
518
|
+
this.scene = scene;
|
|
519
|
+
this.controller = controller;
|
|
520
|
+
}
|
|
521
|
+
GenerateMedia(position, target, width, height) {
|
|
522
|
+
const resetPosition = this.controller.object.position.clone();
|
|
523
|
+
const resetRotation = this.controller.object.quaternion.clone();
|
|
524
|
+
this.renderer.OnResize(width, height);
|
|
525
|
+
this.controller.object.OnResize(width, height);
|
|
526
|
+
this.controller.object.position.copy(position);
|
|
527
|
+
this.controller.target.copy(target);
|
|
528
|
+
this.controller.update();
|
|
529
|
+
const dataUri = this.DrawCanvas().toDataURL();
|
|
530
|
+
this.controller.object.position.copy(resetPosition);
|
|
531
|
+
this.controller.object.quaternion.copy(resetRotation);
|
|
532
|
+
return dataUri;
|
|
533
|
+
}
|
|
534
|
+
DrawCanvas(canvasElement) {
|
|
535
|
+
const restore = this.renderer.domElement;
|
|
536
|
+
if (canvasElement) {
|
|
537
|
+
this.renderer.domElement = canvasElement;
|
|
538
|
+
}
|
|
539
|
+
this.controller.object.layers.mask = DIVEPerspectiveCamera.LIVE_VIEW_LAYER_MASK;
|
|
540
|
+
this.renderer.render(this.scene, this.controller.object);
|
|
541
|
+
this.controller.object.layers.mask = DIVEPerspectiveCamera.EDITOR_VIEW_LAYER_MASK;
|
|
542
|
+
const returnCanvas = this.renderer.domElement;
|
|
543
|
+
if (canvasElement) {
|
|
544
|
+
this.renderer.domElement = restore;
|
|
545
|
+
}
|
|
546
|
+
return returnCanvas;
|
|
547
|
+
}
|
|
548
|
+
};
|
|
549
|
+
}
|
|
550
|
+
});
|
|
551
|
+
|
|
552
|
+
// src/io/gltf/GLTFIO.ts
|
|
553
|
+
var import_GLTFLoader, import_GLTFExporter, DIVEGLTFIO;
|
|
554
|
+
var init_GLTFIO = __esm({
|
|
555
|
+
"src/io/gltf/GLTFIO.ts"() {
|
|
556
|
+
"use strict";
|
|
557
|
+
import_GLTFLoader = require("three/examples/jsm/loaders/GLTFLoader");
|
|
558
|
+
import_GLTFExporter = require("three/examples/jsm/exporters/GLTFExporter");
|
|
559
|
+
DIVEGLTFIO = class {
|
|
560
|
+
constructor() {
|
|
561
|
+
this._importer = new import_GLTFLoader.GLTFLoader();
|
|
562
|
+
this._exporter = new import_GLTFExporter.GLTFExporter();
|
|
563
|
+
}
|
|
564
|
+
Import(url, onProgress) {
|
|
565
|
+
return this._importer.loadAsync(url, (progress) => {
|
|
566
|
+
if (!onProgress) return;
|
|
567
|
+
onProgress(progress.loaded / progress.total);
|
|
568
|
+
});
|
|
569
|
+
}
|
|
570
|
+
Export(object, binary, onlyVisible) {
|
|
571
|
+
if (binary) {
|
|
572
|
+
return this._exporter.parseAsync(object, {
|
|
573
|
+
binary,
|
|
574
|
+
onlyVisible
|
|
575
|
+
});
|
|
576
|
+
} else {
|
|
577
|
+
return this._exporter.parseAsync(object, {
|
|
578
|
+
binary,
|
|
579
|
+
onlyVisible
|
|
580
|
+
});
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
};
|
|
584
|
+
}
|
|
585
|
+
});
|
|
586
|
+
|
|
587
|
+
// src/io/IO.ts
|
|
588
|
+
var IO_exports = {};
|
|
589
|
+
__export(IO_exports, {
|
|
590
|
+
DIVEIO: () => DIVEIO
|
|
591
|
+
});
|
|
592
|
+
var DIVEIO;
|
|
593
|
+
var init_IO = __esm({
|
|
594
|
+
"src/io/IO.ts"() {
|
|
595
|
+
"use strict";
|
|
596
|
+
init_GLTFIO();
|
|
597
|
+
DIVEIO = class {
|
|
598
|
+
constructor(scene) {
|
|
599
|
+
this._scene = scene;
|
|
600
|
+
this._gltfIO = new DIVEGLTFIO();
|
|
601
|
+
}
|
|
602
|
+
Import(type, url) {
|
|
603
|
+
switch (type) {
|
|
604
|
+
case "glb": {
|
|
605
|
+
return this._gltfIO.Import(url).catch((error) => {
|
|
606
|
+
console.error(error);
|
|
607
|
+
return null;
|
|
608
|
+
});
|
|
609
|
+
}
|
|
610
|
+
default: {
|
|
611
|
+
console.error("DIVEIO.Import: Unsupported file type: " + type);
|
|
612
|
+
return Promise.reject();
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
Export(type) {
|
|
617
|
+
switch (type) {
|
|
618
|
+
case "glb": {
|
|
619
|
+
return this._gltfIO.Export(this._scene, true, true).then((data) => {
|
|
620
|
+
return this._createBlobURL(data);
|
|
621
|
+
}).catch((error) => {
|
|
622
|
+
console.error(error);
|
|
623
|
+
return null;
|
|
624
|
+
});
|
|
625
|
+
}
|
|
626
|
+
default: {
|
|
627
|
+
console.error("DIVEIO.Export: Unsupported file type: " + type);
|
|
628
|
+
return Promise.reject();
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
_createBlobURL(data) {
|
|
633
|
+
return URL.createObjectURL(new Blob([data]));
|
|
634
|
+
}
|
|
635
|
+
};
|
|
636
|
+
}
|
|
637
|
+
});
|
|
638
|
+
|
|
639
|
+
// src/dive.ts
|
|
640
|
+
var dive_exports = {};
|
|
641
|
+
__export(dive_exports, {
|
|
642
|
+
DIVE: () => DIVE,
|
|
643
|
+
DIVECommunication: () => DIVECommunication,
|
|
644
|
+
DIVEDefaultSettings: () => DIVEDefaultSettings,
|
|
645
|
+
DIVEMath: () => DIVEMath,
|
|
646
|
+
default: () => DIVE
|
|
647
|
+
});
|
|
648
|
+
module.exports = __toCommonJS(dive_exports);
|
|
649
|
+
|
|
650
|
+
// src/renderer/Renderer.ts
|
|
651
|
+
var import_three = require("three");
|
|
652
|
+
var DIVERendererDefaultSettings = {
|
|
653
|
+
antialias: true,
|
|
654
|
+
alpha: true,
|
|
655
|
+
stencil: false,
|
|
656
|
+
shadowMapEnabled: true,
|
|
657
|
+
shadowMapType: import_three.PCFSoftShadowMap,
|
|
658
|
+
toneMapping: import_three.NoToneMapping,
|
|
659
|
+
canvas: void 0
|
|
660
|
+
};
|
|
661
|
+
var DIVERenderer = class extends import_three.WebGLRenderer {
|
|
662
|
+
constructor(rendererSettings = DIVERendererDefaultSettings) {
|
|
663
|
+
super({
|
|
664
|
+
antialias: rendererSettings.antialias || DIVERendererDefaultSettings.antialias,
|
|
665
|
+
alpha: rendererSettings.alpha || DIVERendererDefaultSettings.alpha,
|
|
666
|
+
preserveDrawingBuffer: true,
|
|
667
|
+
canvas: rendererSettings.canvas
|
|
668
|
+
});
|
|
669
|
+
// basic functionality members
|
|
670
|
+
this.paused = false;
|
|
671
|
+
this.running = false;
|
|
672
|
+
this.force = false;
|
|
673
|
+
// pre- and post-render callbacks
|
|
674
|
+
this.preRenderCallbacks = /* @__PURE__ */ new Map();
|
|
675
|
+
this.postRenderCallbacks = /* @__PURE__ */ new Map();
|
|
676
|
+
this.setPixelRatio(window.devicePixelRatio);
|
|
677
|
+
this.shadowMap.enabled = rendererSettings.shadowMapEnabled || DIVERendererDefaultSettings.shadowMapEnabled;
|
|
678
|
+
this.shadowMap.type = rendererSettings.shadowMapType || DIVERendererDefaultSettings.shadowMapType;
|
|
679
|
+
this.toneMapping = rendererSettings.toneMapping || DIVERendererDefaultSettings.toneMapping;
|
|
680
|
+
this.debug.checkShaderErrors = false;
|
|
681
|
+
}
|
|
682
|
+
// Stops renderings and disposes the renderer.
|
|
683
|
+
Dispose() {
|
|
684
|
+
this.StopRenderer();
|
|
685
|
+
this.dispose();
|
|
686
|
+
}
|
|
687
|
+
// Starts the renderer with the given scene and camera.
|
|
688
|
+
StartRenderer(scene, cam) {
|
|
689
|
+
this.setAnimationLoop(() => {
|
|
690
|
+
this.internal_render(scene, cam);
|
|
691
|
+
});
|
|
692
|
+
this.running = true;
|
|
693
|
+
}
|
|
694
|
+
// Pauses the renderer.
|
|
695
|
+
PauseRenderer() {
|
|
696
|
+
this.paused = true;
|
|
697
|
+
}
|
|
698
|
+
// Resumes the renderer after pausing.
|
|
699
|
+
ResumeRenderer() {
|
|
700
|
+
this.paused = false;
|
|
701
|
+
}
|
|
702
|
+
// Stops the renderer completely. Has to be started again with StartRenderer().
|
|
703
|
+
StopRenderer() {
|
|
704
|
+
this.setAnimationLoop(null);
|
|
705
|
+
this.running = false;
|
|
706
|
+
}
|
|
707
|
+
// Resizes the renderer to the given width and height.
|
|
708
|
+
OnResize(width, height) {
|
|
709
|
+
this.setSize(width, height);
|
|
710
|
+
}
|
|
711
|
+
/**
|
|
712
|
+
* Adds a callback to the render loop before actual render call.
|
|
713
|
+
* @param callback Executed before rendering.
|
|
714
|
+
* @returns uuid to remove the callback.
|
|
715
|
+
*/
|
|
716
|
+
AddPreRenderCallback(callback) {
|
|
717
|
+
const newUUID = import_three.MathUtils.generateUUID();
|
|
718
|
+
this.preRenderCallbacks.set(newUUID, callback);
|
|
719
|
+
return newUUID;
|
|
720
|
+
}
|
|
721
|
+
/**
|
|
722
|
+
* Removes a callback from the render loop before actual render call.
|
|
723
|
+
* @param uuid of callback to remove.
|
|
724
|
+
* @returns if removing was successful.
|
|
725
|
+
*/
|
|
726
|
+
RemovePreRenderCallback(uuid) {
|
|
727
|
+
if (!this.preRenderCallbacks.has(uuid)) return false;
|
|
728
|
+
this.preRenderCallbacks.delete(uuid);
|
|
729
|
+
return true;
|
|
730
|
+
}
|
|
731
|
+
/**
|
|
732
|
+
* Adds a callback to the render loop after actual render call.
|
|
733
|
+
* @param callback Executed after rendering.
|
|
734
|
+
* @returns uuid to remove the callback.
|
|
735
|
+
*/
|
|
736
|
+
AddPostRenderCallback(callback) {
|
|
737
|
+
const newUUID = import_three.MathUtils.generateUUID();
|
|
738
|
+
this.postRenderCallbacks.set(newUUID, callback);
|
|
739
|
+
return newUUID;
|
|
740
|
+
}
|
|
741
|
+
/**
|
|
742
|
+
* Removes a callback from the render loop after actual render call.
|
|
743
|
+
* @param uuid of callback to remove.
|
|
744
|
+
* @returns if removing was successful.
|
|
745
|
+
*/
|
|
746
|
+
RemovePostRenderCallback(uuid) {
|
|
747
|
+
if (!this.postRenderCallbacks.has(uuid)) return false;
|
|
748
|
+
this.postRenderCallbacks.delete(uuid);
|
|
749
|
+
return true;
|
|
750
|
+
}
|
|
751
|
+
/**
|
|
752
|
+
* Forces the renderer to render the next frame.
|
|
753
|
+
*/
|
|
754
|
+
ForceRendering() {
|
|
755
|
+
this.force = true;
|
|
756
|
+
}
|
|
757
|
+
/**
|
|
758
|
+
* Internal render loop.
|
|
759
|
+
*
|
|
760
|
+
* To control renderloop you can add callbacks via AddPreRenderCallback() and AddPostRenderCallback().
|
|
761
|
+
* @param scene Scene to render.
|
|
762
|
+
* @param cam Camera to render with.
|
|
763
|
+
*/
|
|
764
|
+
internal_render(scene, cam) {
|
|
765
|
+
if ((this.paused || !this.running) && !this.force) return;
|
|
766
|
+
this.preRenderCallbacks.forEach((callback) => {
|
|
767
|
+
callback();
|
|
768
|
+
});
|
|
769
|
+
this.render(scene, cam);
|
|
770
|
+
this.postRenderCallbacks.forEach((callback) => {
|
|
771
|
+
callback();
|
|
772
|
+
});
|
|
773
|
+
this.force = false;
|
|
774
|
+
}
|
|
775
|
+
};
|
|
776
|
+
|
|
777
|
+
// src/scene/Scene.ts
|
|
778
|
+
var import_three14 = require("three");
|
|
779
|
+
|
|
780
|
+
// src/scene/root/Root.ts
|
|
781
|
+
var import_three11 = require("three");
|
|
782
|
+
|
|
783
|
+
// src/light/AmbientLight.ts
|
|
784
|
+
var import_three2 = require("three");
|
|
785
|
+
init_VisibilityLayerMask();
|
|
786
|
+
var DIVEAmbientLight = class extends import_three2.Object3D {
|
|
787
|
+
constructor() {
|
|
788
|
+
super();
|
|
789
|
+
this.isDIVELight = true;
|
|
790
|
+
this.isDIVEAmbientLight = true;
|
|
791
|
+
this.name = "DIVEAmbientLight";
|
|
792
|
+
this._light = new import_three2.AmbientLight(16777215, 1);
|
|
793
|
+
this._light.layers.mask = PRODUCT_LAYER_MASK;
|
|
794
|
+
this.add(this._light);
|
|
795
|
+
}
|
|
796
|
+
SetColor(color) {
|
|
797
|
+
this._light.color = color;
|
|
798
|
+
}
|
|
799
|
+
SetIntensity(intensity) {
|
|
800
|
+
this._light.intensity = intensity;
|
|
801
|
+
}
|
|
802
|
+
SetEnabled(enabled) {
|
|
803
|
+
this._light.visible = enabled;
|
|
804
|
+
}
|
|
805
|
+
};
|
|
806
|
+
|
|
807
|
+
// src/light/PointLight.ts
|
|
808
|
+
var import_three5 = require("three");
|
|
809
|
+
|
|
810
|
+
// src/com/Communication.ts
|
|
811
|
+
var import_MathUtils = require("three/src/math/MathUtils");
|
|
812
|
+
init_SelectTool();
|
|
813
|
+
var import_lodash = require("lodash");
|
|
814
|
+
var _DIVECommunication = class _DIVECommunication {
|
|
815
|
+
constructor(renderer, scene, controls, toolbox) {
|
|
816
|
+
this.registered = /* @__PURE__ */ new Map();
|
|
817
|
+
// private listeners: { [key: string]: EventListener[] } = {};
|
|
818
|
+
this.listeners = /* @__PURE__ */ new Map();
|
|
819
|
+
this._id = (0, import_MathUtils.generateUUID)();
|
|
820
|
+
this.renderer = renderer;
|
|
821
|
+
this.scene = scene;
|
|
822
|
+
this.controller = controls;
|
|
823
|
+
this.toolbox = toolbox;
|
|
824
|
+
this._mediaGenerator = null;
|
|
825
|
+
this._io = null;
|
|
826
|
+
_DIVECommunication.__instances.push(this);
|
|
827
|
+
}
|
|
828
|
+
static get(id) {
|
|
829
|
+
const fromComID = this.__instances.find(
|
|
830
|
+
(instance) => instance.id === id
|
|
831
|
+
);
|
|
832
|
+
if (fromComID) return fromComID;
|
|
833
|
+
return this.__instances.find(
|
|
834
|
+
(instance) => Array.from(instance.registered.values()).find(
|
|
835
|
+
(object) => object.id === id
|
|
836
|
+
)
|
|
837
|
+
);
|
|
838
|
+
}
|
|
839
|
+
get id() {
|
|
840
|
+
return this._id;
|
|
841
|
+
}
|
|
842
|
+
get mediaGenerator() {
|
|
843
|
+
if (!this._mediaGenerator) {
|
|
844
|
+
const DIVEMediaCreator2 = (init_MediaCreator(), __toCommonJS(MediaCreator_exports)).DIVEMediaCreator;
|
|
845
|
+
this._mediaGenerator = new DIVEMediaCreator2(
|
|
846
|
+
this.renderer,
|
|
847
|
+
this.scene,
|
|
848
|
+
this.controller
|
|
849
|
+
);
|
|
850
|
+
}
|
|
851
|
+
return this._mediaGenerator;
|
|
852
|
+
}
|
|
853
|
+
get io() {
|
|
854
|
+
if (!this._io) {
|
|
855
|
+
const DIVEIO2 = (init_IO(), __toCommonJS(IO_exports)).DIVEIO;
|
|
856
|
+
this._io = new DIVEIO2(this.scene);
|
|
857
|
+
}
|
|
858
|
+
return this._io;
|
|
859
|
+
}
|
|
860
|
+
DestroyInstance() {
|
|
861
|
+
const existingIndex = _DIVECommunication.__instances.findIndex(
|
|
862
|
+
(entry) => entry.id === this.id
|
|
863
|
+
);
|
|
864
|
+
if (existingIndex === -1) return false;
|
|
865
|
+
_DIVECommunication.__instances.splice(existingIndex, 1);
|
|
866
|
+
return true;
|
|
867
|
+
}
|
|
868
|
+
PerformAction(action, payload) {
|
|
869
|
+
let returnValue = false;
|
|
870
|
+
switch (action) {
|
|
871
|
+
case "GET_ALL_SCENE_DATA": {
|
|
872
|
+
returnValue = this.getAllSceneData(
|
|
873
|
+
payload
|
|
874
|
+
);
|
|
875
|
+
break;
|
|
876
|
+
}
|
|
877
|
+
case "GET_ALL_OBJECTS": {
|
|
878
|
+
returnValue = this.getAllObjects(
|
|
879
|
+
payload
|
|
880
|
+
);
|
|
881
|
+
break;
|
|
882
|
+
}
|
|
883
|
+
case "GET_OBJECTS": {
|
|
884
|
+
returnValue = this.getObjects(
|
|
885
|
+
payload
|
|
886
|
+
);
|
|
887
|
+
break;
|
|
888
|
+
}
|
|
889
|
+
case "ADD_OBJECT": {
|
|
890
|
+
returnValue = this.addObject(
|
|
891
|
+
payload
|
|
892
|
+
);
|
|
893
|
+
break;
|
|
894
|
+
}
|
|
895
|
+
case "UPDATE_OBJECT": {
|
|
896
|
+
returnValue = this.updateObject(
|
|
897
|
+
payload
|
|
898
|
+
);
|
|
899
|
+
break;
|
|
900
|
+
}
|
|
901
|
+
case "DELETE_OBJECT": {
|
|
902
|
+
returnValue = this.deleteObject(
|
|
903
|
+
payload
|
|
904
|
+
);
|
|
905
|
+
break;
|
|
906
|
+
}
|
|
907
|
+
case "SELECT_OBJECT": {
|
|
908
|
+
returnValue = this.selectObject(
|
|
909
|
+
payload
|
|
910
|
+
);
|
|
911
|
+
break;
|
|
912
|
+
}
|
|
913
|
+
case "DESELECT_OBJECT": {
|
|
914
|
+
returnValue = this.deselectObject(
|
|
915
|
+
payload
|
|
916
|
+
);
|
|
917
|
+
break;
|
|
918
|
+
}
|
|
919
|
+
case "SET_BACKGROUND": {
|
|
920
|
+
returnValue = this.setBackground(
|
|
921
|
+
payload
|
|
922
|
+
);
|
|
923
|
+
break;
|
|
924
|
+
}
|
|
925
|
+
case "DROP_IT": {
|
|
926
|
+
returnValue = this.dropIt(
|
|
927
|
+
payload
|
|
928
|
+
);
|
|
929
|
+
break;
|
|
930
|
+
}
|
|
931
|
+
case "PLACE_ON_FLOOR": {
|
|
932
|
+
returnValue = this.placeOnFloor(
|
|
933
|
+
payload
|
|
934
|
+
);
|
|
935
|
+
break;
|
|
936
|
+
}
|
|
937
|
+
case "SET_CAMERA_TRANSFORM": {
|
|
938
|
+
returnValue = this.setCameraTransform(
|
|
939
|
+
payload
|
|
940
|
+
);
|
|
941
|
+
break;
|
|
942
|
+
}
|
|
943
|
+
case "GET_CAMERA_TRANSFORM": {
|
|
944
|
+
returnValue = this.getCameraTransform(
|
|
945
|
+
payload
|
|
946
|
+
);
|
|
947
|
+
break;
|
|
948
|
+
}
|
|
949
|
+
case "MOVE_CAMERA": {
|
|
950
|
+
returnValue = this.moveCamera(
|
|
951
|
+
payload
|
|
952
|
+
);
|
|
953
|
+
break;
|
|
954
|
+
}
|
|
955
|
+
case "RESET_CAMERA": {
|
|
956
|
+
returnValue = this.resetCamera(
|
|
957
|
+
payload
|
|
958
|
+
);
|
|
959
|
+
break;
|
|
960
|
+
}
|
|
961
|
+
case "COMPUTE_ENCOMPASSING_VIEW": {
|
|
962
|
+
returnValue = this.computeEncompassingView(
|
|
963
|
+
payload
|
|
964
|
+
);
|
|
965
|
+
break;
|
|
966
|
+
}
|
|
967
|
+
case "SET_CAMERA_LAYER": {
|
|
968
|
+
returnValue = this.setCameraLayer(
|
|
969
|
+
payload
|
|
970
|
+
);
|
|
971
|
+
break;
|
|
972
|
+
}
|
|
973
|
+
case "ZOOM_CAMERA": {
|
|
974
|
+
returnValue = this.zoomCamera(
|
|
975
|
+
payload
|
|
976
|
+
);
|
|
977
|
+
break;
|
|
978
|
+
}
|
|
979
|
+
case "SET_GIZMO_MODE": {
|
|
980
|
+
returnValue = this.setGizmoMode(
|
|
981
|
+
payload
|
|
982
|
+
);
|
|
983
|
+
break;
|
|
984
|
+
}
|
|
985
|
+
case "SET_GIZMO_VISIBILITY": {
|
|
986
|
+
returnValue = this.setGizmoVisibility(
|
|
987
|
+
payload
|
|
988
|
+
);
|
|
989
|
+
break;
|
|
990
|
+
}
|
|
991
|
+
case "USE_TOOL": {
|
|
992
|
+
returnValue = this.useTool(
|
|
993
|
+
payload
|
|
994
|
+
);
|
|
995
|
+
break;
|
|
996
|
+
}
|
|
997
|
+
case "MODEL_LOADED": {
|
|
998
|
+
returnValue = this.modelLoaded(
|
|
999
|
+
payload
|
|
1000
|
+
);
|
|
1001
|
+
break;
|
|
1002
|
+
}
|
|
1003
|
+
case "UPDATE_SCENE": {
|
|
1004
|
+
returnValue = this.updateScene(
|
|
1005
|
+
payload
|
|
1006
|
+
);
|
|
1007
|
+
break;
|
|
1008
|
+
}
|
|
1009
|
+
case "GENERATE_MEDIA": {
|
|
1010
|
+
returnValue = this.generateMedia(
|
|
1011
|
+
payload
|
|
1012
|
+
);
|
|
1013
|
+
break;
|
|
1014
|
+
}
|
|
1015
|
+
case "SET_PARENT": {
|
|
1016
|
+
returnValue = this.setParent(
|
|
1017
|
+
payload
|
|
1018
|
+
);
|
|
1019
|
+
break;
|
|
1020
|
+
}
|
|
1021
|
+
case "EXPORT_SCENE": {
|
|
1022
|
+
returnValue = this.exportScene(
|
|
1023
|
+
payload
|
|
1024
|
+
);
|
|
1025
|
+
break;
|
|
1026
|
+
}
|
|
1027
|
+
default: {
|
|
1028
|
+
console.warn(
|
|
1029
|
+
`DIVECommunication.PerformAction: has been executed with unknown Action type ${action}`
|
|
1030
|
+
);
|
|
1031
|
+
}
|
|
1032
|
+
}
|
|
1033
|
+
this.dispatch(action, payload);
|
|
1034
|
+
return returnValue;
|
|
1035
|
+
}
|
|
1036
|
+
Subscribe(type, listener) {
|
|
1037
|
+
if (!this.listeners.get(type)) this.listeners.set(type, []);
|
|
1038
|
+
this.listeners.get(type).push(listener);
|
|
1039
|
+
return () => {
|
|
1040
|
+
const listenerArray = this.listeners.get(type);
|
|
1041
|
+
if (!listenerArray) return false;
|
|
1042
|
+
const existingIndex = listenerArray.findIndex(
|
|
1043
|
+
(entry) => entry === listener
|
|
1044
|
+
);
|
|
1045
|
+
if (existingIndex === -1) return false;
|
|
1046
|
+
listenerArray.splice(existingIndex, 1);
|
|
1047
|
+
return true;
|
|
1048
|
+
};
|
|
1049
|
+
}
|
|
1050
|
+
dispatch(type, payload) {
|
|
1051
|
+
const listenerArray = this.listeners.get(type);
|
|
1052
|
+
if (!listenerArray) return;
|
|
1053
|
+
listenerArray.forEach((listener) => listener(payload));
|
|
1054
|
+
}
|
|
1055
|
+
getAllSceneData(payload) {
|
|
1056
|
+
const sceneData = {
|
|
1057
|
+
name: this.scene.name,
|
|
1058
|
+
mediaItem: null,
|
|
1059
|
+
backgroundColor: "#" + this.scene.background.getHexString(),
|
|
1060
|
+
floorEnabled: this.scene.Floor.visible,
|
|
1061
|
+
floorColor: "#" + this.scene.Floor.material.color.getHexString(),
|
|
1062
|
+
userCamera: {
|
|
1063
|
+
position: this.controller.object.position.clone(),
|
|
1064
|
+
target: this.controller.target.clone()
|
|
1065
|
+
},
|
|
1066
|
+
spotmarks: [],
|
|
1067
|
+
lights: Array.from(this.registered.values()).filter(
|
|
1068
|
+
(object) => object.entityType === "light"
|
|
1069
|
+
),
|
|
1070
|
+
objects: Array.from(this.registered.values()).filter(
|
|
1071
|
+
(object) => object.entityType === "model"
|
|
1072
|
+
),
|
|
1073
|
+
cameras: Array.from(this.registered.values()).filter(
|
|
1074
|
+
(object) => object.entityType === "pov"
|
|
1075
|
+
),
|
|
1076
|
+
primitives: Array.from(this.registered.values()).filter(
|
|
1077
|
+
(object) => object.entityType === "primitive"
|
|
1078
|
+
),
|
|
1079
|
+
groups: Array.from(this.registered.values()).filter(
|
|
1080
|
+
(object) => object.entityType === "group"
|
|
1081
|
+
)
|
|
1082
|
+
};
|
|
1083
|
+
Object.assign(payload, sceneData);
|
|
1084
|
+
return sceneData;
|
|
1085
|
+
}
|
|
1086
|
+
getAllObjects(payload) {
|
|
1087
|
+
Object.assign(payload, this.registered);
|
|
1088
|
+
return this.registered;
|
|
1089
|
+
}
|
|
1090
|
+
getObjects(payload) {
|
|
1091
|
+
if (payload.ids.length === 0) return [];
|
|
1092
|
+
const objects = [];
|
|
1093
|
+
this.registered.forEach((object) => {
|
|
1094
|
+
if (!payload.ids.includes(object.id)) return;
|
|
1095
|
+
objects.push(object);
|
|
1096
|
+
});
|
|
1097
|
+
return objects;
|
|
1098
|
+
}
|
|
1099
|
+
addObject(payload) {
|
|
1100
|
+
if (this.registered.get(payload.id)) return false;
|
|
1101
|
+
if (payload.parentId === void 0) payload.parentId = null;
|
|
1102
|
+
this.registered.set(payload.id, payload);
|
|
1103
|
+
this.scene.AddSceneObject(payload);
|
|
1104
|
+
return true;
|
|
1105
|
+
}
|
|
1106
|
+
updateObject(payload) {
|
|
1107
|
+
const objectToUpdate = this.registered.get(payload.id);
|
|
1108
|
+
if (!objectToUpdate) return false;
|
|
1109
|
+
this.registered.set(payload.id, (0, import_lodash.merge)(objectToUpdate, payload));
|
|
1110
|
+
const updatedObject = this.registered.get(payload.id);
|
|
1111
|
+
this.scene.UpdateSceneObject(__spreadProps(__spreadValues({}, payload), {
|
|
1112
|
+
id: updatedObject.id,
|
|
1113
|
+
entityType: updatedObject.entityType
|
|
1114
|
+
}));
|
|
1115
|
+
Object.assign(payload, updatedObject);
|
|
1116
|
+
return true;
|
|
1117
|
+
}
|
|
1118
|
+
deleteObject(payload) {
|
|
1119
|
+
const deletedObject = this.registered.get(payload.id);
|
|
1120
|
+
if (!deletedObject) return false;
|
|
1121
|
+
Object.assign(payload, deletedObject);
|
|
1122
|
+
this.registered.delete(payload.id);
|
|
1123
|
+
Array.from(this.registered.values()).forEach((object) => {
|
|
1124
|
+
if (!object.parentId) return;
|
|
1125
|
+
if (object.parentId !== payload.id) return;
|
|
1126
|
+
object.parentId = null;
|
|
1127
|
+
});
|
|
1128
|
+
this.scene.DeleteSceneObject(deletedObject);
|
|
1129
|
+
return true;
|
|
1130
|
+
}
|
|
1131
|
+
selectObject(payload) {
|
|
1132
|
+
const object = this.registered.get(payload.id);
|
|
1133
|
+
if (!object) return false;
|
|
1134
|
+
const sceneObject = this.scene.GetSceneObject(object);
|
|
1135
|
+
if (!sceneObject) return false;
|
|
1136
|
+
if (!("isSelectable" in sceneObject)) return false;
|
|
1137
|
+
const activeTool = this.toolbox.GetActiveTool();
|
|
1138
|
+
if (activeTool && isSelectTool(activeTool)) {
|
|
1139
|
+
activeTool.AttachGizmo(sceneObject);
|
|
1140
|
+
}
|
|
1141
|
+
Object.assign(payload, object);
|
|
1142
|
+
return true;
|
|
1143
|
+
}
|
|
1144
|
+
deselectObject(payload) {
|
|
1145
|
+
const object = this.registered.get(payload.id);
|
|
1146
|
+
if (!object) return false;
|
|
1147
|
+
const sceneObject = this.scene.GetSceneObject(object);
|
|
1148
|
+
if (!sceneObject) return false;
|
|
1149
|
+
if (!("isSelectable" in sceneObject)) return false;
|
|
1150
|
+
const activeTool = this.toolbox.GetActiveTool();
|
|
1151
|
+
if (activeTool && isSelectTool(activeTool)) {
|
|
1152
|
+
activeTool.DetachGizmo();
|
|
1153
|
+
}
|
|
1154
|
+
Object.assign(payload, object);
|
|
1155
|
+
return true;
|
|
1156
|
+
}
|
|
1157
|
+
setBackground(payload) {
|
|
1158
|
+
this.scene.SetBackground(payload.color);
|
|
1159
|
+
return true;
|
|
1160
|
+
}
|
|
1161
|
+
dropIt(payload) {
|
|
1162
|
+
const object = this.registered.get(payload.id);
|
|
1163
|
+
if (!object) return false;
|
|
1164
|
+
const model = this.scene.GetSceneObject(object);
|
|
1165
|
+
model.DropIt();
|
|
1166
|
+
return true;
|
|
1167
|
+
}
|
|
1168
|
+
placeOnFloor(payload) {
|
|
1169
|
+
const object = this.registered.get(payload.id);
|
|
1170
|
+
if (!object) return false;
|
|
1171
|
+
this.scene.PlaceOnFloor(object);
|
|
1172
|
+
return true;
|
|
1173
|
+
}
|
|
1174
|
+
setCameraTransform(payload) {
|
|
1175
|
+
this.controller.object.position.copy(payload.position);
|
|
1176
|
+
this.controller.target.copy(payload.target);
|
|
1177
|
+
this.controller.update();
|
|
1178
|
+
return true;
|
|
1179
|
+
}
|
|
1180
|
+
getCameraTransform(payload) {
|
|
1181
|
+
const transform = {
|
|
1182
|
+
position: this.controller.object.position.clone(),
|
|
1183
|
+
target: this.controller.target.clone()
|
|
1184
|
+
};
|
|
1185
|
+
Object.assign(payload, transform);
|
|
1186
|
+
return transform;
|
|
1187
|
+
}
|
|
1188
|
+
moveCamera(payload) {
|
|
1189
|
+
let position = { x: 0, y: 0, z: 0 };
|
|
1190
|
+
let target = { x: 0, y: 0, z: 0 };
|
|
1191
|
+
if ("id" in payload) {
|
|
1192
|
+
position = this.registered.get(payload.id).position;
|
|
1193
|
+
target = this.registered.get(payload.id).target;
|
|
1194
|
+
} else {
|
|
1195
|
+
position = payload.position;
|
|
1196
|
+
target = payload.target;
|
|
1197
|
+
}
|
|
1198
|
+
this.controller.MoveTo(
|
|
1199
|
+
position,
|
|
1200
|
+
target,
|
|
1201
|
+
payload.duration,
|
|
1202
|
+
payload.locked
|
|
1203
|
+
);
|
|
1204
|
+
return true;
|
|
1205
|
+
}
|
|
1206
|
+
setCameraLayer(payload) {
|
|
1207
|
+
this.controller.object.SetCameraLayer(payload.layer);
|
|
1208
|
+
return true;
|
|
1209
|
+
}
|
|
1210
|
+
resetCamera(payload) {
|
|
1211
|
+
this.controller.RevertLast(payload.duration);
|
|
1212
|
+
return true;
|
|
1213
|
+
}
|
|
1214
|
+
computeEncompassingView(payload) {
|
|
1215
|
+
const sceneBB = this.scene.ComputeSceneBB();
|
|
1216
|
+
const transform = this.controller.ComputeEncompassingView(sceneBB);
|
|
1217
|
+
Object.assign(payload, transform);
|
|
1218
|
+
return transform;
|
|
1219
|
+
}
|
|
1220
|
+
zoomCamera(payload) {
|
|
1221
|
+
if (payload.direction === "IN") this.controller.ZoomIn(payload.by);
|
|
1222
|
+
if (payload.direction === "OUT") this.controller.ZoomOut(payload.by);
|
|
1223
|
+
return true;
|
|
1224
|
+
}
|
|
1225
|
+
setGizmoMode(payload) {
|
|
1226
|
+
this.toolbox.SetGizmoMode(payload.mode);
|
|
1227
|
+
return true;
|
|
1228
|
+
}
|
|
1229
|
+
setGizmoVisibility(payload) {
|
|
1230
|
+
this.toolbox.SetGizmoVisibility(payload);
|
|
1231
|
+
return payload;
|
|
1232
|
+
}
|
|
1233
|
+
useTool(payload) {
|
|
1234
|
+
this.toolbox.UseTool(payload.tool);
|
|
1235
|
+
return true;
|
|
1236
|
+
}
|
|
1237
|
+
modelLoaded(payload) {
|
|
1238
|
+
this.registered.get(payload.id).loaded = true;
|
|
1239
|
+
return true;
|
|
1240
|
+
}
|
|
1241
|
+
updateScene(payload) {
|
|
1242
|
+
if (payload.name !== void 0) this.scene.name = payload.name;
|
|
1243
|
+
if (payload.backgroundColor !== void 0)
|
|
1244
|
+
this.scene.SetBackground(payload.backgroundColor);
|
|
1245
|
+
if (payload.gridEnabled !== void 0)
|
|
1246
|
+
this.scene.Grid.SetVisibility(payload.gridEnabled);
|
|
1247
|
+
if (payload.floorEnabled !== void 0)
|
|
1248
|
+
this.scene.Floor.SetVisibility(payload.floorEnabled);
|
|
1249
|
+
if (payload.floorColor !== void 0)
|
|
1250
|
+
this.scene.Floor.SetColor(payload.floorColor);
|
|
1251
|
+
payload.name = this.scene.name;
|
|
1252
|
+
payload.backgroundColor = "#" + this.scene.background.getHexString();
|
|
1253
|
+
payload.gridEnabled = this.scene.Grid.visible;
|
|
1254
|
+
payload.floorEnabled = this.scene.Floor.visible;
|
|
1255
|
+
payload.floorColor = "#" + this.scene.Floor.material.color.getHexString();
|
|
1256
|
+
return true;
|
|
1257
|
+
}
|
|
1258
|
+
generateMedia(payload) {
|
|
1259
|
+
let position = { x: 0, y: 0, z: 0 };
|
|
1260
|
+
let target = { x: 0, y: 0, z: 0 };
|
|
1261
|
+
if ("id" in payload) {
|
|
1262
|
+
position = this.registered.get(payload.id).position;
|
|
1263
|
+
target = this.registered.get(payload.id).target;
|
|
1264
|
+
} else {
|
|
1265
|
+
position = payload.position;
|
|
1266
|
+
target = payload.target;
|
|
1267
|
+
}
|
|
1268
|
+
payload.dataUri = this.mediaGenerator.GenerateMedia(
|
|
1269
|
+
position,
|
|
1270
|
+
target,
|
|
1271
|
+
payload.width,
|
|
1272
|
+
payload.height
|
|
1273
|
+
);
|
|
1274
|
+
return true;
|
|
1275
|
+
}
|
|
1276
|
+
setParent(payload) {
|
|
1277
|
+
const object = this.registered.get(payload.object.id);
|
|
1278
|
+
if (!object) return false;
|
|
1279
|
+
const sceneObject = this.scene.GetSceneObject(object);
|
|
1280
|
+
if (!sceneObject) return false;
|
|
1281
|
+
if (payload.parent === null) {
|
|
1282
|
+
this.scene.Root.attach(sceneObject);
|
|
1283
|
+
return true;
|
|
1284
|
+
}
|
|
1285
|
+
if (payload.object.id === payload.parent.id) {
|
|
1286
|
+
return false;
|
|
1287
|
+
}
|
|
1288
|
+
const parent = this.registered.get(payload.parent.id);
|
|
1289
|
+
if (!parent) {
|
|
1290
|
+
this.scene.Root.attach(sceneObject);
|
|
1291
|
+
return true;
|
|
1292
|
+
}
|
|
1293
|
+
const parentObject = this.scene.GetSceneObject(parent);
|
|
1294
|
+
if (!parentObject) {
|
|
1295
|
+
this.scene.Root.attach(sceneObject);
|
|
1296
|
+
return true;
|
|
1297
|
+
}
|
|
1298
|
+
parentObject.attach(sceneObject);
|
|
1299
|
+
return true;
|
|
1300
|
+
}
|
|
1301
|
+
exportScene(payload) {
|
|
1302
|
+
return this.io.Export(payload.type);
|
|
1303
|
+
}
|
|
1304
|
+
};
|
|
1305
|
+
_DIVECommunication.__instances = [];
|
|
1306
|
+
var DIVECommunication = _DIVECommunication;
|
|
1307
|
+
|
|
1308
|
+
// src/light/PointLight.ts
|
|
1309
|
+
init_VisibilityLayerMask();
|
|
1310
|
+
var DIVEPointLight = class extends import_three5.Object3D {
|
|
1311
|
+
constructor() {
|
|
1312
|
+
super();
|
|
1313
|
+
this.isDIVELight = true;
|
|
1314
|
+
this.isDIVEPointLight = true;
|
|
1315
|
+
this.isMovable = true;
|
|
1316
|
+
this.isSelectable = true;
|
|
1317
|
+
this.gizmo = null;
|
|
1318
|
+
this.name = "DIVEPointLight";
|
|
1319
|
+
this.light = new import_three5.PointLight(16777215, 1);
|
|
1320
|
+
this.light.layers.mask = PRODUCT_LAYER_MASK;
|
|
1321
|
+
this.light.castShadow = true;
|
|
1322
|
+
this.light.shadow.mapSize.width = 512;
|
|
1323
|
+
this.light.shadow.mapSize.height = 512;
|
|
1324
|
+
this.add(this.light);
|
|
1325
|
+
const geoSize = 0.1;
|
|
1326
|
+
const geometry = new import_three5.SphereGeometry(
|
|
1327
|
+
geoSize,
|
|
1328
|
+
geoSize * 320,
|
|
1329
|
+
geoSize * 320
|
|
1330
|
+
);
|
|
1331
|
+
const material = new import_three5.MeshBasicMaterial({
|
|
1332
|
+
color: this.light.color,
|
|
1333
|
+
transparent: true,
|
|
1334
|
+
opacity: 0.8,
|
|
1335
|
+
side: import_three5.FrontSide
|
|
1336
|
+
});
|
|
1337
|
+
this.mesh = new import_three5.Mesh(geometry, material);
|
|
1338
|
+
this.mesh.layers.mask = UI_LAYER_MASK;
|
|
1339
|
+
this.add(this.mesh);
|
|
1340
|
+
}
|
|
1341
|
+
SetColor(color) {
|
|
1342
|
+
this.light.color = color;
|
|
1343
|
+
this.mesh.material.color = color;
|
|
1344
|
+
}
|
|
1345
|
+
SetIntensity(intensity) {
|
|
1346
|
+
this.light.intensity = intensity;
|
|
1347
|
+
this.mesh.material.opacity = intensity > 0.8 ? 0.8 : intensity * 0.8;
|
|
1348
|
+
}
|
|
1349
|
+
SetEnabled(enabled) {
|
|
1350
|
+
this.light.visible = enabled;
|
|
1351
|
+
}
|
|
1352
|
+
onMove() {
|
|
1353
|
+
var _a;
|
|
1354
|
+
(_a = DIVECommunication.get(this.userData.id)) == null ? void 0 : _a.PerformAction(
|
|
1355
|
+
"UPDATE_OBJECT",
|
|
1356
|
+
{ id: this.userData.id, position: this.position }
|
|
1357
|
+
);
|
|
1358
|
+
}
|
|
1359
|
+
onSelect() {
|
|
1360
|
+
var _a;
|
|
1361
|
+
(_a = DIVECommunication.get(this.userData.id)) == null ? void 0 : _a.PerformAction(
|
|
1362
|
+
"SELECT_OBJECT",
|
|
1363
|
+
{ id: this.userData.id }
|
|
1364
|
+
);
|
|
1365
|
+
}
|
|
1366
|
+
onDeselect() {
|
|
1367
|
+
var _a;
|
|
1368
|
+
(_a = DIVECommunication.get(this.userData.id)) == null ? void 0 : _a.PerformAction(
|
|
1369
|
+
"DESELECT_OBJECT",
|
|
1370
|
+
{ id: this.userData.id }
|
|
1371
|
+
);
|
|
1372
|
+
}
|
|
1373
|
+
};
|
|
1374
|
+
|
|
1375
|
+
// src/light/SceneLight.ts
|
|
1376
|
+
init_VisibilityLayerMask();
|
|
1377
|
+
var import_three6 = require("three");
|
|
1378
|
+
var DIVESceneLight = class extends import_three6.Object3D {
|
|
1379
|
+
constructor() {
|
|
1380
|
+
super();
|
|
1381
|
+
this.isDIVELight = true;
|
|
1382
|
+
this.isDIVESceneLight = true;
|
|
1383
|
+
this.name = "DIVESceneLight";
|
|
1384
|
+
this._hemiLight = new import_three6.HemisphereLight(16777215, 16777215, 2);
|
|
1385
|
+
this._hemiLight.layers.mask = PRODUCT_LAYER_MASK;
|
|
1386
|
+
this._hemiLight.position.set(0, 50, 0);
|
|
1387
|
+
this.add(this._hemiLight);
|
|
1388
|
+
this._dirLight = new import_three6.DirectionalLight(16777215, 3);
|
|
1389
|
+
this._dirLight.layers.mask = PRODUCT_LAYER_MASK;
|
|
1390
|
+
this._dirLight.position.set(1, 1.75, 1);
|
|
1391
|
+
this._dirLight.position.multiplyScalar(30);
|
|
1392
|
+
this._dirLight.castShadow = true;
|
|
1393
|
+
this._dirLight.shadow.mapSize.width = 2048;
|
|
1394
|
+
this._dirLight.shadow.mapSize.height = 2048;
|
|
1395
|
+
const d = 5;
|
|
1396
|
+
this._dirLight.shadow.camera.left = -d;
|
|
1397
|
+
this._dirLight.shadow.camera.right = d;
|
|
1398
|
+
this._dirLight.shadow.camera.top = d;
|
|
1399
|
+
this._dirLight.shadow.camera.bottom = -d;
|
|
1400
|
+
this._dirLight.shadow.camera.far = 3500;
|
|
1401
|
+
this.add(this._dirLight);
|
|
1402
|
+
}
|
|
1403
|
+
SetColor(color) {
|
|
1404
|
+
this._hemiLight.color = color;
|
|
1405
|
+
this._dirLight.color = color;
|
|
1406
|
+
}
|
|
1407
|
+
SetIntensity(intensity) {
|
|
1408
|
+
this._hemiLight.intensity = intensity * 2;
|
|
1409
|
+
this._dirLight.intensity = intensity * 3;
|
|
1410
|
+
}
|
|
1411
|
+
SetEnabled(enabled) {
|
|
1412
|
+
this._hemiLight.visible = enabled;
|
|
1413
|
+
this._dirLight.visible = enabled;
|
|
1414
|
+
}
|
|
1415
|
+
};
|
|
1416
|
+
|
|
1417
|
+
// src/model/Model.ts
|
|
1418
|
+
var import_three8 = require("three");
|
|
1419
|
+
init_VisibilityLayerMask();
|
|
1420
|
+
|
|
1421
|
+
// src/helper/findSceneRecursive/findSceneRecursive.ts
|
|
1422
|
+
var findSceneRecursive = (object) => {
|
|
1423
|
+
if (object.parent) {
|
|
1424
|
+
return findSceneRecursive(object.parent);
|
|
1425
|
+
}
|
|
1426
|
+
return object;
|
|
1427
|
+
};
|
|
1428
|
+
|
|
1429
|
+
// src/node/Node.ts
|
|
1430
|
+
var import_three7 = require("three");
|
|
1431
|
+
init_VisibilityLayerMask();
|
|
1432
|
+
var DIVENode = class extends import_three7.Object3D {
|
|
1433
|
+
constructor() {
|
|
1434
|
+
super();
|
|
1435
|
+
this.isDIVENode = true;
|
|
1436
|
+
this.isSelectable = true;
|
|
1437
|
+
this.isMovable = true;
|
|
1438
|
+
this.gizmo = null;
|
|
1439
|
+
this.layers.mask = PRODUCT_LAYER_MASK;
|
|
1440
|
+
this._positionWorldBuffer = new import_three7.Vector3();
|
|
1441
|
+
this._boundingBox = new import_three7.Box3();
|
|
1442
|
+
}
|
|
1443
|
+
SetPosition(position) {
|
|
1444
|
+
if (!this.parent) {
|
|
1445
|
+
this.position.set(position.x, position.y, position.z);
|
|
1446
|
+
return;
|
|
1447
|
+
}
|
|
1448
|
+
const newPosition = new import_three7.Vector3(position.x, position.y, position.z);
|
|
1449
|
+
this.position.copy(this.parent.worldToLocal(newPosition));
|
|
1450
|
+
if ("isDIVEGroup" in this.parent) {
|
|
1451
|
+
this.parent.UpdateLineTo(this);
|
|
1452
|
+
}
|
|
1453
|
+
}
|
|
1454
|
+
SetRotation(rotation) {
|
|
1455
|
+
this.rotation.set(rotation.x, rotation.y, rotation.z);
|
|
1456
|
+
}
|
|
1457
|
+
SetScale(scale) {
|
|
1458
|
+
this.scale.set(scale.x, scale.y, scale.z);
|
|
1459
|
+
}
|
|
1460
|
+
SetVisibility(visible) {
|
|
1461
|
+
this.visible = visible;
|
|
1462
|
+
}
|
|
1463
|
+
SetToWorldOrigin() {
|
|
1464
|
+
var _a;
|
|
1465
|
+
this.position.set(0, 0, 0);
|
|
1466
|
+
(_a = DIVECommunication.get(this.userData.id)) == null ? void 0 : _a.PerformAction(
|
|
1467
|
+
"UPDATE_OBJECT",
|
|
1468
|
+
{
|
|
1469
|
+
id: this.userData.id,
|
|
1470
|
+
position: this.getWorldPosition(this._positionWorldBuffer),
|
|
1471
|
+
rotation: this.rotation,
|
|
1472
|
+
scale: this.scale
|
|
1473
|
+
}
|
|
1474
|
+
);
|
|
1475
|
+
}
|
|
1476
|
+
/**
|
|
1477
|
+
* Can be called when the object is moved from a foreign object (gizmo, parent, etc.) to update the object's position.
|
|
1478
|
+
*/
|
|
1479
|
+
onMove() {
|
|
1480
|
+
var _a;
|
|
1481
|
+
(_a = DIVECommunication.get(this.userData.id)) == null ? void 0 : _a.PerformAction(
|
|
1482
|
+
"UPDATE_OBJECT",
|
|
1483
|
+
{
|
|
1484
|
+
id: this.userData.id,
|
|
1485
|
+
position: this.getWorldPosition(this._positionWorldBuffer),
|
|
1486
|
+
rotation: this.rotation,
|
|
1487
|
+
scale: this.scale
|
|
1488
|
+
}
|
|
1489
|
+
);
|
|
1490
|
+
}
|
|
1491
|
+
onSelect() {
|
|
1492
|
+
var _a;
|
|
1493
|
+
(_a = DIVECommunication.get(this.userData.id)) == null ? void 0 : _a.PerformAction(
|
|
1494
|
+
"SELECT_OBJECT",
|
|
1495
|
+
{ id: this.userData.id }
|
|
1496
|
+
);
|
|
1497
|
+
}
|
|
1498
|
+
onDeselect() {
|
|
1499
|
+
var _a;
|
|
1500
|
+
(_a = DIVECommunication.get(this.userData.id)) == null ? void 0 : _a.PerformAction(
|
|
1501
|
+
"DESELECT_OBJECT",
|
|
1502
|
+
{ id: this.userData.id }
|
|
1503
|
+
);
|
|
1504
|
+
}
|
|
1505
|
+
};
|
|
1506
|
+
|
|
1507
|
+
// src/model/Model.ts
|
|
1508
|
+
var DIVEModel = class extends DIVENode {
|
|
1509
|
+
constructor() {
|
|
1510
|
+
super(...arguments);
|
|
1511
|
+
this.isDIVEModel = true;
|
|
1512
|
+
this._mesh = null;
|
|
1513
|
+
this._material = null;
|
|
1514
|
+
}
|
|
1515
|
+
SetModel(gltf) {
|
|
1516
|
+
this.clear();
|
|
1517
|
+
this._boundingBox.makeEmpty();
|
|
1518
|
+
gltf.scene.traverse((child) => {
|
|
1519
|
+
child.castShadow = true;
|
|
1520
|
+
child.receiveShadow = true;
|
|
1521
|
+
child.layers.mask = this.layers.mask;
|
|
1522
|
+
this._boundingBox.expandByObject(child);
|
|
1523
|
+
if (!this._mesh && "isMesh" in child) {
|
|
1524
|
+
this._mesh = child;
|
|
1525
|
+
if (this._material) {
|
|
1526
|
+
this._mesh.material = this._material;
|
|
1527
|
+
} else {
|
|
1528
|
+
this._material = child.material;
|
|
1529
|
+
}
|
|
1530
|
+
}
|
|
1531
|
+
});
|
|
1532
|
+
this.add(gltf.scene);
|
|
1533
|
+
}
|
|
1534
|
+
SetMaterial(material) {
|
|
1535
|
+
if (!this._material) {
|
|
1536
|
+
this._material = new import_three8.MeshStandardMaterial();
|
|
1537
|
+
}
|
|
1538
|
+
if (material.vertexColors !== void 0) {
|
|
1539
|
+
this._material.vertexColors = material.vertexColors;
|
|
1540
|
+
}
|
|
1541
|
+
if (material.color !== void 0) {
|
|
1542
|
+
this._material.color.set(material.color);
|
|
1543
|
+
}
|
|
1544
|
+
if (material.map !== void 0) {
|
|
1545
|
+
this._material.map = material.map;
|
|
1546
|
+
}
|
|
1547
|
+
if (material.normalMap !== void 0) {
|
|
1548
|
+
this._material.normalMap = material.normalMap;
|
|
1549
|
+
}
|
|
1550
|
+
if (material.roughness !== void 0) {
|
|
1551
|
+
this._material.roughness = material.roughness;
|
|
1552
|
+
}
|
|
1553
|
+
if (material.roughnessMap !== void 0) {
|
|
1554
|
+
this._material.roughnessMap = material.roughnessMap;
|
|
1555
|
+
if (this._material.roughnessMap) {
|
|
1556
|
+
this._material.roughness = 1;
|
|
1557
|
+
}
|
|
1558
|
+
}
|
|
1559
|
+
if (material.metalness !== void 0) {
|
|
1560
|
+
this._material.metalness = material.metalness;
|
|
1561
|
+
}
|
|
1562
|
+
if (material.metalnessMap !== void 0) {
|
|
1563
|
+
this._material.metalnessMap = material.metalnessMap;
|
|
1564
|
+
if (this._material.metalnessMap) {
|
|
1565
|
+
this._material.metalness = 1;
|
|
1566
|
+
}
|
|
1567
|
+
}
|
|
1568
|
+
if (this._mesh) {
|
|
1569
|
+
this._mesh.material = this._material;
|
|
1570
|
+
}
|
|
1571
|
+
}
|
|
1572
|
+
PlaceOnFloor() {
|
|
1573
|
+
var _a;
|
|
1574
|
+
const worldPos = this.getWorldPosition(this._positionWorldBuffer);
|
|
1575
|
+
const oldWorldPos = worldPos.clone();
|
|
1576
|
+
worldPos.y = (this._boundingBox.max.y - this._boundingBox.min.y) / 2;
|
|
1577
|
+
if (worldPos.y === oldWorldPos.y) return;
|
|
1578
|
+
(_a = DIVECommunication.get(this.userData.id)) == null ? void 0 : _a.PerformAction(
|
|
1579
|
+
"UPDATE_OBJECT",
|
|
1580
|
+
{
|
|
1581
|
+
id: this.userData.id,
|
|
1582
|
+
position: worldPos,
|
|
1583
|
+
rotation: this.rotation,
|
|
1584
|
+
scale: this.scale
|
|
1585
|
+
}
|
|
1586
|
+
);
|
|
1587
|
+
}
|
|
1588
|
+
DropIt() {
|
|
1589
|
+
if (!this.parent) {
|
|
1590
|
+
console.warn(
|
|
1591
|
+
"DIVEModel: DropIt() called on a model that is not in the scene.",
|
|
1592
|
+
this
|
|
1593
|
+
);
|
|
1594
|
+
return;
|
|
1595
|
+
}
|
|
1596
|
+
const bottomY = this._boundingBox.min.y * this.scale.y;
|
|
1597
|
+
const bbBottomCenter = this.localToWorld(
|
|
1598
|
+
this._boundingBox.getCenter(new import_three8.Vector3()).multiply(this.scale)
|
|
1599
|
+
);
|
|
1600
|
+
bbBottomCenter.y = bottomY + this.position.y;
|
|
1601
|
+
const raycaster = new import_three8.Raycaster(bbBottomCenter, new import_three8.Vector3(0, -1, 0));
|
|
1602
|
+
raycaster.layers.mask = PRODUCT_LAYER_MASK;
|
|
1603
|
+
const intersections = raycaster.intersectObjects(
|
|
1604
|
+
findSceneRecursive(this).Root.children,
|
|
1605
|
+
true
|
|
1606
|
+
);
|
|
1607
|
+
if (intersections.length > 0) {
|
|
1608
|
+
const mesh = intersections[0].object;
|
|
1609
|
+
mesh.geometry.computeBoundingBox();
|
|
1610
|
+
const meshBB = mesh.geometry.boundingBox;
|
|
1611
|
+
const worldPos = mesh.localToWorld(meshBB.max.clone());
|
|
1612
|
+
const oldPos = this.position.clone();
|
|
1613
|
+
const newPos = this.position.clone().setY(worldPos.y).sub(new import_three8.Vector3(0, bottomY, 0));
|
|
1614
|
+
this.position.copy(newPos);
|
|
1615
|
+
if (this.position.y === oldPos.y) return;
|
|
1616
|
+
this.onMove();
|
|
1617
|
+
}
|
|
1618
|
+
}
|
|
1619
|
+
};
|
|
1620
|
+
|
|
1621
|
+
// src/loadingmanager/LoadingManager.ts
|
|
1622
|
+
var import_Addons2 = require("three/examples/jsm/Addons.js");
|
|
1623
|
+
var DIVELoadingManager = class {
|
|
1624
|
+
// ... maybe extend with other loaders later
|
|
1625
|
+
constructor() {
|
|
1626
|
+
this.progress = /* @__PURE__ */ new Map();
|
|
1627
|
+
this.gltfloader = new import_Addons2.GLTFLoader();
|
|
1628
|
+
this.dracoloader = new import_Addons2.DRACOLoader();
|
|
1629
|
+
this.dracoloader.setDecoderPath(
|
|
1630
|
+
"https://www.gstatic.com/draco/v1/decoders/"
|
|
1631
|
+
);
|
|
1632
|
+
this.gltfloader.setDRACOLoader(this.dracoloader);
|
|
1633
|
+
}
|
|
1634
|
+
LoadGLTF(uri) {
|
|
1635
|
+
return __async(this, null, function* () {
|
|
1636
|
+
const progEvent = (p) => {
|
|
1637
|
+
this.progress.set(uri, p.loaded / p.total);
|
|
1638
|
+
};
|
|
1639
|
+
this.progress.set(uri, 0);
|
|
1640
|
+
return new Promise((resolve, reject) => {
|
|
1641
|
+
this.gltfloader.loadAsync(uri, progEvent).then(resolve).catch(reject);
|
|
1642
|
+
});
|
|
1643
|
+
});
|
|
1644
|
+
}
|
|
1645
|
+
PollProgress() {
|
|
1646
|
+
let total = 0;
|
|
1647
|
+
this.progress.forEach((progress) => {
|
|
1648
|
+
total += progress;
|
|
1649
|
+
});
|
|
1650
|
+
if (this.progress.size === 0) return 1;
|
|
1651
|
+
return total / this.progress.size;
|
|
1652
|
+
}
|
|
1653
|
+
};
|
|
1654
|
+
|
|
1655
|
+
// src/primitive/Primitive.ts
|
|
1656
|
+
var import_three9 = require("three");
|
|
1657
|
+
init_VisibilityLayerMask();
|
|
1658
|
+
var DIVEPrimitive = class extends DIVENode {
|
|
1659
|
+
constructor() {
|
|
1660
|
+
super();
|
|
1661
|
+
this.isDIVEPrimitive = true;
|
|
1662
|
+
this._mesh = new import_three9.Mesh();
|
|
1663
|
+
this._mesh.layers.mask = PRODUCT_LAYER_MASK;
|
|
1664
|
+
this._mesh.castShadow = true;
|
|
1665
|
+
this._mesh.receiveShadow = true;
|
|
1666
|
+
this._mesh.material = new import_three9.MeshStandardMaterial();
|
|
1667
|
+
this.add(this._mesh);
|
|
1668
|
+
}
|
|
1669
|
+
SetGeometry(geometry) {
|
|
1670
|
+
const geo = this.assembleGeometry(geometry);
|
|
1671
|
+
if (!geo) return;
|
|
1672
|
+
this._mesh.geometry = geo;
|
|
1673
|
+
this._boundingBox.setFromObject(this._mesh);
|
|
1674
|
+
}
|
|
1675
|
+
SetMaterial(material) {
|
|
1676
|
+
const primitiveMaterial = this._mesh.material;
|
|
1677
|
+
if (material.vertexColors !== void 0) {
|
|
1678
|
+
primitiveMaterial.vertexColors = material.vertexColors;
|
|
1679
|
+
}
|
|
1680
|
+
if (material.color !== void 0) {
|
|
1681
|
+
primitiveMaterial.color = new import_three9.Color(material.color);
|
|
1682
|
+
}
|
|
1683
|
+
if (material.map !== void 0) {
|
|
1684
|
+
primitiveMaterial.map = material.map;
|
|
1685
|
+
}
|
|
1686
|
+
if (material.normalMap !== void 0) {
|
|
1687
|
+
primitiveMaterial.normalMap = material.normalMap;
|
|
1688
|
+
}
|
|
1689
|
+
if (material.roughness !== void 0) {
|
|
1690
|
+
primitiveMaterial.roughness = material.roughness;
|
|
1691
|
+
}
|
|
1692
|
+
if (material.roughnessMap !== void 0) {
|
|
1693
|
+
primitiveMaterial.roughnessMap = material.roughnessMap;
|
|
1694
|
+
if (primitiveMaterial.roughnessMap) {
|
|
1695
|
+
primitiveMaterial.roughness = 1;
|
|
1696
|
+
}
|
|
1697
|
+
}
|
|
1698
|
+
if (material.metalness !== void 0) {
|
|
1699
|
+
primitiveMaterial.metalness = material.metalness;
|
|
1700
|
+
}
|
|
1701
|
+
if (material.metalnessMap !== void 0) {
|
|
1702
|
+
primitiveMaterial.metalnessMap = material.metalnessMap;
|
|
1703
|
+
if (primitiveMaterial.metalnessMap) {
|
|
1704
|
+
primitiveMaterial.metalness = 0;
|
|
1705
|
+
}
|
|
1706
|
+
}
|
|
1707
|
+
if (this._mesh) this._mesh.material = primitiveMaterial;
|
|
1708
|
+
}
|
|
1709
|
+
PlaceOnFloor() {
|
|
1710
|
+
var _a;
|
|
1711
|
+
const worldPos = this.getWorldPosition(this._positionWorldBuffer);
|
|
1712
|
+
const oldWorldPos = worldPos.clone();
|
|
1713
|
+
worldPos.y = (this._boundingBox.max.y - this._boundingBox.min.y) / 2;
|
|
1714
|
+
if (worldPos.y === oldWorldPos.y) return;
|
|
1715
|
+
(_a = DIVECommunication.get(this.userData.id)) == null ? void 0 : _a.PerformAction(
|
|
1716
|
+
"UPDATE_OBJECT",
|
|
1717
|
+
{
|
|
1718
|
+
id: this.userData.id,
|
|
1719
|
+
position: worldPos,
|
|
1720
|
+
rotation: this.rotation,
|
|
1721
|
+
scale: this.scale
|
|
1722
|
+
}
|
|
1723
|
+
);
|
|
1724
|
+
}
|
|
1725
|
+
DropIt() {
|
|
1726
|
+
if (!this.parent) {
|
|
1727
|
+
console.warn(
|
|
1728
|
+
"DIVEPrimitive: DropIt() called on a model that is not in the scene.",
|
|
1729
|
+
this
|
|
1730
|
+
);
|
|
1731
|
+
return;
|
|
1732
|
+
}
|
|
1733
|
+
const bottomY = this._boundingBox.min.y * this.scale.y;
|
|
1734
|
+
const bbBottomCenter = this.localToWorld(
|
|
1735
|
+
this._boundingBox.getCenter(new import_three9.Vector3()).multiply(this.scale)
|
|
1736
|
+
);
|
|
1737
|
+
bbBottomCenter.y = bottomY + this.position.y;
|
|
1738
|
+
const raycaster = new import_three9.Raycaster(bbBottomCenter, new import_three9.Vector3(0, -1, 0));
|
|
1739
|
+
raycaster.layers.mask = PRODUCT_LAYER_MASK;
|
|
1740
|
+
const intersections = raycaster.intersectObjects(
|
|
1741
|
+
findSceneRecursive(this).Root.children,
|
|
1742
|
+
true
|
|
1743
|
+
);
|
|
1744
|
+
if (intersections.length > 0) {
|
|
1745
|
+
const mesh = intersections[0].object;
|
|
1746
|
+
mesh.geometry.computeBoundingBox();
|
|
1747
|
+
const meshBB = mesh.geometry.boundingBox;
|
|
1748
|
+
const worldPos = mesh.localToWorld(meshBB.max.clone());
|
|
1749
|
+
const oldPos = this.position.clone();
|
|
1750
|
+
const newPos = this.position.clone().setY(worldPos.y).sub(new import_three9.Vector3(0, bottomY, 0));
|
|
1751
|
+
this.position.copy(newPos);
|
|
1752
|
+
if (this.position.y === oldPos.y) return;
|
|
1753
|
+
this.onMove();
|
|
1754
|
+
}
|
|
1755
|
+
}
|
|
1756
|
+
assembleGeometry(geometry) {
|
|
1757
|
+
this._mesh.material.flatShading = false;
|
|
1758
|
+
switch (geometry.name.toLowerCase()) {
|
|
1759
|
+
case "cylinder":
|
|
1760
|
+
return this.createCylinderGeometry(geometry);
|
|
1761
|
+
case "sphere":
|
|
1762
|
+
return this.createSphereGeometry(geometry);
|
|
1763
|
+
case "pyramid":
|
|
1764
|
+
this._mesh.material.flatShading = true;
|
|
1765
|
+
return this.createPyramidGeometry(geometry);
|
|
1766
|
+
case "cube":
|
|
1767
|
+
case "box":
|
|
1768
|
+
return this.createBoxGeometry(geometry);
|
|
1769
|
+
case "cone":
|
|
1770
|
+
return this.createConeGeometry(geometry);
|
|
1771
|
+
case "wall":
|
|
1772
|
+
return this.createWallGeometry(geometry);
|
|
1773
|
+
case "plane":
|
|
1774
|
+
return this.createPlaneGeometry(geometry);
|
|
1775
|
+
default: {
|
|
1776
|
+
console.warn(
|
|
1777
|
+
"DIVEPrimitive.assembleGeometry: Invalid geometry type:",
|
|
1778
|
+
geometry.name.toLowerCase()
|
|
1779
|
+
);
|
|
1780
|
+
return null;
|
|
1781
|
+
}
|
|
1782
|
+
}
|
|
1783
|
+
}
|
|
1784
|
+
createCylinderGeometry(geometry) {
|
|
1785
|
+
const geo = new import_three9.CylinderGeometry(
|
|
1786
|
+
geometry.width / 2,
|
|
1787
|
+
geometry.width / 2,
|
|
1788
|
+
geometry.height,
|
|
1789
|
+
64
|
|
1790
|
+
);
|
|
1791
|
+
geo.translate(0, geometry.height / 2, 0);
|
|
1792
|
+
return geo;
|
|
1793
|
+
}
|
|
1794
|
+
createSphereGeometry(geometry) {
|
|
1795
|
+
const geo = new import_three9.SphereGeometry(geometry.width / 2, 256, 256);
|
|
1796
|
+
return geo;
|
|
1797
|
+
}
|
|
1798
|
+
createPyramidGeometry(geometry) {
|
|
1799
|
+
const vertices = new Float32Array([
|
|
1800
|
+
-geometry.width / 2,
|
|
1801
|
+
0,
|
|
1802
|
+
-geometry.depth / 2,
|
|
1803
|
+
// 0
|
|
1804
|
+
geometry.width / 2,
|
|
1805
|
+
0,
|
|
1806
|
+
-geometry.depth / 2,
|
|
1807
|
+
// 1
|
|
1808
|
+
geometry.width / 2,
|
|
1809
|
+
0,
|
|
1810
|
+
geometry.depth / 2,
|
|
1811
|
+
// 2
|
|
1812
|
+
-geometry.width / 2,
|
|
1813
|
+
0,
|
|
1814
|
+
geometry.depth / 2,
|
|
1815
|
+
// 3
|
|
1816
|
+
0,
|
|
1817
|
+
geometry.height,
|
|
1818
|
+
0
|
|
1819
|
+
]);
|
|
1820
|
+
const indices = new Uint16Array([
|
|
1821
|
+
0,
|
|
1822
|
+
1,
|
|
1823
|
+
2,
|
|
1824
|
+
0,
|
|
1825
|
+
2,
|
|
1826
|
+
3,
|
|
1827
|
+
0,
|
|
1828
|
+
4,
|
|
1829
|
+
1,
|
|
1830
|
+
1,
|
|
1831
|
+
4,
|
|
1832
|
+
2,
|
|
1833
|
+
2,
|
|
1834
|
+
4,
|
|
1835
|
+
3,
|
|
1836
|
+
3,
|
|
1837
|
+
4,
|
|
1838
|
+
0
|
|
1839
|
+
]);
|
|
1840
|
+
const geometryBuffer = new import_three9.BufferGeometry();
|
|
1841
|
+
geometryBuffer.setAttribute(
|
|
1842
|
+
"position",
|
|
1843
|
+
new import_three9.BufferAttribute(vertices, 3)
|
|
1844
|
+
);
|
|
1845
|
+
geometryBuffer.setIndex(new import_three9.BufferAttribute(indices, 1));
|
|
1846
|
+
geometryBuffer.computeVertexNormals();
|
|
1847
|
+
geometryBuffer.computeBoundingBox();
|
|
1848
|
+
geometryBuffer.computeBoundingSphere();
|
|
1849
|
+
return geometryBuffer;
|
|
1850
|
+
}
|
|
1851
|
+
createBoxGeometry(geometry) {
|
|
1852
|
+
const geo = new import_three9.BoxGeometry(
|
|
1853
|
+
geometry.width,
|
|
1854
|
+
geometry.height,
|
|
1855
|
+
geometry.depth
|
|
1856
|
+
);
|
|
1857
|
+
geo.translate(0, geometry.height / 2, 0);
|
|
1858
|
+
return geo;
|
|
1859
|
+
}
|
|
1860
|
+
createConeGeometry(geometry) {
|
|
1861
|
+
const geo = new import_three9.ConeGeometry(geometry.width / 2, geometry.height, 256);
|
|
1862
|
+
geo.translate(0, geometry.height / 2, 0);
|
|
1863
|
+
return geo;
|
|
1864
|
+
}
|
|
1865
|
+
createWallGeometry(geometry) {
|
|
1866
|
+
const geo = new import_three9.BoxGeometry(
|
|
1867
|
+
geometry.width,
|
|
1868
|
+
geometry.height,
|
|
1869
|
+
geometry.depth || 0.05,
|
|
1870
|
+
16
|
|
1871
|
+
);
|
|
1872
|
+
geo.translate(0, geometry.height / 2, 0);
|
|
1873
|
+
return geo;
|
|
1874
|
+
}
|
|
1875
|
+
createPlaneGeometry(geometry) {
|
|
1876
|
+
const geo = new import_three9.BoxGeometry(
|
|
1877
|
+
geometry.width,
|
|
1878
|
+
geometry.height,
|
|
1879
|
+
geometry.depth
|
|
1880
|
+
);
|
|
1881
|
+
geo.translate(0, geometry.height / 2, 0);
|
|
1882
|
+
return geo;
|
|
1883
|
+
}
|
|
1884
|
+
};
|
|
1885
|
+
|
|
1886
|
+
// src/group/Group.ts
|
|
1887
|
+
var import_three10 = require("three");
|
|
1888
|
+
var DIVEGroup = class extends DIVENode {
|
|
1889
|
+
// lines to children
|
|
1890
|
+
constructor() {
|
|
1891
|
+
super();
|
|
1892
|
+
this.isDIVEGroup = true;
|
|
1893
|
+
this.name = "DIVEGroup";
|
|
1894
|
+
this._members = [];
|
|
1895
|
+
this._lines = [];
|
|
1896
|
+
}
|
|
1897
|
+
// children objects
|
|
1898
|
+
get members() {
|
|
1899
|
+
return this._members;
|
|
1900
|
+
}
|
|
1901
|
+
SetPosition(position) {
|
|
1902
|
+
super.SetPosition(position);
|
|
1903
|
+
this._members.forEach((member) => {
|
|
1904
|
+
if ("isDIVENode" in member) {
|
|
1905
|
+
member.onMove();
|
|
1906
|
+
}
|
|
1907
|
+
});
|
|
1908
|
+
}
|
|
1909
|
+
SetLinesVisibility(visible, object) {
|
|
1910
|
+
if (!object) {
|
|
1911
|
+
this._lines.forEach((line) => {
|
|
1912
|
+
line.visible = visible;
|
|
1913
|
+
});
|
|
1914
|
+
return;
|
|
1915
|
+
}
|
|
1916
|
+
const index = this._members.indexOf(object);
|
|
1917
|
+
if (index === -1) return;
|
|
1918
|
+
this._lines[index].visible = visible;
|
|
1919
|
+
}
|
|
1920
|
+
attach(object) {
|
|
1921
|
+
const line = this.createLine();
|
|
1922
|
+
this.add(line);
|
|
1923
|
+
this._lines.push(line);
|
|
1924
|
+
super.attach(object);
|
|
1925
|
+
this._members.push(object);
|
|
1926
|
+
this.updateLineTo(line, object);
|
|
1927
|
+
this.SetLinesVisibility(true, object);
|
|
1928
|
+
return this;
|
|
1929
|
+
}
|
|
1930
|
+
remove(object) {
|
|
1931
|
+
const index = this._members.indexOf(object);
|
|
1932
|
+
if (index === -1) return this;
|
|
1933
|
+
const line = this._lines[index];
|
|
1934
|
+
super.remove(line);
|
|
1935
|
+
this._lines.splice(index, 1);
|
|
1936
|
+
super.remove(object);
|
|
1937
|
+
this._members.splice(index, 1);
|
|
1938
|
+
return this;
|
|
1939
|
+
}
|
|
1940
|
+
UpdateLineTo(object) {
|
|
1941
|
+
const index = this._members.indexOf(object);
|
|
1942
|
+
if (index === -1) return;
|
|
1943
|
+
this.updateLineTo(this._lines[index], object);
|
|
1944
|
+
}
|
|
1945
|
+
/**
|
|
1946
|
+
* Adds a line to this grouo as last child.
|
|
1947
|
+
*/
|
|
1948
|
+
createLine() {
|
|
1949
|
+
const geo = new import_three10.BufferGeometry();
|
|
1950
|
+
const mat = new import_three10.LineDashedMaterial({
|
|
1951
|
+
color: 6710886,
|
|
1952
|
+
dashSize: 0.05,
|
|
1953
|
+
gapSize: 0.025
|
|
1954
|
+
});
|
|
1955
|
+
const line = new import_three10.Line(geo, mat);
|
|
1956
|
+
line.visible = false;
|
|
1957
|
+
return line;
|
|
1958
|
+
}
|
|
1959
|
+
/**
|
|
1960
|
+
* Updates a line to the object.
|
|
1961
|
+
*/
|
|
1962
|
+
updateLineTo(line, object) {
|
|
1963
|
+
line.geometry.setFromPoints([
|
|
1964
|
+
new import_three10.Vector3(0, 0, 0),
|
|
1965
|
+
object.position.clone()
|
|
1966
|
+
]);
|
|
1967
|
+
line.computeLineDistances();
|
|
1968
|
+
}
|
|
1969
|
+
// public SetBoundingBoxVisibility(visible: boolean): void {
|
|
1970
|
+
// this._boxMesh.visible = visible;
|
|
1971
|
+
// }
|
|
1972
|
+
// /**
|
|
1973
|
+
// * Recalculates the position of the group based on it's bounding box.
|
|
1974
|
+
// * Children's world positions are kept.
|
|
1975
|
+
// */
|
|
1976
|
+
// private recalculatePosition(): void {
|
|
1977
|
+
// // store all children's world positions
|
|
1978
|
+
// const childrensWorldPositions: Vector3[] = this.children.map((child) => child.getWorldPosition(new Vector3()));
|
|
1979
|
+
// // calculate new center and set it as the group's position
|
|
1980
|
+
// const bbcenter = this.updateBB();
|
|
1981
|
+
// this.position.copy(bbcenter);
|
|
1982
|
+
// // set childrens's positions so their world positions are kept
|
|
1983
|
+
// this.children.forEach((child, i) => {
|
|
1984
|
+
// if (child.uuid === this._boxMesh.uuid) return;
|
|
1985
|
+
// child.position.copy(this.worldToLocal(childrensWorldPositions[i]));
|
|
1986
|
+
// });
|
|
1987
|
+
// DIVECommunication.get(this.userData.id)?.PerformAction('UPDATE_OBJECT', { id: this.userData.id, position: this.position });
|
|
1988
|
+
// }
|
|
1989
|
+
// /**
|
|
1990
|
+
// * Updates the bounding box of the group.
|
|
1991
|
+
// * @returns {Vector3} The new center of the bounding box.
|
|
1992
|
+
// */
|
|
1993
|
+
// private updateBB(): Vector3 {
|
|
1994
|
+
// this._boundingBox.makeEmpty();
|
|
1995
|
+
// if (this.children.length === 1) {
|
|
1996
|
+
// // because we always have the box mesh as 1 child
|
|
1997
|
+
// return this.position.clone();
|
|
1998
|
+
// }
|
|
1999
|
+
// this.children.forEach((child) => {
|
|
2000
|
+
// if (child.uuid === this._boxMesh.uuid) return;
|
|
2001
|
+
// this._boundingBox.expandByObject(child);
|
|
2002
|
+
// });
|
|
2003
|
+
// return this._boundingBox.getCenter(new Vector3());
|
|
2004
|
+
// }
|
|
2005
|
+
// private updateBoxMesh(): void {
|
|
2006
|
+
// if (this.children.length === 1) {
|
|
2007
|
+
// // because we always have the box mesh as 1 child
|
|
2008
|
+
// this._boxMesh.visible = false;
|
|
2009
|
+
// return;
|
|
2010
|
+
// }
|
|
2011
|
+
// this._boxMesh.quaternion.copy(this.quaternion.clone().invert());
|
|
2012
|
+
// this._boxMesh.scale.set(1 / this.scale.x, 1 / this.scale.y, 1 / this.scale.z);
|
|
2013
|
+
// this._boxMesh.geometry = new BoxGeometry(this._boundingBox.max.x - this._boundingBox.min.x, this._boundingBox.max.y - this._boundingBox.min.y, this._boundingBox.max.z - this._boundingBox.min.z);
|
|
2014
|
+
// this._boxMesh.visible = true;
|
|
2015
|
+
// }
|
|
2016
|
+
};
|
|
2017
|
+
|
|
2018
|
+
// src/scene/root/Root.ts
|
|
2019
|
+
var DIVERoot = class extends import_three11.Object3D {
|
|
2020
|
+
constructor() {
|
|
2021
|
+
super();
|
|
2022
|
+
this.isDIVERoot = true;
|
|
2023
|
+
this.name = "Root";
|
|
2024
|
+
this.loadingManager = new DIVELoadingManager();
|
|
2025
|
+
}
|
|
2026
|
+
ComputeSceneBB() {
|
|
2027
|
+
const bb = new import_three11.Box3();
|
|
2028
|
+
this.traverse((object) => {
|
|
2029
|
+
if ("isObject3D" in object) {
|
|
2030
|
+
bb.expandByObject(object);
|
|
2031
|
+
}
|
|
2032
|
+
});
|
|
2033
|
+
return bb;
|
|
2034
|
+
}
|
|
2035
|
+
GetSceneObject(object) {
|
|
2036
|
+
let foundObject;
|
|
2037
|
+
this.traverse((object3D) => {
|
|
2038
|
+
if (foundObject) return;
|
|
2039
|
+
if (object3D.userData.id === object.id) {
|
|
2040
|
+
foundObject = object3D;
|
|
2041
|
+
}
|
|
2042
|
+
});
|
|
2043
|
+
return foundObject;
|
|
2044
|
+
}
|
|
2045
|
+
AddSceneObject(object) {
|
|
2046
|
+
switch (object.entityType) {
|
|
2047
|
+
case "pov": {
|
|
2048
|
+
break;
|
|
2049
|
+
}
|
|
2050
|
+
case "light": {
|
|
2051
|
+
this.updateLight(object);
|
|
2052
|
+
break;
|
|
2053
|
+
}
|
|
2054
|
+
case "model": {
|
|
2055
|
+
this.updateModel(object);
|
|
2056
|
+
break;
|
|
2057
|
+
}
|
|
2058
|
+
case "primitive": {
|
|
2059
|
+
this.updatePrimitive(object);
|
|
2060
|
+
break;
|
|
2061
|
+
}
|
|
2062
|
+
case "group": {
|
|
2063
|
+
this.updateGroup(object);
|
|
2064
|
+
break;
|
|
2065
|
+
}
|
|
2066
|
+
default: {
|
|
2067
|
+
console.warn(
|
|
2068
|
+
`DIVERoot.AddSceneObject: Unknown entity type: ${object.entityType}`
|
|
2069
|
+
);
|
|
2070
|
+
}
|
|
2071
|
+
}
|
|
2072
|
+
}
|
|
2073
|
+
UpdateSceneObject(object) {
|
|
2074
|
+
switch (object.entityType) {
|
|
2075
|
+
case "pov": {
|
|
2076
|
+
break;
|
|
2077
|
+
}
|
|
2078
|
+
case "light": {
|
|
2079
|
+
this.updateLight(object);
|
|
2080
|
+
break;
|
|
2081
|
+
}
|
|
2082
|
+
case "model": {
|
|
2083
|
+
this.updateModel(object);
|
|
2084
|
+
break;
|
|
2085
|
+
}
|
|
2086
|
+
case "primitive": {
|
|
2087
|
+
this.updatePrimitive(object);
|
|
2088
|
+
break;
|
|
2089
|
+
}
|
|
2090
|
+
case "group": {
|
|
2091
|
+
this.updateGroup(object);
|
|
2092
|
+
break;
|
|
2093
|
+
}
|
|
2094
|
+
default: {
|
|
2095
|
+
console.warn(
|
|
2096
|
+
`DIVERoot.UpdateSceneObject: Unknown entity type: ${object.entityType}`
|
|
2097
|
+
);
|
|
2098
|
+
}
|
|
2099
|
+
}
|
|
2100
|
+
}
|
|
2101
|
+
DeleteSceneObject(object) {
|
|
2102
|
+
switch (object.entityType) {
|
|
2103
|
+
case "pov": {
|
|
2104
|
+
break;
|
|
2105
|
+
}
|
|
2106
|
+
case "light": {
|
|
2107
|
+
this.deleteLight(object);
|
|
2108
|
+
break;
|
|
2109
|
+
}
|
|
2110
|
+
case "model": {
|
|
2111
|
+
this.deleteModel(object);
|
|
2112
|
+
break;
|
|
2113
|
+
}
|
|
2114
|
+
case "primitive": {
|
|
2115
|
+
this.deletePrimitive(object);
|
|
2116
|
+
break;
|
|
2117
|
+
}
|
|
2118
|
+
case "group": {
|
|
2119
|
+
this.deleteGroup(object);
|
|
2120
|
+
break;
|
|
2121
|
+
}
|
|
2122
|
+
default: {
|
|
2123
|
+
console.warn(
|
|
2124
|
+
`DIVERoot.DeleteSceneObject: Unknown entity type: ${object.entityType}`
|
|
2125
|
+
);
|
|
2126
|
+
}
|
|
2127
|
+
}
|
|
2128
|
+
}
|
|
2129
|
+
PlaceOnFloor(object) {
|
|
2130
|
+
switch (object.entityType) {
|
|
2131
|
+
case "pov":
|
|
2132
|
+
case "light": {
|
|
2133
|
+
break;
|
|
2134
|
+
}
|
|
2135
|
+
case "model":
|
|
2136
|
+
case "primitive": {
|
|
2137
|
+
this.placeOnFloor(object);
|
|
2138
|
+
break;
|
|
2139
|
+
}
|
|
2140
|
+
default: {
|
|
2141
|
+
console.warn(
|
|
2142
|
+
`DIVERoot.PlaceOnFloor: Unknown entity type: ${object.entityType}`
|
|
2143
|
+
);
|
|
2144
|
+
}
|
|
2145
|
+
}
|
|
2146
|
+
}
|
|
2147
|
+
updateLight(light) {
|
|
2148
|
+
let sceneObject = this.GetSceneObject(light);
|
|
2149
|
+
if (!sceneObject) {
|
|
2150
|
+
switch (light.type) {
|
|
2151
|
+
case "scene": {
|
|
2152
|
+
sceneObject = new DIVESceneLight();
|
|
2153
|
+
break;
|
|
2154
|
+
}
|
|
2155
|
+
case "ambient": {
|
|
2156
|
+
sceneObject = new DIVEAmbientLight();
|
|
2157
|
+
break;
|
|
2158
|
+
}
|
|
2159
|
+
case "point": {
|
|
2160
|
+
sceneObject = new DIVEPointLight();
|
|
2161
|
+
break;
|
|
2162
|
+
}
|
|
2163
|
+
default: {
|
|
2164
|
+
console.warn(
|
|
2165
|
+
`DIVERoot.updateLight: Unknown light type: ${light.type}`
|
|
2166
|
+
);
|
|
2167
|
+
return;
|
|
2168
|
+
}
|
|
2169
|
+
}
|
|
2170
|
+
sceneObject.userData.id = light.id;
|
|
2171
|
+
this.add(sceneObject);
|
|
2172
|
+
}
|
|
2173
|
+
if (light.name !== void 0 && light.name !== null)
|
|
2174
|
+
sceneObject.name = light.name;
|
|
2175
|
+
if (light.position !== void 0 && light.position !== null)
|
|
2176
|
+
sceneObject.position.set(
|
|
2177
|
+
light.position.x,
|
|
2178
|
+
light.position.y,
|
|
2179
|
+
light.position.z
|
|
2180
|
+
);
|
|
2181
|
+
if (light.intensity !== void 0 && light.intensity !== null)
|
|
2182
|
+
sceneObject.SetIntensity(
|
|
2183
|
+
light.intensity
|
|
2184
|
+
);
|
|
2185
|
+
if (light.enabled !== void 0 && light.enabled !== null)
|
|
2186
|
+
sceneObject.SetEnabled(
|
|
2187
|
+
light.enabled
|
|
2188
|
+
);
|
|
2189
|
+
if (light.color !== void 0 && light.color !== null)
|
|
2190
|
+
sceneObject.SetColor(
|
|
2191
|
+
new import_three11.Color(light.color)
|
|
2192
|
+
);
|
|
2193
|
+
if (light.visible !== void 0 && light.visible !== null)
|
|
2194
|
+
sceneObject.visible = light.visible;
|
|
2195
|
+
if (light.parentId !== void 0)
|
|
2196
|
+
this.setParent(__spreadProps(__spreadValues({}, light), { parentId: light.parentId }));
|
|
2197
|
+
}
|
|
2198
|
+
updateModel(model) {
|
|
2199
|
+
let sceneObject = this.GetSceneObject(model);
|
|
2200
|
+
if (!sceneObject) {
|
|
2201
|
+
const created = new DIVEModel();
|
|
2202
|
+
sceneObject = created;
|
|
2203
|
+
sceneObject.userData.id = model.id;
|
|
2204
|
+
this.add(sceneObject);
|
|
2205
|
+
}
|
|
2206
|
+
if (model.uri !== void 0) {
|
|
2207
|
+
this.loadingManager.LoadGLTF(model.uri).then((gltf) => {
|
|
2208
|
+
var _a;
|
|
2209
|
+
sceneObject.SetModel(gltf);
|
|
2210
|
+
(_a = DIVECommunication.get(model.id)) == null ? void 0 : _a.PerformAction(
|
|
2211
|
+
"MODEL_LOADED",
|
|
2212
|
+
{ id: model.id }
|
|
2213
|
+
);
|
|
2214
|
+
});
|
|
2215
|
+
}
|
|
2216
|
+
if (model.name !== void 0) sceneObject.name = model.name;
|
|
2217
|
+
if (model.position !== void 0)
|
|
2218
|
+
sceneObject.SetPosition(model.position);
|
|
2219
|
+
if (model.rotation !== void 0)
|
|
2220
|
+
sceneObject.SetRotation(model.rotation);
|
|
2221
|
+
if (model.scale !== void 0)
|
|
2222
|
+
sceneObject.SetScale(model.scale);
|
|
2223
|
+
if (model.visible !== void 0)
|
|
2224
|
+
sceneObject.SetVisibility(model.visible);
|
|
2225
|
+
if (model.material !== void 0)
|
|
2226
|
+
sceneObject.SetMaterial(model.material);
|
|
2227
|
+
if (model.parentId !== void 0)
|
|
2228
|
+
this.setParent(__spreadProps(__spreadValues({}, model), { parentId: model.parentId }));
|
|
2229
|
+
}
|
|
2230
|
+
updatePrimitive(primitive) {
|
|
2231
|
+
let sceneObject = this.GetSceneObject(primitive);
|
|
2232
|
+
if (!sceneObject) {
|
|
2233
|
+
const created = new DIVEPrimitive();
|
|
2234
|
+
sceneObject = created;
|
|
2235
|
+
sceneObject.userData.id = primitive.id;
|
|
2236
|
+
this.add(sceneObject);
|
|
2237
|
+
}
|
|
2238
|
+
if (primitive.name !== void 0) sceneObject.name = primitive.name;
|
|
2239
|
+
if (primitive.geometry !== void 0)
|
|
2240
|
+
sceneObject.SetGeometry(primitive.geometry);
|
|
2241
|
+
if (primitive.position !== void 0)
|
|
2242
|
+
sceneObject.SetPosition(primitive.position);
|
|
2243
|
+
if (primitive.rotation !== void 0)
|
|
2244
|
+
sceneObject.SetRotation(primitive.rotation);
|
|
2245
|
+
if (primitive.scale !== void 0)
|
|
2246
|
+
sceneObject.SetScale(primitive.scale);
|
|
2247
|
+
if (primitive.visible !== void 0)
|
|
2248
|
+
sceneObject.SetVisibility(primitive.visible);
|
|
2249
|
+
if (primitive.material !== void 0)
|
|
2250
|
+
sceneObject.SetMaterial(primitive.material);
|
|
2251
|
+
if (primitive.parentId !== void 0)
|
|
2252
|
+
this.setParent(__spreadProps(__spreadValues({}, primitive), { parentId: primitive.parentId }));
|
|
2253
|
+
}
|
|
2254
|
+
updateGroup(group) {
|
|
2255
|
+
let sceneObject = this.GetSceneObject(group);
|
|
2256
|
+
if (!sceneObject) {
|
|
2257
|
+
const created = new DIVEGroup();
|
|
2258
|
+
sceneObject = created;
|
|
2259
|
+
sceneObject.userData.id = group.id;
|
|
2260
|
+
this.add(sceneObject);
|
|
2261
|
+
}
|
|
2262
|
+
if (group.name !== void 0) sceneObject.name = group.name;
|
|
2263
|
+
if (group.position !== void 0)
|
|
2264
|
+
sceneObject.SetPosition(group.position);
|
|
2265
|
+
if (group.rotation !== void 0)
|
|
2266
|
+
sceneObject.SetRotation(group.rotation);
|
|
2267
|
+
if (group.scale !== void 0)
|
|
2268
|
+
sceneObject.SetScale(group.scale);
|
|
2269
|
+
if (group.visible !== void 0)
|
|
2270
|
+
sceneObject.SetVisibility(group.visible);
|
|
2271
|
+
if (group.bbVisible !== void 0)
|
|
2272
|
+
sceneObject.SetLinesVisibility(group.bbVisible);
|
|
2273
|
+
if (group.parentId !== void 0)
|
|
2274
|
+
this.setParent(__spreadProps(__spreadValues({}, group), { parentId: group.parentId }));
|
|
2275
|
+
}
|
|
2276
|
+
deleteLight(light) {
|
|
2277
|
+
const sceneObject = this.GetSceneObject(light);
|
|
2278
|
+
if (!sceneObject) {
|
|
2279
|
+
console.warn(
|
|
2280
|
+
`DIVERoot.deleteLight: Light with id ${light.id} not found`
|
|
2281
|
+
);
|
|
2282
|
+
return;
|
|
2283
|
+
}
|
|
2284
|
+
this.detachTransformControls(sceneObject);
|
|
2285
|
+
sceneObject.parent.remove(sceneObject);
|
|
2286
|
+
}
|
|
2287
|
+
deleteModel(model) {
|
|
2288
|
+
const sceneObject = this.GetSceneObject(model);
|
|
2289
|
+
if (!sceneObject) {
|
|
2290
|
+
console.warn(
|
|
2291
|
+
`DIVERoot.deleteModel: Model with id ${model.id} not found`
|
|
2292
|
+
);
|
|
2293
|
+
return;
|
|
2294
|
+
}
|
|
2295
|
+
this.detachTransformControls(sceneObject);
|
|
2296
|
+
sceneObject.parent.remove(sceneObject);
|
|
2297
|
+
}
|
|
2298
|
+
deletePrimitive(primitive) {
|
|
2299
|
+
const sceneObject = this.GetSceneObject(primitive);
|
|
2300
|
+
if (!sceneObject) {
|
|
2301
|
+
console.warn(
|
|
2302
|
+
`DIVERoot.deletePrimitive: Primitive with id ${primitive.id} not found`
|
|
2303
|
+
);
|
|
2304
|
+
return;
|
|
2305
|
+
}
|
|
2306
|
+
this.detachTransformControls(sceneObject);
|
|
2307
|
+
sceneObject.parent.remove(sceneObject);
|
|
2308
|
+
}
|
|
2309
|
+
deleteGroup(group) {
|
|
2310
|
+
const sceneObject = this.GetSceneObject(group);
|
|
2311
|
+
if (!sceneObject) {
|
|
2312
|
+
console.warn(
|
|
2313
|
+
`DIVERoot.deleteGroup: Group with id ${group.id} not found`
|
|
2314
|
+
);
|
|
2315
|
+
return;
|
|
2316
|
+
}
|
|
2317
|
+
this.detachTransformControls(sceneObject);
|
|
2318
|
+
for (let i = sceneObject.members.length - 1; i >= 0; i--) {
|
|
2319
|
+
this.attach(sceneObject.members[i]);
|
|
2320
|
+
}
|
|
2321
|
+
sceneObject.parent.remove(sceneObject);
|
|
2322
|
+
}
|
|
2323
|
+
placeOnFloor(object) {
|
|
2324
|
+
const sceneObject = this.GetSceneObject(object);
|
|
2325
|
+
if (!sceneObject) return;
|
|
2326
|
+
sceneObject.PlaceOnFloor();
|
|
2327
|
+
}
|
|
2328
|
+
setParent(object) {
|
|
2329
|
+
const sceneObject = this.GetSceneObject(object);
|
|
2330
|
+
if (!sceneObject) return;
|
|
2331
|
+
if (object.parentId !== null) {
|
|
2332
|
+
const parent = this.GetSceneObject({
|
|
2333
|
+
id: object.parentId
|
|
2334
|
+
});
|
|
2335
|
+
if (!parent) return;
|
|
2336
|
+
parent.attach(sceneObject);
|
|
2337
|
+
} else {
|
|
2338
|
+
this.attach(sceneObject);
|
|
2339
|
+
}
|
|
2340
|
+
}
|
|
2341
|
+
detachTransformControls(object) {
|
|
2342
|
+
this.findScene(object).children.find((object2) => {
|
|
2343
|
+
if ("isTransformControls" in object2) {
|
|
2344
|
+
object2.detach();
|
|
2345
|
+
}
|
|
2346
|
+
});
|
|
2347
|
+
}
|
|
2348
|
+
findScene(object) {
|
|
2349
|
+
if (object.parent !== null) {
|
|
2350
|
+
return this.findScene(object.parent);
|
|
2351
|
+
}
|
|
2352
|
+
return object;
|
|
2353
|
+
}
|
|
2354
|
+
};
|
|
2355
|
+
|
|
2356
|
+
// src/constant/GridColors.ts
|
|
2357
|
+
var GRID_CENTER_LINE_COLOR = "#888888";
|
|
2358
|
+
var GRID_SIDE_LINE_COLOR = "#dddddd";
|
|
2359
|
+
|
|
2360
|
+
// src/grid/Grid.ts
|
|
2361
|
+
init_VisibilityLayerMask();
|
|
2362
|
+
var import_three12 = require("three");
|
|
2363
|
+
var DIVEGrid = class extends import_three12.Object3D {
|
|
2364
|
+
constructor() {
|
|
2365
|
+
super();
|
|
2366
|
+
this.name = "Grid";
|
|
2367
|
+
const grid = new import_three12.GridHelper(
|
|
2368
|
+
100,
|
|
2369
|
+
100,
|
|
2370
|
+
GRID_CENTER_LINE_COLOR,
|
|
2371
|
+
GRID_SIDE_LINE_COLOR
|
|
2372
|
+
);
|
|
2373
|
+
grid.material.depthTest = false;
|
|
2374
|
+
grid.layers.mask = HELPER_LAYER_MASK;
|
|
2375
|
+
this.add(grid);
|
|
2376
|
+
}
|
|
2377
|
+
SetVisibility(visible) {
|
|
2378
|
+
this.visible = visible;
|
|
2379
|
+
}
|
|
2380
|
+
};
|
|
2381
|
+
|
|
2382
|
+
// src/primitive/floor/Floor.ts
|
|
2383
|
+
var import_three13 = require("three");
|
|
2384
|
+
init_VisibilityLayerMask();
|
|
2385
|
+
var DIVEFloor = class extends import_three13.Mesh {
|
|
2386
|
+
constructor() {
|
|
2387
|
+
super(
|
|
2388
|
+
new import_three13.PlaneGeometry(1e4, 1e4),
|
|
2389
|
+
new import_three13.MeshStandardMaterial({
|
|
2390
|
+
color: new import_three13.Color(150 / 255, 150 / 255, 150 / 255)
|
|
2391
|
+
})
|
|
2392
|
+
);
|
|
2393
|
+
this.isFloor = true;
|
|
2394
|
+
this.name = "Floor";
|
|
2395
|
+
this.layers.mask = PRODUCT_LAYER_MASK;
|
|
2396
|
+
this.receiveShadow = true;
|
|
2397
|
+
this.rotateX(-Math.PI / 2);
|
|
2398
|
+
}
|
|
2399
|
+
SetVisibility(visible) {
|
|
2400
|
+
this.visible = visible;
|
|
2401
|
+
}
|
|
2402
|
+
SetColor(color) {
|
|
2403
|
+
this.material.color = new import_three13.Color(color);
|
|
2404
|
+
}
|
|
2405
|
+
};
|
|
2406
|
+
|
|
2407
|
+
// src/scene/Scene.ts
|
|
2408
|
+
var DIVEScene = class extends import_three14.Scene {
|
|
2409
|
+
get Root() {
|
|
2410
|
+
return this.root;
|
|
2411
|
+
}
|
|
2412
|
+
get Floor() {
|
|
2413
|
+
return this.floor;
|
|
2414
|
+
}
|
|
2415
|
+
get Grid() {
|
|
2416
|
+
return this.grid;
|
|
2417
|
+
}
|
|
2418
|
+
constructor() {
|
|
2419
|
+
super();
|
|
2420
|
+
this.background = new import_three14.Color(16777215);
|
|
2421
|
+
this.root = new DIVERoot();
|
|
2422
|
+
this.add(this.root);
|
|
2423
|
+
this.floor = new DIVEFloor();
|
|
2424
|
+
this.add(this.floor);
|
|
2425
|
+
this.grid = new DIVEGrid();
|
|
2426
|
+
this.add(this.grid);
|
|
2427
|
+
}
|
|
2428
|
+
SetBackground(color) {
|
|
2429
|
+
this.background = new import_three14.Color(color);
|
|
2430
|
+
}
|
|
2431
|
+
ComputeSceneBB() {
|
|
2432
|
+
return this.Root.ComputeSceneBB();
|
|
2433
|
+
}
|
|
2434
|
+
GetSceneObject(object) {
|
|
2435
|
+
return this.Root.GetSceneObject(object);
|
|
2436
|
+
}
|
|
2437
|
+
AddSceneObject(object) {
|
|
2438
|
+
this.Root.AddSceneObject(object);
|
|
2439
|
+
}
|
|
2440
|
+
UpdateSceneObject(object) {
|
|
2441
|
+
this.Root.UpdateSceneObject(object);
|
|
2442
|
+
}
|
|
2443
|
+
DeleteSceneObject(object) {
|
|
2444
|
+
this.Root.DeleteSceneObject(object);
|
|
2445
|
+
}
|
|
2446
|
+
PlaceOnFloor(object) {
|
|
2447
|
+
this.Root.PlaceOnFloor(object);
|
|
2448
|
+
}
|
|
2449
|
+
};
|
|
2450
|
+
|
|
2451
|
+
// src/dive.ts
|
|
2452
|
+
init_PerspectiveCamera();
|
|
2453
|
+
|
|
2454
|
+
// src/controls/OrbitControls.ts
|
|
2455
|
+
var import_OrbitControls = require("three/examples/jsm/controls/OrbitControls");
|
|
2456
|
+
var import_three15 = require("three");
|
|
2457
|
+
var import_tween = require("@tweenjs/tween.js");
|
|
2458
|
+
var DIVEOrbitControlsDefaultSettings = {
|
|
2459
|
+
enableDamping: true,
|
|
2460
|
+
dampingFactor: 0.04
|
|
2461
|
+
};
|
|
2462
|
+
var _DIVEOrbitControls = class _DIVEOrbitControls extends import_OrbitControls.OrbitControls {
|
|
2463
|
+
constructor(camera, renderer, animationSystem, settings = DIVEOrbitControlsDefaultSettings) {
|
|
2464
|
+
super(camera, renderer.domElement);
|
|
2465
|
+
this.last = null;
|
|
2466
|
+
this.animating = false;
|
|
2467
|
+
this.locked = false;
|
|
2468
|
+
this.stopMoveTo = () => {
|
|
2469
|
+
};
|
|
2470
|
+
this.stopRevertLast = () => {
|
|
2471
|
+
};
|
|
2472
|
+
this._removePreRenderCallback = () => {
|
|
2473
|
+
};
|
|
2474
|
+
this.preRenderCallback = () => {
|
|
2475
|
+
if (this.locked) return;
|
|
2476
|
+
this.update();
|
|
2477
|
+
};
|
|
2478
|
+
this._animationSystem = animationSystem;
|
|
2479
|
+
this.domElement = renderer.domElement;
|
|
2480
|
+
this.object = camera;
|
|
2481
|
+
const id = renderer.AddPreRenderCallback(() => {
|
|
2482
|
+
this.preRenderCallback();
|
|
2483
|
+
});
|
|
2484
|
+
this._removePreRenderCallback = () => {
|
|
2485
|
+
renderer.RemovePreRenderCallback(id);
|
|
2486
|
+
};
|
|
2487
|
+
this.enableDamping = settings.enableDamping || DIVEOrbitControlsDefaultSettings.enableDamping;
|
|
2488
|
+
this.dampingFactor = settings.dampingFactor || DIVEOrbitControlsDefaultSettings.dampingFactor;
|
|
2489
|
+
this.object.position.set(0, 2, 2);
|
|
2490
|
+
this.target.copy({ x: 0, y: 0.5, z: 0 });
|
|
2491
|
+
this.update();
|
|
2492
|
+
}
|
|
2493
|
+
Dispose() {
|
|
2494
|
+
this._removePreRenderCallback();
|
|
2495
|
+
this.dispose();
|
|
2496
|
+
}
|
|
2497
|
+
ComputeEncompassingView(bb) {
|
|
2498
|
+
const center = bb.getCenter(new import_three15.Vector3());
|
|
2499
|
+
const size = bb.getSize(new import_three15.Vector3());
|
|
2500
|
+
const distance = Math.max(size.x, size.y, size.z) * 1.25;
|
|
2501
|
+
const direction = this.object.position.clone().normalize();
|
|
2502
|
+
return {
|
|
2503
|
+
position: direction.multiplyScalar(distance),
|
|
2504
|
+
target: center
|
|
2505
|
+
};
|
|
2506
|
+
}
|
|
2507
|
+
ZoomIn(by) {
|
|
2508
|
+
const zoomBy = by || _DIVEOrbitControls.DEFAULT_ZOOM_FACTOR;
|
|
2509
|
+
const { minDistance, maxDistance } = this;
|
|
2510
|
+
this.minDistance = this.maxDistance = import_three15.MathUtils.clamp(
|
|
2511
|
+
this.getDistance() - zoomBy,
|
|
2512
|
+
minDistance + zoomBy,
|
|
2513
|
+
maxDistance - zoomBy
|
|
2514
|
+
);
|
|
2515
|
+
this.update();
|
|
2516
|
+
this.minDistance = minDistance;
|
|
2517
|
+
this.maxDistance = maxDistance;
|
|
2518
|
+
}
|
|
2519
|
+
ZoomOut(by) {
|
|
2520
|
+
const zoomBy = by || _DIVEOrbitControls.DEFAULT_ZOOM_FACTOR;
|
|
2521
|
+
const { minDistance, maxDistance } = this;
|
|
2522
|
+
this.minDistance = this.maxDistance = import_three15.MathUtils.clamp(
|
|
2523
|
+
this.getDistance() + zoomBy,
|
|
2524
|
+
minDistance + zoomBy,
|
|
2525
|
+
maxDistance - zoomBy
|
|
2526
|
+
);
|
|
2527
|
+
this.update();
|
|
2528
|
+
this.minDistance = minDistance;
|
|
2529
|
+
this.maxDistance = maxDistance;
|
|
2530
|
+
}
|
|
2531
|
+
MoveTo(pos, target, duration, lock) {
|
|
2532
|
+
if (this.animating) return;
|
|
2533
|
+
const toPosition = pos || this.object.position.clone();
|
|
2534
|
+
const toTarget = target || this.target.clone();
|
|
2535
|
+
this.stopRevertLast();
|
|
2536
|
+
if (!this.locked)
|
|
2537
|
+
this.last = {
|
|
2538
|
+
pos: this.object.position.clone(),
|
|
2539
|
+
target: this.target.clone()
|
|
2540
|
+
};
|
|
2541
|
+
this.animating = duration > 0;
|
|
2542
|
+
this.locked = lock;
|
|
2543
|
+
this.enabled = false;
|
|
2544
|
+
const tweenPos = this._animationSystem.Animate(this.object.position).to(toPosition, duration).easing(import_tween.Easing.Quadratic.Out).start();
|
|
2545
|
+
const tweenQuat = this._animationSystem.Animate(this.target).to(toTarget, duration).easing(import_tween.Easing.Quadratic.Out).onUpdate(() => {
|
|
2546
|
+
this.object.lookAt(this.target);
|
|
2547
|
+
}).onComplete(() => {
|
|
2548
|
+
this.animating = false;
|
|
2549
|
+
this.enabled = !lock;
|
|
2550
|
+
}).start();
|
|
2551
|
+
this.stopMoveTo = () => {
|
|
2552
|
+
tweenPos.stop();
|
|
2553
|
+
tweenQuat.stop();
|
|
2554
|
+
};
|
|
2555
|
+
}
|
|
2556
|
+
RevertLast(duration) {
|
|
2557
|
+
if (this.animating || !this.locked) return;
|
|
2558
|
+
this.stopMoveTo();
|
|
2559
|
+
this.animating = duration > 0;
|
|
2560
|
+
this.enabled = false;
|
|
2561
|
+
const { pos, target } = this.last;
|
|
2562
|
+
const tweenPos = this._animationSystem.Animate(this.object.position).to(pos, duration).easing(import_tween.Easing.Quadratic.Out).start();
|
|
2563
|
+
const tweenQuat = this._animationSystem.Animate(this.target).to(target, duration).easing(import_tween.Easing.Quadratic.Out).onUpdate(() => {
|
|
2564
|
+
this.object.lookAt(this.target);
|
|
2565
|
+
}).onComplete(() => {
|
|
2566
|
+
this.animating = false;
|
|
2567
|
+
this.locked = false;
|
|
2568
|
+
this.enabled = true;
|
|
2569
|
+
}).start();
|
|
2570
|
+
this.stopRevertLast = () => {
|
|
2571
|
+
tweenPos.stop();
|
|
2572
|
+
tweenQuat.stop();
|
|
2573
|
+
};
|
|
2574
|
+
}
|
|
2575
|
+
};
|
|
2576
|
+
_DIVEOrbitControls.DEFAULT_ZOOM_FACTOR = 1;
|
|
2577
|
+
var DIVEOrbitControls = _DIVEOrbitControls;
|
|
2578
|
+
|
|
2579
|
+
// src/toolbox/Toolbox.ts
|
|
2580
|
+
var DIVEToolbox = class {
|
|
2581
|
+
get selectTool() {
|
|
2582
|
+
if (!this._selectTool) {
|
|
2583
|
+
const DIVESelectTool2 = (init_SelectTool(), __toCommonJS(SelectTool_exports)).DIVESelectTool;
|
|
2584
|
+
this._selectTool = new DIVESelectTool2(
|
|
2585
|
+
this._scene,
|
|
2586
|
+
this._controller
|
|
2587
|
+
);
|
|
2588
|
+
}
|
|
2589
|
+
return this._selectTool;
|
|
2590
|
+
}
|
|
2591
|
+
constructor(scene, controller) {
|
|
2592
|
+
this._scene = scene;
|
|
2593
|
+
this._controller = controller;
|
|
2594
|
+
this._selectTool = null;
|
|
2595
|
+
this._activeTool = null;
|
|
2596
|
+
}
|
|
2597
|
+
Dispose() {
|
|
2598
|
+
this.removeEventListeners();
|
|
2599
|
+
}
|
|
2600
|
+
GetActiveTool() {
|
|
2601
|
+
return this._activeTool;
|
|
2602
|
+
}
|
|
2603
|
+
UseTool(tool) {
|
|
2604
|
+
var _a;
|
|
2605
|
+
(_a = this._activeTool) == null ? void 0 : _a.Deactivate();
|
|
2606
|
+
switch (tool) {
|
|
2607
|
+
case "select": {
|
|
2608
|
+
this.addEventListeners();
|
|
2609
|
+
this.selectTool.Activate();
|
|
2610
|
+
this._activeTool = this.selectTool;
|
|
2611
|
+
break;
|
|
2612
|
+
}
|
|
2613
|
+
case "none": {
|
|
2614
|
+
this.removeEventListeners();
|
|
2615
|
+
this._activeTool = null;
|
|
2616
|
+
break;
|
|
2617
|
+
}
|
|
2618
|
+
default: {
|
|
2619
|
+
console.warn(`DIVEToolBox.UseTool: Unknown tool: ${tool}`);
|
|
2620
|
+
}
|
|
2621
|
+
}
|
|
2622
|
+
}
|
|
2623
|
+
SetGizmoMode(mode) {
|
|
2624
|
+
this.selectTool.SetGizmoMode(mode);
|
|
2625
|
+
}
|
|
2626
|
+
SetGizmoVisibility(active) {
|
|
2627
|
+
this.selectTool.SetGizmoVisibility(active);
|
|
2628
|
+
}
|
|
2629
|
+
onPointerMove(e) {
|
|
2630
|
+
var _a;
|
|
2631
|
+
(_a = this._activeTool) == null ? void 0 : _a.onPointerMove(e);
|
|
2632
|
+
}
|
|
2633
|
+
onPointerDown(e) {
|
|
2634
|
+
var _a;
|
|
2635
|
+
(_a = this._activeTool) == null ? void 0 : _a.onPointerDown(e);
|
|
2636
|
+
}
|
|
2637
|
+
onPointerUp(e) {
|
|
2638
|
+
var _a;
|
|
2639
|
+
(_a = this._activeTool) == null ? void 0 : _a.onPointerUp(e);
|
|
2640
|
+
}
|
|
2641
|
+
onWheel(e) {
|
|
2642
|
+
var _a;
|
|
2643
|
+
(_a = this._activeTool) == null ? void 0 : _a.onWheel(e);
|
|
2644
|
+
}
|
|
2645
|
+
addEventListeners() {
|
|
2646
|
+
this._controller.domElement.addEventListener(
|
|
2647
|
+
"pointermove",
|
|
2648
|
+
(e) => this.onPointerMove(e)
|
|
2649
|
+
);
|
|
2650
|
+
this._controller.domElement.addEventListener(
|
|
2651
|
+
"pointerdown",
|
|
2652
|
+
(e) => this.onPointerDown(e)
|
|
2653
|
+
);
|
|
2654
|
+
this._controller.domElement.addEventListener(
|
|
2655
|
+
"pointerup",
|
|
2656
|
+
(e) => this.onPointerUp(e)
|
|
2657
|
+
);
|
|
2658
|
+
this._controller.domElement.addEventListener(
|
|
2659
|
+
"wheel",
|
|
2660
|
+
(e) => this.onWheel(e)
|
|
2661
|
+
);
|
|
2662
|
+
}
|
|
2663
|
+
removeEventListeners() {
|
|
2664
|
+
this._controller.domElement.removeEventListener(
|
|
2665
|
+
"pointermove",
|
|
2666
|
+
(e) => this.onPointerMove(e)
|
|
2667
|
+
);
|
|
2668
|
+
this._controller.domElement.removeEventListener(
|
|
2669
|
+
"pointerdown",
|
|
2670
|
+
(e) => this.onPointerDown(e)
|
|
2671
|
+
);
|
|
2672
|
+
this._controller.domElement.removeEventListener(
|
|
2673
|
+
"pointerup",
|
|
2674
|
+
(e) => this.onPointerUp(e)
|
|
2675
|
+
);
|
|
2676
|
+
this._controller.domElement.removeEventListener(
|
|
2677
|
+
"wheel",
|
|
2678
|
+
(e) => this.onWheel(e)
|
|
2679
|
+
);
|
|
2680
|
+
}
|
|
2681
|
+
};
|
|
2682
|
+
DIVEToolbox.DefaultTool = "select";
|
|
2683
|
+
|
|
2684
|
+
// src/animation/AnimationSystem.ts
|
|
2685
|
+
var import_tween2 = require("@tweenjs/tween.js");
|
|
2686
|
+
var DIVEAnimationSystem = class {
|
|
2687
|
+
constructor(renderer) {
|
|
2688
|
+
this._renderer = renderer;
|
|
2689
|
+
this._rendererCallbackId = this._renderer.AddPreRenderCallback(() => {
|
|
2690
|
+
this.Update();
|
|
2691
|
+
});
|
|
2692
|
+
}
|
|
2693
|
+
Dispose() {
|
|
2694
|
+
this._renderer.RemovePreRenderCallback(this._rendererCallbackId);
|
|
2695
|
+
}
|
|
2696
|
+
Update() {
|
|
2697
|
+
(0, import_tween2.update)();
|
|
2698
|
+
}
|
|
2699
|
+
Animate(object) {
|
|
2700
|
+
return new import_tween2.Tween(object);
|
|
2701
|
+
}
|
|
2702
|
+
};
|
|
2703
|
+
|
|
2704
|
+
// src/axiscamera/AxisCamera.ts
|
|
2705
|
+
var import_three16 = require("three");
|
|
2706
|
+
var import_three_spritetext = __toESM(require("three-spritetext"), 1);
|
|
2707
|
+
init_VisibilityLayerMask();
|
|
2708
|
+
|
|
2709
|
+
// src/constant/AxisHelperColors.ts
|
|
2710
|
+
var AxesColorRedLetter = "#c20017";
|
|
2711
|
+
var AxesColorGreenLetter = "#00ab26";
|
|
2712
|
+
var AxesColorBlueLetter = "#0081d4";
|
|
2713
|
+
var AxesColorRed = AxesColorRedLetter;
|
|
2714
|
+
var AxesColorGreen = AxesColorGreenLetter;
|
|
2715
|
+
var AxesColorBlue = AxesColorBlueLetter;
|
|
2716
|
+
|
|
2717
|
+
// src/axiscamera/AxisCamera.ts
|
|
2718
|
+
var DIVEAxisCamera = class extends import_three16.OrthographicCamera {
|
|
2719
|
+
constructor(renderer, scene, controls) {
|
|
2720
|
+
super(-1, 1, 1, -1, 0.1, 100);
|
|
2721
|
+
this.layers.mask = COORDINATE_LAYER_MASK;
|
|
2722
|
+
this.axesHelper = new import_three16.AxesHelper(0.5);
|
|
2723
|
+
this.axesHelper.layers.mask = COORDINATE_LAYER_MASK;
|
|
2724
|
+
this.axesHelper.material.depthTest = false;
|
|
2725
|
+
this.axesHelper.position.set(0, 0, -1);
|
|
2726
|
+
this.axesHelper.setColors(
|
|
2727
|
+
new import_three16.Color(AxesColorRed),
|
|
2728
|
+
new import_three16.Color(AxesColorGreen),
|
|
2729
|
+
new import_three16.Color(AxesColorBlue)
|
|
2730
|
+
);
|
|
2731
|
+
const x = new import_three_spritetext.default("X", 0.2, AxesColorRedLetter);
|
|
2732
|
+
const y = new import_three_spritetext.default("Y", 0.2, AxesColorGreenLetter);
|
|
2733
|
+
const z = new import_three_spritetext.default("Z", 0.2, AxesColorBlueLetter);
|
|
2734
|
+
x.layers.mask = COORDINATE_LAYER_MASK;
|
|
2735
|
+
y.layers.mask = COORDINATE_LAYER_MASK;
|
|
2736
|
+
z.layers.mask = COORDINATE_LAYER_MASK;
|
|
2737
|
+
x.position.set(0.7, 0, 0);
|
|
2738
|
+
y.position.set(0, 0.7, 0);
|
|
2739
|
+
z.position.set(0, 0, 0.7);
|
|
2740
|
+
this.axesHelper.add(x);
|
|
2741
|
+
this.axesHelper.add(y);
|
|
2742
|
+
this.axesHelper.add(z);
|
|
2743
|
+
this.add(this.axesHelper);
|
|
2744
|
+
this._renderer = renderer;
|
|
2745
|
+
this._scene = scene;
|
|
2746
|
+
this._scene.add(this);
|
|
2747
|
+
const restoreViewport = new import_three16.Vector4();
|
|
2748
|
+
this._renderCallbackId = renderer.AddPostRenderCallback(() => {
|
|
2749
|
+
const restoreBackground = scene.background;
|
|
2750
|
+
scene.background = null;
|
|
2751
|
+
renderer.getViewport(restoreViewport);
|
|
2752
|
+
renderer.setViewport(0, 0, 150, 150);
|
|
2753
|
+
renderer.autoClear = false;
|
|
2754
|
+
this.SetFromCameraMatrix(controls.object.matrix);
|
|
2755
|
+
renderer.render(scene, this);
|
|
2756
|
+
renderer.setViewport(restoreViewport);
|
|
2757
|
+
renderer.autoClear = true;
|
|
2758
|
+
scene.background = restoreBackground;
|
|
2759
|
+
});
|
|
2760
|
+
}
|
|
2761
|
+
Dispose() {
|
|
2762
|
+
this._renderer.RemovePostRenderCallback(this._renderCallbackId);
|
|
2763
|
+
this._scene.remove(this);
|
|
2764
|
+
}
|
|
2765
|
+
SetFromCameraMatrix(matrix) {
|
|
2766
|
+
this.axesHelper.rotation.setFromRotationMatrix(
|
|
2767
|
+
new import_three16.Matrix4().extractRotation(matrix).invert()
|
|
2768
|
+
);
|
|
2769
|
+
}
|
|
2770
|
+
};
|
|
2771
|
+
|
|
2772
|
+
// src/helper/getObjectDelta/getObjectDelta.ts
|
|
2773
|
+
var getObjectDelta = (a, b) => {
|
|
2774
|
+
if (Object.keys(a).length === 0 && Object.keys(b).length === 0) {
|
|
2775
|
+
return {};
|
|
2776
|
+
}
|
|
2777
|
+
if (typeof a !== "object" || typeof b !== "object") {
|
|
2778
|
+
return b;
|
|
2779
|
+
}
|
|
2780
|
+
let delta = {};
|
|
2781
|
+
Object.keys(b).forEach((key) => {
|
|
2782
|
+
if (!Object.keys(a).includes(key)) {
|
|
2783
|
+
delta = __spreadProps(__spreadValues({}, delta), { [key]: b[key] });
|
|
2784
|
+
return;
|
|
2785
|
+
}
|
|
2786
|
+
if (Array.isArray(b[key])) {
|
|
2787
|
+
if (!Array.isArray(a[key])) {
|
|
2788
|
+
delta = __spreadProps(__spreadValues({}, delta), { [key]: b[key] });
|
|
2789
|
+
return;
|
|
2790
|
+
}
|
|
2791
|
+
const aArray = a[key];
|
|
2792
|
+
const bArray = b[key];
|
|
2793
|
+
if (aArray.length === 0 && bArray.length === 0) {
|
|
2794
|
+
delta = __spreadValues({}, delta);
|
|
2795
|
+
return;
|
|
2796
|
+
}
|
|
2797
|
+
if (aArray.length !== bArray.length) {
|
|
2798
|
+
delta = __spreadProps(__spreadValues({}, delta), { [key]: b[key] });
|
|
2799
|
+
return;
|
|
2800
|
+
}
|
|
2801
|
+
const arrayDeltas = [];
|
|
2802
|
+
bArray.forEach((entry, index) => {
|
|
2803
|
+
const inArrayDelta = getObjectDelta(
|
|
2804
|
+
aArray[index],
|
|
2805
|
+
bArray[index]
|
|
2806
|
+
);
|
|
2807
|
+
if (Object.keys(inArrayDelta).length) {
|
|
2808
|
+
arrayDeltas.push(bArray[index]);
|
|
2809
|
+
}
|
|
2810
|
+
});
|
|
2811
|
+
if (Object.keys(arrayDeltas).length) {
|
|
2812
|
+
delta = __spreadProps(__spreadValues({}, delta), { [key]: arrayDeltas });
|
|
2813
|
+
return;
|
|
2814
|
+
}
|
|
2815
|
+
return;
|
|
2816
|
+
}
|
|
2817
|
+
if (typeof b[key] === "object") {
|
|
2818
|
+
if (typeof a[key] !== "object") {
|
|
2819
|
+
delta = __spreadProps(__spreadValues({}, delta), { [key]: b[key] });
|
|
2820
|
+
return;
|
|
2821
|
+
}
|
|
2822
|
+
const objectDelta = getObjectDelta(
|
|
2823
|
+
a[key],
|
|
2824
|
+
b[key]
|
|
2825
|
+
);
|
|
2826
|
+
if (Object.keys(objectDelta).length) {
|
|
2827
|
+
delta = __spreadProps(__spreadValues({}, delta), { [key]: objectDelta });
|
|
2828
|
+
return;
|
|
2829
|
+
}
|
|
2830
|
+
}
|
|
2831
|
+
if (a[key] !== b[key]) {
|
|
2832
|
+
delta = __spreadProps(__spreadValues({}, delta), { [key]: b[key] });
|
|
2833
|
+
}
|
|
2834
|
+
});
|
|
2835
|
+
return delta;
|
|
2836
|
+
};
|
|
2837
|
+
|
|
2838
|
+
// src/dive.ts
|
|
2839
|
+
var import_MathUtils2 = require("three/src/math/MathUtils");
|
|
2840
|
+
|
|
2841
|
+
// src/info/Info.ts
|
|
2842
|
+
var DIVEInfo = class {
|
|
2843
|
+
/**
|
|
2844
|
+
*
|
|
2845
|
+
* @returns The system the user is using. Possible values are "Android", "iOS", "Windows", "MacOS", "Linux" or "Unknown".
|
|
2846
|
+
*/
|
|
2847
|
+
static GetSystem() {
|
|
2848
|
+
const platform = navigator.platform;
|
|
2849
|
+
if (/Android/.test(navigator.userAgent)) {
|
|
2850
|
+
return "Android";
|
|
2851
|
+
} else if (/iPhone|iPad|iPod/.test(navigator.userAgent)) {
|
|
2852
|
+
return "iOS";
|
|
2853
|
+
} else if (platform.startsWith("Win")) {
|
|
2854
|
+
return "Windows";
|
|
2855
|
+
} else if (platform.startsWith("Mac")) {
|
|
2856
|
+
return "MacOS";
|
|
2857
|
+
} else if (platform.startsWith("Linux")) {
|
|
2858
|
+
return "Linux";
|
|
2859
|
+
} else {
|
|
2860
|
+
return "Unknown";
|
|
2861
|
+
}
|
|
2862
|
+
}
|
|
2863
|
+
/**
|
|
2864
|
+
* @returns A promise that resolves to a boolean indicating whether the user's device supports WebXR.
|
|
2865
|
+
*/
|
|
2866
|
+
static GetSupportsWebXR() {
|
|
2867
|
+
return __async(this, null, function* () {
|
|
2868
|
+
if (this._supportsWebXR !== null) {
|
|
2869
|
+
return this._supportsWebXR;
|
|
2870
|
+
}
|
|
2871
|
+
if (!navigator.xr) {
|
|
2872
|
+
this._supportsWebXR = false;
|
|
2873
|
+
return this._supportsWebXR;
|
|
2874
|
+
}
|
|
2875
|
+
try {
|
|
2876
|
+
const supported = yield navigator.xr.isSessionSupported("immersive-ar");
|
|
2877
|
+
this._supportsWebXR = supported;
|
|
2878
|
+
} catch (error) {
|
|
2879
|
+
this._supportsWebXR = false;
|
|
2880
|
+
}
|
|
2881
|
+
return this._supportsWebXR;
|
|
2882
|
+
});
|
|
2883
|
+
}
|
|
2884
|
+
/**
|
|
2885
|
+
* @returns A boolean indicating whether the user's device supports AR Quick Look.
|
|
2886
|
+
*/
|
|
2887
|
+
static GetSupportsARQuickLook() {
|
|
2888
|
+
const a = document.createElement("a");
|
|
2889
|
+
if (a.relList.supports("ar")) {
|
|
2890
|
+
return true;
|
|
2891
|
+
}
|
|
2892
|
+
const userAgent = navigator.userAgent;
|
|
2893
|
+
const isIOS = /iPad|iPhone|iPod/.test(userAgent) && !window.MSStream;
|
|
2894
|
+
if (!isIOS) {
|
|
2895
|
+
return false;
|
|
2896
|
+
}
|
|
2897
|
+
const match = userAgent.match(/OS (\d+)_/);
|
|
2898
|
+
if (!match || match.length < 2) {
|
|
2899
|
+
return false;
|
|
2900
|
+
}
|
|
2901
|
+
const iOSVersion = parseInt(match[1], 10);
|
|
2902
|
+
const minQuickLookVersion = 12;
|
|
2903
|
+
if (iOSVersion < minQuickLookVersion) {
|
|
2904
|
+
return false;
|
|
2905
|
+
}
|
|
2906
|
+
const isSupportedBrowser = /^((?!chrome|android).)*safari|CriOS|FxiOS/i.test(userAgent);
|
|
2907
|
+
if (isSupportedBrowser) {
|
|
2908
|
+
return true;
|
|
2909
|
+
}
|
|
2910
|
+
return false;
|
|
2911
|
+
}
|
|
2912
|
+
/**
|
|
2913
|
+
* @returns A boolean indicating whether the user's device is a mobile device.
|
|
2914
|
+
*/
|
|
2915
|
+
static get isMobile() {
|
|
2916
|
+
return this.GetSystem() === "Android" || this.GetSystem() === "iOS";
|
|
2917
|
+
}
|
|
2918
|
+
/**
|
|
2919
|
+
* @returns A boolean indicating whether the user's device is a desktop device.
|
|
2920
|
+
*/
|
|
2921
|
+
static get isDesktop() {
|
|
2922
|
+
return !this.isMobile;
|
|
2923
|
+
}
|
|
2924
|
+
/**
|
|
2925
|
+
* @returns A promise that resolves to a boolean indicating whether the user's device is capable of AR.
|
|
2926
|
+
*/
|
|
2927
|
+
static GetIsARCapable() {
|
|
2928
|
+
return __async(this, null, function* () {
|
|
2929
|
+
if (this.GetSupportsARQuickLook()) {
|
|
2930
|
+
return true;
|
|
2931
|
+
}
|
|
2932
|
+
return yield this.GetSupportsWebXR();
|
|
2933
|
+
});
|
|
2934
|
+
}
|
|
2935
|
+
};
|
|
2936
|
+
DIVEInfo._supportsWebXR = null;
|
|
2937
|
+
|
|
2938
|
+
// package.json
|
|
2939
|
+
var package_default = {
|
|
2940
|
+
name: "@shopware-ag/dive",
|
|
2941
|
+
version: "1.16.14",
|
|
2942
|
+
description: "Shopware Spatial Framework",
|
|
2943
|
+
type: "module",
|
|
2944
|
+
main: "./build/dive.cjs",
|
|
2945
|
+
module: "./build/dive.js",
|
|
2946
|
+
types: "./build/dive.d.ts",
|
|
2947
|
+
files: [
|
|
2948
|
+
"build",
|
|
2949
|
+
"LICENSE",
|
|
2950
|
+
"package.json",
|
|
2951
|
+
"README.md",
|
|
2952
|
+
"src"
|
|
2953
|
+
],
|
|
2954
|
+
keywords: [
|
|
2955
|
+
"dive",
|
|
2956
|
+
"shopware",
|
|
2957
|
+
"sw6",
|
|
2958
|
+
"three",
|
|
2959
|
+
"three.js",
|
|
2960
|
+
"3d",
|
|
2961
|
+
"typescript"
|
|
2962
|
+
],
|
|
2963
|
+
repository: "git@github.com:shopware/dive.git",
|
|
2964
|
+
author: "ffrank <f.frank@shopware.com>",
|
|
2965
|
+
license: "MIT",
|
|
2966
|
+
browserslist: [
|
|
2967
|
+
"> 1%, not dead, not ie 11, not op_mini all"
|
|
2968
|
+
],
|
|
2969
|
+
dependencies: {
|
|
2970
|
+
"@tweenjs/tween.js": "^23.1.1",
|
|
2971
|
+
lodash: "^4.17.21",
|
|
2972
|
+
three: "^0.163.0",
|
|
2973
|
+
"three-spritetext": "^1.8.2"
|
|
2974
|
+
},
|
|
2975
|
+
devDependencies: {
|
|
2976
|
+
"@eslint/js": "^9.1.1",
|
|
2977
|
+
"@types/jest": "^29.5.12",
|
|
2978
|
+
"@types/lodash": "^4.17.12",
|
|
2979
|
+
"@types/node": "^20.12.7",
|
|
2980
|
+
"@types/three": "^0.163.0",
|
|
2981
|
+
eslint: "^9.1.1",
|
|
2982
|
+
globals: "^15.0.0",
|
|
2983
|
+
jest: "^29.7.0",
|
|
2984
|
+
"jest-environment-jsdom": "^29.7.0",
|
|
2985
|
+
jsdom: "^24.0.0",
|
|
2986
|
+
prettier: "^3.3.3",
|
|
2987
|
+
"prettier-plugin-multiline-arrays": "^3.0.6",
|
|
2988
|
+
"ts-jest": "^29.1.2",
|
|
2989
|
+
"ts-node": "^10.9.2",
|
|
2990
|
+
tsc: "^2.0.4",
|
|
2991
|
+
tsup: "^8.0.2",
|
|
2992
|
+
typescript: "^5.4.5",
|
|
2993
|
+
"typescript-eslint": "^7.7.1"
|
|
2994
|
+
},
|
|
2995
|
+
scripts: {
|
|
2996
|
+
build: "tsup --env.DIVE_NODE_ENV production",
|
|
2997
|
+
dev: "tsup --watch --env.DIVE_NODE_ENV development",
|
|
2998
|
+
lint: "eslint",
|
|
2999
|
+
"lint:actions": "yarn lint:actions:transpile && yarn lint:actions:check && yarn lint:actions:cleanup",
|
|
3000
|
+
"lint:actions:transpile": "yarn tsc --resolveJsonModule --esModuleInterop ci/lint/lint-actions.ts && mv ci/lint/lint-actions.js ci/lint/lint-actions.cjs",
|
|
3001
|
+
"lint:actions:check": "yarn node ci/lint/lint-actions.cjs",
|
|
3002
|
+
"lint:actions:cleanup": `node -e "require('fs').unlinkSync('ci/lint/lint-actions.cjs')"`,
|
|
3003
|
+
"prettier:check": "prettier --check .",
|
|
3004
|
+
"prettier:fix": "prettier --write .",
|
|
3005
|
+
unit: "jest",
|
|
3006
|
+
coverage: "jest --coverage",
|
|
3007
|
+
"generate-readme": "yarn generate-readme:transpile && yarn generate-readme:write && yarn generate-readme:cleanup",
|
|
3008
|
+
"generate-readme:transpile": "yarn tsc --resolveJsonModule --esModuleInterop ci/readme/generate-readme.ts && mv ci/readme/generate-readme.js ci/readme/generate-readme.cjs",
|
|
3009
|
+
"generate-readme:write": "node ci/readme/generate-readme.cjs",
|
|
3010
|
+
"generate-readme:cleanup": `node -e "require('fs').unlinkSync('ci/readme/generate-readme.cjs')"`
|
|
3011
|
+
}
|
|
3012
|
+
};
|
|
3013
|
+
|
|
3014
|
+
// src/math/helper/shift.ts
|
|
3015
|
+
function shift(value, exponent) {
|
|
3016
|
+
const subvalues = (value + "e").split("e");
|
|
3017
|
+
return +(subvalues[0] + "e" + (+subvalues[1] + (exponent || 0)));
|
|
3018
|
+
}
|
|
3019
|
+
|
|
3020
|
+
// src/math/ceil/ceilExp.ts
|
|
3021
|
+
function ceilExp(number, decimals = 0) {
|
|
3022
|
+
const n = shift(number, +decimals);
|
|
3023
|
+
return shift(Math.ceil(n), -decimals);
|
|
3024
|
+
}
|
|
3025
|
+
|
|
3026
|
+
// src/math/floor/floorExp.ts
|
|
3027
|
+
function floorExp(number, decimals = 0) {
|
|
3028
|
+
const n = shift(number, +decimals);
|
|
3029
|
+
return shift(Math.floor(n), -decimals);
|
|
3030
|
+
}
|
|
3031
|
+
|
|
3032
|
+
// src/math/round/roundExp.ts
|
|
3033
|
+
function roundExponential(number, decimals = 0) {
|
|
3034
|
+
if (number < 0) return -roundExponential(-number, decimals);
|
|
3035
|
+
const n = shift(number, +decimals);
|
|
3036
|
+
return shift(Math.round(n), -decimals);
|
|
3037
|
+
}
|
|
3038
|
+
|
|
3039
|
+
// src/math/signedAngleTo/signedAngleTo.ts
|
|
3040
|
+
function signedAngleTo(vecA, vecB, planeNormal) {
|
|
3041
|
+
return Math.atan2(
|
|
3042
|
+
vecA.clone().cross(vecB).dot(planeNormal),
|
|
3043
|
+
vecB.clone().dot(vecA)
|
|
3044
|
+
);
|
|
3045
|
+
}
|
|
3046
|
+
|
|
3047
|
+
// src/math/toFixed/toFixedExp.ts
|
|
3048
|
+
function toFixedExp(number, decimals = 0) {
|
|
3049
|
+
const n = shift(number, +decimals);
|
|
3050
|
+
return shift(Math.round(n), -decimals).toFixed(decimals);
|
|
3051
|
+
}
|
|
3052
|
+
|
|
3053
|
+
// src/math/truncate/truncateExp.ts
|
|
3054
|
+
function truncateExp(number, decimals = 0) {
|
|
3055
|
+
const n = shift(number, +decimals);
|
|
3056
|
+
return shift(Math.trunc(n), -decimals);
|
|
3057
|
+
}
|
|
3058
|
+
|
|
3059
|
+
// src/math/radToDeg/radToDeg.ts
|
|
3060
|
+
var import_three17 = require("three");
|
|
3061
|
+
function radToDeg(radians) {
|
|
3062
|
+
return (import_three17.MathUtils.radToDeg(radians) + 360) % 360;
|
|
3063
|
+
}
|
|
3064
|
+
|
|
3065
|
+
// src/math/degToRad/degToRad.ts
|
|
3066
|
+
var import_three18 = require("three");
|
|
3067
|
+
function degToRad(degrees) {
|
|
3068
|
+
return import_three18.MathUtils.degToRad(degrees);
|
|
3069
|
+
}
|
|
3070
|
+
|
|
3071
|
+
// src/math/index.ts
|
|
3072
|
+
var DIVEMath = {
|
|
3073
|
+
ceilExp,
|
|
3074
|
+
floorExp,
|
|
3075
|
+
roundExp: roundExponential,
|
|
3076
|
+
toFixedExp,
|
|
3077
|
+
truncateExp,
|
|
3078
|
+
signedAngleTo,
|
|
3079
|
+
radToDeg,
|
|
3080
|
+
degToRad
|
|
3081
|
+
};
|
|
3082
|
+
|
|
3083
|
+
// src/dive.ts
|
|
3084
|
+
var DIVEDefaultSettings = {
|
|
3085
|
+
autoResize: true,
|
|
3086
|
+
displayAxes: false,
|
|
3087
|
+
renderer: DIVERendererDefaultSettings,
|
|
3088
|
+
perspectiveCamera: DIVEPerspectiveCameraDefaultSettings,
|
|
3089
|
+
orbitControls: DIVEOrbitControlsDefaultSettings
|
|
3090
|
+
};
|
|
3091
|
+
var DIVE = class _DIVE {
|
|
3092
|
+
// static members
|
|
3093
|
+
static QuickView(uri) {
|
|
3094
|
+
const dive = new _DIVE();
|
|
3095
|
+
dive.Communication.PerformAction("SET_CAMERA_TRANSFORM", {
|
|
3096
|
+
position: { x: 0, y: 2, z: 2 },
|
|
3097
|
+
target: { x: 0, y: 0.5, z: 0 }
|
|
3098
|
+
});
|
|
3099
|
+
const lightid = (0, import_MathUtils2.generateUUID)();
|
|
3100
|
+
dive.Communication.PerformAction("ADD_OBJECT", {
|
|
3101
|
+
entityType: "light",
|
|
3102
|
+
type: "scene",
|
|
3103
|
+
name: "light",
|
|
3104
|
+
id: lightid,
|
|
3105
|
+
enabled: true,
|
|
3106
|
+
visible: true,
|
|
3107
|
+
intensity: 1,
|
|
3108
|
+
color: 16777215
|
|
3109
|
+
});
|
|
3110
|
+
const modelid = (0, import_MathUtils2.generateUUID)();
|
|
3111
|
+
dive.Communication.Subscribe("MODEL_LOADED", (data) => {
|
|
3112
|
+
if (data.id !== modelid) return;
|
|
3113
|
+
dive.Communication.PerformAction("PLACE_ON_FLOOR", {
|
|
3114
|
+
id: modelid
|
|
3115
|
+
});
|
|
3116
|
+
const transform = dive.Communication.PerformAction(
|
|
3117
|
+
"COMPUTE_ENCOMPASSING_VIEW",
|
|
3118
|
+
{}
|
|
3119
|
+
);
|
|
3120
|
+
dive.Communication.PerformAction("SET_CAMERA_TRANSFORM", {
|
|
3121
|
+
position: transform.position,
|
|
3122
|
+
target: transform.target
|
|
3123
|
+
});
|
|
3124
|
+
});
|
|
3125
|
+
dive.Communication.PerformAction("ADD_OBJECT", {
|
|
3126
|
+
entityType: "model",
|
|
3127
|
+
name: "object",
|
|
3128
|
+
id: modelid,
|
|
3129
|
+
position: { x: 0, y: 0, z: 0 },
|
|
3130
|
+
rotation: { x: 0, y: 0, z: 0 },
|
|
3131
|
+
scale: { x: 1, y: 1, z: 1 },
|
|
3132
|
+
uri,
|
|
3133
|
+
visible: true,
|
|
3134
|
+
loaded: false
|
|
3135
|
+
});
|
|
3136
|
+
dive.Communication.PerformAction("UPDATE_SCENE", {
|
|
3137
|
+
backgroundColor: 16777215,
|
|
3138
|
+
gridEnabled: false,
|
|
3139
|
+
floorColor: 16777215
|
|
3140
|
+
});
|
|
3141
|
+
return dive;
|
|
3142
|
+
}
|
|
3143
|
+
// getters
|
|
3144
|
+
get Communication() {
|
|
3145
|
+
return this.communication;
|
|
3146
|
+
}
|
|
3147
|
+
get Canvas() {
|
|
3148
|
+
return this.renderer.domElement;
|
|
3149
|
+
}
|
|
3150
|
+
get Info() {
|
|
3151
|
+
return DIVEInfo;
|
|
3152
|
+
}
|
|
3153
|
+
// setters
|
|
3154
|
+
set Settings(settings) {
|
|
3155
|
+
var _a;
|
|
3156
|
+
const settingsDelta = getObjectDelta(this._settings, settings);
|
|
3157
|
+
if (settingsDelta.renderer)
|
|
3158
|
+
this.renderer = new DIVERenderer(this._settings.renderer);
|
|
3159
|
+
if (settingsDelta.perspectiveCamera) {
|
|
3160
|
+
if (settingsDelta.perspectiveCamera.fov !== void 0)
|
|
3161
|
+
this.perspectiveCamera.fov = settingsDelta.perspectiveCamera.fov;
|
|
3162
|
+
if (settingsDelta.perspectiveCamera.near !== void 0)
|
|
3163
|
+
this.perspectiveCamera.near = settingsDelta.perspectiveCamera.near;
|
|
3164
|
+
if (settingsDelta.perspectiveCamera.far !== void 0)
|
|
3165
|
+
this.perspectiveCamera.far = settingsDelta.perspectiveCamera.far;
|
|
3166
|
+
this.perspectiveCamera.OnResize(
|
|
3167
|
+
this.renderer.domElement.width,
|
|
3168
|
+
this.renderer.domElement.height
|
|
3169
|
+
);
|
|
3170
|
+
}
|
|
3171
|
+
if (settingsDelta.orbitControls) {
|
|
3172
|
+
if (settingsDelta.orbitControls.enableDamping !== void 0)
|
|
3173
|
+
this.orbitControls.enableDamping = settingsDelta.orbitControls.enableDamping;
|
|
3174
|
+
if (settingsDelta.orbitControls.dampingFactor !== void 0)
|
|
3175
|
+
this.orbitControls.dampingFactor = settingsDelta.orbitControls.dampingFactor;
|
|
3176
|
+
}
|
|
3177
|
+
if (settingsDelta.autoResize !== this._settings.autoResize) {
|
|
3178
|
+
if (settingsDelta.autoResize) {
|
|
3179
|
+
this.addResizeObserver();
|
|
3180
|
+
} else {
|
|
3181
|
+
this.removeResizeObserver();
|
|
3182
|
+
}
|
|
3183
|
+
}
|
|
3184
|
+
if (settingsDelta.displayAxes) {
|
|
3185
|
+
this.axisCamera = new DIVEAxisCamera(
|
|
3186
|
+
this.renderer,
|
|
3187
|
+
this.scene,
|
|
3188
|
+
this.orbitControls
|
|
3189
|
+
);
|
|
3190
|
+
} else {
|
|
3191
|
+
(_a = this.axisCamera) == null ? void 0 : _a.Dispose();
|
|
3192
|
+
this.axisCamera = null;
|
|
3193
|
+
}
|
|
3194
|
+
Object.assign(this._settings, settings);
|
|
3195
|
+
}
|
|
3196
|
+
constructor(settings) {
|
|
3197
|
+
this._settings = __spreadValues(__spreadValues({}, DIVEDefaultSettings), settings !== void 0 ? settings : {});
|
|
3198
|
+
this._resizeObserverId = "";
|
|
3199
|
+
this._width = 0;
|
|
3200
|
+
this._height = 0;
|
|
3201
|
+
this.renderer = new DIVERenderer(this._settings.renderer);
|
|
3202
|
+
this.scene = new DIVEScene();
|
|
3203
|
+
this.perspectiveCamera = new DIVEPerspectiveCamera(
|
|
3204
|
+
this._settings.perspectiveCamera
|
|
3205
|
+
);
|
|
3206
|
+
this.animationSystem = new DIVEAnimationSystem(this.renderer);
|
|
3207
|
+
this.orbitControls = new DIVEOrbitControls(
|
|
3208
|
+
this.perspectiveCamera,
|
|
3209
|
+
this.renderer,
|
|
3210
|
+
this.animationSystem,
|
|
3211
|
+
this._settings.orbitControls
|
|
3212
|
+
);
|
|
3213
|
+
this.toolbox = new DIVEToolbox(this.scene, this.orbitControls);
|
|
3214
|
+
this.communication = new DIVECommunication(
|
|
3215
|
+
this.renderer,
|
|
3216
|
+
this.scene,
|
|
3217
|
+
this.orbitControls,
|
|
3218
|
+
this.toolbox
|
|
3219
|
+
);
|
|
3220
|
+
if (this._settings.displayAxes) {
|
|
3221
|
+
this.axisCamera = new DIVEAxisCamera(
|
|
3222
|
+
this.renderer,
|
|
3223
|
+
this.scene,
|
|
3224
|
+
this.orbitControls
|
|
3225
|
+
);
|
|
3226
|
+
} else {
|
|
3227
|
+
this.axisCamera = null;
|
|
3228
|
+
}
|
|
3229
|
+
if (this._settings.autoResize) {
|
|
3230
|
+
this.addResizeObserver();
|
|
3231
|
+
}
|
|
3232
|
+
this.renderer.StartRenderer(this.scene, this.perspectiveCamera);
|
|
3233
|
+
window.DIVE = {
|
|
3234
|
+
PrintScene: () => {
|
|
3235
|
+
console.log(this.scene);
|
|
3236
|
+
}
|
|
3237
|
+
};
|
|
3238
|
+
console.log(
|
|
3239
|
+
`DIVE ${package_default.version} initialized ${false ? "in development mode" : ""}`
|
|
3240
|
+
);
|
|
3241
|
+
}
|
|
3242
|
+
Dispose() {
|
|
3243
|
+
var _a;
|
|
3244
|
+
this.removeResizeObserver();
|
|
3245
|
+
this.renderer.Dispose();
|
|
3246
|
+
this.orbitControls.Dispose();
|
|
3247
|
+
(_a = this.axisCamera) == null ? void 0 : _a.Dispose();
|
|
3248
|
+
this.animationSystem.Dispose();
|
|
3249
|
+
this.toolbox.Dispose();
|
|
3250
|
+
this.communication.DestroyInstance();
|
|
3251
|
+
}
|
|
3252
|
+
// methods
|
|
3253
|
+
OnResize(width, height) {
|
|
3254
|
+
this.renderer.OnResize(width, height);
|
|
3255
|
+
this.perspectiveCamera.OnResize(width, height);
|
|
3256
|
+
}
|
|
3257
|
+
addResizeObserver() {
|
|
3258
|
+
this._resizeObserverId = this.renderer.AddPreRenderCallback(() => {
|
|
3259
|
+
const canvasWrapper = this.renderer.domElement.parentElement;
|
|
3260
|
+
if (!canvasWrapper) return;
|
|
3261
|
+
const { clientWidth, clientHeight } = canvasWrapper;
|
|
3262
|
+
if (clientWidth === this._width && clientHeight === this._height)
|
|
3263
|
+
return;
|
|
3264
|
+
this.OnResize(clientWidth, clientHeight);
|
|
3265
|
+
this._width = clientWidth;
|
|
3266
|
+
this._height = clientHeight;
|
|
3267
|
+
});
|
|
3268
|
+
}
|
|
3269
|
+
removeResizeObserver() {
|
|
3270
|
+
this.renderer.RemovePreRenderCallback(this._resizeObserverId);
|
|
3271
|
+
}
|
|
3272
|
+
};
|
|
3273
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
3274
|
+
0 && (module.exports = {
|
|
3275
|
+
DIVE,
|
|
3276
|
+
DIVECommunication,
|
|
3277
|
+
DIVEDefaultSettings,
|
|
3278
|
+
DIVEMath
|
|
3279
|
+
});
|
|
3280
|
+
//# sourceMappingURL=dive.cjs.map
|