babylon.actionManager.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. var BABYLON;
  2. (function (BABYLON) {
  3. var ActionEvent = (function () {
  4. function ActionEvent(source, pointerX, pointerY, meshUnderPointer) {
  5. this.source = source;
  6. this.pointerX = pointerX;
  7. this.pointerY = pointerY;
  8. this.meshUnderPointer = meshUnderPointer;
  9. }
  10. ActionEvent.CreateNew = function (source) {
  11. var scene = source.getScene();
  12. return new ActionEvent(source, scene.pointerX, scene.pointerY, scene.meshUnderPointer);
  13. };
  14. return ActionEvent;
  15. })();
  16. BABYLON.ActionEvent = ActionEvent;
  17. var ActionManager = (function () {
  18. function ActionManager(scene) {
  19. // Members
  20. this.actions = new Array();
  21. this._scene = scene;
  22. }
  23. Object.defineProperty(ActionManager, "NothingTrigger", {
  24. get: function () {
  25. return ActionManager._NothingTrigger;
  26. },
  27. enumerable: true,
  28. configurable: true
  29. });
  30. Object.defineProperty(ActionManager, "OnPickTrigger", {
  31. get: function () {
  32. return ActionManager._OnPickTrigger;
  33. },
  34. enumerable: true,
  35. configurable: true
  36. });
  37. Object.defineProperty(ActionManager, "OnLeftPickTrigger", {
  38. get: function () {
  39. return ActionManager._OnLeftPickTrigger;
  40. },
  41. enumerable: true,
  42. configurable: true
  43. });
  44. Object.defineProperty(ActionManager, "OnRightPickTrigger", {
  45. get: function () {
  46. return ActionManager._OnRightPickTrigger;
  47. },
  48. enumerable: true,
  49. configurable: true
  50. });
  51. Object.defineProperty(ActionManager, "OnCenterPickTrigger", {
  52. get: function () {
  53. return ActionManager._OnCenterPickTrigger;
  54. },
  55. enumerable: true,
  56. configurable: true
  57. });
  58. Object.defineProperty(ActionManager, "OnPointerOverTrigger", {
  59. get: function () {
  60. return ActionManager._OnPointerOverTrigger;
  61. },
  62. enumerable: true,
  63. configurable: true
  64. });
  65. Object.defineProperty(ActionManager, "OnPointerOutTrigger", {
  66. get: function () {
  67. return ActionManager._OnPointerOutTrigger;
  68. },
  69. enumerable: true,
  70. configurable: true
  71. });
  72. Object.defineProperty(ActionManager, "OnEveryFrameTrigger", {
  73. get: function () {
  74. return ActionManager._OnEveryFrameTrigger;
  75. },
  76. enumerable: true,
  77. configurable: true
  78. });
  79. // Methods
  80. ActionManager.prototype.getScene = function () {
  81. return this._scene;
  82. };
  83. ActionManager.prototype.registerAction = function (action) {
  84. if (action.trigger === ActionManager.OnEveryFrameTrigger) {
  85. if (this.getScene().actionManager !== this) {
  86. BABYLON.Tools.Warn("OnEveryFrameTrigger can only be used with scene.actionManager");
  87. return null;
  88. }
  89. }
  90. this.actions.push(action);
  91. action._actionManager = this;
  92. action._prepare();
  93. return action;
  94. };
  95. ActionManager.prototype.processTrigger = function (trigger, evt) {
  96. for (var index = 0; index < this.actions.length; index++) {
  97. var action = this.actions[index];
  98. if (action.trigger === trigger) {
  99. action._executeCurrent(evt);
  100. }
  101. }
  102. };
  103. ActionManager.prototype._getEffectiveTarget = function (target, propertyPath) {
  104. var properties = propertyPath.split(".");
  105. for (var index = 0; index < properties.length - 1; index++) {
  106. target = target[properties[index]];
  107. }
  108. return target;
  109. };
  110. ActionManager.prototype._getProperty = function (propertyPath) {
  111. var properties = propertyPath.split(".");
  112. return properties[properties.length - 1];
  113. };
  114. ActionManager._NothingTrigger = 0;
  115. ActionManager._OnPickTrigger = 1;
  116. ActionManager._OnLeftPickTrigger = 2;
  117. ActionManager._OnRightPickTrigger = 3;
  118. ActionManager._OnCenterPickTrigger = 4;
  119. ActionManager._OnPointerOverTrigger = 5;
  120. ActionManager._OnPointerOutTrigger = 6;
  121. ActionManager._OnEveryFrameTrigger = 7;
  122. return ActionManager;
  123. })();
  124. BABYLON.ActionManager = ActionManager;
  125. })(BABYLON || (BABYLON = {}));
  126. //# sourceMappingURL=babylon.actionManager.js.map