@shopware-ag/dive 1.1.1 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -0
- package/build/dive.cjs +45 -0
- package/build/dive.cjs.map +1 -1
- package/build/dive.d.cts +9 -0
- package/build/dive.d.ts +9 -0
- package/build/dive.js +48 -3
- package/build/dive.js.map +1 -1
- package/package.json +1 -1
- package/src/com/Communication.ts +15 -0
- package/src/com/__test__/Communication.test.ts +41 -0
- package/src/com/actions/index.ts +2 -0
- package/src/com/actions/object/model/dropit.ts +4 -0
- package/src/helper/findSceneRecursive/__test__/findSceneRecursive.test.ts +40 -0
- package/src/helper/findSceneRecursive/findSceneRecursive.ts +16 -0
- package/src/model/Model.ts +35 -1
- package/src/model/__test__/Model.test.ts +141 -8
- /package/src/helper/getObjectDelta/__test__/{getObjectDelta.spec.ts → getObjectDelta.test.ts} +0 -0
package/README.md
CHANGED
|
@@ -46,6 +46,7 @@ module.exports = () => {
|
|
|
46
46
|
resolve: {
|
|
47
47
|
extensions: ['.ts', '.cjs', '.js'],
|
|
48
48
|
alias: {
|
|
49
|
+
three: path.resolve(__dirname, 'path/to/node_modules/three'),
|
|
49
50
|
"@shopware-ag/dive": path.resolve(__dirname, 'path/to/node_modules/@shopware-ag/dive'),
|
|
50
51
|
}
|
|
51
52
|
},
|
|
@@ -57,6 +58,7 @@ module.exports = () => {
|
|
|
57
58
|
test: /\.(js|ts)$/,
|
|
58
59
|
loader: 'swc-loader',
|
|
59
60
|
include: [
|
|
61
|
+
path.resolve(__dirname, 'path/to/node_modules/three'),
|
|
60
62
|
path.resolve(__dirname, 'path/to/node_modules/@shopware-ag/dive')
|
|
61
63
|
],
|
|
62
64
|
options: {
|
|
@@ -170,6 +172,7 @@ In the following you find a list of all available actions to perform on DIVEComm
|
|
|
170
172
|
| [ZOOM_CAMERA](./src/com/actions/camera/zoomcamera.ts) | Zoom in or out
|
|
171
173
|
| [GENERATE_MEDIA](./src/com/actions/media/generatemedia.ts) | Generate a screenshot with the specified parameters
|
|
172
174
|
| [MODEL_LOADED](./src/com/actions/object/model/modelloaded.ts) | Is performed when a model file is completely loaded
|
|
175
|
+
| [DROP_IT](./src/com/actions/object/model/dropit.ts) | Places the model onto the nextg underlying object's bounding box
|
|
173
176
|
| [PLACE_ON_FLOOR](./src/com/actions/object/model/placeonfloor.ts) | Set a model onto to the floor
|
|
174
177
|
| [ADD_OBJECT](./src/com/actions/object/addobject.ts) | Add an object to the scene
|
|
175
178
|
| [UPDATE_OBJECT](./src/com/actions/object/updateobject.ts) | Update an existing object
|
package/build/dive.cjs
CHANGED
|
@@ -296,6 +296,10 @@ var _DIVECommunication = class _DIVECommunication {
|
|
|
296
296
|
returnValue = this.setBackground(payload);
|
|
297
297
|
break;
|
|
298
298
|
}
|
|
299
|
+
case "DROP_IT": {
|
|
300
|
+
returnValue = this.dropIt(payload);
|
|
301
|
+
break;
|
|
302
|
+
}
|
|
299
303
|
case "PLACE_ON_FLOOR": {
|
|
300
304
|
returnValue = this.placeOnFloor(payload);
|
|
301
305
|
break;
|
|
@@ -429,6 +433,13 @@ var _DIVECommunication = class _DIVECommunication {
|
|
|
429
433
|
this.scene.SetBackground(payload.color);
|
|
430
434
|
return true;
|
|
431
435
|
}
|
|
436
|
+
dropIt(payload) {
|
|
437
|
+
const object = this.registered.get(payload.id);
|
|
438
|
+
if (!object) return false;
|
|
439
|
+
const model = this.scene.GetSceneObject(object);
|
|
440
|
+
model.DropIt();
|
|
441
|
+
return true;
|
|
442
|
+
}
|
|
432
443
|
placeOnFloor(payload) {
|
|
433
444
|
if (!this.registered.get(payload.id)) return false;
|
|
434
445
|
this.scene.PlaceOnFloor(payload);
|
|
@@ -658,6 +669,16 @@ var import_three8 = require("three");
|
|
|
658
669
|
|
|
659
670
|
// src/model/Model.ts
|
|
660
671
|
var import_three7 = require("three");
|
|
672
|
+
|
|
673
|
+
// src/helper/findSceneRecursive/findSceneRecursive.ts
|
|
674
|
+
var findSceneRecursive = (object) => {
|
|
675
|
+
if (object.parent) {
|
|
676
|
+
return findSceneRecursive(object.parent);
|
|
677
|
+
}
|
|
678
|
+
return object;
|
|
679
|
+
};
|
|
680
|
+
|
|
681
|
+
// src/model/Model.ts
|
|
661
682
|
var DIVEModel = class extends import_three7.Object3D {
|
|
662
683
|
constructor() {
|
|
663
684
|
super();
|
|
@@ -696,6 +717,30 @@ var DIVEModel = class extends import_three7.Object3D {
|
|
|
696
717
|
this.position.y = -this.boundingBox.min.y * this.scale.y;
|
|
697
718
|
(_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 });
|
|
698
719
|
}
|
|
720
|
+
DropIt() {
|
|
721
|
+
var _a;
|
|
722
|
+
if (!this.parent) {
|
|
723
|
+
console.warn("DIVEModel: DropIt() called on a model that is not in the scene.", this);
|
|
724
|
+
return;
|
|
725
|
+
}
|
|
726
|
+
const bottomY = this.boundingBox.min.y * this.scale.y;
|
|
727
|
+
const bbBottomCenter = this.localToWorld(this.boundingBox.getCenter(new import_three7.Vector3()).multiply(this.scale));
|
|
728
|
+
bbBottomCenter.y = bottomY + this.position.y;
|
|
729
|
+
const raycaster = new import_three7.Raycaster(bbBottomCenter, new import_three7.Vector3(0, -1, 0));
|
|
730
|
+
raycaster.layers.mask = PRODUCT_LAYER_MASK;
|
|
731
|
+
const intersections = raycaster.intersectObjects(findSceneRecursive(this).Root.children, true);
|
|
732
|
+
if (intersections.length > 0) {
|
|
733
|
+
const mesh = intersections[0].object;
|
|
734
|
+
mesh.geometry.computeBoundingBox();
|
|
735
|
+
const meshBB = mesh.geometry.boundingBox;
|
|
736
|
+
const worldPos = mesh.localToWorld(meshBB.max.clone());
|
|
737
|
+
const oldPos = this.position.clone();
|
|
738
|
+
const newPos = this.position.clone().setY(worldPos.y).add(new import_three7.Vector3(0, bottomY, 0));
|
|
739
|
+
this.position.copy(newPos);
|
|
740
|
+
if (this.position.y === oldPos.y) return;
|
|
741
|
+
(_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 });
|
|
742
|
+
}
|
|
743
|
+
}
|
|
699
744
|
onMove() {
|
|
700
745
|
var _a;
|
|
701
746
|
(_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 });
|