@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/build/dive.js
CHANGED
|
@@ -261,6 +261,10 @@ var _DIVECommunication = class _DIVECommunication {
|
|
|
261
261
|
returnValue = this.setBackground(payload);
|
|
262
262
|
break;
|
|
263
263
|
}
|
|
264
|
+
case "DROP_IT": {
|
|
265
|
+
returnValue = this.dropIt(payload);
|
|
266
|
+
break;
|
|
267
|
+
}
|
|
264
268
|
case "PLACE_ON_FLOOR": {
|
|
265
269
|
returnValue = this.placeOnFloor(payload);
|
|
266
270
|
break;
|
|
@@ -394,6 +398,13 @@ var _DIVECommunication = class _DIVECommunication {
|
|
|
394
398
|
this.scene.SetBackground(payload.color);
|
|
395
399
|
return true;
|
|
396
400
|
}
|
|
401
|
+
dropIt(payload) {
|
|
402
|
+
const object = this.registered.get(payload.id);
|
|
403
|
+
if (!object) return false;
|
|
404
|
+
const model = this.scene.GetSceneObject(object);
|
|
405
|
+
model.DropIt();
|
|
406
|
+
return true;
|
|
407
|
+
}
|
|
397
408
|
placeOnFloor(payload) {
|
|
398
409
|
if (!this.registered.get(payload.id)) return false;
|
|
399
410
|
this.scene.PlaceOnFloor(payload);
|
|
@@ -622,7 +633,17 @@ var DIVELightRoot = class extends Object3D4 {
|
|
|
622
633
|
import { Object3D as Object3D6 } from "three";
|
|
623
634
|
|
|
624
635
|
// src/model/Model.ts
|
|
625
|
-
import { Box3, Object3D as Object3D5, Vector3 } from "three";
|
|
636
|
+
import { Box3, Object3D as Object3D5, Raycaster, Vector3 } from "three";
|
|
637
|
+
|
|
638
|
+
// src/helper/findSceneRecursive/findSceneRecursive.ts
|
|
639
|
+
var findSceneRecursive = (object) => {
|
|
640
|
+
if (object.parent) {
|
|
641
|
+
return findSceneRecursive(object.parent);
|
|
642
|
+
}
|
|
643
|
+
return object;
|
|
644
|
+
};
|
|
645
|
+
|
|
646
|
+
// src/model/Model.ts
|
|
626
647
|
var DIVEModel = class extends Object3D5 {
|
|
627
648
|
constructor() {
|
|
628
649
|
super();
|
|
@@ -661,6 +682,30 @@ var DIVEModel = class extends Object3D5 {
|
|
|
661
682
|
this.position.y = -this.boundingBox.min.y * this.scale.y;
|
|
662
683
|
(_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 });
|
|
663
684
|
}
|
|
685
|
+
DropIt() {
|
|
686
|
+
var _a;
|
|
687
|
+
if (!this.parent) {
|
|
688
|
+
console.warn("DIVEModel: DropIt() called on a model that is not in the scene.", this);
|
|
689
|
+
return;
|
|
690
|
+
}
|
|
691
|
+
const bottomY = this.boundingBox.min.y * this.scale.y;
|
|
692
|
+
const bbBottomCenter = this.localToWorld(this.boundingBox.getCenter(new Vector3()).multiply(this.scale));
|
|
693
|
+
bbBottomCenter.y = bottomY + this.position.y;
|
|
694
|
+
const raycaster = new Raycaster(bbBottomCenter, new Vector3(0, -1, 0));
|
|
695
|
+
raycaster.layers.mask = PRODUCT_LAYER_MASK;
|
|
696
|
+
const intersections = raycaster.intersectObjects(findSceneRecursive(this).Root.children, true);
|
|
697
|
+
if (intersections.length > 0) {
|
|
698
|
+
const mesh = intersections[0].object;
|
|
699
|
+
mesh.geometry.computeBoundingBox();
|
|
700
|
+
const meshBB = mesh.geometry.boundingBox;
|
|
701
|
+
const worldPos = mesh.localToWorld(meshBB.max.clone());
|
|
702
|
+
const oldPos = this.position.clone();
|
|
703
|
+
const newPos = this.position.clone().setY(worldPos.y).add(new Vector3(0, bottomY, 0));
|
|
704
|
+
this.position.copy(newPos);
|
|
705
|
+
if (this.position.y === oldPos.y) return;
|
|
706
|
+
(_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 });
|
|
707
|
+
}
|
|
708
|
+
}
|
|
664
709
|
onMove() {
|
|
665
710
|
var _a;
|
|
666
711
|
(_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 });
|
|
@@ -1062,7 +1107,7 @@ var DIVEMediaCreator = class {
|
|
|
1062
1107
|
};
|
|
1063
1108
|
|
|
1064
1109
|
// src/toolbox/select/SelectTool.ts
|
|
1065
|
-
import { Raycaster, Vector2 } from "three";
|
|
1110
|
+
import { Raycaster as Raycaster2, Vector2 } from "three";
|
|
1066
1111
|
import { TransformControls } from "three/examples/jsm/Addons.js";
|
|
1067
1112
|
|
|
1068
1113
|
// src/toolbox/BaseTool.ts
|
|
@@ -1090,7 +1135,7 @@ var DIVESelectTool = class extends DIVEBaseTool {
|
|
|
1090
1135
|
this.canvas = controller.domElement;
|
|
1091
1136
|
this.scene = scene;
|
|
1092
1137
|
this.controller = controller;
|
|
1093
|
-
this.raycaster = new
|
|
1138
|
+
this.raycaster = new Raycaster2();
|
|
1094
1139
|
this.raycaster.layers.mask = PRODUCT_LAYER_MASK | HELPER_LAYER_MASK;
|
|
1095
1140
|
this.gizmo = new TransformControls(this.controller.object, this.canvas);
|
|
1096
1141
|
this.gizmo.layers.mask = UI_LAYER_MASK;
|