瀏覽代碼

make behaviors and gizmos public

Trevor Baron 7 年之前
父節點
當前提交
e442056822

+ 11 - 8
src/Gizmos/babylon.axisDragGizmo.ts

@@ -3,7 +3,10 @@ module BABYLON {
      * Single axis drag gizmo
      * Single axis drag gizmo
      */
      */
     export class AxisDragGizmo extends Gizmo {
     export class AxisDragGizmo extends Gizmo {
-        private _dragBehavior:PointerDragBehavior;
+        /**
+         * Drag behavior responsible for the gizmos dragging interactions
+         */
+        public dragBehavior:PointerDragBehavior;
         private _pointerObserver:Nullable<Observer<PointerInfo>> = null;
         private _pointerObserver:Nullable<Observer<PointerInfo>> = null;
         /**
         /**
          * Drag distance in babylon units that the gizmo will snap to when dragged (Default: 0)
          * Drag distance in babylon units that the gizmo will snap to when dragged (Default: 0)
@@ -55,10 +58,10 @@ module BABYLON {
             var tmpVector = new Vector3();
             var tmpVector = new Vector3();
             var tmpSnapEvent = {snapDistance: 0};
             var tmpSnapEvent = {snapDistance: 0};
             // Add drag behavior to handle events when the gizmo is dragged
             // Add drag behavior to handle events when the gizmo is dragged
-            this._dragBehavior = new PointerDragBehavior({dragAxis: dragAxis});
-            this._dragBehavior.moveAttached = false;
-            this._rootMesh.addBehavior(this._dragBehavior);
-            this._dragBehavior.onDragObservable.add((event)=>{
+            this.dragBehavior = new PointerDragBehavior({dragAxis: dragAxis});
+            this.dragBehavior.moveAttached = false;
+            this._rootMesh.addBehavior(this.dragBehavior);
+            this.dragBehavior.onDragObservable.add((event)=>{
                 if(this.attachedMesh){
                 if(this.attachedMesh){
                     // Snapping logic
                     // Snapping logic
                     if(this.snapDistance == 0){
                     if(this.snapDistance == 0){
@@ -91,8 +94,8 @@ module BABYLON {
             });
             });
         }
         }
         protected _attachedMeshChanged(value:Nullable<AbstractMesh>){
         protected _attachedMeshChanged(value:Nullable<AbstractMesh>){
-            if(this._dragBehavior){
-                this._dragBehavior.enabled = value?true:false;
+            if(this.dragBehavior){
+                this.dragBehavior.enabled = value?true:false;
             }
             }
         }
         }
         /**
         /**
@@ -101,7 +104,7 @@ module BABYLON {
         public dispose(){
         public dispose(){
             this.onSnapObservable.clear();
             this.onSnapObservable.clear();
             this.gizmoLayer.utilityLayerScene.onPointerObservable.remove(this._pointerObserver);
             this.gizmoLayer.utilityLayerScene.onPointerObservable.remove(this._pointerObserver);
-            this._dragBehavior.detach();
+            this.dragBehavior.detach();
             super.dispose();
             super.dispose();
         } 
         } 
     }
     }

+ 11 - 8
src/Gizmos/babylon.axisScaleGizmo.ts

@@ -3,7 +3,10 @@ module BABYLON {
      * Single axis scale gizmo
      * Single axis scale gizmo
      */
      */
     export class AxisScaleGizmo extends Gizmo {
     export class AxisScaleGizmo extends Gizmo {
-        private _dragBehavior:PointerDragBehavior;
+        /**
+         * Drag behavior responsible for the gizmos dragging interactions
+         */
+        public dragBehavior:PointerDragBehavior;
         private _pointerObserver:Nullable<Observer<PointerInfo>> = null;
         private _pointerObserver:Nullable<Observer<PointerInfo>> = null;
         /**
         /**
          * Scale distance in babylon units that the gizmo will snap to when dragged (Default: 0)
          * Scale distance in babylon units that the gizmo will snap to when dragged (Default: 0)
@@ -51,14 +54,14 @@ module BABYLON {
             this._rootMesh.addChild(arrow);
             this._rootMesh.addChild(arrow);
 
 
             // Add drag behavior to handle events when the gizmo is dragged
             // Add drag behavior to handle events when the gizmo is dragged
-            this._dragBehavior = new PointerDragBehavior({dragAxis: dragAxis});
-            this._dragBehavior.moveAttached = false;
-            this._rootMesh.addBehavior(this._dragBehavior);
+            this.dragBehavior = new PointerDragBehavior({dragAxis: dragAxis});
+            this.dragBehavior.moveAttached = false;
+            this._rootMesh.addBehavior(this.dragBehavior);
 
 
             var currentSnapDragDistance = 0;
             var currentSnapDragDistance = 0;
             var tmpVector = new Vector3();
             var tmpVector = new Vector3();
             var tmpSnapEvent = {snapDistance: 0};
             var tmpSnapEvent = {snapDistance: 0};
-            this._dragBehavior.onDragObservable.add((event)=>{                
+            this.dragBehavior.onDragObservable.add((event)=>{                
                 if(this.attachedMesh){
                 if(this.attachedMesh){
                     // Snapping logic
                     // Snapping logic
                     var snapped = false;
                     var snapped = false;
@@ -114,8 +117,8 @@ module BABYLON {
         }
         }
         
         
         protected _attachedMeshChanged(value:Nullable<AbstractMesh>){
         protected _attachedMeshChanged(value:Nullable<AbstractMesh>){
-            if(this._dragBehavior){
-                this._dragBehavior.enabled = value ? true : false;
+            if(this.dragBehavior){
+                this.dragBehavior.enabled = value ? true : false;
             }
             }
         }
         }
         
         
@@ -125,7 +128,7 @@ module BABYLON {
         public dispose(){
         public dispose(){
             this.onSnapObservable.clear();
             this.onSnapObservable.clear();
             this.gizmoLayer.utilityLayerScene.onPointerObservable.remove(this._pointerObserver);
             this.gizmoLayer.utilityLayerScene.onPointerObservable.remove(this._pointerObserver);
-            this._dragBehavior.detach();
+            this.dragBehavior.detach();
             super.dispose();
             super.dispose();
         } 
         } 
     }
     }

+ 12 - 9
src/Gizmos/babylon.planeRotationGizmo.ts

@@ -3,7 +3,10 @@ module BABYLON {
      * Single plane rotation gizmo
      * Single plane rotation gizmo
      */
      */
     export class PlaneRotationGizmo extends Gizmo {
     export class PlaneRotationGizmo extends Gizmo {
-        private _dragBehavior:PointerDragBehavior;
+        /**
+         * Drag behavior responsible for the gizmos dragging interactions
+         */
+        public dragBehavior:PointerDragBehavior;
         private _pointerObserver:Nullable<Observer<PointerInfo>> = null;
         private _pointerObserver:Nullable<Observer<PointerInfo>> = null;
         
         
         /**
         /**
@@ -47,13 +50,13 @@ module BABYLON {
             
             
             this._rootMesh.addChild(parentMesh);
             this._rootMesh.addChild(parentMesh);
             // Add drag behavior to handle events when the gizmo is dragged
             // Add drag behavior to handle events when the gizmo is dragged
-            this._dragBehavior = new PointerDragBehavior({dragPlaneNormal: planeNormal});
-            this._dragBehavior.moveAttached = false;
-            this._rootMesh.addBehavior(this._dragBehavior);
+            this.dragBehavior = new PointerDragBehavior({dragPlaneNormal: planeNormal});
+            this.dragBehavior.moveAttached = false;
+            this._rootMesh.addBehavior(this.dragBehavior);
 
 
             var lastDragPosition:Nullable<Vector3> = null;
             var lastDragPosition:Nullable<Vector3> = null;
 
 
-            this._dragBehavior.onDragStartObservable.add((e)=>{
+            this.dragBehavior.onDragStartObservable.add((e)=>{
                 if(this.attachedMesh){
                 if(this.attachedMesh){
                     lastDragPosition = e.dragPlanePoint;
                     lastDragPosition = e.dragPlanePoint;
                 }
                 }
@@ -65,7 +68,7 @@ module BABYLON {
 
 
             var tmpSnapEvent = {snapDistance: 0};
             var tmpSnapEvent = {snapDistance: 0};
             var currentSnapDragDistance = 0;
             var currentSnapDragDistance = 0;
-            this._dragBehavior.onDragObservable.add((event)=>{
+            this.dragBehavior.onDragObservable.add((event)=>{
                 if(this.attachedMesh && lastDragPosition){
                 if(this.attachedMesh && lastDragPosition){
                     if(!this.attachedMesh.rotationQuaternion){
                     if(!this.attachedMesh.rotationQuaternion){
                         this.attachedMesh.rotationQuaternion = new BABYLON.Quaternion();
                         this.attachedMesh.rotationQuaternion = new BABYLON.Quaternion();
@@ -135,8 +138,8 @@ module BABYLON {
         }
         }
 
 
         protected _attachedMeshChanged(value:Nullable<AbstractMesh>){
         protected _attachedMeshChanged(value:Nullable<AbstractMesh>){
-            if(this._dragBehavior){
-                this._dragBehavior.enabled = value ? true : false;
+            if(this.dragBehavior){
+                this.dragBehavior.enabled = value ? true : false;
             }
             }
         }
         }
 
 
@@ -146,7 +149,7 @@ module BABYLON {
         public dispose(){
         public dispose(){
             this.onSnapObservable.clear();
             this.onSnapObservable.clear();
             this.gizmoLayer.utilityLayerScene.onPointerObservable.remove(this._pointerObserver);
             this.gizmoLayer.utilityLayerScene.onPointerObservable.remove(this._pointerObserver);
-            this._dragBehavior.detach();
+            this.dragBehavior.detach();
             super.dispose();
             super.dispose();
         } 
         } 
     }
     }

+ 27 - 18
src/Gizmos/babylon.positionGizmo.ts

@@ -3,15 +3,24 @@ module BABYLON {
      * Gizmo that enables dragging a mesh along 3 axis
      * Gizmo that enables dragging a mesh along 3 axis
      */
      */
     export class PositionGizmo extends Gizmo {
     export class PositionGizmo extends Gizmo {
-        private _xDrag:AxisDragGizmo;
-        private _yDrag:AxisDragGizmo;
-        private _zDrag:AxisDragGizmo;
+        /**
+         * Internal gizmo used for interactions on the x axis
+         */
+        public xGizmo:AxisDragGizmo;
+        /**
+         * Internal gizmo used for interactions on the y axis
+         */
+        public yGizmo:AxisDragGizmo;
+        /**
+         * Internal gizmo used for interactions on the z axis
+         */
+        public zGizmo:AxisDragGizmo;
 
 
         public set attachedMesh(mesh:Nullable<AbstractMesh>){
         public set attachedMesh(mesh:Nullable<AbstractMesh>){
-            if(this._xDrag){
-                this._xDrag.attachedMesh = mesh;
-                this._yDrag.attachedMesh = mesh;
-                this._zDrag.attachedMesh = mesh;
+            if(this.xGizmo){
+                this.xGizmo.attachedMesh = mesh;
+                this.yGizmo.attachedMesh = mesh;
+                this.zGizmo.attachedMesh = mesh;
             }
             }
         }
         }
     /**
     /**
@@ -20,30 +29,30 @@ module BABYLON {
          */
          */
         constructor(gizmoLayer:UtilityLayerRenderer=UtilityLayerRenderer.DefaultUtilityLayer){
         constructor(gizmoLayer:UtilityLayerRenderer=UtilityLayerRenderer.DefaultUtilityLayer){
             super(gizmoLayer);
             super(gizmoLayer);
-            this._xDrag = new AxisDragGizmo(new Vector3(1,0,0), BABYLON.Color3.Green().scale(0.5), gizmoLayer);
-            this._yDrag = new AxisDragGizmo(new Vector3(0,1,0), BABYLON.Color3.Red().scale(0.5), gizmoLayer);
-            this._zDrag = new AxisDragGizmo(new Vector3(0,0,1), BABYLON.Color3.Blue().scale(0.5), gizmoLayer);
+            this.xGizmo = new AxisDragGizmo(new Vector3(1,0,0), BABYLON.Color3.Green().scale(0.5), gizmoLayer);
+            this.yGizmo = new AxisDragGizmo(new Vector3(0,1,0), BABYLON.Color3.Red().scale(0.5), gizmoLayer);
+            this.zGizmo = new AxisDragGizmo(new Vector3(0,0,1), BABYLON.Color3.Blue().scale(0.5), gizmoLayer);
             this.attachedMesh = null;
             this.attachedMesh = null;
         }
         }
 
 
         public set updateGizmoRotationToMatchAttachedMesh(value:boolean){
         public set updateGizmoRotationToMatchAttachedMesh(value:boolean){
-            if(this._xDrag){
-                this._xDrag.updateGizmoRotationToMatchAttachedMesh = value;
-                this._yDrag.updateGizmoRotationToMatchAttachedMesh = value;
-                this._zDrag.updateGizmoRotationToMatchAttachedMesh = value;
+            if(this.xGizmo){
+                this.xGizmo.updateGizmoRotationToMatchAttachedMesh = value;
+                this.yGizmo.updateGizmoRotationToMatchAttachedMesh = value;
+                this.zGizmo.updateGizmoRotationToMatchAttachedMesh = value;
             }
             }
         }
         }
         public get updateGizmoRotationToMatchAttachedMesh(){
         public get updateGizmoRotationToMatchAttachedMesh(){
-            return this._xDrag.updateGizmoRotationToMatchAttachedMesh;
+            return this.xGizmo.updateGizmoRotationToMatchAttachedMesh;
         }
         }
         
         
         /**
         /**
          * Disposes of the gizmo
          * Disposes of the gizmo
          */
          */
         public dispose(){
         public dispose(){
-            this._xDrag.dispose();
-            this._yDrag.dispose();
-            this._zDrag.dispose();
+            this.xGizmo.dispose();
+            this.yGizmo.dispose();
+            this.zGizmo.dispose();
         }
         }
     }
     }
 }
 }

+ 27 - 18
src/Gizmos/babylon.rotationGizmo.ts

@@ -3,15 +3,24 @@ module BABYLON {
      * Gizmo that enables rotating a mesh along 3 axis
      * Gizmo that enables rotating a mesh along 3 axis
      */
      */
     export class RotationGizmo extends Gizmo {
     export class RotationGizmo extends Gizmo {
-        private _xDrag:PlaneRotationGizmo;
-        private _yDrag:PlaneRotationGizmo;
-        private _zDrag:PlaneRotationGizmo;
+        /**
+         * Internal gizmo used for interactions on the x axis
+         */
+        public xGizmo:PlaneRotationGizmo;
+        /**
+         * Internal gizmo used for interactions on the y axis
+         */
+        public yGizmo:PlaneRotationGizmo;
+        /**
+         * Internal gizmo used for interactions on the z axis
+         */
+        public zGizmo:PlaneRotationGizmo;
 
 
         public set attachedMesh(mesh:Nullable<AbstractMesh>){
         public set attachedMesh(mesh:Nullable<AbstractMesh>){
-            if(this._xDrag){
-                this._xDrag.attachedMesh = mesh;
-                this._yDrag.attachedMesh = mesh;
-                this._zDrag.attachedMesh = mesh;
+            if(this.xGizmo){
+                this.xGizmo.attachedMesh = mesh;
+                this.yGizmo.attachedMesh = mesh;
+                this.zGizmo.attachedMesh = mesh;
             }
             }
         }
         }
         /**
         /**
@@ -20,30 +29,30 @@ module BABYLON {
          */
          */
         constructor(gizmoLayer:UtilityLayerRenderer=UtilityLayerRenderer.DefaultUtilityLayer){
         constructor(gizmoLayer:UtilityLayerRenderer=UtilityLayerRenderer.DefaultUtilityLayer){
             super(gizmoLayer);
             super(gizmoLayer);
-            this._xDrag = new PlaneRotationGizmo(new Vector3(1,0,0), BABYLON.Color3.Green().scale(0.5), gizmoLayer);
-            this._yDrag = new PlaneRotationGizmo(new Vector3(0,1,0), BABYLON.Color3.Red().scale(0.5), gizmoLayer);
-            this._zDrag = new PlaneRotationGizmo(new Vector3(0,0,1), BABYLON.Color3.Blue().scale(0.5), gizmoLayer);
+            this.xGizmo = new PlaneRotationGizmo(new Vector3(1,0,0), BABYLON.Color3.Green().scale(0.5), gizmoLayer);
+            this.yGizmo = new PlaneRotationGizmo(new Vector3(0,1,0), BABYLON.Color3.Red().scale(0.5), gizmoLayer);
+            this.zGizmo = new PlaneRotationGizmo(new Vector3(0,0,1), BABYLON.Color3.Blue().scale(0.5), gizmoLayer);
             this.attachedMesh = null;
             this.attachedMesh = null;
         }
         }
 
 
         public set updateGizmoRotationToMatchAttachedMesh(value:boolean){
         public set updateGizmoRotationToMatchAttachedMesh(value:boolean){
-            if(this._xDrag){
-                this._xDrag.updateGizmoRotationToMatchAttachedMesh = value;
-                this._yDrag.updateGizmoRotationToMatchAttachedMesh = value;
-                this._zDrag.updateGizmoRotationToMatchAttachedMesh = value;
+            if(this.xGizmo){
+                this.xGizmo.updateGizmoRotationToMatchAttachedMesh = value;
+                this.yGizmo.updateGizmoRotationToMatchAttachedMesh = value;
+                this.zGizmo.updateGizmoRotationToMatchAttachedMesh = value;
             }
             }
         }
         }
         public get updateGizmoRotationToMatchAttachedMesh(){
         public get updateGizmoRotationToMatchAttachedMesh(){
-            return this._xDrag.updateGizmoRotationToMatchAttachedMesh;
+            return this.xGizmo.updateGizmoRotationToMatchAttachedMesh;
         }
         }
 
 
         /**
         /**
          * Disposes of the gizmo
          * Disposes of the gizmo
          */
          */
         public dispose(){
         public dispose(){
-            this._xDrag.dispose();
-            this._yDrag.dispose();
-            this._zDrag.dispose();
+            this.xGizmo.dispose();
+            this.yGizmo.dispose();
+            this.zGizmo.dispose();
         }
         }
     }
     }
 }
 }

+ 27 - 18
src/Gizmos/babylon.scaleGizmo.ts

@@ -3,15 +3,24 @@ module BABYLON {
      * Gizmo that enables scaling a mesh along 3 axis
      * Gizmo that enables scaling a mesh along 3 axis
      */
      */
     export class ScaleGizmo extends Gizmo {
     export class ScaleGizmo extends Gizmo {
-        private _xDrag:AxisScaleGizmo;
-        private _yDrag:AxisScaleGizmo;
-        private _zDrag:AxisScaleGizmo;
+        /**
+         * Internal gizmo used for interactions on the x axis
+         */
+        public xGizmo:AxisScaleGizmo;
+        /**
+         * Internal gizmo used for interactions on the y axis
+         */
+        public yGizmo:AxisScaleGizmo;
+        /**
+         * Internal gizmo used for interactions on the z axis
+         */
+        public zGizmo:AxisScaleGizmo;
 
 
         public set attachedMesh(mesh:Nullable<AbstractMesh>){
         public set attachedMesh(mesh:Nullable<AbstractMesh>){
-            if(this._xDrag){
-                this._xDrag.attachedMesh = mesh;
-                this._yDrag.attachedMesh = mesh;
-                this._zDrag.attachedMesh = mesh;
+            if(this.xGizmo){
+                this.xGizmo.attachedMesh = mesh;
+                this.yGizmo.attachedMesh = mesh;
+                this.zGizmo.attachedMesh = mesh;
             }
             }
         }
         }
         /**
         /**
@@ -20,30 +29,30 @@ module BABYLON {
          */
          */
         constructor(gizmoLayer:UtilityLayerRenderer=UtilityLayerRenderer.DefaultUtilityLayer){
         constructor(gizmoLayer:UtilityLayerRenderer=UtilityLayerRenderer.DefaultUtilityLayer){
             super(gizmoLayer);
             super(gizmoLayer);
-            this._xDrag = new AxisScaleGizmo(new Vector3(1,0,0), BABYLON.Color3.Green().scale(0.5), gizmoLayer);
-            this._yDrag = new AxisScaleGizmo(new Vector3(0,1,0), BABYLON.Color3.Red().scale(0.5), gizmoLayer);
-            this._zDrag = new AxisScaleGizmo(new Vector3(0,0,1), BABYLON.Color3.Blue().scale(0.5), gizmoLayer);
+            this.xGizmo = new AxisScaleGizmo(new Vector3(1,0,0), BABYLON.Color3.Green().scale(0.5), gizmoLayer);
+            this.yGizmo = new AxisScaleGizmo(new Vector3(0,1,0), BABYLON.Color3.Red().scale(0.5), gizmoLayer);
+            this.zGizmo = new AxisScaleGizmo(new Vector3(0,0,1), BABYLON.Color3.Blue().scale(0.5), gizmoLayer);
             this.attachedMesh = null;
             this.attachedMesh = null;
         }
         }
 
 
         public set updateGizmoRotationToMatchAttachedMesh(value:boolean){
         public set updateGizmoRotationToMatchAttachedMesh(value:boolean){
-            if(this._xDrag){
-                this._xDrag.updateGizmoRotationToMatchAttachedMesh = value;
-                this._yDrag.updateGizmoRotationToMatchAttachedMesh = value;
-                this._zDrag.updateGizmoRotationToMatchAttachedMesh = value;
+            if(this.xGizmo){
+                this.xGizmo.updateGizmoRotationToMatchAttachedMesh = value;
+                this.yGizmo.updateGizmoRotationToMatchAttachedMesh = value;
+                this.zGizmo.updateGizmoRotationToMatchAttachedMesh = value;
             }
             }
         }
         }
         public get updateGizmoRotationToMatchAttachedMesh(){
         public get updateGizmoRotationToMatchAttachedMesh(){
-            return this._xDrag.updateGizmoRotationToMatchAttachedMesh;
+            return this.xGizmo.updateGizmoRotationToMatchAttachedMesh;
         }
         }
 
 
         /**
         /**
          * Disposes of the gizmo
          * Disposes of the gizmo
          */
          */
         public dispose(){
         public dispose(){
-            this._xDrag.dispose();
-            this._yDrag.dispose();
-            this._zDrag.dispose();
+            this.xGizmo.dispose();
+            this.yGizmo.dispose();
+            this.zGizmo.dispose();
         }
         }
     }
     }
 }
 }