babylon.directActions.js 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. var __extends = (this && this.__extends) || function (d, b) {
  2. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  3. function __() { this.constructor = d; }
  4. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  5. };
  6. var BABYLON;
  7. (function (BABYLON) {
  8. var SwitchBooleanAction = (function (_super) {
  9. __extends(SwitchBooleanAction, _super);
  10. function SwitchBooleanAction(triggerOptions, target, propertyPath, condition) {
  11. _super.call(this, triggerOptions, condition);
  12. this.propertyPath = propertyPath;
  13. this._target = target;
  14. }
  15. SwitchBooleanAction.prototype._prepare = function () {
  16. this._target = this._getEffectiveTarget(this._target, this.propertyPath);
  17. this._property = this._getProperty(this.propertyPath);
  18. };
  19. SwitchBooleanAction.prototype.execute = function () {
  20. this._target[this._property] = !this._target[this._property];
  21. };
  22. return SwitchBooleanAction;
  23. })(BABYLON.Action);
  24. BABYLON.SwitchBooleanAction = SwitchBooleanAction;
  25. var SetStateAction = (function (_super) {
  26. __extends(SetStateAction, _super);
  27. function SetStateAction(triggerOptions, target, value, condition) {
  28. _super.call(this, triggerOptions, condition);
  29. this.value = value;
  30. this._target = target;
  31. }
  32. SetStateAction.prototype.execute = function () {
  33. this._target.state = this.value;
  34. };
  35. return SetStateAction;
  36. })(BABYLON.Action);
  37. BABYLON.SetStateAction = SetStateAction;
  38. var SetValueAction = (function (_super) {
  39. __extends(SetValueAction, _super);
  40. function SetValueAction(triggerOptions, target, propertyPath, value, condition) {
  41. _super.call(this, triggerOptions, condition);
  42. this.propertyPath = propertyPath;
  43. this.value = value;
  44. this._target = target;
  45. }
  46. SetValueAction.prototype._prepare = function () {
  47. this._target = this._getEffectiveTarget(this._target, this.propertyPath);
  48. this._property = this._getProperty(this.propertyPath);
  49. };
  50. SetValueAction.prototype.execute = function () {
  51. this._target[this._property] = this.value;
  52. };
  53. return SetValueAction;
  54. })(BABYLON.Action);
  55. BABYLON.SetValueAction = SetValueAction;
  56. var IncrementValueAction = (function (_super) {
  57. __extends(IncrementValueAction, _super);
  58. function IncrementValueAction(triggerOptions, target, propertyPath, value, condition) {
  59. _super.call(this, triggerOptions, condition);
  60. this.propertyPath = propertyPath;
  61. this.value = value;
  62. this._target = target;
  63. }
  64. IncrementValueAction.prototype._prepare = function () {
  65. this._target = this._getEffectiveTarget(this._target, this.propertyPath);
  66. this._property = this._getProperty(this.propertyPath);
  67. if (typeof this._target[this._property] !== "number") {
  68. BABYLON.Tools.Warn("Warning: IncrementValueAction can only be used with number values");
  69. }
  70. };
  71. IncrementValueAction.prototype.execute = function () {
  72. this._target[this._property] += this.value;
  73. };
  74. return IncrementValueAction;
  75. })(BABYLON.Action);
  76. BABYLON.IncrementValueAction = IncrementValueAction;
  77. var PlayAnimationAction = (function (_super) {
  78. __extends(PlayAnimationAction, _super);
  79. function PlayAnimationAction(triggerOptions, target, from, to, loop, condition) {
  80. _super.call(this, triggerOptions, condition);
  81. this.from = from;
  82. this.to = to;
  83. this.loop = loop;
  84. this._target = target;
  85. }
  86. PlayAnimationAction.prototype._prepare = function () {
  87. };
  88. PlayAnimationAction.prototype.execute = function () {
  89. var scene = this._actionManager.getScene();
  90. scene.beginAnimation(this._target, this.from, this.to, this.loop);
  91. };
  92. return PlayAnimationAction;
  93. })(BABYLON.Action);
  94. BABYLON.PlayAnimationAction = PlayAnimationAction;
  95. var StopAnimationAction = (function (_super) {
  96. __extends(StopAnimationAction, _super);
  97. function StopAnimationAction(triggerOptions, target, condition) {
  98. _super.call(this, triggerOptions, condition);
  99. this._target = target;
  100. }
  101. StopAnimationAction.prototype._prepare = function () {
  102. };
  103. StopAnimationAction.prototype.execute = function () {
  104. var scene = this._actionManager.getScene();
  105. scene.stopAnimation(this._target);
  106. };
  107. return StopAnimationAction;
  108. })(BABYLON.Action);
  109. BABYLON.StopAnimationAction = StopAnimationAction;
  110. var DoNothingAction = (function (_super) {
  111. __extends(DoNothingAction, _super);
  112. function DoNothingAction(triggerOptions, condition) {
  113. if (triggerOptions === void 0) { triggerOptions = BABYLON.ActionManager.NothingTrigger; }
  114. _super.call(this, triggerOptions, condition);
  115. }
  116. DoNothingAction.prototype.execute = function () {
  117. };
  118. return DoNothingAction;
  119. })(BABYLON.Action);
  120. BABYLON.DoNothingAction = DoNothingAction;
  121. var CombineAction = (function (_super) {
  122. __extends(CombineAction, _super);
  123. function CombineAction(triggerOptions, children, condition) {
  124. _super.call(this, triggerOptions, condition);
  125. this.children = children;
  126. }
  127. CombineAction.prototype._prepare = function () {
  128. for (var index = 0; index < this.children.length; index++) {
  129. this.children[index]._actionManager = this._actionManager;
  130. this.children[index]._prepare();
  131. }
  132. };
  133. CombineAction.prototype.execute = function (evt) {
  134. for (var index = 0; index < this.children.length; index++) {
  135. this.children[index].execute(evt);
  136. }
  137. };
  138. return CombineAction;
  139. })(BABYLON.Action);
  140. BABYLON.CombineAction = CombineAction;
  141. var ExecuteCodeAction = (function (_super) {
  142. __extends(ExecuteCodeAction, _super);
  143. function ExecuteCodeAction(triggerOptions, func, condition) {
  144. _super.call(this, triggerOptions, condition);
  145. this.func = func;
  146. }
  147. ExecuteCodeAction.prototype.execute = function (evt) {
  148. this.func(evt);
  149. };
  150. return ExecuteCodeAction;
  151. })(BABYLON.Action);
  152. BABYLON.ExecuteCodeAction = ExecuteCodeAction;
  153. var SetParentAction = (function (_super) {
  154. __extends(SetParentAction, _super);
  155. function SetParentAction(triggerOptions, target, parent, condition) {
  156. _super.call(this, triggerOptions, condition);
  157. this._target = target;
  158. this._parent = parent;
  159. }
  160. SetParentAction.prototype._prepare = function () {
  161. };
  162. SetParentAction.prototype.execute = function () {
  163. if (this._target.parent === this._parent) {
  164. return;
  165. }
  166. var invertParentWorldMatrix = this._parent.getWorldMatrix().clone();
  167. invertParentWorldMatrix.invert();
  168. this._target.position = BABYLON.Vector3.TransformCoordinates(this._target.position, invertParentWorldMatrix);
  169. this._target.parent = this._parent;
  170. };
  171. return SetParentAction;
  172. })(BABYLON.Action);
  173. BABYLON.SetParentAction = SetParentAction;
  174. var PlaySoundAction = (function (_super) {
  175. __extends(PlaySoundAction, _super);
  176. function PlaySoundAction(triggerOptions, sound, condition) {
  177. _super.call(this, triggerOptions, condition);
  178. this._sound = sound;
  179. }
  180. PlaySoundAction.prototype._prepare = function () {
  181. };
  182. PlaySoundAction.prototype.execute = function () {
  183. if (this._sound !== undefined)
  184. this._sound.play();
  185. };
  186. return PlaySoundAction;
  187. })(BABYLON.Action);
  188. BABYLON.PlaySoundAction = PlaySoundAction;
  189. var StopSoundAction = (function (_super) {
  190. __extends(StopSoundAction, _super);
  191. function StopSoundAction(triggerOptions, sound, condition) {
  192. _super.call(this, triggerOptions, condition);
  193. this._sound = sound;
  194. }
  195. StopSoundAction.prototype._prepare = function () {
  196. };
  197. StopSoundAction.prototype.execute = function () {
  198. if (this._sound !== undefined)
  199. this._sound.stop();
  200. };
  201. return StopSoundAction;
  202. })(BABYLON.Action);
  203. BABYLON.StopSoundAction = StopSoundAction;
  204. })(BABYLON || (BABYLON = {}));