babylon.directActions.js 7.5 KB

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