babylon.actionManager.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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. ActionManager.prototype.registerAction = function (action) {
  114. if (action.trigger === ActionManager.OnEveryFrameTrigger) {
  115. if (this.getScene().actionManager !== this) {
  116. BABYLON.Tools.Warn("OnEveryFrameTrigger can only be used with scene.actionManager");
  117. return null;
  118. }
  119. }
  120. this.actions.push(action);
  121. action._actionManager = this;
  122. action._prepare();
  123. return action;
  124. };
  125. ActionManager.prototype.processTrigger = function (trigger, evt) {
  126. for (var index = 0; index < this.actions.length; index++) {
  127. var action = this.actions[index];
  128. if (action.trigger === trigger) {
  129. action._executeCurrent(evt);
  130. }
  131. }
  132. };
  133. ActionManager.prototype._getEffectiveTarget = function (target, propertyPath) {
  134. var properties = propertyPath.split(".");
  135. for (var index = 0; index < properties.length - 1; index++) {
  136. target = target[properties[index]];
  137. }
  138. return target;
  139. };
  140. ActionManager.prototype._getProperty = function (propertyPath) {
  141. var properties = propertyPath.split(".");
  142. return properties[properties.length - 1];
  143. };
  144. ActionManager._NothingTrigger = 0;
  145. ActionManager._OnPickTrigger = 1;
  146. ActionManager._OnLeftPickTrigger = 2;
  147. ActionManager._OnRightPickTrigger = 3;
  148. ActionManager._OnCenterPickTrigger = 4;
  149. ActionManager._OnPointerOverTrigger = 5;
  150. ActionManager._OnPointerOutTrigger = 6;
  151. ActionManager._OnEveryFrameTrigger = 7;
  152. ActionManager._OnIntersectionEnterTrigger = 8;
  153. ActionManager._OnIntersectionExitTrigger = 9;
  154. return ActionManager;
  155. })();
  156. BABYLON.ActionManager = ActionManager;
  157. })(BABYLON || (BABYLON = {}));
  158. //# sourceMappingURL=babylon.actionManager.js.map