@shopware-ag/dive 1.18.2 → 1.18.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shopware-ag/dive",
3
- "version": "1.18.2",
3
+ "version": "1.18.3",
4
4
  "description": "Shopware Spatial Framework",
5
5
  "type": "module",
6
6
  "main": "./build/dive.cjs",
@@ -268,6 +268,12 @@ export class DIVECommunication {
268
268
  );
269
269
  break;
270
270
  }
271
+ case 'SET_GIZMO_SCALE_LINKED': {
272
+ returnValue = this.setGizmoScaleLinked(
273
+ payload as Actions['SET_GIZMO_SCALE_LINKED']['PAYLOAD'],
274
+ );
275
+ break;
276
+ }
271
277
  case 'USE_TOOL': {
272
278
  returnValue = this.useTool(
273
279
  payload as Actions['USE_TOOL']['PAYLOAD'],
@@ -664,6 +670,14 @@ export class DIVECommunication {
664
670
  return payload;
665
671
  }
666
672
 
673
+ private setGizmoScaleLinked(
674
+ payload: Actions['SET_GIZMO_SCALE_LINKED']['PAYLOAD'],
675
+ ): Actions['SET_GIZMO_SCALE_LINKED']['RETURN'] {
676
+ console.log('SET_GIZMO_SCALE_LINKED', payload);
677
+ this.toolbox.SetGizmoScaleLinked(payload);
678
+ return payload;
679
+ }
680
+
667
681
  private useTool(
668
682
  payload: Actions['USE_TOOL']['PAYLOAD'],
669
683
  ): Actions['USE_TOOL']['RETURN'] {
@@ -20,6 +20,7 @@ import DESELECT_OBJECT from './object/deselectobject.ts';
20
20
  import GET_CAMERA_TRANSFORM from './camera/getcameratransform.ts';
21
21
  import DROP_IT from './object/model/dropit.ts';
22
22
  import SET_GIZMO_VISIBILITY from './toolbox/transform/setgizmovisible.js';
23
+ import SET_GIZMO_SCALE_LINKED from './toolbox/transform/setgizmoscalelinked.ts';
23
24
  import COMPUTE_ENCOMPASSING_VIEW from './camera/computeencompassingview.ts';
24
25
  import USE_TOOL from './toolbox/usetool.ts';
25
26
  import SET_PARENT from './object/setparent.ts';
@@ -47,6 +48,7 @@ export interface Actions {
47
48
  ZOOM_CAMERA: ZOOM_CAMERA;
48
49
  SET_GIZMO_MODE: SET_GIZMO_MODE;
49
50
  SET_GIZMO_VISIBILITY: SET_GIZMO_VISIBILITY;
51
+ SET_GIZMO_SCALE_LINKED: SET_GIZMO_SCALE_LINKED;
50
52
  USE_TOOL: USE_TOOL;
51
53
  MODEL_LOADED: MODEL_LOADED;
52
54
  UPDATE_SCENE: UPDATE_SCENE;
@@ -0,0 +1,5 @@
1
+ export default interface SET_GIZMO_SCALE_LINKED {
2
+ DESCRIPTION: "Sets the gizmo's unified scale mode.";
3
+ PAYLOAD: boolean;
4
+ RETURN: boolean;
5
+ }
@@ -79,6 +79,10 @@ export default class DIVEToolbox {
79
79
  this.selectTool.SetGizmoVisibility(active);
80
80
  }
81
81
 
82
+ public SetGizmoScaleLinked(linked: boolean): void {
83
+ this.selectTool.SetGizmoScaleLinked(linked);
84
+ }
85
+
82
86
  public onPointerMove(e: PointerEvent): void {
83
87
  this._activeTool?.onPointerMove(e);
84
88
  }
@@ -17,6 +17,7 @@ jest.mock('../select/SelectTool.ts', () => {
17
17
  this.onWheel = jest.fn();
18
18
  this.SetGizmoMode = jest.fn();
19
19
  this.SetGizmoVisibility = jest.fn();
20
+ this.SetGizmoScaleLinked = jest.fn();
20
21
  return this;
21
22
  }),
22
23
  };
@@ -134,4 +135,9 @@ describe('dive/toolbox/DIVEToolBox', () => {
134
135
  const toolBox = new DIVEToolbox({} as DIVEScene, mockController);
135
136
  expect(() => toolBox.SetGizmoVisibility(true)).not.toThrow();
136
137
  });
138
+
139
+ it('should set gizmo unified scale', () => {
140
+ const toolBox = new DIVEToolbox({} as DIVEScene, mockController);
141
+ expect(() => toolBox.SetGizmoScaleLinked(true)).not.toThrow();
142
+ });
137
143
  });
@@ -5,6 +5,12 @@ import { TransformControls } from 'three/examples/jsm/controls/TransformControls
5
5
  import { type DIVEMovable } from '../../interface/Movable.ts';
6
6
  import { implementsInterface } from '../../helper/isInterface/implementsInterface.ts';
7
7
  import { DIVEGizmo } from '../../gizmo/Gizmo.ts';
8
+ import { type Mesh, type MeshBasicMaterial } from 'three';
9
+ import {
10
+ AxesColorBlue,
11
+ AxesColorGreen,
12
+ AxesColorRed,
13
+ } from '../../constant/AxisHelperColors.ts';
8
14
 
9
15
  export const isTransformTool = (
10
16
  tool: DIVEBaseTool,
@@ -27,13 +33,17 @@ export interface DIVEObjectEventMap {
27
33
  export default class DIVETransformTool extends DIVEBaseTool {
28
34
  readonly isTransformTool: boolean = true;
29
35
 
36
+ private _scaleLinked: boolean;
37
+
30
38
  protected _gizmo: TransformControls | DIVEGizmo;
31
39
 
32
40
  constructor(scene: DIVEScene, controller: DIVEOrbitControls) {
33
41
  super(scene, controller);
34
42
  this.name = 'DIVETransformTool';
35
43
 
36
- this._gizmo = this.initGizmo();
44
+ this._scaleLinked = false;
45
+
46
+ this._gizmo = this.initGizmo() as TransformControls;
37
47
 
38
48
  this._scene.add(this._gizmo);
39
49
  }
@@ -63,6 +73,10 @@ export default class DIVETransformTool extends DIVEBaseTool {
63
73
  }
64
74
  }
65
75
 
76
+ public SetGizmoScaleLinked(linked: boolean): void {
77
+ this._scaleLinked = linked;
78
+ }
79
+
66
80
  // only used for optimizing pointer events with DIVEGizmo
67
81
  // public onPointerDown(e: PointerEvent): void {
68
82
  // super.onPointerDown(e);
@@ -88,6 +102,31 @@ export default class DIVETransformTool extends DIVEBaseTool {
88
102
  // g.debug = true;
89
103
  g.mode = 'translate';
90
104
 
105
+ g.traverse((child) => {
106
+ if (!('isMesh' in child)) return;
107
+
108
+ const material = (child as Mesh).material as MeshBasicMaterial;
109
+
110
+ if (child.name === 'X') {
111
+ material.color.set(AxesColorRed);
112
+ }
113
+ if (child.name === 'Y') {
114
+ material.color.set(AxesColorGreen);
115
+ }
116
+ if (child.name === 'Z') {
117
+ material.color.set(AxesColorBlue);
118
+ }
119
+ if (child.name === 'XY') {
120
+ material.color.set(AxesColorBlue);
121
+ }
122
+ if (child.name === 'YZ') {
123
+ material.color.set(AxesColorRed);
124
+ }
125
+ if (child.name === 'XZ') {
126
+ material.color.set(AxesColorGreen);
127
+ }
128
+ });
129
+
91
130
  // happens when pointerDown event is called on gizmo
92
131
  g.addEventListener('mouseDown', () => {
93
132
  this._controller.enabled = false;
@@ -104,6 +143,12 @@ export default class DIVETransformTool extends DIVEBaseTool {
104
143
  return;
105
144
  if (!g.object.onMove) return;
106
145
  g.object.onMove();
146
+
147
+ if (this._scaleLinked) {
148
+ const scale = g.object.scale;
149
+ const averageScale = (scale.x + scale.y + scale.z) / 3;
150
+ g.object.scale.set(averageScale, averageScale, averageScale);
151
+ }
107
152
  });
108
153
 
109
154
  // happens when pointerUp event is called on gizmo
@@ -6,6 +6,7 @@ import { DIVERenderer } from '../../../renderer/Renderer';
6
6
  import { type DIVEBaseTool } from '../../BaseTool';
7
7
  import { Tween } from '@tweenjs/tween.js';
8
8
  import { DIVEAnimationSystem } from '../../../animation/AnimationSystem';
9
+ import { type TransformControls } from 'three/examples/jsm/controls/TransformControls';
9
10
 
10
11
  jest.mock('../../../renderer/Renderer', () => {
11
12
  return jest.fn(function () {
@@ -129,4 +130,18 @@ describe('dive/toolbox/select/DIVETransformTool', () => {
129
130
 
130
131
  expect(() => transformTool.SetGizmoVisibility(false)).not.toThrow();
131
132
  });
133
+
134
+ it('should set gizmo unified scaling', () => {
135
+ expect(() => transformTool.SetGizmoScaleLinked(true)).not.toThrow();
136
+
137
+ // mock that gizmo is in scene
138
+ jest.spyOn(mockScene.children, 'includes').mockReturnValueOnce(true);
139
+
140
+ expect(() => transformTool.SetGizmoVisibility(false)).not.toThrow();
141
+ });
142
+
143
+ it('should scale unified if linked', () => {
144
+ transformTool.SetGizmoScaleLinked(true);
145
+ transformTool['initGizmo']();
146
+ });
132
147
  });