cylinderPanel.ts 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /// <reference path="../../../../dist/preview release/babylon.d.ts"/>
  2. module BABYLON.GUI {
  3. /**
  4. * Class used to create a container panel deployed on the surface of a cylinder
  5. */
  6. export class CylinderPanel extends VolumeBasedPanel {
  7. private _radius = 5.0;
  8. /**
  9. * Gets or sets the radius of the cylinder where to project controls (5 by default)
  10. */
  11. public get radius(): float {
  12. return this._radius;
  13. }
  14. public set radius(value: float) {
  15. if (this._radius === value) {
  16. return;
  17. }
  18. this._radius = value;
  19. Tools.SetImmediate(() => {
  20. this._arrangeChildren();
  21. });
  22. }
  23. protected _mapGridNode(control: Control3D, nodePosition: Vector3) {
  24. let newPos = this._cylindricalMapping(nodePosition);
  25. let mesh = control.mesh;
  26. if (!mesh) {
  27. return;
  28. }
  29. switch (this.orientation) {
  30. case Container3D.FACEORIGIN_ORIENTATION:
  31. mesh.lookAt(new BABYLON.Vector3(-newPos.x, 0, -newPos.z));
  32. break;
  33. case Container3D.FACEORIGINREVERSED_ORIENTATION:
  34. mesh.lookAt(new BABYLON.Vector3(newPos.x, 0, newPos.z));
  35. break;
  36. case Container3D.FACEFORWARD_ORIENTATION:
  37. mesh.lookAt(new BABYLON.Vector3(0, 0, 1));
  38. break;
  39. case Container3D.FACEFORWARDREVERSED_ORIENTATION:
  40. mesh.lookAt(new BABYLON.Vector3(0, 0, -1));
  41. break;
  42. }
  43. control.position = newPos;
  44. }
  45. private _cylindricalMapping(source: Vector3)
  46. {
  47. let newPos = new Vector3(0, source.y, this._radius);
  48. let yAngle = (source.x / this._radius);
  49. Matrix.RotationYawPitchRollToRef(yAngle, 0, 0, Tmp.Matrix[0]);
  50. return Vector3.TransformNormal(newPos, Tmp.Matrix[0]);
  51. }
  52. }
  53. }