瀏覽代碼

Gizmo Mesh Upgrade - Fix bug zooming out causes gizmo mesh to go haywire

Dave Gould 4 年之前
父節點
當前提交
248af68847
共有 3 個文件被更改,包括 9 次插入9 次删除
  1. 9 5
      src/Gizmos/axisScaleGizmo.ts
  2. 0 2
      src/Gizmos/rotationGizmo.ts
  3. 0 2
      src/Gizmos/scaleGizmo.ts

+ 9 - 5
src/Gizmos/axisScaleGizmo.ts

@@ -88,12 +88,16 @@ export class AxisScaleGizmo extends Gizmo {
         const lineScale = arrowTail.scaling.clone();
 
         const increaseGizmoMesh = (dragDistance: number) => {
-            const scalar = 0.15; // This will increase the rate of gizmo size on drag
+            const dragStrength = this.sensitivity * dragDistance * ((this.scaleRatio * 3) / this._rootMesh.scaling.length());
+            const scalar = 1; // This will increase the rate of gizmo size on drag
             const originalScale = arrowTail.scaling.y;
-            const newScale = originalScale + dragDistance * scalar;
-            arrowMesh.position.z += ((newScale - originalScale) / 4);
-            arrowTail.scaling.y = newScale;
-            arrowTail.position.z = arrowMesh.position.z / 2;
+            const newScale = originalScale + dragStrength * scalar;
+            const newMeshPosition = arrowMesh.position.z + ((newScale - originalScale) / 4);
+            if (newMeshPosition >= 0) {
+                arrowMesh.position.z = newMeshPosition;
+                arrowTail.scaling.y = newScale;
+                arrowTail.position.z = arrowMesh.position.z / 2;
+            }
         };
 
         const resetGizmoMesh = () => {

+ 0 - 2
src/Gizmos/rotationGizmo.ts

@@ -176,7 +176,6 @@ export class RotationGizmo extends Gizmo {
         const pointerObserver = this.gizmoLayer.utilityLayerScene.onPointerObservable.add((pointerInfo) => {
             if (pointerInfo.pickInfo) {
                 // On Hover Logic
-                console.log(pointerInfo.pickInfo.pickedMesh?.id);
                 if (pointerInfo.type === PointerEventTypes.POINTERMOVE) {
                     if (this.dragging) { return; }
                     this.gizmoAxisCache.forEach((statusMap, parentMesh) => {
@@ -200,7 +199,6 @@ export class RotationGizmo extends Gizmo {
                         this.dragging = true;
                         const statusMap = this.gizmoAxisCache.get(pointerInfo.pickInfo.pickedMesh?.parent as Mesh);
                         statusMap!.active = true;
-                        console.log(this.gizmoAxisCache);
                         this.gizmoAxisCache.forEach((statusMap, parentMesh) => {
                             const isHovered = pointerInfo.pickInfo && (parentMesh.getChildMeshes().indexOf((pointerInfo.pickInfo.pickedMesh as Mesh)) != -1);
                             const material = isHovered || statusMap.active ? statusMap.hoverMaterial : statusMap.disableMaterial;

+ 0 - 2
src/Gizmos/scaleGizmo.ts

@@ -252,7 +252,6 @@ export class ScaleGizmo extends Gizmo {
         const pointerObserver = this.gizmoLayer.utilityLayerScene.onPointerObservable.add((pointerInfo) => {
             if (pointerInfo.pickInfo) {
                 // On Hover Logic
-                console.log(pointerInfo.pickInfo.pickedMesh?.id);
                 if (pointerInfo.type === PointerEventTypes.POINTERMOVE) {
                     if (this.dragging) { return; }
                     this.gizmoAxisCache.forEach((statusMap, parentMesh) => {
@@ -276,7 +275,6 @@ export class ScaleGizmo extends Gizmo {
                         this.dragging = true;
                         const statusMap = this.gizmoAxisCache.get(pointerInfo.pickInfo.pickedMesh?.parent as Mesh);
                         statusMap!.active = true;
-                        console.log(this.gizmoAxisCache);
                         this.gizmoAxisCache.forEach((statusMap, parentMesh) => {
                             const isHovered = pointerInfo.pickInfo && (parentMesh.getChildMeshes().indexOf((pointerInfo.pickInfo.pickedMesh as Mesh)) != -1);
                             const material = isHovered || statusMap.active ? statusMap.hoverMaterial : statusMap.disableMaterial;