babylon.directActions.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  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 = this._effectiveTarget = target;
  14. }
  15. SwitchBooleanAction.prototype._prepare = function () {
  16. this._effectiveTarget = this._getEffectiveTarget(this._effectiveTarget, this.propertyPath);
  17. this._property = this._getProperty(this.propertyPath);
  18. };
  19. SwitchBooleanAction.prototype.execute = function () {
  20. this._effectiveTarget[this._property] = !this._effectiveTarget[this._property];
  21. };
  22. SwitchBooleanAction.prototype.serialize = function (parent) {
  23. return _super.prototype._serialize.call(this, {
  24. name: "SwitchBooleanAction",
  25. properties: [
  26. BABYLON.Action._GetTargetProperty(this._target),
  27. { name: "propertyPath", value: this.propertyPath }
  28. ]
  29. }, parent);
  30. };
  31. return SwitchBooleanAction;
  32. }(BABYLON.Action));
  33. BABYLON.SwitchBooleanAction = SwitchBooleanAction;
  34. var SetStateAction = (function (_super) {
  35. __extends(SetStateAction, _super);
  36. function SetStateAction(triggerOptions, target, value, condition) {
  37. _super.call(this, triggerOptions, condition);
  38. this.value = value;
  39. this._target = target;
  40. }
  41. SetStateAction.prototype.execute = function () {
  42. this._target.state = this.value;
  43. };
  44. SetStateAction.prototype.serialize = function (parent) {
  45. return _super.prototype._serialize.call(this, {
  46. name: "SetStateAction",
  47. properties: [
  48. BABYLON.Action._GetTargetProperty(this._target),
  49. { name: "value", value: this.value }
  50. ]
  51. }, parent);
  52. };
  53. return SetStateAction;
  54. }(BABYLON.Action));
  55. BABYLON.SetStateAction = SetStateAction;
  56. var SetValueAction = (function (_super) {
  57. __extends(SetValueAction, _super);
  58. function SetValueAction(triggerOptions, target, propertyPath, value, condition) {
  59. _super.call(this, triggerOptions, condition);
  60. this.propertyPath = propertyPath;
  61. this.value = value;
  62. this._target = this._effectiveTarget = target;
  63. }
  64. SetValueAction.prototype._prepare = function () {
  65. this._effectiveTarget = this._getEffectiveTarget(this._effectiveTarget, this.propertyPath);
  66. this._property = this._getProperty(this.propertyPath);
  67. };
  68. SetValueAction.prototype.execute = function () {
  69. this._effectiveTarget[this._property] = this.value;
  70. };
  71. SetValueAction.prototype.serialize = function (parent) {
  72. return _super.prototype._serialize.call(this, {
  73. name: "SetValueAction",
  74. properties: [
  75. BABYLON.Action._GetTargetProperty(this._target),
  76. { name: "propertyPath", value: this.propertyPath },
  77. { name: "value", value: BABYLON.Action._SerializeValueAsString(this.value) }
  78. ]
  79. }, parent);
  80. };
  81. return SetValueAction;
  82. }(BABYLON.Action));
  83. BABYLON.SetValueAction = SetValueAction;
  84. var IncrementValueAction = (function (_super) {
  85. __extends(IncrementValueAction, _super);
  86. function IncrementValueAction(triggerOptions, target, propertyPath, value, condition) {
  87. _super.call(this, triggerOptions, condition);
  88. this.propertyPath = propertyPath;
  89. this.value = value;
  90. this._target = this._effectiveTarget = target;
  91. }
  92. IncrementValueAction.prototype._prepare = function () {
  93. this._effectiveTarget = this._getEffectiveTarget(this._effectiveTarget, this.propertyPath);
  94. this._property = this._getProperty(this.propertyPath);
  95. if (typeof this._effectiveTarget[this._property] !== "number") {
  96. BABYLON.Tools.Warn("Warning: IncrementValueAction can only be used with number values");
  97. }
  98. };
  99. IncrementValueAction.prototype.execute = function () {
  100. this._effectiveTarget[this._property] += this.value;
  101. };
  102. IncrementValueAction.prototype.serialize = function (parent) {
  103. return _super.prototype._serialize.call(this, {
  104. name: "IncrementValueAction",
  105. properties: [
  106. BABYLON.Action._GetTargetProperty(this._target),
  107. { name: "propertyPath", value: this.propertyPath },
  108. { name: "value", value: BABYLON.Action._SerializeValueAsString(this.value) }
  109. ]
  110. }, parent);
  111. };
  112. return IncrementValueAction;
  113. }(BABYLON.Action));
  114. BABYLON.IncrementValueAction = IncrementValueAction;
  115. var PlayAnimationAction = (function (_super) {
  116. __extends(PlayAnimationAction, _super);
  117. function PlayAnimationAction(triggerOptions, target, from, to, loop, condition) {
  118. _super.call(this, triggerOptions, condition);
  119. this.from = from;
  120. this.to = to;
  121. this.loop = loop;
  122. this._target = target;
  123. }
  124. PlayAnimationAction.prototype._prepare = function () {
  125. };
  126. PlayAnimationAction.prototype.execute = function () {
  127. var scene = this._actionManager.getScene();
  128. scene.beginAnimation(this._target, this.from, this.to, this.loop);
  129. };
  130. PlayAnimationAction.prototype.serialize = function (parent) {
  131. return _super.prototype._serialize.call(this, {
  132. name: "PlayAnimationAction",
  133. properties: [
  134. BABYLON.Action._GetTargetProperty(this._target),
  135. { name: "from", value: String(this.from) },
  136. { name: "to", value: String(this.to) },
  137. { name: "loop", value: BABYLON.Action._SerializeValueAsString(this.loop) || false }
  138. ]
  139. }, parent);
  140. };
  141. return PlayAnimationAction;
  142. }(BABYLON.Action));
  143. BABYLON.PlayAnimationAction = PlayAnimationAction;
  144. var StopAnimationAction = (function (_super) {
  145. __extends(StopAnimationAction, _super);
  146. function StopAnimationAction(triggerOptions, target, condition) {
  147. _super.call(this, triggerOptions, condition);
  148. this._target = target;
  149. }
  150. StopAnimationAction.prototype._prepare = function () {
  151. };
  152. StopAnimationAction.prototype.execute = function () {
  153. var scene = this._actionManager.getScene();
  154. scene.stopAnimation(this._target);
  155. };
  156. StopAnimationAction.prototype.serialize = function (parent) {
  157. return _super.prototype._serialize.call(this, {
  158. name: "StopAnimationAction",
  159. properties: [BABYLON.Action._GetTargetProperty(this._target)]
  160. }, parent);
  161. };
  162. return StopAnimationAction;
  163. }(BABYLON.Action));
  164. BABYLON.StopAnimationAction = StopAnimationAction;
  165. var DoNothingAction = (function (_super) {
  166. __extends(DoNothingAction, _super);
  167. function DoNothingAction(triggerOptions, condition) {
  168. if (triggerOptions === void 0) { triggerOptions = BABYLON.ActionManager.NothingTrigger; }
  169. _super.call(this, triggerOptions, condition);
  170. }
  171. DoNothingAction.prototype.execute = function () {
  172. };
  173. DoNothingAction.prototype.serialize = function (parent) {
  174. return _super.prototype._serialize.call(this, {
  175. name: "DoNothingAction",
  176. properties: []
  177. }, parent);
  178. };
  179. return DoNothingAction;
  180. }(BABYLON.Action));
  181. BABYLON.DoNothingAction = DoNothingAction;
  182. var CombineAction = (function (_super) {
  183. __extends(CombineAction, _super);
  184. function CombineAction(triggerOptions, children, condition) {
  185. _super.call(this, triggerOptions, condition);
  186. this.children = children;
  187. }
  188. CombineAction.prototype._prepare = function () {
  189. for (var index = 0; index < this.children.length; index++) {
  190. this.children[index]._actionManager = this._actionManager;
  191. this.children[index]._prepare();
  192. }
  193. };
  194. CombineAction.prototype.execute = function (evt) {
  195. for (var index = 0; index < this.children.length; index++) {
  196. this.children[index].execute(evt);
  197. }
  198. };
  199. CombineAction.prototype.serialize = function (parent) {
  200. var serializationObject = _super.prototype._serialize.call(this, {
  201. name: "CombineAction",
  202. properties: [],
  203. combine: []
  204. }, parent);
  205. for (var i = 0; i < this.children.length; i++) {
  206. serializationObject.combine.push(this.children[i].serialize(null));
  207. }
  208. return serializationObject;
  209. };
  210. return CombineAction;
  211. }(BABYLON.Action));
  212. BABYLON.CombineAction = CombineAction;
  213. var ExecuteCodeAction = (function (_super) {
  214. __extends(ExecuteCodeAction, _super);
  215. function ExecuteCodeAction(triggerOptions, func, condition) {
  216. _super.call(this, triggerOptions, condition);
  217. this.func = func;
  218. }
  219. ExecuteCodeAction.prototype.execute = function (evt) {
  220. this.func(evt);
  221. };
  222. return ExecuteCodeAction;
  223. }(BABYLON.Action));
  224. BABYLON.ExecuteCodeAction = ExecuteCodeAction;
  225. var SetParentAction = (function (_super) {
  226. __extends(SetParentAction, _super);
  227. function SetParentAction(triggerOptions, target, parent, condition) {
  228. _super.call(this, triggerOptions, condition);
  229. this._target = target;
  230. this._parent = parent;
  231. }
  232. SetParentAction.prototype._prepare = function () {
  233. };
  234. SetParentAction.prototype.execute = function () {
  235. if (this._target.parent === this._parent) {
  236. return;
  237. }
  238. var invertParentWorldMatrix = this._parent.getWorldMatrix().clone();
  239. invertParentWorldMatrix.invert();
  240. this._target.position = BABYLON.Vector3.TransformCoordinates(this._target.position, invertParentWorldMatrix);
  241. this._target.parent = this._parent;
  242. };
  243. SetParentAction.prototype.serialize = function (parent) {
  244. return _super.prototype._serialize.call(this, {
  245. name: "SetParentAction",
  246. properties: [
  247. BABYLON.Action._GetTargetProperty(this._target),
  248. BABYLON.Action._GetTargetProperty(this._parent),
  249. ]
  250. }, parent);
  251. };
  252. return SetParentAction;
  253. }(BABYLON.Action));
  254. BABYLON.SetParentAction = SetParentAction;
  255. var PlaySoundAction = (function (_super) {
  256. __extends(PlaySoundAction, _super);
  257. function PlaySoundAction(triggerOptions, sound, condition) {
  258. _super.call(this, triggerOptions, condition);
  259. this._sound = sound;
  260. }
  261. PlaySoundAction.prototype._prepare = function () {
  262. };
  263. PlaySoundAction.prototype.execute = function () {
  264. if (this._sound !== undefined)
  265. this._sound.play();
  266. };
  267. PlaySoundAction.prototype.serialize = function (parent) {
  268. return _super.prototype._serialize.call(this, {
  269. name: "PlaySoundAction",
  270. properties: [{ name: "sound", value: this._sound.name }]
  271. }, parent);
  272. };
  273. return PlaySoundAction;
  274. }(BABYLON.Action));
  275. BABYLON.PlaySoundAction = PlaySoundAction;
  276. var StopSoundAction = (function (_super) {
  277. __extends(StopSoundAction, _super);
  278. function StopSoundAction(triggerOptions, sound, condition) {
  279. _super.call(this, triggerOptions, condition);
  280. this._sound = sound;
  281. }
  282. StopSoundAction.prototype._prepare = function () {
  283. };
  284. StopSoundAction.prototype.execute = function () {
  285. if (this._sound !== undefined)
  286. this._sound.stop();
  287. };
  288. StopSoundAction.prototype.serialize = function (parent) {
  289. return _super.prototype._serialize.call(this, {
  290. name: "StopSoundAction",
  291. properties: [{ name: "sound", value: this._sound.name }]
  292. }, parent);
  293. };
  294. return StopSoundAction;
  295. }(BABYLON.Action));
  296. BABYLON.StopSoundAction = StopSoundAction;
  297. })(BABYLON || (BABYLON = {}));