Browse Source

Merge pull request #7119 from CedricGuillemet/sensibilityAxisScaleGizmo

sensibility factor for axisScaleGizmo
David Catuhe 5 năm trước cách đây
mục cha
commit
d60acefa3d

+ 1 - 0
dist/preview release/what's new.md

@@ -23,6 +23,7 @@
 - Added support for dual shock gamepads ([Deltakosh](https://github.com/deltakosh/))
 - Support Vive Focus 3Dof controller ([TrevorDev](https://github.com/TrevorDev))
 - Planar positioning support for GizmoManager ([Balupg](https://github.com/balupg))
+- ScaleGizmo and AxisScaleGizmo sensitivity factor ([CedricGuillemet](https://github.com/CedricGuillemet))
 - Individual gizmos can now be enabled/disabled ([Balupg](https://github.com/balupg))
 - Unify preparation of instance attributes. Added `MaterialHelper.PushAttributesForInstances` ([MarkusBillharz](https://github.com/MarkusBillharz))
 - Added support for PBR [irradiance map](https://doc.babylonjs.com/how_to/physically_based_rendering_master#irradiance-map)

+ 5 - 1
src/Gizmos/axisScaleGizmo.ts

@@ -37,6 +37,10 @@ export class AxisScaleGizmo extends Gizmo {
      * If the scaling operation should be done on all axis (default: false)
      */
     public uniformScaling = false;
+    /**
+     * Custom sensitivity value for the drag strength
+     */
+    public sensitivity = 1;
 
     private _isEnabled: boolean = true;
     private _parent: Nullable<ScaleGizmo> = null;
@@ -92,7 +96,7 @@ export class AxisScaleGizmo extends Gizmo {
         this.dragBehavior.onDragObservable.add((event) => {
             if (this.attachedMesh) {
                 // Drag strength is modified by the scale of the gizmo (eg. for small objects like boombox the strength will be increased to match the behavior of larger objects)
-                var dragStrength = event.dragDistance * ((this.scaleRatio * 3) / this._rootMesh.scaling.length());
+                var dragStrength = this.sensitivity * event.dragDistance * ((this.scaleRatio * 3) / this._rootMesh.scaling.length());
 
                 // Snapping logic
                 var snapped = false;

+ 16 - 0
src/Gizmos/scaleGizmo.ts

@@ -37,6 +37,7 @@ export class ScaleGizmo extends Gizmo {
     private _scaleRatio: number;
     private _uniformScalingMesh: Mesh;
     private _octahedron: Mesh;
+    private _sensitivity: number = 1;
 
     /** Fires an event when any of it's sub gizmos are dragged */
     public onDragStartObservable = new Observable();
@@ -142,6 +143,21 @@ export class ScaleGizmo extends Gizmo {
     }
 
     /**
+     * Sensitivity factor for dragging (Default: 1)
+     */
+    public set sensitivity(value: number) {
+        this._sensitivity = value;
+        [this.xGizmo, this.yGizmo, this.zGizmo, this.uniformScaleGizmo].forEach((gizmo) => {
+            if (gizmo) {
+                gizmo.sensitivity = value;
+            }
+        });
+    }
+    public get sensitivity() {
+        return this._sensitivity;
+    }
+
+    /**
      * Disposes of the gizmo
      */
     public dispose() {