babylon.directActions.js 6.9 KB

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