babylon.directActions.js 14 KB

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