Browse Source

Merge pull request #4755 from TrevorDev/customMeshesOnGizmos

ability to customize meshes on gizmos
David Catuhe 7 năm trước cách đây
mục cha
commit
dd711d23ad

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

@@ -74,6 +74,7 @@
 - Added onPoseUpdatedFromDeviceObservable to webVRCamera to detect when the camera's pose has been updated ([TrevorDev](https://github.com/TrevorDev))
 - Added attachToBoxBehavior to attach UI to a bounding box ([TrevorDev](https://github.com/TrevorDev))
 - Gizmo manager's internal gizmos are now public ([TrevorDev](https://github.com/TrevorDev))
+- Ability to customize meshes on gizmos ([TrevorDev](https://github.com/TrevorDev))
 
 ### glTF Loader
 

+ 3 - 0
src/Gizmos/babylon.axisDragGizmo.ts

@@ -82,6 +82,9 @@ module BABYLON {
             })
 
             this._pointerObserver = gizmoLayer.utilityLayerScene.onPointerObservable.add((pointerInfo, eventState)=>{
+                if(this._customMeshSet){
+                    return;
+                }
                 if(pointerInfo.pickInfo && (this._rootMesh.getChildMeshes().indexOf(<Mesh>pointerInfo.pickInfo.pickedMesh) != -1)){
                     this._rootMesh.getChildMeshes().forEach((m)=>{
                         m.material = hoverMaterial;

+ 4 - 1
src/Gizmos/babylon.axisScaleGizmo.ts

@@ -90,6 +90,9 @@ module BABYLON {
             })
 
             this._pointerObserver = gizmoLayer.utilityLayerScene.onPointerObservable.add((pointerInfo, eventState)=>{
+                if(this._customMeshSet){
+                    return;
+                }
                 if(pointerInfo.pickInfo && (this._rootMesh.getChildMeshes().indexOf(<Mesh>pointerInfo.pickInfo.pickedMesh) != -1)){
                     this._rootMesh.getChildMeshes().forEach((m)=>{
                         m.material = hoverMaterial;
@@ -116,6 +119,6 @@ module BABYLON {
             this.gizmoLayer.utilityLayerScene.onPointerObservable.remove(this._pointerObserver);
             this.dragBehavior.detach();
             super.dispose();
-        } 
+        }
     }
 }

+ 7 - 0
src/Gizmos/babylon.boundingBoxGizmo.ts

@@ -426,5 +426,12 @@ module BABYLON {
             box.visibility = 0;
             return box;
         }
+        /**
+         * CustomMeshes are not supported by this gizmo
+         * @param mesh The mesh to replace the default mesh of the gizmo
+         */
+        public setCustomMesh(mesh:Mesh){
+            Tools.Error("Custom meshes are not supported on this gizmo");
+        }
     }
 }

+ 20 - 0
src/Gizmos/babylon.gizmo.ts

@@ -11,6 +11,10 @@ module BABYLON {
         private _scaleFactor = 3;
         private _tmpMatrix = new Matrix();
         /**
+         * If a custom mesh has been set (Default: false)
+         */
+        protected _customMeshSet = false;
+        /**
          * Mesh that the gizmo will be attached to. (eg. on a drag gizmo the mesh that will be dragged)
          * * When set, interactions will be enabled
          */
@@ -22,6 +26,22 @@ module BABYLON {
             this._rootMesh.setEnabled(value?true:false);
             this._attachedMeshChanged(value);
         }
+
+        /**
+         * Disposes and replaces the current meshes in the gizmo with the specified mesh
+         * @param mesh The mesh to replace the default mesh of the gizmo
+         */
+        public setCustomMesh(mesh:Mesh){
+            if(mesh.getScene() != this.gizmoLayer.utilityLayerScene){
+                throw "When setting a custom mesh on a gizmo, the custom meshes scene must be the same as the gizmos (eg. gizmo.gizmoLayer.utilityLayerScene)";
+            }
+            this._rootMesh.getChildMeshes().forEach((c)=>{
+                c.dispose();
+            })
+            mesh.parent = this._rootMesh;
+            this._customMeshSet = true;
+        }
+
         /**
          * If set the gizmo's rotation will be updated to match the attached mesh each frame (Default: true)
          */

+ 4 - 1
src/Gizmos/babylon.planeRotationGizmo.ts

@@ -133,6 +133,9 @@ module BABYLON {
             })
 
             this._pointerObserver = gizmoLayer.utilityLayerScene.onPointerObservable.add((pointerInfo, eventState)=>{
+                if(this._customMeshSet){
+                    return;
+                }
                 if(pointerInfo.pickInfo && (this._rootMesh.getChildMeshes().indexOf(<Mesh>pointerInfo.pickInfo.pickedMesh) != -1)){
                     this._rootMesh.getChildMeshes().forEach((m)=>{
                         m.material = hoverMaterial;
@@ -159,6 +162,6 @@ module BABYLON {
             this.gizmoLayer.utilityLayerScene.onPointerObservable.remove(this._pointerObserver);
             this.dragBehavior.detach();
             super.dispose();
-        } 
+        }
     }
 }

+ 8 - 0
src/Gizmos/babylon.positionGizmo.ts

@@ -54,5 +54,13 @@ module BABYLON {
             this.yGizmo.dispose();
             this.zGizmo.dispose();
         }
+
+        /**
+         * CustomMeshes are not supported by this gizmo
+         * @param mesh The mesh to replace the default mesh of the gizmo
+         */
+        public setCustomMesh(mesh:Mesh){
+            Tools.Error("Custom meshes are not supported on this gizmo, please set the custom meshes on the gizmos contained within this one (gizmo.xGizmo, gizmo.yGizmo, gizmo.zGizmo)");
+        }
     }
 }

+ 8 - 0
src/Gizmos/babylon.rotationGizmo.ts

@@ -54,5 +54,13 @@ module BABYLON {
             this.yGizmo.dispose();
             this.zGizmo.dispose();
         }
+
+        /**
+         * CustomMeshes are not supported by this gizmo
+         * @param mesh The mesh to replace the default mesh of the gizmo
+         */
+        public setCustomMesh(mesh:Mesh){
+            Tools.Error("Custom meshes are not supported on this gizmo, please set the custom meshes on the gizmos contained within this one (gizmo.xGizmo, gizmo.yGizmo, gizmo.zGizmo)");
+        }
     }
 }