babylon.interpolateValueAction.js 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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) {
  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._target = target;
  18. }
  19. InterpolateValueAction.prototype._prepare = function () {
  20. this._target = this._getEffectiveTarget(this._target, this.propertyPath);
  21. this._property = this._getProperty(this.propertyPath);
  22. };
  23. InterpolateValueAction.prototype.execute = function () {
  24. var scene = this._actionManager.getScene();
  25. var keys = [
  26. {
  27. frame: 0,
  28. value: this._target[this._property]
  29. }, {
  30. frame: 100,
  31. value: this.value
  32. }
  33. ];
  34. var dataType;
  35. if (typeof this.value === "number") {
  36. dataType = BABYLON.Animation.ANIMATIONTYPE_FLOAT;
  37. }
  38. else if (this.value instanceof BABYLON.Color3) {
  39. dataType = BABYLON.Animation.ANIMATIONTYPE_COLOR3;
  40. }
  41. else if (this.value instanceof BABYLON.Vector3) {
  42. dataType = BABYLON.Animation.ANIMATIONTYPE_VECTOR3;
  43. }
  44. else if (this.value instanceof BABYLON.Matrix) {
  45. dataType = BABYLON.Animation.ANIMATIONTYPE_MATRIX;
  46. }
  47. else if (this.value instanceof BABYLON.Quaternion) {
  48. dataType = BABYLON.Animation.ANIMATIONTYPE_QUATERNION;
  49. }
  50. else {
  51. BABYLON.Tools.Warn("InterpolateValueAction: Unsupported type (" + typeof this.value + ")");
  52. return;
  53. }
  54. var animation = new BABYLON.Animation("InterpolateValueAction", this._property, 100 * (1000.0 / this.duration), dataType, BABYLON.Animation.ANIMATIONLOOPMODE_CONSTANT);
  55. animation.setKeys(keys);
  56. if (this.stopOtherAnimations) {
  57. scene.stopAnimation(this._target);
  58. }
  59. scene.beginDirectAnimation(this._target, [animation], 0, 100);
  60. };
  61. return InterpolateValueAction;
  62. })(BABYLON.Action);
  63. BABYLON.InterpolateValueAction = InterpolateValueAction;
  64. })(BABYLON || (BABYLON = {}));