babylon.actionManager.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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. scene._actionManagers.push(this);
  23. }
  24. Object.defineProperty(ActionManager, "NothingTrigger", {
  25. get: function () {
  26. return ActionManager._NothingTrigger;
  27. },
  28. enumerable: true,
  29. configurable: true
  30. });
  31. Object.defineProperty(ActionManager, "OnPickTrigger", {
  32. get: function () {
  33. return ActionManager._OnPickTrigger;
  34. },
  35. enumerable: true,
  36. configurable: true
  37. });
  38. Object.defineProperty(ActionManager, "OnLeftPickTrigger", {
  39. get: function () {
  40. return ActionManager._OnLeftPickTrigger;
  41. },
  42. enumerable: true,
  43. configurable: true
  44. });
  45. Object.defineProperty(ActionManager, "OnRightPickTrigger", {
  46. get: function () {
  47. return ActionManager._OnRightPickTrigger;
  48. },
  49. enumerable: true,
  50. configurable: true
  51. });
  52. Object.defineProperty(ActionManager, "OnCenterPickTrigger", {
  53. get: function () {
  54. return ActionManager._OnCenterPickTrigger;
  55. },
  56. enumerable: true,
  57. configurable: true
  58. });
  59. Object.defineProperty(ActionManager, "OnPointerOverTrigger", {
  60. get: function () {
  61. return ActionManager._OnPointerOverTrigger;
  62. },
  63. enumerable: true,
  64. configurable: true
  65. });
  66. Object.defineProperty(ActionManager, "OnPointerOutTrigger", {
  67. get: function () {
  68. return ActionManager._OnPointerOutTrigger;
  69. },
  70. enumerable: true,
  71. configurable: true
  72. });
  73. Object.defineProperty(ActionManager, "OnEveryFrameTrigger", {
  74. get: function () {
  75. return ActionManager._OnEveryFrameTrigger;
  76. },
  77. enumerable: true,
  78. configurable: true
  79. });
  80. Object.defineProperty(ActionManager, "OnIntersectionEnterTrigger", {
  81. get: function () {
  82. return ActionManager._OnIntersectionEnterTrigger;
  83. },
  84. enumerable: true,
  85. configurable: true
  86. });
  87. Object.defineProperty(ActionManager, "OnIntersectionExitTrigger", {
  88. get: function () {
  89. return ActionManager._OnIntersectionExitTrigger;
  90. },
  91. enumerable: true,
  92. configurable: true
  93. });
  94. // Methods
  95. ActionManager.prototype.dispose = function () {
  96. var index = this._scene._actionManagers.indexOf(this);
  97. if (index > -1) {
  98. this._scene._actionManagers.splice(index, 1);
  99. }
  100. };
  101. ActionManager.prototype.getScene = function () {
  102. return this._scene;
  103. };
  104. ActionManager.prototype.hasSpecificTriggers = function (triggers) {
  105. for (var index = 0; index < this.actions.length; index++) {
  106. var action = this.actions[index];
  107. if (triggers.indexOf(action.trigger) > -1) {
  108. return true;
  109. }
  110. }
  111. return false;
  112. };
  113. Object.defineProperty(ActionManager.prototype, "hasPointerTriggers", {
  114. get: function () {
  115. for (var index = 0; index < this.actions.length; index++) {
  116. var action = this.actions[index];
  117. if (action.trigger >= ActionManager._OnPickTrigger && action.trigger <= ActionManager._OnPointerOutTrigger) {
  118. return true;
  119. }
  120. }
  121. return false;
  122. },
  123. enumerable: true,
  124. configurable: true
  125. });
  126. Object.defineProperty(ActionManager.prototype, "hasPickTriggers", {
  127. get: function () {
  128. for (var index = 0; index < this.actions.length; index++) {
  129. var action = this.actions[index];
  130. if (action.trigger >= ActionManager._OnPickTrigger && action.trigger <= ActionManager._OnCenterPickTrigger) {
  131. return true;
  132. }
  133. }
  134. return false;
  135. },
  136. enumerable: true,
  137. configurable: true
  138. });
  139. ActionManager.prototype.registerAction = function (action) {
  140. if (action.trigger === ActionManager.OnEveryFrameTrigger) {
  141. if (this.getScene().actionManager !== this) {
  142. BABYLON.Tools.Warn("OnEveryFrameTrigger can only be used with scene.actionManager");
  143. return null;
  144. }
  145. }
  146. this.actions.push(action);
  147. action._actionManager = this;
  148. action._prepare();
  149. return action;
  150. };
  151. ActionManager.prototype.processTrigger = function (trigger, evt) {
  152. for (var index = 0; index < this.actions.length; index++) {
  153. var action = this.actions[index];
  154. if (action.trigger === trigger) {
  155. action._executeCurrent(evt);
  156. }
  157. }
  158. };
  159. ActionManager.prototype._getEffectiveTarget = function (target, propertyPath) {
  160. var properties = propertyPath.split(".");
  161. for (var index = 0; index < properties.length - 1; index++) {
  162. target = target[properties[index]];
  163. }
  164. return target;
  165. };
  166. ActionManager.prototype._getProperty = function (propertyPath) {
  167. var properties = propertyPath.split(".");
  168. return properties[properties.length - 1];
  169. };
  170. ActionManager._NothingTrigger = 0;
  171. ActionManager._OnPickTrigger = 1;
  172. ActionManager._OnLeftPickTrigger = 2;
  173. ActionManager._OnRightPickTrigger = 3;
  174. ActionManager._OnCenterPickTrigger = 4;
  175. ActionManager._OnPointerOverTrigger = 5;
  176. ActionManager._OnPointerOutTrigger = 6;
  177. ActionManager._OnEveryFrameTrigger = 7;
  178. ActionManager._OnIntersectionEnterTrigger = 8;
  179. ActionManager._OnIntersectionExitTrigger = 9;
  180. return ActionManager;
  181. })();
  182. BABYLON.ActionManager = ActionManager;
  183. })(BABYLON || (BABYLON = {}));
  184. //# sourceMappingURL=babylon.actionManager.js.map