@shopware-ag/dive
Advanced tools
Comparing version 1.3.2 to 1.4.0
@@ -357,2 +357,9 @@ import { ShadowMapType, ToneMapping, WebGLRenderer, Scene, Camera, PerspectiveCamera, Vector3Like, Mesh, ColorRepresentation, Object3D, Intersection, Vector2, Raycaster, Vector3 } from 'three'; | ||
interface DESELECT_OBJECT { | ||
'PAYLOAD': Partial<COMEntity> & { | ||
id: string; | ||
}; | ||
'RETURN': boolean; | ||
} | ||
interface GET_CAMERA_TRANSFORM { | ||
@@ -381,2 +388,3 @@ 'PAYLOAD': object; | ||
SELECT_OBJECT: SELECT_OBJECT; | ||
DESELECT_OBJECT: DESELECT_OBJECT; | ||
SET_BACKGROUND: SET_BACKGROUND; | ||
@@ -533,2 +541,3 @@ DROP_IT: DROP_IT; | ||
private selectObject; | ||
private deselectObject; | ||
private setBackground; | ||
@@ -535,0 +544,0 @@ private dropIt; |
@@ -260,2 +260,6 @@ var __defProp = Object.defineProperty; | ||
} | ||
case "DESELECT_OBJECT": { | ||
returnValue = this.deselectObject(payload); | ||
break; | ||
} | ||
case "SET_BACKGROUND": { | ||
@@ -396,6 +400,17 @@ returnValue = this.setBackground(payload); | ||
this.toolbox.UseTool("select"); | ||
this.toolbox.GetActiveTool().Select(sceneObject); | ||
this.toolbox.GetActiveTool().AttachGizmo(sceneObject); | ||
Object.assign(payload, object); | ||
return true; | ||
} | ||
deselectObject(payload) { | ||
const object = this.registered.get(payload.id); | ||
if (!object) return false; | ||
const sceneObject = this.scene.GetSceneObject(object); | ||
if (!sceneObject) return false; | ||
if (!("isSelectable" in sceneObject)) return false; | ||
this.toolbox.UseTool("select"); | ||
this.toolbox.GetActiveTool().DetachGizmo(); | ||
Object.assign(payload, object); | ||
return true; | ||
} | ||
setBackground(payload) { | ||
@@ -511,3 +526,3 @@ this.scene.SetBackground(payload.color); | ||
this.mesh = new Mesh(geometry, material); | ||
this.mesh.layers.mask = HELPER_LAYER_MASK; | ||
this.mesh.layers.mask = UI_LAYER_MASK; | ||
this.add(this.mesh); | ||
@@ -530,2 +545,10 @@ } | ||
} | ||
onSelect() { | ||
var _a; | ||
(_a = DIVECommunication.get(this.userData.id)) == null ? void 0 : _a.PerformAction("SELECT_OBJECT", { id: this.userData.id }); | ||
} | ||
onDeselect() { | ||
var _a; | ||
(_a = DIVECommunication.get(this.userData.id)) == null ? void 0 : _a.PerformAction("DESELECT_OBJECT", { id: this.userData.id }); | ||
} | ||
}; | ||
@@ -728,2 +751,10 @@ | ||
} | ||
onSelect() { | ||
var _a; | ||
(_a = DIVECommunication.get(this.userData.id)) == null ? void 0 : _a.PerformAction("SELECT_OBJECT", { id: this.userData.id }); | ||
} | ||
onDeselect() { | ||
var _a; | ||
(_a = DIVECommunication.get(this.userData.id)) == null ? void 0 : _a.PerformAction("DESELECT_OBJECT", { id: this.userData.id }); | ||
} | ||
}; | ||
@@ -1359,2 +1390,14 @@ | ||
this._gizmo.mode = "translate"; | ||
this._gizmo.addEventListener("mouseDown", () => { | ||
controller.enabled = false; | ||
}); | ||
this._gizmo.addEventListener("mouseUp", () => { | ||
controller.enabled = true; | ||
}); | ||
this._gizmo.addEventListener("objectChange", () => { | ||
if (!this._gizmo.object) return; | ||
if (!("isMoveable" in this._gizmo.object)) return; | ||
if (!("onMove" in this._gizmo.object)) return; | ||
this._gizmo.object.onMove(); | ||
}); | ||
scene.add(this._gizmo); | ||
@@ -1388,2 +1431,12 @@ } | ||
if (selectable.onSelect) selectable.onSelect(); | ||
this.AttachGizmo(selectable); | ||
} | ||
Deselect(selectable) { | ||
if (selectable.onDeselect) selectable.onDeselect(); | ||
this.DetachGizmo(); | ||
} | ||
DetachGizmo() { | ||
this._gizmo.detach(); | ||
} | ||
AttachGizmo(selectable) { | ||
if ("isMoveable" in selectable) { | ||
@@ -1394,6 +1447,2 @@ const movable = selectable; | ||
} | ||
Deselect(selectable) { | ||
if (selectable.onDeselect) selectable.onDeselect(); | ||
this._gizmo.detach(); | ||
} | ||
onClick(e) { | ||
@@ -1400,0 +1449,0 @@ super.onClick(e); |
{ | ||
"name": "@shopware-ag/dive", | ||
"version": "1.3.2", | ||
"version": "1.4.0", | ||
"description": "Shopware Spatial Framework", | ||
@@ -5,0 +5,0 @@ "type": "module", |
@@ -165,4 +165,14 @@ | ||
| [GET_ALL_SCENE_DATA](./src/com/actions/scene/getallscenedata.ts) | Return all scene data that is currently set | ||
| [GET_ALL_OBJECTS](./src/com/actions/object/getallobjects.ts) | Return a map of all objects | ||
| [GET_OBJECTS](./src/com/actions/object/getobjects.ts) | Return an array of all objects with given ids | ||
| [PLACE_ON_FLOOR](./src/com/actions/object/model/placeonfloor.ts) | Set a model onto to the floor | ||
| [ADD_OBJECT](./src/com/actions/object/addobject.ts) | Add an object to the scene | ||
| [UPDATE_OBJECT](./src/com/actions/object/updateobject.ts) | Update an existing object | ||
| [DELETE_OBJECT](./src/com/actions/object/deleteobject.ts) | Delete an existing object | ||
| [SELECT_OBJECT](./src/com/actions/object/selectobject.ts) | Select an existing object in the scene | ||
| [DESELECT_OBJECT](./src/com/actions/object/deselectobject.ts) | Deselect an existing object in the scene | ||
| [SET_BACKGROUND](./src/com/actions/scene/setbackground.ts) | Set a background color | ||
| [UPDATE_SCENE](./src/com/actions/scene/updatescene.ts) | Update scene data | ||
| [DROP_IT](./src/com/actions/object/model/dropit.ts) | Places the model onto the next underlying object's bounding box | ||
| [PLACE_ON_FLOOR](./src/com/actions/object/model/placeonfloor.ts) | Places the model onto the floor (zero plane) | ||
| [SET_CAMERA_TRANSFORM](./src/com/actions/camera/setcameratransform.ts) | Set camera transformation (w/o animation, used to initially set up camera) | ||
| [GET_CAMERA_TRANSFORM](./src/com/actions/camera/getcameratransform.ts) | Return currenty camera transformation | ||
@@ -172,14 +182,7 @@ | [MOVE_CAMERA](./src/com/actions/camera/movecamera.ts) | Move camera to a specific position or the position of a previously defined POV (with an animation) | ||
| [SET_CAMERA_LAYER](./src/com/actions/camera/setcameralayer.ts) | Set camera layer to switch between live view and editor view | ||
| [SET_CAMERA_TRANSFORM](./src/com/actions/camera/setcameratransform.ts) | Set camera transformation (w/o animation, used to initially set up camera) | ||
| [ZOOM_CAMERA](./src/com/actions/camera/zoomcamera.ts) | Zoom in or out | ||
| [SET_GIZMO_MODE](./src/com/actions/toolbox/select/setgizmomode.ts) | Set gizmo mode | ||
| [MODEL_LOADED](./src/com/actions/object/model/modelloaded.ts) | Is performed when a model file is completely loaded | ||
| [UPDATE_SCENE](./src/com/actions/scene/updatescene.ts) | Update scene data | ||
| [GENERATE_MEDIA](./src/com/actions/media/generatemedia.ts) | Generate a screenshot with the specified parameters | ||
| [MODEL_LOADED](./src/com/actions/object/model/modelloaded.ts) | Is performed when a model file is completely loaded | ||
| [DROP_IT](./src/com/actions/object/model/dropit.ts) | Places the model onto the nextg underlying object's bounding box | ||
| [PLACE_ON_FLOOR](./src/com/actions/object/model/placeonfloor.ts) | Set a model onto to the floor | ||
| [ADD_OBJECT](./src/com/actions/object/addobject.ts) | Add an object to the scene | ||
| [UPDATE_OBJECT](./src/com/actions/object/updateobject.ts) | Update an existing object | ||
| [DELETE_OBJECT](./src/com/actions/object/deleteobject.ts) | Delete an existing object | ||
| [GET_ALL_OBJECTS](./src/com/actions/object/getallobjects.ts) | Return a map of all objects | ||
| [GET_OBJECTS](./src/com/actions/object/getobjects.ts) | Return a map of all objects (with the opportunity to filter for ids) | ||
| [SELECT_OBJECT](./src/com/actions/object/selectobject.ts) | Select an existing object in the scene | ||
| [SET_GIZMO_MODE](./src/com/actions/toolbox/select/setgizmomode.ts) | Set gizmo mode |
@@ -164,2 +164,3 @@ import DIVE, { DIVESettings } from '../dive.ts'; | ||
expect((window as any).DIVE.PrintScene).toBeDefined(); | ||
console.log = jest.fn(); | ||
expect(() => (window as any).DIVE.PrintScene()).not.toThrow(); | ||
@@ -166,0 +167,0 @@ }); |
@@ -116,7 +116,9 @@ import DIVECommunication from '../Communication'; | ||
const mockSelect = jest.fn(); | ||
const mockAttach = jest.fn(); | ||
const mockDetach = jest.fn(); | ||
const mockToolBox = { | ||
UseTool: jest.fn(), | ||
GetActiveTool: jest.fn().mockReturnValue({ | ||
Select: mockSelect, | ||
AttachGizmo: mockAttach, | ||
DetachGizmo: mockDetach, | ||
}), | ||
@@ -544,5 +546,31 @@ SetGizmoMode: jest.fn(), | ||
expect(success3).toBe(true); | ||
expect(mockSelect).toHaveBeenCalledTimes(1); | ||
expect(mockAttach).toHaveBeenCalledTimes(1); | ||
}); | ||
it('should perform action DESELECT_OBJECT', () => { | ||
const success0 = testCom.PerformAction('DESELECT_OBJECT', { id: 'test0' }); | ||
expect(success0).toBe(false); | ||
const mock0 = { | ||
entityType: "pov", | ||
id: "test0", | ||
position: { x: 0, y: 0, z: 0 }, | ||
target: { x: 0, y: 0, z: 0 }, | ||
} as COMPov; | ||
testCom.PerformAction('ADD_OBJECT', mock0); | ||
jest.spyOn(mockScene, 'GetSceneObject').mockReturnValueOnce(undefined); | ||
const success1 = testCom.PerformAction('DESELECT_OBJECT', { id: 'test0' }); | ||
expect(success1).toBe(false); | ||
jest.spyOn(mockScene, 'GetSceneObject').mockReturnValueOnce({} as unknown as Object3D); | ||
const success2 = testCom.PerformAction('DESELECT_OBJECT', { id: 'test0' }); | ||
expect(success2).toBe(false); | ||
jest.spyOn(mockScene, 'GetSceneObject').mockReturnValueOnce({ isSelectable: true } as unknown as Object3D); | ||
const success3 = testCom.PerformAction('DESELECT_OBJECT', { id: 'test0' }); | ||
expect(success3).toBe(true); | ||
expect(mockDetach).toHaveBeenCalledTimes(1); | ||
}); | ||
it('should perform action SET_CAMERA_TRANSFORM', () => { | ||
@@ -549,0 +577,0 @@ const success = testCom.PerformAction('SET_CAMERA_TRANSFORM', { |
@@ -19,2 +19,3 @@ import SET_BACKGROUND from "./scene/setbackground.ts"; | ||
import SELECT_OBJECT from "./object/selectobject.ts"; | ||
import DESELECT_OBJECT from "./object/deselectobject.ts"; | ||
import GET_CAMERA_TRANSFORM from "./camera/getcameratransform.ts"; | ||
@@ -31,2 +32,3 @@ import DROP_IT from "./object/model/dropit.ts"; | ||
SELECT_OBJECT: SELECT_OBJECT, | ||
DESELECT_OBJECT: DESELECT_OBJECT, | ||
SET_BACKGROUND: SET_BACKGROUND, | ||
@@ -33,0 +35,0 @@ DROP_IT: DROP_IT, |
@@ -103,2 +103,6 @@ import { Color, MeshStandardMaterial, MathUtils } from "three"; | ||
} | ||
case 'DESELECT_OBJECT': { | ||
returnValue = this.deselectObject(payload as Actions['DESELECT_OBJECT']['PAYLOAD']); | ||
break; | ||
} | ||
case 'SET_BACKGROUND': { | ||
@@ -273,3 +277,3 @@ returnValue = this.setBackground(payload as Actions['SET_BACKGROUND']['PAYLOAD']); | ||
this.toolbox.UseTool('select'); | ||
(this.toolbox.GetActiveTool() as DIVESelectTool).Select(sceneObject as DIVESelectable); | ||
(this.toolbox.GetActiveTool() as DIVESelectTool).AttachGizmo(sceneObject as DIVESelectable); | ||
@@ -282,2 +286,20 @@ // copy object to payload to use later | ||
private deselectObject(payload: Actions['DESELECT_OBJECT']['PAYLOAD']): Actions['DESELECT_OBJECT']['RETURN'] { | ||
const object = this.registered.get(payload.id); | ||
if (!object) return false; | ||
const sceneObject = this.scene.GetSceneObject(object); | ||
if (!sceneObject) return false; | ||
if (!('isSelectable' in sceneObject)) return false; | ||
this.toolbox.UseTool('select'); | ||
(this.toolbox.GetActiveTool() as DIVESelectTool).DetachGizmo(); | ||
// copy object to payload to use later | ||
Object.assign(payload, object); | ||
return true; | ||
} | ||
private setBackground(payload: Actions['SET_BACKGROUND']['PAYLOAD']): Actions['SET_BACKGROUND']['RETURN'] { | ||
@@ -284,0 +306,0 @@ this.scene.SetBackground(payload.color); |
@@ -111,2 +111,20 @@ import DIVEPointLight from '../PointLight.ts'; | ||
}); | ||
it('should onSelect', () => { | ||
const testLight = new DIVEPointLight(); | ||
testLight.userData.id = 'something'; | ||
expect(() => testLight.onSelect()).not.toThrow(); | ||
jest.spyOn(DIVECommunication, 'get').mockReturnValueOnce(undefined); | ||
expect(() => testLight.onSelect()).not.toThrow(); | ||
}); | ||
it('should onDeselect', () => { | ||
const testLight = new DIVEPointLight(); | ||
testLight.userData.id = 'something'; | ||
expect(() => testLight.onDeselect()).not.toThrow(); | ||
jest.spyOn(DIVECommunication, 'get').mockReturnValueOnce(undefined); | ||
expect(() => testLight.onDeselect()).not.toThrow(); | ||
}); | ||
}); |
import { PointLight, Color, SphereGeometry, MeshBasicMaterial, Mesh, FrontSide, Object3D } from 'three'; | ||
import DIVECommunication from '../com/Communication'; | ||
import { HELPER_LAYER_MASK, PRODUCT_LAYER_MASK } from '../constant/VisibilityLayerMask'; | ||
import { PRODUCT_LAYER_MASK, UI_LAYER_MASK } from '../constant/VisibilityLayerMask'; | ||
import { DIVEMoveable } from '../interface/Moveable'; | ||
@@ -47,3 +47,3 @@ import { DIVESelectable } from '../interface/Selectable'; | ||
this.mesh = new Mesh(geometry, material); | ||
this.mesh.layers.mask = HELPER_LAYER_MASK; | ||
this.mesh.layers.mask = UI_LAYER_MASK; | ||
@@ -72,2 +72,10 @@ this.add(this.mesh); | ||
} | ||
public onSelect(): void { | ||
DIVECommunication.get(this.userData.id)?.PerformAction('SELECT_OBJECT', { id: this.userData.id }); | ||
} | ||
public onDeselect(): void { | ||
DIVECommunication.get(this.userData.id)?.PerformAction('DESELECT_OBJECT', { id: this.userData.id }); | ||
} | ||
} |
@@ -296,2 +296,22 @@ import Model from '../Model'; | ||
}); | ||
it('should onSelect', () => { | ||
const testLight = new Model(); | ||
testLight.userData.id = 'something'; | ||
expect(() => testLight.onSelect()).not.toThrow(); | ||
jest.spyOn(DIVECommunication, 'get').mockReturnValueOnce(undefined); | ||
expect(() => testLight.onSelect()).not.toThrow(); | ||
}); | ||
it('should onDeselect', () => { | ||
const testLight = new Model(); | ||
testLight.userData.id = 'something'; | ||
expect(() => testLight.onDeselect()).not.toThrow(); | ||
jest.spyOn(DIVECommunication, 'get').mockReturnValueOnce(undefined); | ||
expect(() => testLight.onDeselect()).not.toThrow(); | ||
}); | ||
}); |
@@ -106,2 +106,10 @@ import { Box3, type Mesh, Object3D, Raycaster, Vector3, Vector3Like } from 'three'; | ||
} | ||
public onSelect(): void { | ||
DIVECommunication.get(this.userData.id)?.PerformAction('SELECT_OBJECT', { id: this.userData.id }); | ||
} | ||
public onDeselect(): void { | ||
DIVECommunication.get(this.userData.id)?.PerformAction('DESELECT_OBJECT', { id: this.userData.id }); | ||
} | ||
} |
@@ -33,6 +33,3 @@ import { Object3D } from "three"; | ||
if ('isMoveable' in selectable) { | ||
const movable = selectable as (Object3D & DIVESelectable & DIVEMoveable); | ||
this._gizmo.attach(movable); | ||
} | ||
this.AttachGizmo(selectable); | ||
} | ||
@@ -42,5 +39,17 @@ | ||
if (selectable.onDeselect) selectable.onDeselect(); | ||
this.DetachGizmo(); | ||
} | ||
public DetachGizmo(): void { | ||
this._gizmo.detach(); | ||
} | ||
public AttachGizmo(selectable: DIVESelectable): void { | ||
if ('isMoveable' in selectable) { | ||
const movable = selectable as (Object3D & DIVESelectable & DIVEMoveable); | ||
this._gizmo.attach(movable); | ||
} | ||
} | ||
public onClick(e: PointerEvent): void { | ||
@@ -47,0 +56,0 @@ super.onClick(e); |
@@ -5,2 +5,3 @@ import DIVEBaseTool from "../BaseTool.ts"; | ||
import { TransformControls } from "three/examples/jsm/Addons"; | ||
import { type DIVEMoveable } from "../../interface/Moveable.ts"; | ||
@@ -29,2 +30,17 @@ export interface DIVEObjectEventMap { | ||
this._gizmo.addEventListener('mouseDown', () => { | ||
controller.enabled = false; | ||
}); | ||
this._gizmo.addEventListener('mouseUp', () => { | ||
controller.enabled = true; | ||
}); | ||
this._gizmo.addEventListener('objectChange', () => { | ||
if (!this._gizmo.object) return; | ||
if (!('isMoveable' in this._gizmo.object)) return; | ||
if (!('onMove' in this._gizmo.object)) return; | ||
(this._gizmo.object as DIVEMoveable).onMove!(); | ||
}); | ||
scene.add(this._gizmo); | ||
@@ -31,0 +47,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
678399
119
10612
187