babylon.interpolateValueAction.ts 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. module BABYLON {
  2. export class InterpolateValueAction extends Action {
  3. private _target: any;
  4. private _property: string;
  5. constructor(triggerOptions: any, target: any, public propertyPath: string, public value: any, public duration: number = 1000, condition?: Condition, public stopOtherAnimations?: boolean) {
  6. super(triggerOptions, condition);
  7. this._target = target;
  8. }
  9. public _prepare(): void {
  10. this._target = this._getEffectiveTarget(this._target, this.propertyPath);
  11. this._property = this._getProperty(this.propertyPath);
  12. }
  13. public execute(): void {
  14. var scene = this._actionManager.getScene();
  15. var keys = [
  16. {
  17. frame: 0,
  18. value: this._target[this._property]
  19. }, {
  20. frame: 100,
  21. value: this.value
  22. }
  23. ];
  24. var dataType: number;
  25. if (typeof this.value === "number") {
  26. dataType = Animation.ANIMATIONTYPE_FLOAT;
  27. } else if (this.value instanceof Color3) {
  28. dataType = Animation.ANIMATIONTYPE_COLOR3;
  29. } else if (this.value instanceof Vector3) {
  30. dataType = Animation.ANIMATIONTYPE_VECTOR3;
  31. } else if (this.value instanceof Matrix) {
  32. dataType = Animation.ANIMATIONTYPE_MATRIX;
  33. } else if (this.value instanceof Quaternion) {
  34. dataType = Animation.ANIMATIONTYPE_QUATERNION;
  35. } else {
  36. Tools.Warn("InterpolateValueAction: Unsupported type (" + typeof this.value + ")");
  37. return;
  38. }
  39. var animation = new Animation("InterpolateValueAction", this._property, 100 * (1000.0 / this.duration), dataType, Animation.ANIMATIONLOOPMODE_CONSTANT);
  40. animation.setKeys(keys);
  41. if (this.stopOtherAnimations) {
  42. scene.stopAnimation(this._target);
  43. }
  44. scene.beginDirectAnimation(this._target, [animation], 0, 100);
  45. }
  46. }
  47. }