babylon.interpolateValueAction.ts 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. module BABYLON {
  2. export class InterpolateValueAction extends Action {
  3. private _target: any;
  4. private _property: string;
  5. constructor(trigger: number, public targetType: number, public targetName: string, public propertyPath: string, public value: any, public duration: number = 1000, condition?: Condition) {
  6. super(trigger, condition);
  7. }
  8. public _prepare(): void {
  9. this._target = this._getTarget(this.targetType, this.targetName);
  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 = Animation.ANIMATIONTYPE_FLOAT;
  25. if (this.value instanceof Color3) {
  26. dataType = Animation.ANIMATIONTYPE_COLOR3;
  27. } else if (this.value instanceof Vector3) {
  28. dataType = Animation.ANIMATIONTYPE_VECTOR3;
  29. } else if (this.value instanceof Matrix) {
  30. dataType = Animation.ANIMATIONTYPE_MATRIX;
  31. } else if (this.value instanceof Quaternion) {
  32. dataType = Animation.ANIMATIONTYPE_QUATERNION;
  33. }
  34. var animation = new BABYLON.Animation("InterpolateValueAction", this._property, 100 * (1000.0 / this.duration), dataType, Animation.ANIMATIONLOOPMODE_CONSTANT);
  35. animation.setKeys(keys);
  36. scene.beginDirectAnimation(this._target, [animation], 0, 100);
  37. }
  38. }
  39. }