babylon.animation.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582
  1. var BABYLON;
  2. (function (BABYLON) {
  3. var AnimationRange = (function () {
  4. function AnimationRange(name, from, to) {
  5. this.name = name;
  6. this.from = from;
  7. this.to = to;
  8. }
  9. return AnimationRange;
  10. })();
  11. BABYLON.AnimationRange = AnimationRange;
  12. /**
  13. * Composed of a frame, and an action function
  14. */
  15. var AnimationEvent = (function () {
  16. function AnimationEvent(frame, action, onlyOnce) {
  17. this.frame = frame;
  18. this.action = action;
  19. this.onlyOnce = onlyOnce;
  20. this.isDone = false;
  21. }
  22. return AnimationEvent;
  23. })();
  24. BABYLON.AnimationEvent = AnimationEvent;
  25. var Animation = (function () {
  26. function Animation(name, targetProperty, framePerSecond, dataType, loopMode) {
  27. this.name = name;
  28. this.targetProperty = targetProperty;
  29. this.framePerSecond = framePerSecond;
  30. this.dataType = dataType;
  31. this.loopMode = loopMode;
  32. this._offsetsCache = {};
  33. this._highLimitsCache = {};
  34. this._stopped = false;
  35. // The set of event that will be linked to this animation
  36. this._events = new Array();
  37. this.allowMatricesInterpolation = false;
  38. this._ranges = {};
  39. this.targetPropertyPath = targetProperty.split(".");
  40. this.dataType = dataType;
  41. this.loopMode = loopMode === undefined ? Animation.ANIMATIONLOOPMODE_CYCLE : loopMode;
  42. }
  43. Animation._PrepareAnimation = function (targetProperty, framePerSecond, totalFrame, from, to, loopMode, easingFunction) {
  44. var dataType = undefined;
  45. if (!isNaN(parseFloat(from)) && isFinite(from)) {
  46. dataType = Animation.ANIMATIONTYPE_FLOAT;
  47. }
  48. else if (from instanceof BABYLON.Quaternion) {
  49. dataType = Animation.ANIMATIONTYPE_QUATERNION;
  50. }
  51. else if (from instanceof BABYLON.Vector3) {
  52. dataType = Animation.ANIMATIONTYPE_VECTOR3;
  53. }
  54. else if (from instanceof BABYLON.Vector2) {
  55. dataType = Animation.ANIMATIONTYPE_VECTOR2;
  56. }
  57. else if (from instanceof BABYLON.Color3) {
  58. dataType = Animation.ANIMATIONTYPE_COLOR3;
  59. }
  60. if (dataType == undefined) {
  61. return null;
  62. }
  63. var animation = new Animation(name, targetProperty, framePerSecond, dataType, loopMode);
  64. var keys = [];
  65. keys.push({ frame: 0, value: from });
  66. keys.push({ frame: totalFrame, value: to });
  67. animation.setKeys(keys);
  68. if (easingFunction !== undefined) {
  69. animation.setEasingFunction(easingFunction);
  70. }
  71. return animation;
  72. };
  73. Animation.CreateAndStartAnimation = function (name, node, targetProperty, framePerSecond, totalFrame, from, to, loopMode, easingFunction, onAnimationEnd) {
  74. var animation = Animation._PrepareAnimation(targetProperty, framePerSecond, totalFrame, from, to, loopMode, easingFunction);
  75. return node.getScene().beginDirectAnimation(node, [animation], 0, totalFrame, (animation.loopMode === 1), 1.0, onAnimationEnd);
  76. };
  77. Animation.CreateMergeAndStartAnimation = function (name, node, targetProperty, framePerSecond, totalFrame, from, to, loopMode, easingFunction, onAnimationEnd) {
  78. var animation = Animation._PrepareAnimation(targetProperty, framePerSecond, totalFrame, from, to, loopMode, easingFunction);
  79. node.animations.push(animation);
  80. return node.getScene().beginAnimation(node, 0, totalFrame, (animation.loopMode === 1), 1.0, onAnimationEnd);
  81. };
  82. // Methods
  83. /**
  84. * Add an event to this animation.
  85. */
  86. Animation.prototype.addEvent = function (event) {
  87. this._events.push(event);
  88. };
  89. /**
  90. * Remove all events found at the given frame
  91. * @param frame
  92. */
  93. Animation.prototype.removeEvents = function (frame) {
  94. for (var index = 0; index < this._events.length; index++) {
  95. if (this._events[index].frame === frame) {
  96. this._events.splice(index, 1);
  97. index--;
  98. }
  99. }
  100. };
  101. Animation.prototype.createRange = function (name, from, to) {
  102. // check name not already in use; could happen for bones after serialized
  103. if (!this._ranges[name]) {
  104. this._ranges[name] = new AnimationRange(name, from, to);
  105. }
  106. };
  107. Animation.prototype.deleteRange = function (name, deleteFrames) {
  108. if (deleteFrames === void 0) { deleteFrames = true; }
  109. if (this._ranges[name]) {
  110. if (deleteFrames) {
  111. var from = this._ranges[name].from;
  112. var to = this._ranges[name].to;
  113. // this loop MUST go high to low for multiple splices to work
  114. for (var key = this._keys.length - 1; key >= 0; key--) {
  115. if (this._keys[key].frame >= from && this._keys[key].frame <= to) {
  116. this._keys.splice(key, 1);
  117. }
  118. }
  119. }
  120. this._ranges[name] = undefined; // said much faster than 'delete this._range[name]'
  121. }
  122. };
  123. Animation.prototype.getRange = function (name) {
  124. return this._ranges[name];
  125. };
  126. Animation.prototype.reset = function () {
  127. this._offsetsCache = {};
  128. this._highLimitsCache = {};
  129. this.currentFrame = 0;
  130. };
  131. Animation.prototype.isStopped = function () {
  132. return this._stopped;
  133. };
  134. Animation.prototype.getKeys = function () {
  135. return this._keys;
  136. };
  137. Animation.prototype.getHighestFrame = function () {
  138. var ret = 0;
  139. for (var key = 0, nKeys = this._keys.length; key < nKeys; key++) {
  140. if (ret < this._keys[key].frame) {
  141. ret = this._keys[key].frame;
  142. }
  143. }
  144. return ret;
  145. };
  146. Animation.prototype.getEasingFunction = function () {
  147. return this._easingFunction;
  148. };
  149. Animation.prototype.setEasingFunction = function (easingFunction) {
  150. this._easingFunction = easingFunction;
  151. };
  152. Animation.prototype.floatInterpolateFunction = function (startValue, endValue, gradient) {
  153. return startValue + (endValue - startValue) * gradient;
  154. };
  155. Animation.prototype.quaternionInterpolateFunction = function (startValue, endValue, gradient) {
  156. return BABYLON.Quaternion.Slerp(startValue, endValue, gradient);
  157. };
  158. Animation.prototype.vector3InterpolateFunction = function (startValue, endValue, gradient) {
  159. return BABYLON.Vector3.Lerp(startValue, endValue, gradient);
  160. };
  161. Animation.prototype.vector2InterpolateFunction = function (startValue, endValue, gradient) {
  162. return BABYLON.Vector2.Lerp(startValue, endValue, gradient);
  163. };
  164. Animation.prototype.color3InterpolateFunction = function (startValue, endValue, gradient) {
  165. return BABYLON.Color3.Lerp(startValue, endValue, gradient);
  166. };
  167. Animation.prototype.matrixInterpolateFunction = function (startValue, endValue, gradient) {
  168. return BABYLON.Matrix.Lerp(startValue, endValue, gradient);
  169. };
  170. Animation.prototype.clone = function () {
  171. var clone = new Animation(this.name, this.targetPropertyPath.join("."), this.framePerSecond, this.dataType, this.loopMode);
  172. if (this._keys) {
  173. clone.setKeys(this._keys);
  174. }
  175. return clone;
  176. };
  177. Animation.prototype.setKeys = function (values) {
  178. this._keys = values.slice(0);
  179. this._offsetsCache = {};
  180. this._highLimitsCache = {};
  181. };
  182. Animation.prototype._getKeyValue = function (value) {
  183. if (typeof value === "function") {
  184. return value();
  185. }
  186. return value;
  187. };
  188. Animation.prototype._interpolate = function (currentFrame, repeatCount, loopMode, offsetValue, highLimitValue) {
  189. if (loopMode === Animation.ANIMATIONLOOPMODE_CONSTANT && repeatCount > 0) {
  190. return highLimitValue.clone ? highLimitValue.clone() : highLimitValue;
  191. }
  192. this.currentFrame = currentFrame;
  193. // Try to get a hash to find the right key
  194. var startKey = Math.max(0, Math.min(this._keys.length - 1, Math.floor(this._keys.length * (currentFrame - this._keys[0].frame) / (this._keys[this._keys.length - 1].frame - this._keys[0].frame)) - 1));
  195. if (this._keys[startKey].frame >= currentFrame) {
  196. while (startKey - 1 >= 0 && this._keys[startKey].frame >= currentFrame) {
  197. startKey--;
  198. }
  199. }
  200. for (var key = startKey; key < this._keys.length; key++) {
  201. if (this._keys[key + 1].frame >= currentFrame) {
  202. var startValue = this._getKeyValue(this._keys[key].value);
  203. var endValue = this._getKeyValue(this._keys[key + 1].value);
  204. // gradient : percent of currentFrame between the frame inf and the frame sup
  205. var gradient = (currentFrame - this._keys[key].frame) / (this._keys[key + 1].frame - this._keys[key].frame);
  206. // check for easingFunction and correction of gradient
  207. if (this._easingFunction != null) {
  208. gradient = this._easingFunction.ease(gradient);
  209. }
  210. switch (this.dataType) {
  211. // Float
  212. case Animation.ANIMATIONTYPE_FLOAT:
  213. switch (loopMode) {
  214. case Animation.ANIMATIONLOOPMODE_CYCLE:
  215. case Animation.ANIMATIONLOOPMODE_CONSTANT:
  216. return this.floatInterpolateFunction(startValue, endValue, gradient);
  217. case Animation.ANIMATIONLOOPMODE_RELATIVE:
  218. return offsetValue * repeatCount + this.floatInterpolateFunction(startValue, endValue, gradient);
  219. }
  220. break;
  221. // Quaternion
  222. case Animation.ANIMATIONTYPE_QUATERNION:
  223. var quaternion = null;
  224. switch (loopMode) {
  225. case Animation.ANIMATIONLOOPMODE_CYCLE:
  226. case Animation.ANIMATIONLOOPMODE_CONSTANT:
  227. quaternion = this.quaternionInterpolateFunction(startValue, endValue, gradient);
  228. break;
  229. case Animation.ANIMATIONLOOPMODE_RELATIVE:
  230. quaternion = this.quaternionInterpolateFunction(startValue, endValue, gradient).add(offsetValue.scale(repeatCount));
  231. break;
  232. }
  233. return quaternion;
  234. // Vector3
  235. case Animation.ANIMATIONTYPE_VECTOR3:
  236. switch (loopMode) {
  237. case Animation.ANIMATIONLOOPMODE_CYCLE:
  238. case Animation.ANIMATIONLOOPMODE_CONSTANT:
  239. return this.vector3InterpolateFunction(startValue, endValue, gradient);
  240. case Animation.ANIMATIONLOOPMODE_RELATIVE:
  241. return this.vector3InterpolateFunction(startValue, endValue, gradient).add(offsetValue.scale(repeatCount));
  242. }
  243. // Vector2
  244. case Animation.ANIMATIONTYPE_VECTOR2:
  245. switch (loopMode) {
  246. case Animation.ANIMATIONLOOPMODE_CYCLE:
  247. case Animation.ANIMATIONLOOPMODE_CONSTANT:
  248. return this.vector2InterpolateFunction(startValue, endValue, gradient);
  249. case Animation.ANIMATIONLOOPMODE_RELATIVE:
  250. return this.vector2InterpolateFunction(startValue, endValue, gradient).add(offsetValue.scale(repeatCount));
  251. }
  252. // Color3
  253. case Animation.ANIMATIONTYPE_COLOR3:
  254. switch (loopMode) {
  255. case Animation.ANIMATIONLOOPMODE_CYCLE:
  256. case Animation.ANIMATIONLOOPMODE_CONSTANT:
  257. return this.color3InterpolateFunction(startValue, endValue, gradient);
  258. case Animation.ANIMATIONLOOPMODE_RELATIVE:
  259. return this.color3InterpolateFunction(startValue, endValue, gradient).add(offsetValue.scale(repeatCount));
  260. }
  261. // Matrix
  262. case Animation.ANIMATIONTYPE_MATRIX:
  263. switch (loopMode) {
  264. case Animation.ANIMATIONLOOPMODE_CYCLE:
  265. case Animation.ANIMATIONLOOPMODE_CONSTANT:
  266. if (this.allowMatricesInterpolation) {
  267. return this.matrixInterpolateFunction(startValue, endValue, gradient);
  268. }
  269. case Animation.ANIMATIONLOOPMODE_RELATIVE:
  270. return startValue;
  271. }
  272. default:
  273. break;
  274. }
  275. break;
  276. }
  277. }
  278. return this._getKeyValue(this._keys[this._keys.length - 1].value);
  279. };
  280. Animation.prototype.setValue = function (currentValue) {
  281. // Set value
  282. if (this.targetPropertyPath.length > 1) {
  283. var property = this._target[this.targetPropertyPath[0]];
  284. for (var index = 1; index < this.targetPropertyPath.length - 1; index++) {
  285. property = property[this.targetPropertyPath[index]];
  286. }
  287. property[this.targetPropertyPath[this.targetPropertyPath.length - 1]] = currentValue;
  288. }
  289. else {
  290. this._target[this.targetPropertyPath[0]] = currentValue;
  291. }
  292. if (this._target.markAsDirty) {
  293. this._target.markAsDirty(this.targetProperty);
  294. }
  295. };
  296. Animation.prototype.goToFrame = function (frame) {
  297. if (frame < this._keys[0].frame) {
  298. frame = this._keys[0].frame;
  299. }
  300. else if (frame > this._keys[this._keys.length - 1].frame) {
  301. frame = this._keys[this._keys.length - 1].frame;
  302. }
  303. var currentValue = this._interpolate(frame, 0, this.loopMode);
  304. this.setValue(currentValue);
  305. };
  306. Animation.prototype.animate = function (delay, from, to, loop, speedRatio) {
  307. if (!this.targetPropertyPath || this.targetPropertyPath.length < 1) {
  308. this._stopped = true;
  309. return false;
  310. }
  311. var returnValue = true;
  312. // Adding a start key at frame 0 if missing
  313. if (this._keys[0].frame !== 0) {
  314. var newKey = { frame: 0, value: this._keys[0].value };
  315. this._keys.splice(0, 0, newKey);
  316. }
  317. // Check limits
  318. if (from < this._keys[0].frame || from > this._keys[this._keys.length - 1].frame) {
  319. from = this._keys[0].frame;
  320. }
  321. if (to < this._keys[0].frame || to > this._keys[this._keys.length - 1].frame) {
  322. to = this._keys[this._keys.length - 1].frame;
  323. }
  324. // Compute ratio
  325. var range = to - from;
  326. var offsetValue;
  327. // ratio represents the frame delta between from and to
  328. var ratio = delay * (this.framePerSecond * speedRatio) / 1000.0;
  329. var highLimitValue = 0;
  330. if (ratio > range && !loop) {
  331. returnValue = false;
  332. highLimitValue = this._getKeyValue(this._keys[this._keys.length - 1].value);
  333. }
  334. else {
  335. // Get max value if required
  336. if (this.loopMode !== Animation.ANIMATIONLOOPMODE_CYCLE) {
  337. var keyOffset = to.toString() + from.toString();
  338. if (!this._offsetsCache[keyOffset]) {
  339. var fromValue = this._interpolate(from, 0, Animation.ANIMATIONLOOPMODE_CYCLE);
  340. var toValue = this._interpolate(to, 0, Animation.ANIMATIONLOOPMODE_CYCLE);
  341. switch (this.dataType) {
  342. // Float
  343. case Animation.ANIMATIONTYPE_FLOAT:
  344. this._offsetsCache[keyOffset] = toValue - fromValue;
  345. break;
  346. // Quaternion
  347. case Animation.ANIMATIONTYPE_QUATERNION:
  348. this._offsetsCache[keyOffset] = toValue.subtract(fromValue);
  349. break;
  350. // Vector3
  351. case Animation.ANIMATIONTYPE_VECTOR3:
  352. this._offsetsCache[keyOffset] = toValue.subtract(fromValue);
  353. // Vector2
  354. case Animation.ANIMATIONTYPE_VECTOR2:
  355. this._offsetsCache[keyOffset] = toValue.subtract(fromValue);
  356. // Color3
  357. case Animation.ANIMATIONTYPE_COLOR3:
  358. this._offsetsCache[keyOffset] = toValue.subtract(fromValue);
  359. default:
  360. break;
  361. }
  362. this._highLimitsCache[keyOffset] = toValue;
  363. }
  364. highLimitValue = this._highLimitsCache[keyOffset];
  365. offsetValue = this._offsetsCache[keyOffset];
  366. }
  367. }
  368. if (offsetValue === undefined) {
  369. switch (this.dataType) {
  370. // Float
  371. case Animation.ANIMATIONTYPE_FLOAT:
  372. offsetValue = 0;
  373. break;
  374. // Quaternion
  375. case Animation.ANIMATIONTYPE_QUATERNION:
  376. offsetValue = new BABYLON.Quaternion(0, 0, 0, 0);
  377. break;
  378. // Vector3
  379. case Animation.ANIMATIONTYPE_VECTOR3:
  380. offsetValue = BABYLON.Vector3.Zero();
  381. break;
  382. // Vector2
  383. case Animation.ANIMATIONTYPE_VECTOR2:
  384. offsetValue = BABYLON.Vector2.Zero();
  385. break;
  386. // Color3
  387. case Animation.ANIMATIONTYPE_COLOR3:
  388. offsetValue = BABYLON.Color3.Black();
  389. }
  390. }
  391. // Compute value
  392. var repeatCount = (ratio / range) >> 0;
  393. var currentFrame = returnValue ? from + ratio % range : to;
  394. var currentValue = this._interpolate(currentFrame, repeatCount, this.loopMode, offsetValue, highLimitValue);
  395. // Check events
  396. for (var index = 0; index < this._events.length; index++) {
  397. if (currentFrame >= this._events[index].frame) {
  398. var event = this._events[index];
  399. if (!event.isDone) {
  400. // If event should be done only once, remove it.
  401. if (event.onlyOnce) {
  402. this._events.splice(index, 1);
  403. index--;
  404. }
  405. event.isDone = true;
  406. event.action();
  407. } // Don't do anything if the event has already be done.
  408. }
  409. else if (this._events[index].isDone && !this._events[index].onlyOnce) {
  410. // reset event, the animation is looping
  411. this._events[index].isDone = false;
  412. }
  413. }
  414. // Set value
  415. this.setValue(currentValue);
  416. if (!returnValue) {
  417. this._stopped = true;
  418. }
  419. return returnValue;
  420. };
  421. Animation.prototype.serialize = function () {
  422. var serializationObject = {};
  423. serializationObject.name = this.name;
  424. serializationObject.property = this.targetProperty;
  425. serializationObject.framePerSecond = this.framePerSecond;
  426. serializationObject.dataType = this.dataType;
  427. serializationObject.loopBehavior = this.loopMode;
  428. var dataType = this.dataType;
  429. serializationObject.keys = [];
  430. var keys = this.getKeys();
  431. for (var index = 0; index < keys.length; index++) {
  432. var animationKey = keys[index];
  433. var key = {};
  434. key.frame = animationKey.frame;
  435. switch (dataType) {
  436. case Animation.ANIMATIONTYPE_FLOAT:
  437. key.values = [animationKey.value];
  438. break;
  439. case Animation.ANIMATIONTYPE_QUATERNION:
  440. case Animation.ANIMATIONTYPE_MATRIX:
  441. case Animation.ANIMATIONTYPE_VECTOR3:
  442. case Animation.ANIMATIONTYPE_COLOR3:
  443. key.values = animationKey.value.asArray();
  444. break;
  445. }
  446. serializationObject.keys.push(key);
  447. }
  448. serializationObject.ranges = [];
  449. for (var name in this._ranges) {
  450. var range = {};
  451. range.name = name;
  452. range.from = this._ranges[name].from;
  453. range.to = this._ranges[name].to;
  454. serializationObject.ranges.push(range);
  455. }
  456. return serializationObject;
  457. };
  458. Object.defineProperty(Animation, "ANIMATIONTYPE_FLOAT", {
  459. get: function () {
  460. return Animation._ANIMATIONTYPE_FLOAT;
  461. },
  462. enumerable: true,
  463. configurable: true
  464. });
  465. Object.defineProperty(Animation, "ANIMATIONTYPE_VECTOR3", {
  466. get: function () {
  467. return Animation._ANIMATIONTYPE_VECTOR3;
  468. },
  469. enumerable: true,
  470. configurable: true
  471. });
  472. Object.defineProperty(Animation, "ANIMATIONTYPE_VECTOR2", {
  473. get: function () {
  474. return Animation._ANIMATIONTYPE_VECTOR2;
  475. },
  476. enumerable: true,
  477. configurable: true
  478. });
  479. Object.defineProperty(Animation, "ANIMATIONTYPE_QUATERNION", {
  480. get: function () {
  481. return Animation._ANIMATIONTYPE_QUATERNION;
  482. },
  483. enumerable: true,
  484. configurable: true
  485. });
  486. Object.defineProperty(Animation, "ANIMATIONTYPE_MATRIX", {
  487. get: function () {
  488. return Animation._ANIMATIONTYPE_MATRIX;
  489. },
  490. enumerable: true,
  491. configurable: true
  492. });
  493. Object.defineProperty(Animation, "ANIMATIONTYPE_COLOR3", {
  494. get: function () {
  495. return Animation._ANIMATIONTYPE_COLOR3;
  496. },
  497. enumerable: true,
  498. configurable: true
  499. });
  500. Object.defineProperty(Animation, "ANIMATIONLOOPMODE_RELATIVE", {
  501. get: function () {
  502. return Animation._ANIMATIONLOOPMODE_RELATIVE;
  503. },
  504. enumerable: true,
  505. configurable: true
  506. });
  507. Object.defineProperty(Animation, "ANIMATIONLOOPMODE_CYCLE", {
  508. get: function () {
  509. return Animation._ANIMATIONLOOPMODE_CYCLE;
  510. },
  511. enumerable: true,
  512. configurable: true
  513. });
  514. Object.defineProperty(Animation, "ANIMATIONLOOPMODE_CONSTANT", {
  515. get: function () {
  516. return Animation._ANIMATIONLOOPMODE_CONSTANT;
  517. },
  518. enumerable: true,
  519. configurable: true
  520. });
  521. Animation.Parse = function (parsedAnimation) {
  522. var animation = new Animation(parsedAnimation.name, parsedAnimation.property, parsedAnimation.framePerSecond, parsedAnimation.dataType, parsedAnimation.loopBehavior);
  523. var dataType = parsedAnimation.dataType;
  524. var keys = [];
  525. for (var index = 0; index < parsedAnimation.keys.length; index++) {
  526. var key = parsedAnimation.keys[index];
  527. var data;
  528. switch (dataType) {
  529. case Animation.ANIMATIONTYPE_FLOAT:
  530. data = key.values[0];
  531. break;
  532. case Animation.ANIMATIONTYPE_QUATERNION:
  533. data = BABYLON.Quaternion.FromArray(key.values);
  534. break;
  535. case Animation.ANIMATIONTYPE_MATRIX:
  536. data = BABYLON.Matrix.FromArray(key.values);
  537. break;
  538. case Animation.ANIMATIONTYPE_COLOR3:
  539. data = BABYLON.Color3.FromArray(key.values);
  540. break;
  541. case Animation.ANIMATIONTYPE_VECTOR3:
  542. default:
  543. data = BABYLON.Vector3.FromArray(key.values);
  544. break;
  545. }
  546. keys.push({
  547. frame: key.frame,
  548. value: data
  549. });
  550. }
  551. animation.setKeys(keys);
  552. if (parsedAnimation.ranges) {
  553. for (var index = 0; index < parsedAnimation.ranges.length; index++) {
  554. data = parsedAnimation.ranges[index];
  555. animation.createRange(data.name, data.from, data.to);
  556. }
  557. }
  558. return animation;
  559. };
  560. Animation.AppendSerializedAnimations = function (source, destination) {
  561. if (source.animations) {
  562. destination.animations = [];
  563. for (var animationIndex = 0; animationIndex < source.animations.length; animationIndex++) {
  564. var animation = source.animations[animationIndex];
  565. destination.animations.push(animation.serialize());
  566. }
  567. }
  568. };
  569. // Statics
  570. Animation._ANIMATIONTYPE_FLOAT = 0;
  571. Animation._ANIMATIONTYPE_VECTOR3 = 1;
  572. Animation._ANIMATIONTYPE_QUATERNION = 2;
  573. Animation._ANIMATIONTYPE_MATRIX = 3;
  574. Animation._ANIMATIONTYPE_COLOR3 = 4;
  575. Animation._ANIMATIONTYPE_VECTOR2 = 5;
  576. Animation._ANIMATIONLOOPMODE_RELATIVE = 0;
  577. Animation._ANIMATIONLOOPMODE_CYCLE = 1;
  578. Animation._ANIMATIONLOOPMODE_CONSTANT = 2;
  579. return Animation;
  580. })();
  581. BABYLON.Animation = Animation;
  582. })(BABYLON || (BABYLON = {}));