babylon.interpolateValueAction.js 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 InterpolateValueAction = (function (_super) {
  9. __extends(InterpolateValueAction, _super);
  10. function InterpolateValueAction(triggerOptions, target, propertyPath, value, duration, condition, stopOtherAnimations, onInterpolationDone) {
  11. if (duration === void 0) { duration = 1000; }
  12. _super.call(this, triggerOptions, condition);
  13. this.propertyPath = propertyPath;
  14. this.value = value;
  15. this.duration = duration;
  16. this.stopOtherAnimations = stopOtherAnimations;
  17. this.onInterpolationDone = onInterpolationDone;
  18. this._target = this._effectiveTarget = target;
  19. }
  20. InterpolateValueAction.prototype._prepare = function () {
  21. this._effectiveTarget = this._getEffectiveTarget(this._effectiveTarget, this.propertyPath);
  22. this._property = this._getProperty(this.propertyPath);
  23. };
  24. InterpolateValueAction.prototype.execute = function () {
  25. var scene = this._actionManager.getScene();
  26. var keys = [
  27. {
  28. frame: 0,
  29. value: this._effectiveTarget[this._property]
  30. }, {
  31. frame: 100,
  32. value: this.value
  33. }
  34. ];
  35. var dataType;
  36. if (typeof this.value === "number") {
  37. dataType = BABYLON.Animation.ANIMATIONTYPE_FLOAT;
  38. }
  39. else if (this.value instanceof BABYLON.Color3) {
  40. dataType = BABYLON.Animation.ANIMATIONTYPE_COLOR3;
  41. }
  42. else if (this.value instanceof BABYLON.Vector3) {
  43. dataType = BABYLON.Animation.ANIMATIONTYPE_VECTOR3;
  44. }
  45. else if (this.value instanceof BABYLON.Matrix) {
  46. dataType = BABYLON.Animation.ANIMATIONTYPE_MATRIX;
  47. }
  48. else if (this.value instanceof BABYLON.Quaternion) {
  49. dataType = BABYLON.Animation.ANIMATIONTYPE_QUATERNION;
  50. }
  51. else {
  52. BABYLON.Tools.Warn("InterpolateValueAction: Unsupported type (" + typeof this.value + ")");
  53. return;
  54. }
  55. var animation = new BABYLON.Animation("InterpolateValueAction", this._property, 100 * (1000.0 / this.duration), dataType, BABYLON.Animation.ANIMATIONLOOPMODE_CONSTANT);
  56. animation.setKeys(keys);
  57. if (this.stopOtherAnimations) {
  58. scene.stopAnimation(this._effectiveTarget);
  59. }
  60. scene.beginDirectAnimation(this._effectiveTarget, [animation], 0, 100, false, 1, this.onInterpolationDone);
  61. };
  62. InterpolateValueAction.prototype.serialize = function (parent) {
  63. return _super.prototype._serialize.call(this, {
  64. name: "InterpolateValueAction",
  65. properties: [
  66. BABYLON.Action._GetTargetProperty(this._target),
  67. { name: "propertyPath", value: this.propertyPath },
  68. { name: "value", value: BABYLON.Action._SerializeValueAsString(this.value) },
  69. { name: "duration", value: BABYLON.Action._SerializeValueAsString(this.duration) },
  70. { name: "stopOtherAnimations", value: BABYLON.Action._SerializeValueAsString(this.stopOtherAnimations) || false }
  71. ]
  72. }, parent);
  73. };
  74. return InterpolateValueAction;
  75. })(BABYLON.Action);
  76. BABYLON.InterpolateValueAction = InterpolateValueAction;
  77. })(BABYLON || (BABYLON = {}));