babylon.rotationGizmo.ts 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. module BABYLON {
  2. /**
  3. * Gizmo that enables rotating a mesh along 3 axis
  4. */
  5. export class RotationGizmo extends Gizmo {
  6. private _xDrag:PlaneRotationGizmo;
  7. private _yDrag:PlaneRotationGizmo;
  8. private _zDrag:PlaneRotationGizmo;
  9. public set attachedMesh(mesh:Nullable<AbstractMesh>){
  10. if(this._xDrag){
  11. this._xDrag.attachedMesh = mesh;
  12. this._yDrag.attachedMesh = mesh;
  13. this._zDrag.attachedMesh = mesh;
  14. }
  15. }
  16. /**
  17. * Creates a RotationGizmo
  18. * @param gizmoLayer The utility layer the gizmo will be added to
  19. */
  20. constructor(gizmoLayer:UtilityLayerRenderer){
  21. super(gizmoLayer);
  22. this._xDrag = new PlaneRotationGizmo(gizmoLayer, new Vector3(1,0,0), BABYLON.Color3.Green().scale(0.5));
  23. this._yDrag = new PlaneRotationGizmo(gizmoLayer, new Vector3(0,1,0), BABYLON.Color3.Red().scale(0.5));
  24. this._zDrag = new PlaneRotationGizmo(gizmoLayer, new Vector3(0,0,1), BABYLON.Color3.Blue().scale(0.5));
  25. this.attachedMesh = null;
  26. }
  27. public set updateGizmoRotationToMatchAttachedMesh(value:boolean){
  28. if(this._xDrag){
  29. this._xDrag.updateGizmoRotationToMatchAttachedMesh = value;
  30. this._yDrag.updateGizmoRotationToMatchAttachedMesh = value;
  31. this._zDrag.updateGizmoRotationToMatchAttachedMesh = value;
  32. }
  33. }
  34. public get updateGizmoRotationToMatchAttachedMesh(){
  35. return this._xDrag.updateGizmoRotationToMatchAttachedMesh;
  36. }
  37. /**
  38. * Disposes of the gizmo
  39. */
  40. public dispose(){
  41. this._xDrag.dispose();
  42. this._yDrag.dispose();
  43. this._zDrag.dispose();
  44. }
  45. }
  46. }