Explorar el Código

Gizmo Mesh Upgrade - Support Usecase of single axis instantiation

Dave Gould hace 4 años
padre
commit
032cb6c1c3

+ 19 - 0
src/Gizmos/axisDragGizmo.ts

@@ -13,6 +13,7 @@ import { StandardMaterial } from "../Materials/standardMaterial";
 import { Scene } from "../scene";
 import { PositionGizmo } from "./positionGizmo";
 import { Color3 } from '../Maths/math.color';
+import { LinesMesh } from 'Meshes/linesMesh';
 /**
  * Single axis drag gizmo
  */
@@ -153,6 +154,24 @@ export class AxisDragGizmo extends Gizmo {
             }
         });
 
+        this._pointerObserver = gizmoLayer.utilityLayerScene.onPointerObservable.add((pointerInfo) => {
+            if (this._customMeshSet) {
+                return;
+            }
+            this._isHovered = !!(pointerInfo.pickInfo && (this._rootMesh.getChildMeshes().indexOf(<Mesh>pointerInfo.pickInfo.pickedMesh) != -1));
+            if (!this._parent) {
+                // Enable Hover Events for AxisViewer use-case
+                var material = this._isHovered ? this._hoverMaterial : this._coloredMaterial;
+                this._rootMesh.getChildMeshes().forEach((m) => {
+                    m.material = material;
+                    if ((<LinesMesh>m).color) {
+                        (<LinesMesh>m).color = material.diffuseColor;
+                    }
+                });
+            }
+        });
+
+
         var light = gizmoLayer._getSharedGizmoLight();
         light.includedOnlyMeshes = light.includedOnlyMeshes.concat(this._rootMesh.getChildMeshes(false));
 

+ 17 - 0
src/Gizmos/axisScaleGizmo.ts

@@ -174,6 +174,23 @@ export class AxisScaleGizmo extends Gizmo {
         };
         this._parent?.addToAxisCache((this._gizmoMesh as Mesh), cache);
 
+        this._pointerObserver = gizmoLayer.utilityLayerScene.onPointerObservable.add((pointerInfo) => {
+            if (this._customMeshSet) {
+                return;
+            }
+            this._isHovered = !!(pointerInfo.pickInfo && (this._rootMesh.getChildMeshes().indexOf(<Mesh>pointerInfo.pickInfo.pickedMesh) != -1));
+            if (!this._parent) {
+                // Enable Hover Events for AxisViewer use-case
+                var material = this._isHovered ? this._hoverMaterial : this._coloredMaterial;
+                this._rootMesh.getChildMeshes().forEach((m) => {
+                    m.material = material;
+                    if ((<LinesMesh>m).color) {
+                        (<LinesMesh>m).color = material.diffuseColor;
+                    }
+                });
+            }
+        });
+
         var light = gizmoLayer._getSharedGizmoLight();
         light.includedOnlyMeshes = light.includedOnlyMeshes.concat(this._rootMesh.getChildMeshes());
     }

+ 1 - 11
src/Gizmos/planeDragGizmo.ts

@@ -50,17 +50,7 @@ export class PlaneDragGizmo extends Gizmo {
         dragPlane.parent = plane;
         return plane;
     }
-
-    /** @hidden */
-    public static _CreateArrowInstance(scene: Scene, arrow: TransformNode): TransformNode {
-        const instance = new TransformNode("arrow", scene);
-        for (const mesh of arrow.getChildMeshes()) {
-            const childInstance = (mesh as Mesh).createInstance(mesh.name);
-            childInstance.parent = instance;
-        }
-        return instance;
-    }
-
+    
     /**
      * Creates a PlaneDragGizmo
      * @param gizmoLayer The utility layer the gizmo will be added to

+ 17 - 13
src/Gizmos/planeRotationGizmo.ts

@@ -12,6 +12,7 @@ import { UtilityLayerRenderer } from "../Rendering/utilityLayerRenderer";
 import { StandardMaterial } from "../Materials/standardMaterial";
 import { RotationGizmo } from "./rotationGizmo";
 import { Angle } from '../Maths/math.path';
+import { LinesMesh } from 'Meshes/linesMesh';
 
 /**
  * Single plane rotation gizmo
@@ -221,19 +222,22 @@ export class PlaneRotationGizmo extends Gizmo {
             }
         });
 
-        // this._pointerObserver = gizmoLayer.utilityLayerScene.onPointerObservable.add((pointerInfo) => {
-        //     if (this._customMeshSet) {
-        //         return;
-        //     }
-        //     this._isHovered = !!(pointerInfo.pickInfo && (this._rootMesh.getChildMeshes().indexOf(<Mesh>pointerInfo.pickInfo.pickedMesh) != -1));
-        //     var material = this._isHovered ? hoverMaterial : coloredMaterial;
-        //     this._rootMesh.getChildMeshes().forEach((m) => {
-        //         m.material = material;
-        //         if ((<LinesMesh>m).color) {
-        //             (<LinesMesh>m).color = material.diffuseColor;
-        //         }
-        //     });
-        // });
+        this._pointerObserver = gizmoLayer.utilityLayerScene.onPointerObservable.add((pointerInfo) => {
+            if (this._customMeshSet) {
+                return;
+            }
+            this._isHovered = !!(pointerInfo.pickInfo && (this._rootMesh.getChildMeshes().indexOf(<Mesh>pointerInfo.pickInfo.pickedMesh) != -1));
+            if (!this._parent) {
+                // Enable Hover Events for AxisViewer use-case
+                var material = this._isHovered ? this._hoverMaterial : this._coloredMaterial;
+                this._rootMesh.getChildMeshes().forEach((m) => {
+                    m.material = material;
+                    if ((<LinesMesh>m).color) {
+                        (<LinesMesh>m).color = material.diffuseColor;
+                    }
+                });
+            }
+        });
 
         var light = gizmoLayer._getSharedGizmoLight();
         light.includedOnlyMeshes = light.includedOnlyMeshes.concat(this._rootMesh.getChildMeshes(false));