@shopware-ag/dive 1.15.4 → 1.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/dive.cjs +188 -20
- package/build/dive.cjs.map +1 -1
- package/build/dive.d.cts +17 -3
- package/build/dive.d.ts +17 -3
- package/build/dive.js +190 -22
- package/build/dive.js.map +1 -1
- package/package.json +3 -1
- package/src/com/Communication.ts +23 -2
- package/src/com/__test__/Communication.test.ts +27 -6
- package/src/com/actions/index.ts +2 -0
- package/src/com/actions/scene/exportscene.ts +6 -0
- package/src/com/types/COMBaseEntity.ts +1 -1
- package/src/dive.ts +2 -1
- package/src/io/IO.ts +107 -0
- package/src/io/__test__/IO.test.ts +145 -0
- package/src/io/gltf/GLTFIO.ts +53 -0
- package/src/io/gltf/__test__/GLTFIO.test.ts +175 -0
- package/src/primitive/Primitive.ts +5 -3
- package/src/primitive/__test__/Primitive.test.ts +4 -2
- package/src/scene/root/Root.ts +12 -16
- package/src/scene/root/__test__/Root.test.ts +9 -9
- package/src/types/SceneType.ts +14 -0
- package/src/types/index.ts +2 -0
package/build/dive.cjs
CHANGED
|
@@ -499,6 +499,95 @@ var init_MediaCreator = __esm({
|
|
|
499
499
|
}
|
|
500
500
|
});
|
|
501
501
|
|
|
502
|
+
// src/io/gltf/GLTFIO.ts
|
|
503
|
+
var import_GLTFLoader, import_GLTFExporter, DIVEGLTFIO;
|
|
504
|
+
var init_GLTFIO = __esm({
|
|
505
|
+
"src/io/gltf/GLTFIO.ts"() {
|
|
506
|
+
"use strict";
|
|
507
|
+
import_GLTFLoader = require("three/examples/jsm/loaders/GLTFLoader");
|
|
508
|
+
import_GLTFExporter = require("three/examples/jsm/exporters/GLTFExporter");
|
|
509
|
+
DIVEGLTFIO = class {
|
|
510
|
+
constructor() {
|
|
511
|
+
this._importer = new import_GLTFLoader.GLTFLoader();
|
|
512
|
+
this._exporter = new import_GLTFExporter.GLTFExporter();
|
|
513
|
+
}
|
|
514
|
+
Import(url, onProgress) {
|
|
515
|
+
return this._importer.loadAsync(url, (progress) => {
|
|
516
|
+
if (!onProgress) return;
|
|
517
|
+
onProgress(progress.loaded / progress.total);
|
|
518
|
+
});
|
|
519
|
+
}
|
|
520
|
+
Export(object, binary, onlyVisible) {
|
|
521
|
+
if (binary) {
|
|
522
|
+
return this._exporter.parseAsync(object, { binary, onlyVisible });
|
|
523
|
+
} else {
|
|
524
|
+
return this._exporter.parseAsync(object, { binary, onlyVisible });
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
};
|
|
528
|
+
}
|
|
529
|
+
});
|
|
530
|
+
|
|
531
|
+
// src/io/IO.ts
|
|
532
|
+
var IO_exports = {};
|
|
533
|
+
__export(IO_exports, {
|
|
534
|
+
DIVEIO: () => DIVEIO
|
|
535
|
+
});
|
|
536
|
+
var DIVEIO;
|
|
537
|
+
var init_IO = __esm({
|
|
538
|
+
"src/io/IO.ts"() {
|
|
539
|
+
"use strict";
|
|
540
|
+
init_GLTFIO();
|
|
541
|
+
DIVEIO = class {
|
|
542
|
+
constructor(scene) {
|
|
543
|
+
this._scene = scene;
|
|
544
|
+
this._gltfIO = new DIVEGLTFIO();
|
|
545
|
+
}
|
|
546
|
+
Import(type, url) {
|
|
547
|
+
return this._importFromURL(type, url).catch((error) => {
|
|
548
|
+
console.error(error);
|
|
549
|
+
return null;
|
|
550
|
+
});
|
|
551
|
+
}
|
|
552
|
+
Export(type) {
|
|
553
|
+
return this._exportToURL(type).catch((error) => {
|
|
554
|
+
console.error(error);
|
|
555
|
+
return null;
|
|
556
|
+
});
|
|
557
|
+
}
|
|
558
|
+
_importFromURL(type, url) {
|
|
559
|
+
switch (type) {
|
|
560
|
+
case "glb": {
|
|
561
|
+
return this._gltfIO.Import(url);
|
|
562
|
+
}
|
|
563
|
+
default: {
|
|
564
|
+
return Promise.reject("Unsupported file type: " + type);
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
_exportToURL(type) {
|
|
569
|
+
switch (type) {
|
|
570
|
+
case "glb": {
|
|
571
|
+
return new Promise((resolve, reject) => {
|
|
572
|
+
this._gltfIO.Export(this._scene, true, true).then((data) => {
|
|
573
|
+
resolve(this._createBlobURL(data));
|
|
574
|
+
}).catch((error) => {
|
|
575
|
+
reject(error);
|
|
576
|
+
});
|
|
577
|
+
});
|
|
578
|
+
}
|
|
579
|
+
default: {
|
|
580
|
+
return Promise.reject("Unsupported file type: " + type);
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
_createBlobURL(data) {
|
|
585
|
+
return URL.createObjectURL(new Blob([data]));
|
|
586
|
+
}
|
|
587
|
+
};
|
|
588
|
+
}
|
|
589
|
+
});
|
|
590
|
+
|
|
502
591
|
// src/dive.ts
|
|
503
592
|
var dive_exports = {};
|
|
504
593
|
__export(dive_exports, {
|
|
@@ -673,6 +762,7 @@ var import_three5 = require("three");
|
|
|
673
762
|
// src/com/Communication.ts
|
|
674
763
|
var import_MathUtils = require("three/src/math/MathUtils");
|
|
675
764
|
init_SelectTool();
|
|
765
|
+
var import_lodash = require("lodash");
|
|
676
766
|
var _DIVECommunication = class _DIVECommunication {
|
|
677
767
|
constructor(renderer, scene, controls, toolbox) {
|
|
678
768
|
this.registered = /* @__PURE__ */ new Map();
|
|
@@ -684,6 +774,7 @@ var _DIVECommunication = class _DIVECommunication {
|
|
|
684
774
|
this.controller = controls;
|
|
685
775
|
this.toolbox = toolbox;
|
|
686
776
|
this._mediaGenerator = null;
|
|
777
|
+
this._io = null;
|
|
687
778
|
_DIVECommunication.__instances.push(this);
|
|
688
779
|
}
|
|
689
780
|
static get(id) {
|
|
@@ -701,6 +792,13 @@ var _DIVECommunication = class _DIVECommunication {
|
|
|
701
792
|
}
|
|
702
793
|
return this._mediaGenerator;
|
|
703
794
|
}
|
|
795
|
+
get io() {
|
|
796
|
+
if (!this._io) {
|
|
797
|
+
const DIVEIO2 = (init_IO(), __toCommonJS(IO_exports)).DIVEIO;
|
|
798
|
+
this._io = new DIVEIO2(this.scene);
|
|
799
|
+
}
|
|
800
|
+
return this._io;
|
|
801
|
+
}
|
|
704
802
|
DestroyInstance() {
|
|
705
803
|
const existingIndex = _DIVECommunication.__instances.findIndex((entry) => entry.id === this.id);
|
|
706
804
|
if (existingIndex === -1) return false;
|
|
@@ -810,6 +908,10 @@ var _DIVECommunication = class _DIVECommunication {
|
|
|
810
908
|
returnValue = this.setParent(payload);
|
|
811
909
|
break;
|
|
812
910
|
}
|
|
911
|
+
case "EXPORT_SCENE": {
|
|
912
|
+
returnValue = this.exportScene(payload);
|
|
913
|
+
break;
|
|
914
|
+
}
|
|
813
915
|
}
|
|
814
916
|
this.dispatch(action, payload);
|
|
815
917
|
return returnValue;
|
|
@@ -867,7 +969,7 @@ var _DIVECommunication = class _DIVECommunication {
|
|
|
867
969
|
}
|
|
868
970
|
addObject(payload) {
|
|
869
971
|
if (this.registered.get(payload.id)) return false;
|
|
870
|
-
if (payload.
|
|
972
|
+
if (payload.parentId === void 0) payload.parentId = null;
|
|
871
973
|
this.registered.set(payload.id, payload);
|
|
872
974
|
this.scene.AddSceneObject(payload);
|
|
873
975
|
return true;
|
|
@@ -875,7 +977,7 @@ var _DIVECommunication = class _DIVECommunication {
|
|
|
875
977
|
updateObject(payload) {
|
|
876
978
|
const objectToUpdate = this.registered.get(payload.id);
|
|
877
979
|
if (!objectToUpdate) return false;
|
|
878
|
-
this.registered.set(payload.id,
|
|
980
|
+
this.registered.set(payload.id, (0, import_lodash.merge)(objectToUpdate, payload));
|
|
879
981
|
const updatedObject = this.registered.get(payload.id);
|
|
880
982
|
this.scene.UpdateSceneObject(__spreadProps(__spreadValues({}, payload), { id: updatedObject.id, entityType: updatedObject.entityType }));
|
|
881
983
|
Object.assign(payload, updatedObject);
|
|
@@ -1044,6 +1146,9 @@ var _DIVECommunication = class _DIVECommunication {
|
|
|
1044
1146
|
parentObject.attach(sceneObject);
|
|
1045
1147
|
return true;
|
|
1046
1148
|
}
|
|
1149
|
+
exportScene(payload) {
|
|
1150
|
+
return this.io.Export(payload.type);
|
|
1151
|
+
}
|
|
1047
1152
|
};
|
|
1048
1153
|
_DIVECommunication.__instances = [];
|
|
1049
1154
|
var DIVECommunication = _DIVECommunication;
|
|
@@ -1385,7 +1490,7 @@ var DIVEPrimitive = class extends DIVENode {
|
|
|
1385
1490
|
DropIt() {
|
|
1386
1491
|
var _a;
|
|
1387
1492
|
if (!this.parent) {
|
|
1388
|
-
console.warn("
|
|
1493
|
+
console.warn("DIVEPrimitive: DropIt() called on a model that is not in the scene.", this);
|
|
1389
1494
|
return;
|
|
1390
1495
|
}
|
|
1391
1496
|
const bottomY = this._boundingBox.min.y * this.scale.y;
|
|
@@ -1407,7 +1512,7 @@ var DIVEPrimitive = class extends DIVENode {
|
|
|
1407
1512
|
}
|
|
1408
1513
|
}
|
|
1409
1514
|
assembleGeometry(geometry) {
|
|
1410
|
-
switch (geometry.name) {
|
|
1515
|
+
switch (geometry.name.toLowerCase()) {
|
|
1411
1516
|
case "cylinder":
|
|
1412
1517
|
return this.createCylinderGeometry(geometry);
|
|
1413
1518
|
case "sphere":
|
|
@@ -1422,8 +1527,10 @@ var DIVEPrimitive = class extends DIVENode {
|
|
|
1422
1527
|
return this.createWallGeometry(geometry);
|
|
1423
1528
|
case "plane":
|
|
1424
1529
|
return this.createPlaneGeometry(geometry);
|
|
1425
|
-
default:
|
|
1530
|
+
default: {
|
|
1531
|
+
console.warn("DIVEPrimitive: Invalid geometry type:", geometry.name.toLowerCase());
|
|
1426
1532
|
return new import_three9.BufferGeometry();
|
|
1533
|
+
}
|
|
1427
1534
|
}
|
|
1428
1535
|
}
|
|
1429
1536
|
createCylinderGeometry(geometry) {
|
|
@@ -1706,7 +1813,7 @@ var DIVERoot = class extends import_three11.Object3D {
|
|
|
1706
1813
|
break;
|
|
1707
1814
|
}
|
|
1708
1815
|
default: {
|
|
1709
|
-
console.warn(`
|
|
1816
|
+
console.warn(`DIVERoot.updateLight: Unknown light type: ${light.type}`);
|
|
1710
1817
|
return;
|
|
1711
1818
|
}
|
|
1712
1819
|
}
|
|
@@ -1719,7 +1826,7 @@ var DIVERoot = class extends import_three11.Object3D {
|
|
|
1719
1826
|
if (light.enabled !== void 0 && light.enabled !== null) sceneObject.SetEnabled(light.enabled);
|
|
1720
1827
|
if (light.color !== void 0 && light.color !== null) sceneObject.SetColor(new import_three11.Color(light.color));
|
|
1721
1828
|
if (light.visible !== void 0 && light.visible !== null) sceneObject.visible = light.visible;
|
|
1722
|
-
if (light.
|
|
1829
|
+
if (light.parentId !== void 0) this.setParent(__spreadProps(__spreadValues({}, light), { parentId: light.parentId }));
|
|
1723
1830
|
}
|
|
1724
1831
|
updateModel(model) {
|
|
1725
1832
|
let sceneObject = this.GetSceneObject(model);
|
|
@@ -1742,7 +1849,7 @@ var DIVERoot = class extends import_three11.Object3D {
|
|
|
1742
1849
|
if (model.scale !== void 0) sceneObject.SetScale(model.scale);
|
|
1743
1850
|
if (model.visible !== void 0) sceneObject.SetVisibility(model.visible);
|
|
1744
1851
|
if (model.material !== void 0) sceneObject.SetMaterial(model.material);
|
|
1745
|
-
if (model.
|
|
1852
|
+
if (model.parentId !== void 0) this.setParent(__spreadProps(__spreadValues({}, model), { parentId: model.parentId }));
|
|
1746
1853
|
}
|
|
1747
1854
|
updatePrimitive(primitive) {
|
|
1748
1855
|
let sceneObject = this.GetSceneObject(primitive);
|
|
@@ -1759,7 +1866,7 @@ var DIVERoot = class extends import_three11.Object3D {
|
|
|
1759
1866
|
if (primitive.scale !== void 0) sceneObject.SetScale(primitive.scale);
|
|
1760
1867
|
if (primitive.visible !== void 0) sceneObject.SetVisibility(primitive.visible);
|
|
1761
1868
|
if (primitive.material !== void 0) sceneObject.SetMaterial(primitive.material);
|
|
1762
|
-
if (primitive.
|
|
1869
|
+
if (primitive.parentId !== void 0) this.setParent(__spreadProps(__spreadValues({}, primitive), { parentId: primitive.parentId }));
|
|
1763
1870
|
}
|
|
1764
1871
|
updateGroup(group) {
|
|
1765
1872
|
let sceneObject = this.GetSceneObject(group);
|
|
@@ -1775,12 +1882,12 @@ var DIVERoot = class extends import_three11.Object3D {
|
|
|
1775
1882
|
if (group.scale !== void 0) sceneObject.SetScale(group.scale);
|
|
1776
1883
|
if (group.visible !== void 0) sceneObject.SetVisibility(group.visible);
|
|
1777
1884
|
if (group.bbVisible !== void 0) sceneObject.SetLinesVisibility(group.bbVisible);
|
|
1778
|
-
if (group.
|
|
1885
|
+
if (group.parentId !== void 0) this.setParent(__spreadProps(__spreadValues({}, group), { parentId: group.parentId }));
|
|
1779
1886
|
}
|
|
1780
1887
|
deleteLight(light) {
|
|
1781
1888
|
const sceneObject = this.GetSceneObject(light);
|
|
1782
1889
|
if (!sceneObject) {
|
|
1783
|
-
console.warn(`
|
|
1890
|
+
console.warn(`DIVERoot.deleteLight: Light with id ${light.id} not found`);
|
|
1784
1891
|
return;
|
|
1785
1892
|
}
|
|
1786
1893
|
this.detachTransformControls(sceneObject);
|
|
@@ -1789,7 +1896,7 @@ var DIVERoot = class extends import_three11.Object3D {
|
|
|
1789
1896
|
deleteModel(model) {
|
|
1790
1897
|
const sceneObject = this.GetSceneObject(model);
|
|
1791
1898
|
if (!sceneObject) {
|
|
1792
|
-
console.warn(`
|
|
1899
|
+
console.warn(`DIVERoot.deleteModel: Model with id ${model.id} not found`);
|
|
1793
1900
|
return;
|
|
1794
1901
|
}
|
|
1795
1902
|
this.detachTransformControls(sceneObject);
|
|
@@ -1798,7 +1905,7 @@ var DIVERoot = class extends import_three11.Object3D {
|
|
|
1798
1905
|
deletePrimitive(primitive) {
|
|
1799
1906
|
const sceneObject = this.GetSceneObject(primitive);
|
|
1800
1907
|
if (!sceneObject) {
|
|
1801
|
-
console.warn(`
|
|
1908
|
+
console.warn(`DIVERoot.deletePrimitive: Primitive with id ${primitive.id} not found`);
|
|
1802
1909
|
return;
|
|
1803
1910
|
}
|
|
1804
1911
|
this.detachTransformControls(sceneObject);
|
|
@@ -1807,7 +1914,7 @@ var DIVERoot = class extends import_three11.Object3D {
|
|
|
1807
1914
|
deleteGroup(group) {
|
|
1808
1915
|
const sceneObject = this.GetSceneObject(group);
|
|
1809
1916
|
if (!sceneObject) {
|
|
1810
|
-
console.warn(`
|
|
1917
|
+
console.warn(`DIVERoot.deleteGroup: Group with id ${group.id} not found`);
|
|
1811
1918
|
return;
|
|
1812
1919
|
}
|
|
1813
1920
|
this.detachTransformControls(sceneObject);
|
|
@@ -1824,11 +1931,8 @@ var DIVERoot = class extends import_three11.Object3D {
|
|
|
1824
1931
|
setParent(object) {
|
|
1825
1932
|
const sceneObject = this.GetSceneObject(object);
|
|
1826
1933
|
if (!sceneObject) return;
|
|
1827
|
-
if (
|
|
1828
|
-
|
|
1829
|
-
}
|
|
1830
|
-
if (object.parent !== null) {
|
|
1831
|
-
const parent = this.GetSceneObject(object.parent);
|
|
1934
|
+
if (object.parentId !== null) {
|
|
1935
|
+
const parent = this.GetSceneObject({ id: object.parentId });
|
|
1832
1936
|
if (!parent) return;
|
|
1833
1937
|
parent.attach(sceneObject);
|
|
1834
1938
|
} else {
|
|
@@ -2376,6 +2480,70 @@ var DIVEInfo = class {
|
|
|
2376
2480
|
};
|
|
2377
2481
|
DIVEInfo._supportsWebXR = null;
|
|
2378
2482
|
|
|
2483
|
+
// package.json
|
|
2484
|
+
var package_default = {
|
|
2485
|
+
name: "@shopware-ag/dive",
|
|
2486
|
+
version: "1.16.0",
|
|
2487
|
+
description: "Shopware Spatial Framework",
|
|
2488
|
+
type: "module",
|
|
2489
|
+
main: "./build/dive.cjs",
|
|
2490
|
+
module: "./build/dive.js",
|
|
2491
|
+
types: "./build/dive.d.ts",
|
|
2492
|
+
files: [
|
|
2493
|
+
"build",
|
|
2494
|
+
"LICENSE",
|
|
2495
|
+
"package.json",
|
|
2496
|
+
"README.md",
|
|
2497
|
+
"src"
|
|
2498
|
+
],
|
|
2499
|
+
keywords: [
|
|
2500
|
+
"dive",
|
|
2501
|
+
"shopware",
|
|
2502
|
+
"sw6",
|
|
2503
|
+
"three",
|
|
2504
|
+
"three.js",
|
|
2505
|
+
"3d",
|
|
2506
|
+
"typescript"
|
|
2507
|
+
],
|
|
2508
|
+
repository: "git@github.com:shopware/dive.git",
|
|
2509
|
+
author: "ffrank <f.frank@shopware.com>",
|
|
2510
|
+
license: "MIT",
|
|
2511
|
+
browserslist: [
|
|
2512
|
+
"> 1%, not dead, not ie 11, not op_mini all"
|
|
2513
|
+
],
|
|
2514
|
+
dependencies: {
|
|
2515
|
+
"@tweenjs/tween.js": "^23.1.1",
|
|
2516
|
+
lodash: "^4.17.21",
|
|
2517
|
+
three: "^0.163.0",
|
|
2518
|
+
"three-spritetext": "^1.8.2"
|
|
2519
|
+
},
|
|
2520
|
+
devDependencies: {
|
|
2521
|
+
"@eslint/js": "^9.1.1",
|
|
2522
|
+
"@types/jest": "^29.5.12",
|
|
2523
|
+
"@types/lodash": "^4.17.12",
|
|
2524
|
+
"@types/node": "^20.12.7",
|
|
2525
|
+
"@types/three": "^0.163.0",
|
|
2526
|
+
eslint: "^9.1.1",
|
|
2527
|
+
globals: "^15.0.0",
|
|
2528
|
+
jest: "^29.7.0",
|
|
2529
|
+
"jest-environment-jsdom": "^29.7.0",
|
|
2530
|
+
jsdom: "^24.0.0",
|
|
2531
|
+
"ts-jest": "^29.1.2",
|
|
2532
|
+
"ts-node": "^10.9.2",
|
|
2533
|
+
tsup: "^8.0.2",
|
|
2534
|
+
typescript: "^5.4.5",
|
|
2535
|
+
"typescript-eslint": "^7.7.1"
|
|
2536
|
+
},
|
|
2537
|
+
scripts: {
|
|
2538
|
+
build: "tsup && yarn genmd",
|
|
2539
|
+
watch: "tsup --watch",
|
|
2540
|
+
lint: "eslint",
|
|
2541
|
+
unit: "jest",
|
|
2542
|
+
coverage: "jest --coverage",
|
|
2543
|
+
genmd: "node ./scripts/genmd.js"
|
|
2544
|
+
}
|
|
2545
|
+
};
|
|
2546
|
+
|
|
2379
2547
|
// src/math/helper/shift.ts
|
|
2380
2548
|
function shift(value, exponent) {
|
|
2381
2549
|
const subvalues = (value + "e").split("e");
|
|
@@ -2551,7 +2719,7 @@ var DIVE = class _DIVE {
|
|
|
2551
2719
|
console.log(this.scene);
|
|
2552
2720
|
}
|
|
2553
2721
|
};
|
|
2554
|
-
console.log(
|
|
2722
|
+
console.log(`DIVE ${package_default.version} initialized`);
|
|
2555
2723
|
}
|
|
2556
2724
|
Dispose() {
|
|
2557
2725
|
var _a;
|