@shopware-ag/dive 1.0.7
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/LICENSE +21 -0
- package/README.md +161 -0
- package/build/dive.cjs +1551 -0
- package/build/dive.cjs.map +1 -0
- package/build/dive.d.cts +558 -0
- package/build/dive.d.ts +558 -0
- package/build/dive.js +1516 -0
- package/build/dive.js.map +1 -0
- package/package.json +57 -0
- package/src/dive.ts +210 -0
package/build/dive.js
ADDED
|
@@ -0,0 +1,1516 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
var __async = (__this, __arguments, generator) => {
|
|
21
|
+
return new Promise((resolve, reject) => {
|
|
22
|
+
var fulfilled = (value) => {
|
|
23
|
+
try {
|
|
24
|
+
step(generator.next(value));
|
|
25
|
+
} catch (e) {
|
|
26
|
+
reject(e);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
var rejected = (value) => {
|
|
30
|
+
try {
|
|
31
|
+
step(generator.throw(value));
|
|
32
|
+
} catch (e) {
|
|
33
|
+
reject(e);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
37
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
// src/dive.ts
|
|
42
|
+
import { Vector4 } from "three";
|
|
43
|
+
|
|
44
|
+
// src/renderer/Renderer.ts
|
|
45
|
+
import { MathUtils, NoToneMapping, PCFSoftShadowMap, WebGLRenderer } from "three";
|
|
46
|
+
var DIVERendererDefaultSettings = {
|
|
47
|
+
antialias: true,
|
|
48
|
+
alpha: true,
|
|
49
|
+
stencil: false,
|
|
50
|
+
shadowMapEnabled: true,
|
|
51
|
+
shadowMapType: PCFSoftShadowMap,
|
|
52
|
+
toneMapping: NoToneMapping
|
|
53
|
+
};
|
|
54
|
+
var DIVERenderer = class extends WebGLRenderer {
|
|
55
|
+
constructor(rendererSettings = DIVERendererDefaultSettings) {
|
|
56
|
+
super({
|
|
57
|
+
antialias: rendererSettings.antialias,
|
|
58
|
+
alpha: rendererSettings.alpha,
|
|
59
|
+
preserveDrawingBuffer: true
|
|
60
|
+
});
|
|
61
|
+
// basic functionality members
|
|
62
|
+
this.paused = false;
|
|
63
|
+
this.running = false;
|
|
64
|
+
this.force = false;
|
|
65
|
+
// pre- and post-render callbacks
|
|
66
|
+
this.preRenderCallbacks = /* @__PURE__ */ new Map();
|
|
67
|
+
this.postRenderCallbacks = /* @__PURE__ */ new Map();
|
|
68
|
+
this.setPixelRatio(window.devicePixelRatio);
|
|
69
|
+
this.shadowMap.enabled = rendererSettings.shadowMapEnabled;
|
|
70
|
+
this.shadowMap.type = rendererSettings.shadowMapType;
|
|
71
|
+
this.toneMapping = rendererSettings.toneMapping;
|
|
72
|
+
this.debug.checkShaderErrors = false;
|
|
73
|
+
}
|
|
74
|
+
// Starts the renderer with the given scene and camera.
|
|
75
|
+
StartRenderer(scene, cam) {
|
|
76
|
+
this.setAnimationLoop(() => {
|
|
77
|
+
this.internal_render(scene, cam);
|
|
78
|
+
});
|
|
79
|
+
this.running = true;
|
|
80
|
+
}
|
|
81
|
+
// Pauses the renderer.
|
|
82
|
+
PauseRenderer() {
|
|
83
|
+
this.paused = true;
|
|
84
|
+
}
|
|
85
|
+
// Resumes the renderer after pausing.
|
|
86
|
+
ResumeRenderer() {
|
|
87
|
+
this.paused = false;
|
|
88
|
+
}
|
|
89
|
+
// Stops the renderer completely. Has to be started again with StartRenderer().
|
|
90
|
+
StopRenderer() {
|
|
91
|
+
this.setAnimationLoop(null);
|
|
92
|
+
this.running = false;
|
|
93
|
+
}
|
|
94
|
+
// Resizes the renderer to the given width and height.
|
|
95
|
+
OnResize(width, height) {
|
|
96
|
+
this.setSize(width, height);
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Adds a callback to the render loop before actual render call.
|
|
100
|
+
* @param callback Executed before rendering.
|
|
101
|
+
* @returns uuid to remove the callback.
|
|
102
|
+
*/
|
|
103
|
+
AddPreRenderCallback(callback) {
|
|
104
|
+
const newUUID = MathUtils.generateUUID();
|
|
105
|
+
this.preRenderCallbacks.set(newUUID, callback);
|
|
106
|
+
return newUUID;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Removes a callback from the render loop before actual render call.
|
|
110
|
+
* @param uuid of callback to remove.
|
|
111
|
+
* @returns if removing was successful.
|
|
112
|
+
*/
|
|
113
|
+
RemovePreRenderCallback(uuid) {
|
|
114
|
+
if (!this.preRenderCallbacks.has(uuid))
|
|
115
|
+
return false;
|
|
116
|
+
this.preRenderCallbacks.delete(uuid);
|
|
117
|
+
return true;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Adds a callback to the render loop after actual render call.
|
|
121
|
+
* @param callback Executed after rendering.
|
|
122
|
+
* @returns uuid to remove the callback.
|
|
123
|
+
*/
|
|
124
|
+
AddPostRenderCallback(callback) {
|
|
125
|
+
const newUUID = MathUtils.generateUUID();
|
|
126
|
+
this.postRenderCallbacks.set(newUUID, callback);
|
|
127
|
+
return newUUID;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Removes a callback from the render loop after actual render call.
|
|
131
|
+
* @param uuid of callback to remove.
|
|
132
|
+
* @returns if removing was successful.
|
|
133
|
+
*/
|
|
134
|
+
RemovePostRenderCallback(uuid) {
|
|
135
|
+
if (!this.postRenderCallbacks.has(uuid))
|
|
136
|
+
return false;
|
|
137
|
+
this.postRenderCallbacks.delete(uuid);
|
|
138
|
+
return true;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Forces the renderer to render the next frame.
|
|
142
|
+
*/
|
|
143
|
+
ForceRendering() {
|
|
144
|
+
this.force = true;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Internal render loop.
|
|
148
|
+
*
|
|
149
|
+
* To control renderloop you can add callbacks via AddPreRenderCallback() and AddPostRenderCallback().
|
|
150
|
+
* @param scene Scene to render.
|
|
151
|
+
* @param cam Camera to render with.
|
|
152
|
+
*/
|
|
153
|
+
internal_render(scene, cam) {
|
|
154
|
+
if ((this.paused || !this.running) && !this.force)
|
|
155
|
+
return;
|
|
156
|
+
this.preRenderCallbacks.forEach((callback) => {
|
|
157
|
+
callback();
|
|
158
|
+
});
|
|
159
|
+
this.render(scene, cam);
|
|
160
|
+
this.postRenderCallbacks.forEach((callback) => {
|
|
161
|
+
callback();
|
|
162
|
+
});
|
|
163
|
+
this.force = false;
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
// src/scene/Scene.ts
|
|
168
|
+
import { Color as Color7, Scene as Scene2 } from "three";
|
|
169
|
+
|
|
170
|
+
// src/scene/root/Root.ts
|
|
171
|
+
import { Object3D as Object3D6 } from "three";
|
|
172
|
+
|
|
173
|
+
// src/scene/root/lightroot/LightRoot.ts
|
|
174
|
+
import { Color as Color5, Object3D as Object3D2 } from "three";
|
|
175
|
+
|
|
176
|
+
// src/light/AmbientLight.ts
|
|
177
|
+
import { AmbientLight } from "three";
|
|
178
|
+
|
|
179
|
+
// src/constant/VisibilityLayerMask.ts
|
|
180
|
+
var DEFAULT_LAYER_MASK = 1;
|
|
181
|
+
var COORDINATE_LAYER_MASK = 2;
|
|
182
|
+
var UI_LAYER_MASK = 4;
|
|
183
|
+
var HELPER_LAYER_MASK = 8;
|
|
184
|
+
var PRODUCT_LAYER_MASK = 16;
|
|
185
|
+
|
|
186
|
+
// src/light/AmbientLight.ts
|
|
187
|
+
var DIVEAmbientLight = class extends AmbientLight {
|
|
188
|
+
constructor() {
|
|
189
|
+
super(16777215, 1);
|
|
190
|
+
this.layers.mask = PRODUCT_LAYER_MASK;
|
|
191
|
+
}
|
|
192
|
+
SetColor(color) {
|
|
193
|
+
this.color = color;
|
|
194
|
+
}
|
|
195
|
+
SetIntensity(intensity) {
|
|
196
|
+
this.intensity = intensity;
|
|
197
|
+
}
|
|
198
|
+
SetEnabled(enabled) {
|
|
199
|
+
this.visible = enabled;
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
// src/light/PointLight.ts
|
|
204
|
+
import { PointLight, SphereGeometry, MeshBasicMaterial, Mesh, FrontSide } from "three";
|
|
205
|
+
|
|
206
|
+
// src/com/Communication.ts
|
|
207
|
+
import { MathUtils as MathUtils2 } from "three";
|
|
208
|
+
var _DIVECommunication = class _DIVECommunication {
|
|
209
|
+
constructor(scene, controls, toolbox, mediaGenerator) {
|
|
210
|
+
this.registered = /* @__PURE__ */ new Map();
|
|
211
|
+
// private listeners: { [key: string]: EventListener[] } = {};
|
|
212
|
+
this.listeners = /* @__PURE__ */ new Map();
|
|
213
|
+
this.id = MathUtils2.generateUUID();
|
|
214
|
+
this.scene = scene;
|
|
215
|
+
this.controller = controls;
|
|
216
|
+
this.toolbox = toolbox;
|
|
217
|
+
this.mediaGenerator = mediaGenerator;
|
|
218
|
+
_DIVECommunication.__instances.push(this);
|
|
219
|
+
}
|
|
220
|
+
static get(id) {
|
|
221
|
+
return this.__instances.find((instance) => Array.from(instance.registered.values()).find((object) => object.id === id));
|
|
222
|
+
}
|
|
223
|
+
DestroyInstance() {
|
|
224
|
+
const existingIndex = _DIVECommunication.__instances.findIndex((entry) => entry.id === this.id);
|
|
225
|
+
if (existingIndex === -1)
|
|
226
|
+
return false;
|
|
227
|
+
_DIVECommunication.__instances.splice(existingIndex, 1);
|
|
228
|
+
return true;
|
|
229
|
+
}
|
|
230
|
+
PerformAction(action, payload) {
|
|
231
|
+
let returnValue = false;
|
|
232
|
+
switch (action) {
|
|
233
|
+
case "GET_ALL_SCENE_DATA": {
|
|
234
|
+
returnValue = this.getAllSceneData(payload);
|
|
235
|
+
break;
|
|
236
|
+
}
|
|
237
|
+
case "GET_ALL_OBJECTS": {
|
|
238
|
+
returnValue = this.getAllObjects(payload);
|
|
239
|
+
break;
|
|
240
|
+
}
|
|
241
|
+
case "GET_OBJECTS": {
|
|
242
|
+
returnValue = this.getObjects(payload);
|
|
243
|
+
break;
|
|
244
|
+
}
|
|
245
|
+
case "ADD_OBJECT": {
|
|
246
|
+
returnValue = this.addObject(payload);
|
|
247
|
+
break;
|
|
248
|
+
}
|
|
249
|
+
case "UPDATE_OBJECT": {
|
|
250
|
+
returnValue = this.updateObject(payload);
|
|
251
|
+
break;
|
|
252
|
+
}
|
|
253
|
+
case "DELETE_OBJECT": {
|
|
254
|
+
returnValue = this.deleteObject(payload);
|
|
255
|
+
break;
|
|
256
|
+
}
|
|
257
|
+
case "SELECT_OBJECT": {
|
|
258
|
+
returnValue = this.selectObject(payload);
|
|
259
|
+
break;
|
|
260
|
+
}
|
|
261
|
+
case "SET_BACKGROUND": {
|
|
262
|
+
returnValue = this.setBackground(payload);
|
|
263
|
+
break;
|
|
264
|
+
}
|
|
265
|
+
case "PLACE_ON_FLOOR": {
|
|
266
|
+
returnValue = this.placeOnFloor(payload);
|
|
267
|
+
break;
|
|
268
|
+
}
|
|
269
|
+
case "SET_CAMERA_TRANSFORM": {
|
|
270
|
+
returnValue = this.setCameraTransform(payload);
|
|
271
|
+
break;
|
|
272
|
+
}
|
|
273
|
+
case "GET_CAMERA_TRANSFORM": {
|
|
274
|
+
returnValue = this.getCameraTransform(payload);
|
|
275
|
+
break;
|
|
276
|
+
}
|
|
277
|
+
case "MOVE_CAMERA": {
|
|
278
|
+
returnValue = this.moveCamera(payload);
|
|
279
|
+
break;
|
|
280
|
+
}
|
|
281
|
+
case "RESET_CAMERA": {
|
|
282
|
+
returnValue = this.resetCamera(payload);
|
|
283
|
+
break;
|
|
284
|
+
}
|
|
285
|
+
case "SET_CAMERA_LAYER": {
|
|
286
|
+
returnValue = this.setCameraLayer(payload);
|
|
287
|
+
break;
|
|
288
|
+
}
|
|
289
|
+
case "ZOOM_CAMERA": {
|
|
290
|
+
returnValue = this.zoomCamera(payload);
|
|
291
|
+
break;
|
|
292
|
+
}
|
|
293
|
+
case "SET_GIZMO_MODE": {
|
|
294
|
+
returnValue = this.setGizmoMode(payload);
|
|
295
|
+
break;
|
|
296
|
+
}
|
|
297
|
+
case "MODEL_LOADED": {
|
|
298
|
+
returnValue = this.modelLoaded(payload);
|
|
299
|
+
break;
|
|
300
|
+
}
|
|
301
|
+
case "UPDATE_SCENE": {
|
|
302
|
+
returnValue = this.updateScene(payload);
|
|
303
|
+
break;
|
|
304
|
+
}
|
|
305
|
+
case "GENERATE_MEDIA": {
|
|
306
|
+
returnValue = this.generateMedia(payload);
|
|
307
|
+
break;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
this.dispatch(action, payload);
|
|
311
|
+
return returnValue;
|
|
312
|
+
}
|
|
313
|
+
Subscribe(type, listener) {
|
|
314
|
+
if (!this.listeners.get(type))
|
|
315
|
+
this.listeners.set(type, []);
|
|
316
|
+
this.listeners.get(type).push(listener);
|
|
317
|
+
return () => {
|
|
318
|
+
const listenerArray = this.listeners.get(type);
|
|
319
|
+
if (!listenerArray)
|
|
320
|
+
return false;
|
|
321
|
+
const existingIndex = listenerArray.findIndex((entry) => entry === listener);
|
|
322
|
+
if (existingIndex === -1)
|
|
323
|
+
return false;
|
|
324
|
+
listenerArray.splice(existingIndex, 1);
|
|
325
|
+
return true;
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
dispatch(type, payload) {
|
|
329
|
+
const listenerArray = this.listeners.get(type);
|
|
330
|
+
if (!listenerArray)
|
|
331
|
+
return;
|
|
332
|
+
listenerArray.forEach((listener) => listener(payload));
|
|
333
|
+
}
|
|
334
|
+
getAllSceneData(payload) {
|
|
335
|
+
const sceneData = {
|
|
336
|
+
name: this.scene.name,
|
|
337
|
+
mediaItem: null,
|
|
338
|
+
backgroundColor: "#" + this.scene.background.getHexString(),
|
|
339
|
+
floorEnabled: this.scene.Root.Floor.visible,
|
|
340
|
+
floorColor: "#" + this.scene.Root.Floor.material.color.getHexString(),
|
|
341
|
+
userCamera: {
|
|
342
|
+
position: this.controller.object.position.clone(),
|
|
343
|
+
target: this.controller.target.clone()
|
|
344
|
+
},
|
|
345
|
+
spotmarks: [],
|
|
346
|
+
lights: Array.from(this.registered.values()).filter((object) => object.entityType === "light"),
|
|
347
|
+
objects: Array.from(this.registered.values()).filter((object) => object.entityType === "model"),
|
|
348
|
+
cameras: Array.from(this.registered.values()).filter((object) => object.entityType === "pov")
|
|
349
|
+
};
|
|
350
|
+
Object.assign(payload, sceneData);
|
|
351
|
+
return sceneData;
|
|
352
|
+
}
|
|
353
|
+
getAllObjects(payload) {
|
|
354
|
+
Object.assign(payload, this.registered);
|
|
355
|
+
return this.registered;
|
|
356
|
+
}
|
|
357
|
+
getObjects(payload) {
|
|
358
|
+
this.registered.forEach((object) => {
|
|
359
|
+
if (payload.ids && payload.ids.length > 0 && !payload.ids.includes(object.id))
|
|
360
|
+
return;
|
|
361
|
+
payload.map.set(object.id, object);
|
|
362
|
+
});
|
|
363
|
+
return payload.map;
|
|
364
|
+
}
|
|
365
|
+
addObject(payload) {
|
|
366
|
+
if (this.registered.get(payload.id))
|
|
367
|
+
return false;
|
|
368
|
+
this.registered.set(payload.id, payload);
|
|
369
|
+
this.scene.AddSceneObject(payload);
|
|
370
|
+
return true;
|
|
371
|
+
}
|
|
372
|
+
updateObject(payload) {
|
|
373
|
+
const objectToUpdate = this.registered.get(payload.id);
|
|
374
|
+
if (!objectToUpdate)
|
|
375
|
+
return false;
|
|
376
|
+
this.registered.set(payload.id, __spreadValues(__spreadValues({}, objectToUpdate), payload));
|
|
377
|
+
const updatedObject = this.registered.get(payload.id);
|
|
378
|
+
this.scene.UpdateSceneObject(updatedObject);
|
|
379
|
+
Object.assign(payload, updatedObject);
|
|
380
|
+
return true;
|
|
381
|
+
}
|
|
382
|
+
deleteObject(payload) {
|
|
383
|
+
const deletedObject = this.registered.get(payload.id);
|
|
384
|
+
if (!deletedObject)
|
|
385
|
+
return false;
|
|
386
|
+
Object.assign(payload, deletedObject);
|
|
387
|
+
this.registered.delete(payload.id);
|
|
388
|
+
this.scene.DeleteSceneObject(deletedObject);
|
|
389
|
+
return true;
|
|
390
|
+
}
|
|
391
|
+
selectObject(payload) {
|
|
392
|
+
const object = this.registered.get(payload.id);
|
|
393
|
+
if (!object)
|
|
394
|
+
return false;
|
|
395
|
+
const sceneObject = this.scene.GetSceneObject(object);
|
|
396
|
+
if (!sceneObject)
|
|
397
|
+
return false;
|
|
398
|
+
if (!("isSelectable" in sceneObject))
|
|
399
|
+
return false;
|
|
400
|
+
this.toolbox.UseTool("select");
|
|
401
|
+
this.toolbox.GetActiveTool().Select(sceneObject);
|
|
402
|
+
Object.assign(payload, object);
|
|
403
|
+
return true;
|
|
404
|
+
}
|
|
405
|
+
setBackground(payload) {
|
|
406
|
+
this.scene.SetBackground(payload.color);
|
|
407
|
+
return true;
|
|
408
|
+
}
|
|
409
|
+
placeOnFloor(payload) {
|
|
410
|
+
if (!this.registered.get(payload.id))
|
|
411
|
+
return false;
|
|
412
|
+
this.scene.PlaceOnFloor(payload);
|
|
413
|
+
return true;
|
|
414
|
+
}
|
|
415
|
+
setCameraTransform(payload) {
|
|
416
|
+
this.controller.object.position.copy(payload.position);
|
|
417
|
+
this.controller.target.copy(payload.target);
|
|
418
|
+
this.controller.update();
|
|
419
|
+
return true;
|
|
420
|
+
}
|
|
421
|
+
getCameraTransform(payload) {
|
|
422
|
+
const transform = {
|
|
423
|
+
position: this.controller.object.position.clone(),
|
|
424
|
+
target: this.controller.target.clone()
|
|
425
|
+
};
|
|
426
|
+
Object.assign(payload, transform);
|
|
427
|
+
return transform;
|
|
428
|
+
}
|
|
429
|
+
moveCamera(payload) {
|
|
430
|
+
let position = { x: 0, y: 0, z: 0 };
|
|
431
|
+
let target = { x: 0, y: 0, z: 0 };
|
|
432
|
+
if ("id" in payload) {
|
|
433
|
+
position = this.registered.get(payload.id).position;
|
|
434
|
+
target = this.registered.get(payload.id).target;
|
|
435
|
+
} else {
|
|
436
|
+
position = payload.position;
|
|
437
|
+
target = payload.target;
|
|
438
|
+
}
|
|
439
|
+
this.controller.MoveTo(position, target, payload.duration, payload.locked);
|
|
440
|
+
return true;
|
|
441
|
+
}
|
|
442
|
+
setCameraLayer(payload) {
|
|
443
|
+
this.controller.object.SetCameraLayer(payload.layer);
|
|
444
|
+
return true;
|
|
445
|
+
}
|
|
446
|
+
resetCamera(payload) {
|
|
447
|
+
this.controller.RevertLast(payload.duration);
|
|
448
|
+
return true;
|
|
449
|
+
}
|
|
450
|
+
zoomCamera(payload) {
|
|
451
|
+
if (payload.direction === "IN")
|
|
452
|
+
this.controller.ZoomIn(payload.by);
|
|
453
|
+
if (payload.direction === "OUT")
|
|
454
|
+
this.controller.ZoomOut(payload.by);
|
|
455
|
+
return true;
|
|
456
|
+
}
|
|
457
|
+
setGizmoMode(payload) {
|
|
458
|
+
this.toolbox.SetGizmoMode(payload.mode);
|
|
459
|
+
return true;
|
|
460
|
+
}
|
|
461
|
+
modelLoaded(payload) {
|
|
462
|
+
this.registered.get(payload.id).loaded = true;
|
|
463
|
+
return true;
|
|
464
|
+
}
|
|
465
|
+
updateScene(payload) {
|
|
466
|
+
if (payload.name !== void 0)
|
|
467
|
+
this.scene.name = payload.name;
|
|
468
|
+
if (payload.backgroundColor !== void 0)
|
|
469
|
+
this.scene.SetBackground(payload.backgroundColor);
|
|
470
|
+
if (payload.floorEnabled !== void 0)
|
|
471
|
+
this.scene.Root.Floor.SetVisibility(payload.floorEnabled);
|
|
472
|
+
if (payload.floorColor !== void 0)
|
|
473
|
+
this.scene.Root.Floor.SetColor(payload.floorColor);
|
|
474
|
+
payload.name = this.scene.name;
|
|
475
|
+
payload.backgroundColor = "#" + this.scene.background.getHexString();
|
|
476
|
+
payload.floorEnabled = this.scene.Root.Floor.visible;
|
|
477
|
+
payload.floorColor = "#" + this.scene.Root.Floor.material.color.getHexString();
|
|
478
|
+
return true;
|
|
479
|
+
}
|
|
480
|
+
generateMedia(payload) {
|
|
481
|
+
let position = { x: 0, y: 0, z: 0 };
|
|
482
|
+
let target = { x: 0, y: 0, z: 0 };
|
|
483
|
+
if ("id" in payload) {
|
|
484
|
+
position = this.registered.get(payload.id).position;
|
|
485
|
+
target = this.registered.get(payload.id).target;
|
|
486
|
+
} else {
|
|
487
|
+
position = payload.position;
|
|
488
|
+
target = payload.target;
|
|
489
|
+
}
|
|
490
|
+
payload.dataUri = this.mediaGenerator.GenerateMedia(position, target, payload.width, payload.height);
|
|
491
|
+
return true;
|
|
492
|
+
}
|
|
493
|
+
};
|
|
494
|
+
_DIVECommunication.__instances = [];
|
|
495
|
+
var DIVECommunication = _DIVECommunication;
|
|
496
|
+
|
|
497
|
+
// src/light/PointLight.ts
|
|
498
|
+
var DIVEPointLight = class extends PointLight {
|
|
499
|
+
constructor() {
|
|
500
|
+
super(16777215, 1);
|
|
501
|
+
this.isMoveable = true;
|
|
502
|
+
this.isSelectable = true;
|
|
503
|
+
this.gizmo = null;
|
|
504
|
+
this.layers.mask = PRODUCT_LAYER_MASK;
|
|
505
|
+
this.castShadow = true;
|
|
506
|
+
this.shadow.mapSize.width = 512;
|
|
507
|
+
this.shadow.mapSize.height = 512;
|
|
508
|
+
const geoSize = 0.1;
|
|
509
|
+
const geometry = new SphereGeometry(geoSize, geoSize * 320, geoSize * 320);
|
|
510
|
+
const material = new MeshBasicMaterial({ color: this.color, transparent: true, opacity: 0.8, side: FrontSide });
|
|
511
|
+
const mesh = new Mesh(geometry, material);
|
|
512
|
+
mesh.layers.mask = HELPER_LAYER_MASK;
|
|
513
|
+
this.add(mesh);
|
|
514
|
+
}
|
|
515
|
+
SetColor(color) {
|
|
516
|
+
this.color = color;
|
|
517
|
+
this.children[0].material.color = color;
|
|
518
|
+
}
|
|
519
|
+
SetIntensity(intensity) {
|
|
520
|
+
this.intensity = intensity;
|
|
521
|
+
this.children[0].material.opacity = intensity > 0.8 ? 0.8 : intensity * 0.8;
|
|
522
|
+
}
|
|
523
|
+
SetEnabled(enabled) {
|
|
524
|
+
this.visible = enabled;
|
|
525
|
+
}
|
|
526
|
+
onMove() {
|
|
527
|
+
var _a;
|
|
528
|
+
(_a = DIVECommunication.get(this.userData.id)) == null ? void 0 : _a.PerformAction("UPDATE_OBJECT", { id: this.userData.id, position: this.position });
|
|
529
|
+
}
|
|
530
|
+
};
|
|
531
|
+
|
|
532
|
+
// src/light/SceneLight.ts
|
|
533
|
+
import { DirectionalLight, HemisphereLight, Object3D } from "three";
|
|
534
|
+
var DIVESceneLight = class extends Object3D {
|
|
535
|
+
constructor() {
|
|
536
|
+
super();
|
|
537
|
+
this.name = "SceneLight";
|
|
538
|
+
this.hemiLight = new HemisphereLight(16777215, 16777215, 2);
|
|
539
|
+
this.hemiLight.layers.mask = PRODUCT_LAYER_MASK;
|
|
540
|
+
this.hemiLight.position.set(0, 50, 0);
|
|
541
|
+
this.add(this.hemiLight);
|
|
542
|
+
this.dirLight = new DirectionalLight(16777215, 3);
|
|
543
|
+
this.dirLight.layers.mask = PRODUCT_LAYER_MASK;
|
|
544
|
+
this.dirLight.position.set(1, 1.75, 1);
|
|
545
|
+
this.dirLight.position.multiplyScalar(30);
|
|
546
|
+
this.dirLight.castShadow = true;
|
|
547
|
+
this.dirLight.shadow.mapSize.width = 2048;
|
|
548
|
+
this.dirLight.shadow.mapSize.height = 2048;
|
|
549
|
+
const d = 5;
|
|
550
|
+
this.dirLight.shadow.camera.left = -d;
|
|
551
|
+
this.dirLight.shadow.camera.right = d;
|
|
552
|
+
this.dirLight.shadow.camera.top = d;
|
|
553
|
+
this.dirLight.shadow.camera.bottom = -d;
|
|
554
|
+
this.dirLight.shadow.camera.far = 3500;
|
|
555
|
+
this.add(this.dirLight);
|
|
556
|
+
}
|
|
557
|
+
SetColor(color) {
|
|
558
|
+
this.hemiLight.color = color;
|
|
559
|
+
this.dirLight.color = color;
|
|
560
|
+
}
|
|
561
|
+
SetIntensity(intensity) {
|
|
562
|
+
this.hemiLight.intensity = intensity * 2;
|
|
563
|
+
this.dirLight.intensity = intensity * 3;
|
|
564
|
+
}
|
|
565
|
+
SetEnabled(enabled) {
|
|
566
|
+
this.visible = enabled;
|
|
567
|
+
}
|
|
568
|
+
};
|
|
569
|
+
|
|
570
|
+
// src/scene/root/lightroot/LightRoot.ts
|
|
571
|
+
var DIVELightRoot = class extends Object3D2 {
|
|
572
|
+
constructor() {
|
|
573
|
+
super();
|
|
574
|
+
this.name = "LightRoot";
|
|
575
|
+
}
|
|
576
|
+
GetLight(object) {
|
|
577
|
+
if (object.id === void 0) {
|
|
578
|
+
console.warn("LightRoot.GetLight: object.id is undefined");
|
|
579
|
+
return void 0;
|
|
580
|
+
}
|
|
581
|
+
return this.children.find((object3D) => object3D.userData.id === object.id);
|
|
582
|
+
}
|
|
583
|
+
UpdateLight(light) {
|
|
584
|
+
if (light.id === void 0) {
|
|
585
|
+
console.warn(`LightRoot.UpdateLight: light.id is undefined`);
|
|
586
|
+
return;
|
|
587
|
+
}
|
|
588
|
+
let sceneObject = this.children.find((object3D) => object3D.userData.id === light.id);
|
|
589
|
+
if (!sceneObject) {
|
|
590
|
+
switch (light.type) {
|
|
591
|
+
case "scene": {
|
|
592
|
+
sceneObject = new DIVESceneLight();
|
|
593
|
+
break;
|
|
594
|
+
}
|
|
595
|
+
case "ambient": {
|
|
596
|
+
sceneObject = new DIVEAmbientLight();
|
|
597
|
+
break;
|
|
598
|
+
}
|
|
599
|
+
case "point": {
|
|
600
|
+
sceneObject = new DIVEPointLight();
|
|
601
|
+
break;
|
|
602
|
+
}
|
|
603
|
+
default: {
|
|
604
|
+
console.warn(`LightRoot.UpdateLight: Unknown light type: ${light.type}`);
|
|
605
|
+
return;
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
sceneObject.userData.id = light.id;
|
|
609
|
+
this.add(sceneObject);
|
|
610
|
+
}
|
|
611
|
+
if (light.name !== void 0 && light.name !== null)
|
|
612
|
+
sceneObject.name = light.name;
|
|
613
|
+
if (light.position !== void 0 && light.position !== null)
|
|
614
|
+
sceneObject.position.set(light.position.x, light.position.y, light.position.z);
|
|
615
|
+
if (light.intensity !== void 0 && light.intensity !== null)
|
|
616
|
+
sceneObject.SetIntensity(light.intensity);
|
|
617
|
+
if (light.enabled !== void 0 && light.enabled !== null)
|
|
618
|
+
sceneObject.SetEnabled(light.enabled);
|
|
619
|
+
if (light.color !== void 0 && light.color !== null)
|
|
620
|
+
sceneObject.SetColor(new Color5(light.color));
|
|
621
|
+
}
|
|
622
|
+
DeleteLight(light) {
|
|
623
|
+
var _a;
|
|
624
|
+
if (light.id === void 0) {
|
|
625
|
+
console.warn("LightRoot.DeleteLight: light.id is undefined");
|
|
626
|
+
return;
|
|
627
|
+
}
|
|
628
|
+
const sceneObject = this.children.find((object3D) => object3D.userData.id === light.id);
|
|
629
|
+
if (!sceneObject) {
|
|
630
|
+
console.warn(`LightRoot.DeleteLight: Light with id ${light.id} not found`);
|
|
631
|
+
return;
|
|
632
|
+
}
|
|
633
|
+
if ("isMoveable" in sceneObject) {
|
|
634
|
+
(_a = sceneObject.gizmo) == null ? void 0 : _a.detach();
|
|
635
|
+
}
|
|
636
|
+
this.remove(sceneObject);
|
|
637
|
+
}
|
|
638
|
+
};
|
|
639
|
+
|
|
640
|
+
// src/scene/root/modelroot/ModelRoot.ts
|
|
641
|
+
import { Object3D as Object3D4 } from "three";
|
|
642
|
+
|
|
643
|
+
// src/model/Model.ts
|
|
644
|
+
import { Box3, Object3D as Object3D3, Vector3 } from "three";
|
|
645
|
+
var DIVEModel = class extends Object3D3 {
|
|
646
|
+
constructor() {
|
|
647
|
+
super();
|
|
648
|
+
this.isSelectable = true;
|
|
649
|
+
this.isMoveable = true;
|
|
650
|
+
this.gizmo = null;
|
|
651
|
+
this.layers.mask = PRODUCT_LAYER_MASK;
|
|
652
|
+
this.boundingBox = new Box3();
|
|
653
|
+
}
|
|
654
|
+
SetModel(gltf) {
|
|
655
|
+
this.clear();
|
|
656
|
+
gltf.scene.traverse((child) => {
|
|
657
|
+
child.castShadow = true;
|
|
658
|
+
child.receiveShadow = true;
|
|
659
|
+
child.layers.mask = this.layers.mask;
|
|
660
|
+
this.boundingBox.expandByObject(child);
|
|
661
|
+
});
|
|
662
|
+
this.add(gltf.scene);
|
|
663
|
+
}
|
|
664
|
+
SetPosition(position) {
|
|
665
|
+
this.position.set(position.x, position.y, position.z);
|
|
666
|
+
}
|
|
667
|
+
SetRotation(rotation) {
|
|
668
|
+
this.rotation.setFromVector3(new Vector3(rotation.x, rotation.y, rotation.z));
|
|
669
|
+
}
|
|
670
|
+
SetScale(scale) {
|
|
671
|
+
this.scale.set(scale.x, scale.y, scale.z);
|
|
672
|
+
}
|
|
673
|
+
SetToWorldOrigin() {
|
|
674
|
+
var _a;
|
|
675
|
+
this.position.set(0, 0, 0);
|
|
676
|
+
(_a = DIVECommunication.get(this.userData.id)) == null ? void 0 : _a.PerformAction("UPDATE_OBJECT", { id: this.userData.id, position: this.position, rotation: this.rotation, scale: this.scale });
|
|
677
|
+
}
|
|
678
|
+
PlaceOnFloor() {
|
|
679
|
+
var _a;
|
|
680
|
+
this.position.y = -this.boundingBox.min.y * this.scale.y;
|
|
681
|
+
(_a = DIVECommunication.get(this.userData.id)) == null ? void 0 : _a.PerformAction("UPDATE_OBJECT", { id: this.userData.id, position: this.position, rotation: this.rotation, scale: this.scale });
|
|
682
|
+
}
|
|
683
|
+
onMove() {
|
|
684
|
+
var _a;
|
|
685
|
+
(_a = DIVECommunication.get(this.userData.id)) == null ? void 0 : _a.PerformAction("UPDATE_OBJECT", { id: this.userData.id, position: this.position, rotation: this.rotation, scale: this.scale });
|
|
686
|
+
}
|
|
687
|
+
};
|
|
688
|
+
|
|
689
|
+
// src/loadingmanager/LoadingManager.ts
|
|
690
|
+
import { DRACOLoader, GLTFLoader } from "three/examples/jsm/Addons.js";
|
|
691
|
+
var DIVELoadingManager = class {
|
|
692
|
+
// ... maybe extend with other loaders later
|
|
693
|
+
constructor() {
|
|
694
|
+
this.progress = /* @__PURE__ */ new Map();
|
|
695
|
+
this.gltfloader = new GLTFLoader();
|
|
696
|
+
this.dracoloader = new DRACOLoader();
|
|
697
|
+
this.dracoloader.setDecoderPath("https://www.gstatic.com/draco/v1/decoders/");
|
|
698
|
+
this.gltfloader.setDRACOLoader(this.dracoloader);
|
|
699
|
+
}
|
|
700
|
+
LoadGLTF(uri) {
|
|
701
|
+
return __async(this, null, function* () {
|
|
702
|
+
const progEvent = (p) => {
|
|
703
|
+
this.progress.set(uri, p.loaded / p.total);
|
|
704
|
+
};
|
|
705
|
+
this.progress.set(uri, 0);
|
|
706
|
+
return new Promise((resolve, reject) => {
|
|
707
|
+
this.gltfloader.loadAsync(uri, progEvent).then(resolve).catch(reject);
|
|
708
|
+
});
|
|
709
|
+
});
|
|
710
|
+
}
|
|
711
|
+
PollProgress() {
|
|
712
|
+
let total = 0;
|
|
713
|
+
this.progress.forEach((progress) => {
|
|
714
|
+
total += progress;
|
|
715
|
+
});
|
|
716
|
+
if (this.progress.size === 0)
|
|
717
|
+
return 1;
|
|
718
|
+
return total / this.progress.size;
|
|
719
|
+
}
|
|
720
|
+
};
|
|
721
|
+
|
|
722
|
+
// src/scene/root/modelroot/ModelRoot.ts
|
|
723
|
+
var DIVEModelRoot = class extends Object3D4 {
|
|
724
|
+
constructor() {
|
|
725
|
+
super();
|
|
726
|
+
this.name = "ModelRoot";
|
|
727
|
+
this.loadingManager = new DIVELoadingManager();
|
|
728
|
+
}
|
|
729
|
+
GetModel(object) {
|
|
730
|
+
if (object.id === void 0) {
|
|
731
|
+
console.warn("ModelRoot.GetModel: object.id is undefined");
|
|
732
|
+
return void 0;
|
|
733
|
+
}
|
|
734
|
+
return this.children.find((object3D) => object3D.userData.id === object.id);
|
|
735
|
+
}
|
|
736
|
+
UpdateModel(object) {
|
|
737
|
+
if (object.id === void 0) {
|
|
738
|
+
console.warn("ModelRoot.UpdateModel: object.id is undefined");
|
|
739
|
+
return;
|
|
740
|
+
}
|
|
741
|
+
let sceneObject = this.children.find((object3D) => object3D.userData.id === object.id);
|
|
742
|
+
if (!sceneObject && object.uri !== void 0) {
|
|
743
|
+
const model = new DIVEModel();
|
|
744
|
+
sceneObject = model;
|
|
745
|
+
sceneObject.userData.id = object.id;
|
|
746
|
+
this.add(sceneObject);
|
|
747
|
+
this.loadingManager.LoadGLTF(object.uri).then((gltf) => {
|
|
748
|
+
var _a;
|
|
749
|
+
model.SetModel(gltf);
|
|
750
|
+
(_a = DIVECommunication.get(object.id)) == null ? void 0 : _a.PerformAction("MODEL_LOADED", { id: object.id });
|
|
751
|
+
});
|
|
752
|
+
}
|
|
753
|
+
if (object.position !== void 0)
|
|
754
|
+
sceneObject.SetPosition(object.position);
|
|
755
|
+
if (object.rotation !== void 0)
|
|
756
|
+
sceneObject.SetRotation(object.rotation);
|
|
757
|
+
if (object.scale !== void 0)
|
|
758
|
+
sceneObject.SetScale(object.scale);
|
|
759
|
+
}
|
|
760
|
+
DeleteModel(object) {
|
|
761
|
+
var _a;
|
|
762
|
+
if (object.id === void 0) {
|
|
763
|
+
console.warn(`ModelRoot.DeleteModel: object.id is undefined`);
|
|
764
|
+
return;
|
|
765
|
+
}
|
|
766
|
+
const sceneObject = this.children.find((object3D) => object3D.userData.id === object.id);
|
|
767
|
+
if (!sceneObject) {
|
|
768
|
+
console.warn(`ModelRoot.DeleteModel: Model with id ${object.id} not found`);
|
|
769
|
+
return;
|
|
770
|
+
}
|
|
771
|
+
if ("isMoveable" in sceneObject) {
|
|
772
|
+
(_a = sceneObject.gizmo) == null ? void 0 : _a.detach();
|
|
773
|
+
}
|
|
774
|
+
this.remove(sceneObject);
|
|
775
|
+
}
|
|
776
|
+
PlaceOnFloor(object) {
|
|
777
|
+
if (object.id === void 0)
|
|
778
|
+
console.warn("ModelRoot.PlaceOnFloor: object.id is undefined");
|
|
779
|
+
const sceneObject = this.children.find((object3D) => object3D.userData.id === object.id);
|
|
780
|
+
if (!sceneObject)
|
|
781
|
+
return;
|
|
782
|
+
sceneObject.PlaceOnFloor();
|
|
783
|
+
}
|
|
784
|
+
};
|
|
785
|
+
|
|
786
|
+
// src/primitive/floor/Floor.ts
|
|
787
|
+
import { Color as Color6, Mesh as Mesh2, MeshStandardMaterial as MeshStandardMaterial2, PlaneGeometry } from "three";
|
|
788
|
+
var DIVEFloor = class extends Mesh2 {
|
|
789
|
+
constructor() {
|
|
790
|
+
super(new PlaneGeometry(1e4, 1e4), new MeshStandardMaterial2({ color: new Color6(150 / 255, 150 / 255, 150 / 255) }));
|
|
791
|
+
this.isFloor = true;
|
|
792
|
+
this.name = "Floor";
|
|
793
|
+
this.layers.mask = PRODUCT_LAYER_MASK;
|
|
794
|
+
this.receiveShadow = true;
|
|
795
|
+
this.rotateX(-Math.PI / 2);
|
|
796
|
+
}
|
|
797
|
+
SetVisibility(visible) {
|
|
798
|
+
this.visible = visible;
|
|
799
|
+
}
|
|
800
|
+
SetColor(color) {
|
|
801
|
+
this.material.color = new Color6(color);
|
|
802
|
+
}
|
|
803
|
+
};
|
|
804
|
+
|
|
805
|
+
// src/constant/GridColors.ts
|
|
806
|
+
var GRID_CENTER_LINE_COLOR = "#888888";
|
|
807
|
+
var GRID_SIDE_LINE_COLOR = "#dddddd";
|
|
808
|
+
|
|
809
|
+
// src/grid/Grid.ts
|
|
810
|
+
import { GridHelper, Object3D as Object3D5 } from "three";
|
|
811
|
+
var DIVEGrid = class extends Object3D5 {
|
|
812
|
+
constructor() {
|
|
813
|
+
super();
|
|
814
|
+
this.name = "Grid";
|
|
815
|
+
const grid = new GridHelper(100, 100, GRID_CENTER_LINE_COLOR, GRID_SIDE_LINE_COLOR);
|
|
816
|
+
grid.material.depthTest = false;
|
|
817
|
+
grid.layers.mask = HELPER_LAYER_MASK;
|
|
818
|
+
this.add(grid);
|
|
819
|
+
}
|
|
820
|
+
};
|
|
821
|
+
|
|
822
|
+
// src/scene/root/Root.ts
|
|
823
|
+
var DIVERoot = class extends Object3D6 {
|
|
824
|
+
get Floor() {
|
|
825
|
+
return this.floor;
|
|
826
|
+
}
|
|
827
|
+
get Grid() {
|
|
828
|
+
return this.grid;
|
|
829
|
+
}
|
|
830
|
+
constructor() {
|
|
831
|
+
super();
|
|
832
|
+
this.name = "Root";
|
|
833
|
+
this.lightRoot = new DIVELightRoot();
|
|
834
|
+
this.add(this.lightRoot);
|
|
835
|
+
this.modelRoot = new DIVEModelRoot();
|
|
836
|
+
this.add(this.modelRoot);
|
|
837
|
+
this.floor = new DIVEFloor();
|
|
838
|
+
this.add(this.floor);
|
|
839
|
+
this.grid = new DIVEGrid();
|
|
840
|
+
this.add(this.grid);
|
|
841
|
+
}
|
|
842
|
+
GetSceneObject(object) {
|
|
843
|
+
switch (object.entityType) {
|
|
844
|
+
case "pov": {
|
|
845
|
+
return void 0;
|
|
846
|
+
}
|
|
847
|
+
case "light": {
|
|
848
|
+
return this.lightRoot.GetLight(object);
|
|
849
|
+
}
|
|
850
|
+
case "model": {
|
|
851
|
+
return this.modelRoot.GetModel(object);
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
}
|
|
855
|
+
AddSceneObject(object) {
|
|
856
|
+
switch (object.entityType) {
|
|
857
|
+
case "pov": {
|
|
858
|
+
break;
|
|
859
|
+
}
|
|
860
|
+
case "light": {
|
|
861
|
+
this.lightRoot.UpdateLight(object);
|
|
862
|
+
break;
|
|
863
|
+
}
|
|
864
|
+
case "model": {
|
|
865
|
+
this.modelRoot.UpdateModel(object);
|
|
866
|
+
break;
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
}
|
|
870
|
+
UpdateSceneObject(object) {
|
|
871
|
+
switch (object.entityType) {
|
|
872
|
+
case "pov": {
|
|
873
|
+
break;
|
|
874
|
+
}
|
|
875
|
+
case "light": {
|
|
876
|
+
this.lightRoot.UpdateLight(object);
|
|
877
|
+
break;
|
|
878
|
+
}
|
|
879
|
+
case "model": {
|
|
880
|
+
this.modelRoot.UpdateModel(object);
|
|
881
|
+
break;
|
|
882
|
+
}
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
DeleteSceneObject(object) {
|
|
886
|
+
switch (object.entityType) {
|
|
887
|
+
case "pov": {
|
|
888
|
+
break;
|
|
889
|
+
}
|
|
890
|
+
case "light": {
|
|
891
|
+
this.lightRoot.DeleteLight(object);
|
|
892
|
+
break;
|
|
893
|
+
}
|
|
894
|
+
case "model": {
|
|
895
|
+
this.modelRoot.DeleteModel(object);
|
|
896
|
+
break;
|
|
897
|
+
}
|
|
898
|
+
}
|
|
899
|
+
}
|
|
900
|
+
PlaceOnFloor(object) {
|
|
901
|
+
this.modelRoot.PlaceOnFloor(object);
|
|
902
|
+
}
|
|
903
|
+
};
|
|
904
|
+
|
|
905
|
+
// src/scene/Scene.ts
|
|
906
|
+
var DIVEScene = class extends Scene2 {
|
|
907
|
+
get Root() {
|
|
908
|
+
return this.root;
|
|
909
|
+
}
|
|
910
|
+
constructor() {
|
|
911
|
+
super();
|
|
912
|
+
this.root = new DIVERoot();
|
|
913
|
+
this.add(this.root);
|
|
914
|
+
}
|
|
915
|
+
SetBackground(color) {
|
|
916
|
+
this.background = new Color7(color);
|
|
917
|
+
}
|
|
918
|
+
GetSceneObject(object) {
|
|
919
|
+
return this.Root.GetSceneObject(object);
|
|
920
|
+
}
|
|
921
|
+
AddSceneObject(object) {
|
|
922
|
+
this.Root.UpdateSceneObject(object);
|
|
923
|
+
}
|
|
924
|
+
UpdateSceneObject(object) {
|
|
925
|
+
this.Root.UpdateSceneObject(object);
|
|
926
|
+
}
|
|
927
|
+
DeleteSceneObject(object) {
|
|
928
|
+
this.Root.DeleteSceneObject(object);
|
|
929
|
+
}
|
|
930
|
+
PlaceOnFloor(object) {
|
|
931
|
+
this.Root.PlaceOnFloor(object);
|
|
932
|
+
}
|
|
933
|
+
};
|
|
934
|
+
|
|
935
|
+
// src/camera/PerspectiveCamera.ts
|
|
936
|
+
import { PerspectiveCamera } from "three";
|
|
937
|
+
var DIVEPerspectiveCameraDefaultSettings = {
|
|
938
|
+
fov: 80,
|
|
939
|
+
near: 0.1,
|
|
940
|
+
far: 1e3
|
|
941
|
+
};
|
|
942
|
+
var _DIVEPerspectiveCamera = class _DIVEPerspectiveCamera extends PerspectiveCamera {
|
|
943
|
+
constructor(settings = DIVEPerspectiveCameraDefaultSettings) {
|
|
944
|
+
super(settings.fov, 1, settings.near, settings.far);
|
|
945
|
+
this.onSetCameraLayer = () => {
|
|
946
|
+
};
|
|
947
|
+
this.layers.mask = _DIVEPerspectiveCamera.EDITOR_VIEW_LAYER_MASK;
|
|
948
|
+
}
|
|
949
|
+
OnResize(width, height) {
|
|
950
|
+
this.aspect = width / height;
|
|
951
|
+
this.updateProjectionMatrix();
|
|
952
|
+
}
|
|
953
|
+
SetCameraLayer(layer) {
|
|
954
|
+
this.layers.mask = layer === "LIVE" ? _DIVEPerspectiveCamera.LIVE_VIEW_LAYER_MASK : _DIVEPerspectiveCamera.EDITOR_VIEW_LAYER_MASK;
|
|
955
|
+
this.onSetCameraLayer(this.layers.mask);
|
|
956
|
+
}
|
|
957
|
+
};
|
|
958
|
+
_DIVEPerspectiveCamera.EDITOR_VIEW_LAYER_MASK = DEFAULT_LAYER_MASK | UI_LAYER_MASK | HELPER_LAYER_MASK | PRODUCT_LAYER_MASK;
|
|
959
|
+
_DIVEPerspectiveCamera.LIVE_VIEW_LAYER_MASK = PRODUCT_LAYER_MASK;
|
|
960
|
+
var DIVEPerspectiveCamera = _DIVEPerspectiveCamera;
|
|
961
|
+
|
|
962
|
+
// src/controls/OrbitControls.ts
|
|
963
|
+
import { OrbitControls } from "three/examples/jsm/Addons.js";
|
|
964
|
+
import { MathUtils as MathUtils3 } from "three";
|
|
965
|
+
import { Easing, Tween } from "@tweenjs/tween.js";
|
|
966
|
+
var DIVEOrbitControlsDefaultSettings = {
|
|
967
|
+
enableDamping: true,
|
|
968
|
+
dampingFactor: 0.04
|
|
969
|
+
};
|
|
970
|
+
var _DIVEOrbitControls = class _DIVEOrbitControls extends OrbitControls {
|
|
971
|
+
constructor(camera, renderer, settings = DIVEOrbitControlsDefaultSettings) {
|
|
972
|
+
super(camera, renderer.domElement);
|
|
973
|
+
this.last = null;
|
|
974
|
+
this.animating = false;
|
|
975
|
+
this.locked = false;
|
|
976
|
+
this.stopMoveTo = () => {
|
|
977
|
+
};
|
|
978
|
+
this.stopRevertLast = () => {
|
|
979
|
+
};
|
|
980
|
+
this.preRenderCallback = () => {
|
|
981
|
+
if (this.locked)
|
|
982
|
+
return;
|
|
983
|
+
this.update();
|
|
984
|
+
};
|
|
985
|
+
this.domElement = renderer.domElement;
|
|
986
|
+
this.object = camera;
|
|
987
|
+
renderer.AddPreRenderCallback(() => {
|
|
988
|
+
this.preRenderCallback();
|
|
989
|
+
});
|
|
990
|
+
this.addEventListener("change", () => {
|
|
991
|
+
window.dispatchEvent(new CustomEvent("dive:orbitcontrols:change", { detail: { object: this.object } }));
|
|
992
|
+
});
|
|
993
|
+
this.enableDamping = settings.enableDamping;
|
|
994
|
+
this.dampingFactor = settings.dampingFactor;
|
|
995
|
+
}
|
|
996
|
+
ZoomIn(by) {
|
|
997
|
+
const zoomBy = by || _DIVEOrbitControls.DEFAULT_ZOOM_FACTOR;
|
|
998
|
+
const { minDistance, maxDistance } = this;
|
|
999
|
+
this.minDistance = this.maxDistance = MathUtils3.clamp(this.getDistance() - zoomBy, minDistance + zoomBy, maxDistance - zoomBy);
|
|
1000
|
+
this.update();
|
|
1001
|
+
this.minDistance = minDistance;
|
|
1002
|
+
this.maxDistance = maxDistance;
|
|
1003
|
+
}
|
|
1004
|
+
ZoomOut(by) {
|
|
1005
|
+
const zoomBy = by || _DIVEOrbitControls.DEFAULT_ZOOM_FACTOR;
|
|
1006
|
+
const { minDistance, maxDistance } = this;
|
|
1007
|
+
this.minDistance = this.maxDistance = MathUtils3.clamp(this.getDistance() + zoomBy, minDistance + zoomBy, maxDistance - zoomBy);
|
|
1008
|
+
this.update();
|
|
1009
|
+
this.minDistance = minDistance;
|
|
1010
|
+
this.maxDistance = maxDistance;
|
|
1011
|
+
}
|
|
1012
|
+
MoveTo(pos, target, duration, lock) {
|
|
1013
|
+
if (this.animating)
|
|
1014
|
+
return;
|
|
1015
|
+
const toPosition = pos || this.object.position.clone();
|
|
1016
|
+
const toTarget = target || this.target.clone();
|
|
1017
|
+
this.stopRevertLast();
|
|
1018
|
+
if (!this.locked)
|
|
1019
|
+
this.last = { pos: this.object.position.clone(), target: this.target.clone() };
|
|
1020
|
+
this.animating = duration > 0;
|
|
1021
|
+
this.locked = lock;
|
|
1022
|
+
this.enabled = false;
|
|
1023
|
+
const tweenPos = new Tween(this.object.position).to(toPosition, duration).easing(Easing.Quadratic.Out).start();
|
|
1024
|
+
const tweenQuat = new Tween(this.target).to(toTarget, duration).easing(Easing.Quadratic.Out).onUpdate(() => {
|
|
1025
|
+
this.object.lookAt(this.target);
|
|
1026
|
+
}).onComplete(() => {
|
|
1027
|
+
this.animating = false;
|
|
1028
|
+
this.enabled = !lock;
|
|
1029
|
+
}).start();
|
|
1030
|
+
this.stopMoveTo = () => {
|
|
1031
|
+
tweenPos.stop();
|
|
1032
|
+
tweenQuat.stop();
|
|
1033
|
+
};
|
|
1034
|
+
}
|
|
1035
|
+
RevertLast(duration) {
|
|
1036
|
+
if (this.animating || !this.locked)
|
|
1037
|
+
return;
|
|
1038
|
+
this.stopMoveTo();
|
|
1039
|
+
this.animating = duration > 0;
|
|
1040
|
+
this.enabled = false;
|
|
1041
|
+
const { pos, target } = this.last;
|
|
1042
|
+
const tweenPos = new Tween(this.object.position).to(pos, duration).easing(Easing.Quadratic.Out).start();
|
|
1043
|
+
const tweenQuat = new Tween(this.target).to(target, duration).easing(Easing.Quadratic.Out).onUpdate(() => {
|
|
1044
|
+
this.object.lookAt(this.target);
|
|
1045
|
+
}).onComplete(() => {
|
|
1046
|
+
this.animating = false;
|
|
1047
|
+
this.locked = false;
|
|
1048
|
+
this.enabled = true;
|
|
1049
|
+
}).start();
|
|
1050
|
+
this.stopRevertLast = () => {
|
|
1051
|
+
tweenPos.stop();
|
|
1052
|
+
tweenQuat.stop();
|
|
1053
|
+
};
|
|
1054
|
+
}
|
|
1055
|
+
};
|
|
1056
|
+
_DIVEOrbitControls.DEFAULT_ZOOM_FACTOR = 1;
|
|
1057
|
+
var DIVEOrbitControls = _DIVEOrbitControls;
|
|
1058
|
+
|
|
1059
|
+
// src/mediacreator/MediaCreator.ts
|
|
1060
|
+
var DIVEMediaCreator = class {
|
|
1061
|
+
constructor(renderer, scene, controller) {
|
|
1062
|
+
this.renderer = renderer;
|
|
1063
|
+
this.scene = scene;
|
|
1064
|
+
this.controller = controller;
|
|
1065
|
+
}
|
|
1066
|
+
GenerateMedia(position, target, width, height) {
|
|
1067
|
+
const resetPosition = this.controller.object.position.clone();
|
|
1068
|
+
const resetRotation = this.controller.object.quaternion.clone();
|
|
1069
|
+
this.renderer.OnResize(width, height);
|
|
1070
|
+
this.controller.object.OnResize(width, height);
|
|
1071
|
+
this.controller.object.position.copy(position);
|
|
1072
|
+
this.controller.target.copy(target);
|
|
1073
|
+
this.controller.update();
|
|
1074
|
+
const dataUri = this.DrawCanvas().toDataURL();
|
|
1075
|
+
this.controller.object.position.copy(resetPosition);
|
|
1076
|
+
this.controller.object.quaternion.copy(resetRotation);
|
|
1077
|
+
return dataUri;
|
|
1078
|
+
}
|
|
1079
|
+
DrawCanvas(canvasElement) {
|
|
1080
|
+
const restore = this.renderer.domElement;
|
|
1081
|
+
if (canvasElement) {
|
|
1082
|
+
this.renderer.domElement = canvasElement;
|
|
1083
|
+
}
|
|
1084
|
+
this.controller.object.layers.mask = DIVEPerspectiveCamera.LIVE_VIEW_LAYER_MASK;
|
|
1085
|
+
this.renderer.render(this.scene, this.controller.object);
|
|
1086
|
+
this.controller.object.layers.mask = DIVEPerspectiveCamera.EDITOR_VIEW_LAYER_MASK;
|
|
1087
|
+
const returnCanvas = this.renderer.domElement;
|
|
1088
|
+
if (canvasElement) {
|
|
1089
|
+
this.renderer.domElement = restore;
|
|
1090
|
+
}
|
|
1091
|
+
return returnCanvas;
|
|
1092
|
+
}
|
|
1093
|
+
};
|
|
1094
|
+
|
|
1095
|
+
// src/toolbox/select/SelectTool.ts
|
|
1096
|
+
import { Raycaster, Vector2 } from "three";
|
|
1097
|
+
import { TransformControls } from "three/examples/jsm/Addons.js";
|
|
1098
|
+
|
|
1099
|
+
// src/toolbox/BaseTool.ts
|
|
1100
|
+
var DIVEBaseTool = class {
|
|
1101
|
+
constructor() {
|
|
1102
|
+
this.name = "BaseTool";
|
|
1103
|
+
}
|
|
1104
|
+
Activate() {
|
|
1105
|
+
}
|
|
1106
|
+
Deactivate() {
|
|
1107
|
+
}
|
|
1108
|
+
onPointerDown(e) {
|
|
1109
|
+
}
|
|
1110
|
+
onPointerUp(e) {
|
|
1111
|
+
}
|
|
1112
|
+
onWheel(e) {
|
|
1113
|
+
}
|
|
1114
|
+
};
|
|
1115
|
+
|
|
1116
|
+
// src/toolbox/select/SelectTool.ts
|
|
1117
|
+
var DIVESelectTool = class extends DIVEBaseTool {
|
|
1118
|
+
constructor(scene, controller) {
|
|
1119
|
+
super();
|
|
1120
|
+
this.name = "SelectTool";
|
|
1121
|
+
this.canvas = controller.domElement;
|
|
1122
|
+
this.scene = scene;
|
|
1123
|
+
this.controller = controller;
|
|
1124
|
+
this.raycaster = new Raycaster();
|
|
1125
|
+
this.raycaster.layers.mask = PRODUCT_LAYER_MASK | HELPER_LAYER_MASK;
|
|
1126
|
+
this.gizmo = new TransformControls(this.controller.object, this.canvas);
|
|
1127
|
+
this.gizmo.layers.mask = UI_LAYER_MASK;
|
|
1128
|
+
this.gizmo.getRaycaster().layers.mask = UI_LAYER_MASK & this.controller.object.layers.mask;
|
|
1129
|
+
this.gizmo.traverse((child) => {
|
|
1130
|
+
child.layers.mask = UI_LAYER_MASK;
|
|
1131
|
+
});
|
|
1132
|
+
this.gizmo.addEventListener("objectChange", () => {
|
|
1133
|
+
if (!this.gizmo.object)
|
|
1134
|
+
return;
|
|
1135
|
+
if (!("onMove" in this.gizmo.object))
|
|
1136
|
+
return;
|
|
1137
|
+
if (typeof this.gizmo.object.onMove !== "function")
|
|
1138
|
+
return;
|
|
1139
|
+
this.gizmo.object.onMove();
|
|
1140
|
+
});
|
|
1141
|
+
this.controller.object.onSetCameraLayer = (mask) => {
|
|
1142
|
+
this.gizmo.getRaycaster().layers.mask = UI_LAYER_MASK & mask;
|
|
1143
|
+
};
|
|
1144
|
+
this.gizmo.addEventListener("dragging-changed", function(event) {
|
|
1145
|
+
controller.enabled = !event.value;
|
|
1146
|
+
});
|
|
1147
|
+
this.scene.add(this.gizmo);
|
|
1148
|
+
}
|
|
1149
|
+
Activate() {
|
|
1150
|
+
}
|
|
1151
|
+
SetGizmoMode(mode) {
|
|
1152
|
+
this.gizmo.setMode(mode);
|
|
1153
|
+
}
|
|
1154
|
+
Select(selectable) {
|
|
1155
|
+
if (selectable.onSelect)
|
|
1156
|
+
selectable.onSelect();
|
|
1157
|
+
if ("isMoveable" in selectable) {
|
|
1158
|
+
const movable = selectable;
|
|
1159
|
+
movable.gizmo = this.gizmo;
|
|
1160
|
+
this.gizmo.attach(movable);
|
|
1161
|
+
}
|
|
1162
|
+
}
|
|
1163
|
+
Deselect(selectable) {
|
|
1164
|
+
if (selectable.onDeselect)
|
|
1165
|
+
selectable.onDeselect();
|
|
1166
|
+
if ("isMoveable" in selectable)
|
|
1167
|
+
selectable.gizmo = null;
|
|
1168
|
+
this.gizmo.detach();
|
|
1169
|
+
}
|
|
1170
|
+
onPointerUp(e) {
|
|
1171
|
+
const pointerPos = new Vector2(e.offsetX / this.canvas.clientWidth * 2 - 1, e.offsetY / this.canvas.clientHeight * -2 + 1);
|
|
1172
|
+
this.raycaster.setFromCamera(pointerPos, this.controller.object);
|
|
1173
|
+
const first = this.raycastFirst();
|
|
1174
|
+
const selectable = this.findSelectableInterface(first == null ? void 0 : first.object);
|
|
1175
|
+
if (!first || !selectable) {
|
|
1176
|
+
if (this.gizmo.object)
|
|
1177
|
+
this.Deselect(this.gizmo.object);
|
|
1178
|
+
return;
|
|
1179
|
+
}
|
|
1180
|
+
this.Select(selectable);
|
|
1181
|
+
}
|
|
1182
|
+
findSelectableInterface(child) {
|
|
1183
|
+
if (child === void 0)
|
|
1184
|
+
return void 0;
|
|
1185
|
+
if (child.parent === null) {
|
|
1186
|
+
return void 0;
|
|
1187
|
+
}
|
|
1188
|
+
if ("isSelectable" in child) {
|
|
1189
|
+
return child;
|
|
1190
|
+
}
|
|
1191
|
+
return this.findSelectableInterface(child.parent);
|
|
1192
|
+
}
|
|
1193
|
+
raycastFirst() {
|
|
1194
|
+
return this.raycastAll()[0];
|
|
1195
|
+
}
|
|
1196
|
+
raycastAll() {
|
|
1197
|
+
return this.raycaster.intersectObjects(this.scene.Root.children, true);
|
|
1198
|
+
}
|
|
1199
|
+
};
|
|
1200
|
+
|
|
1201
|
+
// src/toolbox/Toolbox.ts
|
|
1202
|
+
var DIVEToolbox = class {
|
|
1203
|
+
constructor(scene, controller) {
|
|
1204
|
+
this.removeListenersCallback = () => {
|
|
1205
|
+
};
|
|
1206
|
+
this.selectTool = new DIVESelectTool(scene, controller);
|
|
1207
|
+
controller.domElement.addEventListener("pointerdown", this.onPointerDown.bind(this));
|
|
1208
|
+
controller.domElement.addEventListener("pointerup", this.onPointerUp.bind(this));
|
|
1209
|
+
controller.domElement.addEventListener("wheel", this.onWheel.bind(this));
|
|
1210
|
+
this.removeListenersCallback = () => {
|
|
1211
|
+
controller.domElement.removeEventListener("pointerdown", this.onPointerDown.bind(this));
|
|
1212
|
+
controller.domElement.removeEventListener("pointerup", this.onPointerUp.bind(this));
|
|
1213
|
+
controller.domElement.removeEventListener("wheel", this.onWheel.bind(this));
|
|
1214
|
+
};
|
|
1215
|
+
this.activeTool = this.selectTool;
|
|
1216
|
+
this.activeTool.Activate();
|
|
1217
|
+
}
|
|
1218
|
+
dispose() {
|
|
1219
|
+
this.removeListenersCallback();
|
|
1220
|
+
}
|
|
1221
|
+
GetActiveTool() {
|
|
1222
|
+
return this.activeTool;
|
|
1223
|
+
}
|
|
1224
|
+
UseTool(tool) {
|
|
1225
|
+
this.activeTool.Deactivate();
|
|
1226
|
+
switch (tool) {
|
|
1227
|
+
case "select": {
|
|
1228
|
+
this.selectTool.Activate();
|
|
1229
|
+
this.activeTool = this.selectTool;
|
|
1230
|
+
break;
|
|
1231
|
+
}
|
|
1232
|
+
default: {
|
|
1233
|
+
throw new Error(`ToolBox.UseTool: Unknown tool: ${tool}`);
|
|
1234
|
+
}
|
|
1235
|
+
}
|
|
1236
|
+
}
|
|
1237
|
+
SetGizmoMode(mode) {
|
|
1238
|
+
this.selectTool.SetGizmoMode(mode);
|
|
1239
|
+
}
|
|
1240
|
+
onPointerDown(e) {
|
|
1241
|
+
this.activeTool.onPointerDown(e);
|
|
1242
|
+
}
|
|
1243
|
+
onPointerUp(e) {
|
|
1244
|
+
this.activeTool.onPointerUp(e);
|
|
1245
|
+
}
|
|
1246
|
+
onWheel(e) {
|
|
1247
|
+
this.activeTool.onWheel(e);
|
|
1248
|
+
}
|
|
1249
|
+
};
|
|
1250
|
+
DIVEToolbox.DefaultTool = "select";
|
|
1251
|
+
|
|
1252
|
+
// src/animation/AnimationSystem.ts
|
|
1253
|
+
import { update as updateTween } from "@tweenjs/tween.js";
|
|
1254
|
+
var DIVEAnimationSystem = class {
|
|
1255
|
+
update() {
|
|
1256
|
+
updateTween();
|
|
1257
|
+
}
|
|
1258
|
+
};
|
|
1259
|
+
|
|
1260
|
+
// src/axiscamera/AxisCamera.ts
|
|
1261
|
+
import { AxesHelper, Color as Color8, Matrix4, OrthographicCamera } from "three";
|
|
1262
|
+
import SpriteText from "three-spritetext";
|
|
1263
|
+
|
|
1264
|
+
// src/constant/AxisHelperColors.ts
|
|
1265
|
+
var AxesColorRedLetter = "#c20017";
|
|
1266
|
+
var AxesColorGreenLetter = "#00ab26";
|
|
1267
|
+
var AxesColorBlueLetter = "#0081d4";
|
|
1268
|
+
var AxesColorRed = AxesColorRedLetter;
|
|
1269
|
+
var AxesColorGreen = AxesColorGreenLetter;
|
|
1270
|
+
var AxesColorBlue = AxesColorBlueLetter;
|
|
1271
|
+
|
|
1272
|
+
// src/axiscamera/AxisCamera.ts
|
|
1273
|
+
var DIVEAxisCamera = class extends OrthographicCamera {
|
|
1274
|
+
constructor() {
|
|
1275
|
+
super(-1, 1, 1, -1, 0.1, 100);
|
|
1276
|
+
this.layers.mask = COORDINATE_LAYER_MASK;
|
|
1277
|
+
this.axesHelper = new AxesHelper(0.5);
|
|
1278
|
+
this.axesHelper.layers.mask = COORDINATE_LAYER_MASK;
|
|
1279
|
+
this.axesHelper.material.depthTest = false;
|
|
1280
|
+
this.axesHelper.position.set(0, 0, -1);
|
|
1281
|
+
this.axesHelper.setColors(
|
|
1282
|
+
new Color8(AxesColorRed),
|
|
1283
|
+
new Color8(AxesColorGreen),
|
|
1284
|
+
new Color8(AxesColorBlue)
|
|
1285
|
+
);
|
|
1286
|
+
const x = new SpriteText("X", 0.2, AxesColorRedLetter);
|
|
1287
|
+
const y = new SpriteText("Y", 0.2, AxesColorGreenLetter);
|
|
1288
|
+
const z = new SpriteText("Z", 0.2, AxesColorBlueLetter);
|
|
1289
|
+
x.layers.mask = COORDINATE_LAYER_MASK;
|
|
1290
|
+
y.layers.mask = COORDINATE_LAYER_MASK;
|
|
1291
|
+
z.layers.mask = COORDINATE_LAYER_MASK;
|
|
1292
|
+
x.position.set(0.7, 0, 0);
|
|
1293
|
+
y.position.set(0, 0.7, 0);
|
|
1294
|
+
z.position.set(0, 0, 0.7);
|
|
1295
|
+
this.axesHelper.add(x);
|
|
1296
|
+
this.axesHelper.add(y);
|
|
1297
|
+
this.axesHelper.add(z);
|
|
1298
|
+
this.add(this.axesHelper);
|
|
1299
|
+
}
|
|
1300
|
+
SetFromCameraMatrix(matrix) {
|
|
1301
|
+
this.axesHelper.rotation.setFromRotationMatrix(new Matrix4().extractRotation(matrix).invert());
|
|
1302
|
+
}
|
|
1303
|
+
};
|
|
1304
|
+
|
|
1305
|
+
// src/helper/getObjectDelta/getObjectDelta.ts
|
|
1306
|
+
var getObjectDelta = (a, b) => {
|
|
1307
|
+
if (Object.keys(a).length === 0 && Object.keys(b).length === 0) {
|
|
1308
|
+
return {};
|
|
1309
|
+
}
|
|
1310
|
+
if (typeof a !== "object" || typeof b !== "object") {
|
|
1311
|
+
return b;
|
|
1312
|
+
}
|
|
1313
|
+
let delta = {};
|
|
1314
|
+
Object.keys(b).forEach((key) => {
|
|
1315
|
+
if (!Object.keys(a).includes(key)) {
|
|
1316
|
+
delta = __spreadProps(__spreadValues({}, delta), { [key]: b[key] });
|
|
1317
|
+
return;
|
|
1318
|
+
}
|
|
1319
|
+
if (Array.isArray(b[key])) {
|
|
1320
|
+
if (!Array.isArray(a[key])) {
|
|
1321
|
+
delta = __spreadProps(__spreadValues({}, delta), { [key]: b[key] });
|
|
1322
|
+
return;
|
|
1323
|
+
}
|
|
1324
|
+
const aArray = a[key];
|
|
1325
|
+
const bArray = b[key];
|
|
1326
|
+
if (aArray.length === 0 && bArray.length === 0) {
|
|
1327
|
+
delta = __spreadValues({}, delta);
|
|
1328
|
+
return;
|
|
1329
|
+
}
|
|
1330
|
+
if (aArray.length !== bArray.length) {
|
|
1331
|
+
delta = __spreadProps(__spreadValues({}, delta), { [key]: b[key] });
|
|
1332
|
+
return;
|
|
1333
|
+
}
|
|
1334
|
+
const arrayDeltas = [];
|
|
1335
|
+
bArray.forEach((entry, index) => {
|
|
1336
|
+
const inArrayDelta = getObjectDelta(aArray[index], bArray[index]);
|
|
1337
|
+
if (Object.keys(inArrayDelta).length) {
|
|
1338
|
+
arrayDeltas.push(bArray[index]);
|
|
1339
|
+
}
|
|
1340
|
+
});
|
|
1341
|
+
if (Object.keys(arrayDeltas).length) {
|
|
1342
|
+
delta = __spreadProps(__spreadValues({}, delta), { [key]: arrayDeltas });
|
|
1343
|
+
return;
|
|
1344
|
+
}
|
|
1345
|
+
return;
|
|
1346
|
+
}
|
|
1347
|
+
if (typeof b[key] === "object") {
|
|
1348
|
+
if (typeof a[key] !== "object") {
|
|
1349
|
+
delta = __spreadProps(__spreadValues({}, delta), { [key]: b[key] });
|
|
1350
|
+
return;
|
|
1351
|
+
}
|
|
1352
|
+
const objectDelta = getObjectDelta(a[key], b[key]);
|
|
1353
|
+
if (Object.keys(objectDelta).length) {
|
|
1354
|
+
delta = __spreadProps(__spreadValues({}, delta), { [key]: objectDelta });
|
|
1355
|
+
return;
|
|
1356
|
+
}
|
|
1357
|
+
}
|
|
1358
|
+
if (a[key] !== b[key]) {
|
|
1359
|
+
delta = __spreadProps(__spreadValues({}, delta), { [key]: b[key] });
|
|
1360
|
+
}
|
|
1361
|
+
});
|
|
1362
|
+
return delta;
|
|
1363
|
+
};
|
|
1364
|
+
|
|
1365
|
+
// src/math/helper/shift.ts
|
|
1366
|
+
function shift(value, exponent) {
|
|
1367
|
+
const subvalues = (value + "e").split("e");
|
|
1368
|
+
return +(subvalues[0] + "e" + (+subvalues[1] + (exponent || 0)));
|
|
1369
|
+
}
|
|
1370
|
+
|
|
1371
|
+
// src/math/ceil/ceilExp.ts
|
|
1372
|
+
function ceilExp(number, decimals = 0) {
|
|
1373
|
+
const n = shift(number, +decimals);
|
|
1374
|
+
return shift(Math.ceil(n), -decimals);
|
|
1375
|
+
}
|
|
1376
|
+
|
|
1377
|
+
// src/math/floor/floorExp.ts
|
|
1378
|
+
function floorExp(number, decimals = 0) {
|
|
1379
|
+
const n = shift(number, +decimals);
|
|
1380
|
+
return shift(Math.floor(n), -decimals);
|
|
1381
|
+
}
|
|
1382
|
+
|
|
1383
|
+
// src/math/round/roundExp.ts
|
|
1384
|
+
function roundExponential(number, decimals = 0) {
|
|
1385
|
+
if (number < 0)
|
|
1386
|
+
return -roundExponential(-number, decimals);
|
|
1387
|
+
const n = shift(number, +decimals);
|
|
1388
|
+
return shift(Math.round(n), -decimals);
|
|
1389
|
+
}
|
|
1390
|
+
|
|
1391
|
+
// src/math/toFixed/toFixedExp.ts
|
|
1392
|
+
function toFixedExp(number, decimals = 0) {
|
|
1393
|
+
const n = shift(number, +decimals);
|
|
1394
|
+
return shift(Math.round(n), -decimals).toFixed(decimals);
|
|
1395
|
+
}
|
|
1396
|
+
|
|
1397
|
+
// src/math/truncate/truncateExp.ts
|
|
1398
|
+
function truncateExp(number, decimals = 0) {
|
|
1399
|
+
const n = shift(number, +decimals);
|
|
1400
|
+
return shift(Math.trunc(n), -decimals);
|
|
1401
|
+
}
|
|
1402
|
+
|
|
1403
|
+
// src/math/index.ts
|
|
1404
|
+
var DIVEMath = {
|
|
1405
|
+
ceilExp,
|
|
1406
|
+
floorExp,
|
|
1407
|
+
roundExp: roundExponential,
|
|
1408
|
+
toFixedExp,
|
|
1409
|
+
truncateExp
|
|
1410
|
+
};
|
|
1411
|
+
|
|
1412
|
+
// src/dive.ts
|
|
1413
|
+
var DIVEDefaultSettings = {
|
|
1414
|
+
autoResize: true,
|
|
1415
|
+
renderer: DIVERendererDefaultSettings,
|
|
1416
|
+
perspectiveCamera: DIVEPerspectiveCameraDefaultSettings,
|
|
1417
|
+
orbitControls: DIVEOrbitControlsDefaultSettings
|
|
1418
|
+
};
|
|
1419
|
+
var DIVE = class {
|
|
1420
|
+
// getters
|
|
1421
|
+
get Communication() {
|
|
1422
|
+
return this.communication;
|
|
1423
|
+
}
|
|
1424
|
+
get Canvas() {
|
|
1425
|
+
return this.renderer.domElement;
|
|
1426
|
+
}
|
|
1427
|
+
// setters
|
|
1428
|
+
set Settings(settings) {
|
|
1429
|
+
const settingsDelta = getObjectDelta(this._settings, settings);
|
|
1430
|
+
if (settingsDelta.renderer)
|
|
1431
|
+
this.renderer = new DIVERenderer(this._settings.renderer);
|
|
1432
|
+
if (settingsDelta.perspectiveCamera) {
|
|
1433
|
+
this.perspectiveCamera.fov = settingsDelta.perspectiveCamera.fov;
|
|
1434
|
+
this.perspectiveCamera.near = settingsDelta.perspectiveCamera.near;
|
|
1435
|
+
this.perspectiveCamera.far = settingsDelta.perspectiveCamera.far;
|
|
1436
|
+
this.perspectiveCamera.OnResize(this.renderer.domElement.width, this.renderer.domElement.height);
|
|
1437
|
+
}
|
|
1438
|
+
if (settingsDelta.orbitControls) {
|
|
1439
|
+
this.orbitControls.enableDamping = settingsDelta.orbitControls.enableDamping;
|
|
1440
|
+
this.orbitControls.dampingFactor = settingsDelta.orbitControls.dampingFactor;
|
|
1441
|
+
}
|
|
1442
|
+
if (settingsDelta.autoResize !== this._settings.autoResize) {
|
|
1443
|
+
if (settingsDelta.autoResize) {
|
|
1444
|
+
this.addResizeObserver();
|
|
1445
|
+
} else {
|
|
1446
|
+
this.removeResizeObserver();
|
|
1447
|
+
}
|
|
1448
|
+
}
|
|
1449
|
+
Object.assign(this._settings, settings);
|
|
1450
|
+
}
|
|
1451
|
+
constructor(settings) {
|
|
1452
|
+
this._settings = __spreadValues(__spreadValues({}, DIVEDefaultSettings), settings !== void 0 ? settings : {});
|
|
1453
|
+
this._resizeObserverId = "";
|
|
1454
|
+
this._width = 0;
|
|
1455
|
+
this._height = 0;
|
|
1456
|
+
this.renderer = new DIVERenderer(this._settings.renderer);
|
|
1457
|
+
this.scene = new DIVEScene();
|
|
1458
|
+
this.perspectiveCamera = new DIVEPerspectiveCamera(this._settings.perspectiveCamera);
|
|
1459
|
+
this.orbitControls = new DIVEOrbitControls(this.perspectiveCamera, this.renderer, this._settings.orbitControls);
|
|
1460
|
+
this.mediaCreator = new DIVEMediaCreator(this.renderer, this.scene, this.orbitControls);
|
|
1461
|
+
this.toolbox = new DIVEToolbox(this.scene, this.orbitControls);
|
|
1462
|
+
this.communication = new DIVECommunication(this.scene, this.orbitControls, this.toolbox, this.mediaCreator);
|
|
1463
|
+
this.animationSystem = new DIVEAnimationSystem();
|
|
1464
|
+
this.renderer.AddPreRenderCallback(() => {
|
|
1465
|
+
this.animationSystem.update();
|
|
1466
|
+
});
|
|
1467
|
+
this.axisCamera = new DIVEAxisCamera();
|
|
1468
|
+
this.scene.add(this.axisCamera);
|
|
1469
|
+
const restoreViewport = new Vector4();
|
|
1470
|
+
this.renderer.AddPostRenderCallback(() => {
|
|
1471
|
+
const restoreBackground = this.scene.background;
|
|
1472
|
+
this.scene.background = null;
|
|
1473
|
+
this.renderer.getViewport(restoreViewport);
|
|
1474
|
+
this.renderer.setViewport(0, 0, 150, 150);
|
|
1475
|
+
this.renderer.autoClear = false;
|
|
1476
|
+
this.axisCamera.SetFromCameraMatrix(this.perspectiveCamera.matrix);
|
|
1477
|
+
this.renderer.render(this.scene, this.axisCamera);
|
|
1478
|
+
this.renderer.setViewport(restoreViewport);
|
|
1479
|
+
this.renderer.autoClear = true;
|
|
1480
|
+
this.scene.background = restoreBackground;
|
|
1481
|
+
});
|
|
1482
|
+
if (this._settings.autoResize) {
|
|
1483
|
+
this.addResizeObserver();
|
|
1484
|
+
}
|
|
1485
|
+
this.renderer.StartRenderer(this.scene, this.perspectiveCamera);
|
|
1486
|
+
}
|
|
1487
|
+
// methods
|
|
1488
|
+
OnResize(width, height) {
|
|
1489
|
+
this.renderer.OnResize(width, height);
|
|
1490
|
+
this.perspectiveCamera.OnResize(width, height);
|
|
1491
|
+
}
|
|
1492
|
+
addResizeObserver() {
|
|
1493
|
+
this._resizeObserverId = this.renderer.AddPreRenderCallback(() => {
|
|
1494
|
+
const canvasWrapper = this.renderer.domElement.parentElement;
|
|
1495
|
+
if (!canvasWrapper)
|
|
1496
|
+
return;
|
|
1497
|
+
const { clientWidth, clientHeight } = canvasWrapper;
|
|
1498
|
+
if (clientWidth === this._width && clientHeight === this._height)
|
|
1499
|
+
return;
|
|
1500
|
+
this.OnResize(clientWidth, clientHeight);
|
|
1501
|
+
this._width = clientWidth;
|
|
1502
|
+
this._height = clientHeight;
|
|
1503
|
+
});
|
|
1504
|
+
}
|
|
1505
|
+
removeResizeObserver() {
|
|
1506
|
+
this.renderer.RemovePreRenderCallback(this._resizeObserverId);
|
|
1507
|
+
}
|
|
1508
|
+
};
|
|
1509
|
+
export {
|
|
1510
|
+
DIVE,
|
|
1511
|
+
DIVECommunication,
|
|
1512
|
+
DIVEDefaultSettings,
|
|
1513
|
+
DIVEMath,
|
|
1514
|
+
DIVE as default
|
|
1515
|
+
};
|
|
1516
|
+
//# sourceMappingURL=dive.js.map
|