babylon.positionGizmo.ts 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. module BABYLON {
  2. /**
  3. * Gizmo that enables dragging a mesh along 3 axis
  4. */
  5. export class PositionGizmo extends Gizmo {
  6. /**
  7. * Internal gizmo used for interactions on the x axis
  8. */
  9. public xGizmo:AxisDragGizmo;
  10. /**
  11. * Internal gizmo used for interactions on the y axis
  12. */
  13. public yGizmo:AxisDragGizmo;
  14. /**
  15. * Internal gizmo used for interactions on the z axis
  16. */
  17. public zGizmo:AxisDragGizmo;
  18. public set attachedMesh(mesh:Nullable<AbstractMesh>){
  19. if(this.xGizmo){
  20. this.xGizmo.attachedMesh = mesh;
  21. this.yGizmo.attachedMesh = mesh;
  22. this.zGizmo.attachedMesh = mesh;
  23. }
  24. }
  25. /**
  26. * Creates a PositionGizmo
  27. * @param gizmoLayer The utility layer the gizmo will be added to
  28. */
  29. constructor(gizmoLayer:UtilityLayerRenderer=UtilityLayerRenderer.DefaultUtilityLayer){
  30. super(gizmoLayer);
  31. this.xGizmo = new AxisDragGizmo(new Vector3(1,0,0), BABYLON.Color3.Green().scale(0.5), gizmoLayer);
  32. this.yGizmo = new AxisDragGizmo(new Vector3(0,1,0), BABYLON.Color3.Red().scale(0.5), gizmoLayer);
  33. this.zGizmo = new AxisDragGizmo(new Vector3(0,0,1), BABYLON.Color3.Blue().scale(0.5), gizmoLayer);
  34. this.attachedMesh = null;
  35. }
  36. public set updateGizmoRotationToMatchAttachedMesh(value:boolean){
  37. if(this.xGizmo){
  38. this.xGizmo.updateGizmoRotationToMatchAttachedMesh = value;
  39. this.yGizmo.updateGizmoRotationToMatchAttachedMesh = value;
  40. this.zGizmo.updateGizmoRotationToMatchAttachedMesh = value;
  41. }
  42. }
  43. public get updateGizmoRotationToMatchAttachedMesh(){
  44. return this.xGizmo.updateGizmoRotationToMatchAttachedMesh;
  45. }
  46. /**
  47. * Drag distance in babylon units that the gizmo will snap to when dragged (Default: 0)
  48. */
  49. public set snapDistance(value:number){
  50. if(this.xGizmo){
  51. this.xGizmo.snapDistance = value;
  52. this.yGizmo.snapDistance = value;
  53. this.zGizmo.snapDistance = value;
  54. }
  55. }
  56. public get snapDistance(){
  57. return this.xGizmo.snapDistance;
  58. }
  59. /**
  60. * Disposes of the gizmo
  61. */
  62. public dispose(){
  63. this.xGizmo.dispose();
  64. this.yGizmo.dispose();
  65. this.zGizmo.dispose();
  66. }
  67. /**
  68. * CustomMeshes are not supported by this gizmo
  69. * @param mesh The mesh to replace the default mesh of the gizmo
  70. */
  71. public setCustomMesh(mesh:Mesh){
  72. 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)");
  73. }
  74. }
  75. }