@shopware-ag/dive 1.1.2 → 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 CHANGED
@@ -172,6 +172,7 @@ In the following you find a list of all available actions to perform on DIVEComm
172
172
  | [ZOOM_CAMERA](./src/com/actions/camera/zoomcamera.ts) | Zoom in or out
173
173
  | [GENERATE_MEDIA](./src/com/actions/media/generatemedia.ts) | Generate a screenshot with the specified parameters
174
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
175
176
  | [PLACE_ON_FLOOR](./src/com/actions/object/model/placeonfloor.ts) | Set a model onto to the floor
176
177
  | [ADD_OBJECT](./src/com/actions/object/addobject.ts) | Add an object to the scene
177
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 });