|
@@ -5,12 +5,12 @@
|
|
private _highLimitsCache = {};
|
|
private _highLimitsCache = {};
|
|
private _stopped = false;
|
|
private _stopped = false;
|
|
public _target;
|
|
public _target;
|
|
- private _easingFunction: BABYLON.IEasingFunction;
|
|
|
|
|
|
+ private _easingFunction: IEasingFunction;
|
|
|
|
|
|
public targetPropertyPath: string[];
|
|
public targetPropertyPath: string[];
|
|
public currentFrame: number;
|
|
public currentFrame: number;
|
|
|
|
|
|
- public static CreateAndStartAnimation(name: string, mesh: BABYLON.AbstractMesh, tartgetProperty: string,
|
|
|
|
|
|
+ public static CreateAndStartAnimation(name: string, mesh: AbstractMesh, tartgetProperty: string,
|
|
framePerSecond: number, totalFrame: number,
|
|
framePerSecond: number, totalFrame: number,
|
|
from: any, to: any, loopMode?: number) {
|
|
from: any, to: any, loopMode?: number) {
|
|
|
|
|
|
@@ -18,13 +18,13 @@
|
|
|
|
|
|
if (!isNaN(parseFloat(from)) && isFinite(from)) {
|
|
if (!isNaN(parseFloat(from)) && isFinite(from)) {
|
|
dataType = Animation.ANIMATIONTYPE_FLOAT;
|
|
dataType = Animation.ANIMATIONTYPE_FLOAT;
|
|
- } else if (from instanceof BABYLON.Quaternion) {
|
|
|
|
|
|
+ } else if (from instanceof Quaternion) {
|
|
dataType = Animation.ANIMATIONTYPE_QUATERNION;
|
|
dataType = Animation.ANIMATIONTYPE_QUATERNION;
|
|
- } else if (from instanceof BABYLON.Vector3) {
|
|
|
|
|
|
+ } else if (from instanceof Vector3) {
|
|
dataType = Animation.ANIMATIONTYPE_VECTOR3;
|
|
dataType = Animation.ANIMATIONTYPE_VECTOR3;
|
|
- } else if (from instanceof BABYLON.Vector2) {
|
|
|
|
|
|
+ } else if (from instanceof Vector2) {
|
|
dataType = Animation.ANIMATIONTYPE_VECTOR2;
|
|
dataType = Animation.ANIMATIONTYPE_VECTOR2;
|
|
- } else if (from instanceof BABYLON.Color3) {
|
|
|
|
|
|
+ } else if (from instanceof Color3) {
|
|
dataType = Animation.ANIMATIONTYPE_COLOR3;
|
|
dataType = Animation.ANIMATIONTYPE_COLOR3;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -41,11 +41,10 @@
|
|
|
|
|
|
mesh.animations.push(animation);
|
|
mesh.animations.push(animation);
|
|
|
|
|
|
- mesh.getScene().beginAnimation(mesh, 0, totalFrame, (animation.loopMode == 1));
|
|
|
|
|
|
+ mesh.getScene().beginAnimation(mesh, 0, totalFrame, (animation.loopMode === 1));
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
constructor(public name: string, public targetProperty: string, public framePerSecond: number, public dataType: number, public loopMode?: number) {
|
|
constructor(public name: string, public targetProperty: string, public framePerSecond: number, public dataType: number, public loopMode?: number) {
|
|
this.targetPropertyPath = targetProperty.split(".");
|
|
this.targetPropertyPath = targetProperty.split(".");
|
|
this.dataType = dataType;
|
|
this.dataType = dataType;
|
|
@@ -65,7 +64,7 @@
|
|
return this._easingFunction;
|
|
return this._easingFunction;
|
|
}
|
|
}
|
|
|
|
|
|
- public setEasingFunction(easingFunction: BABYLON.EasingFunction) {
|
|
|
|
|
|
+ public setEasingFunction(easingFunction: EasingFunction) {
|
|
this._easingFunction = easingFunction;
|
|
this._easingFunction = easingFunction;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -74,19 +73,19 @@
|
|
}
|
|
}
|
|
|
|
|
|
public quaternionInterpolateFunction(startValue: Quaternion, endValue: Quaternion, gradient: number): Quaternion {
|
|
public quaternionInterpolateFunction(startValue: Quaternion, endValue: Quaternion, gradient: number): Quaternion {
|
|
- return BABYLON.Quaternion.Slerp(startValue, endValue, gradient);
|
|
|
|
|
|
+ return Quaternion.Slerp(startValue, endValue, gradient);
|
|
}
|
|
}
|
|
|
|
|
|
public vector3InterpolateFunction(startValue: Vector3, endValue: Vector3, gradient: number): Vector3 {
|
|
public vector3InterpolateFunction(startValue: Vector3, endValue: Vector3, gradient: number): Vector3 {
|
|
- return BABYLON.Vector3.Lerp(startValue, endValue, gradient);
|
|
|
|
|
|
+ return Vector3.Lerp(startValue, endValue, gradient);
|
|
}
|
|
}
|
|
|
|
|
|
public vector2InterpolateFunction(startValue: Vector2, endValue: Vector2, gradient: number): Vector2 {
|
|
public vector2InterpolateFunction(startValue: Vector2, endValue: Vector2, gradient: number): Vector2 {
|
|
- return BABYLON.Vector2.Lerp(startValue, endValue, gradient);
|
|
|
|
|
|
+ return Vector2.Lerp(startValue, endValue, gradient);
|
|
}
|
|
}
|
|
|
|
|
|
public color3InterpolateFunction(startValue: Color3, endValue: Color3, gradient: number): Color3 {
|
|
public color3InterpolateFunction(startValue: Color3, endValue: Color3, gradient: number): Color3 {
|
|
- return BABYLON.Color3.Lerp(startValue, endValue, gradient);
|
|
|
|
|
|
+ return Color3.Lerp(startValue, endValue, gradient);
|
|
}
|
|
}
|
|
|
|
|
|
public clone(): Animation {
|
|
public clone(): Animation {
|
|
@@ -103,6 +102,13 @@
|
|
this._highLimitsCache = {};
|
|
this._highLimitsCache = {};
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private _getKeyValue(value: any): any {
|
|
|
|
+ if (typeof value === "function") {
|
|
|
|
+ return value();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return value;
|
|
|
|
+ }
|
|
|
|
|
|
private _interpolate(currentFrame: number, repeatCount: number, loopMode: number, offsetValue?, highLimitValue?) {
|
|
private _interpolate(currentFrame: number, repeatCount: number, loopMode: number, offsetValue?, highLimitValue?) {
|
|
if (loopMode === Animation.ANIMATIONLOOPMODE_CONSTANT && repeatCount > 0) {
|
|
if (loopMode === Animation.ANIMATIONLOOPMODE_CONSTANT && repeatCount > 0) {
|
|
@@ -115,8 +121,8 @@
|
|
// for each frame, we need the key just before the frame superior
|
|
// for each frame, we need the key just before the frame superior
|
|
if (this._keys[key + 1].frame >= currentFrame) {
|
|
if (this._keys[key + 1].frame >= currentFrame) {
|
|
|
|
|
|
- var startValue = this._keys[key].value;
|
|
|
|
- var endValue = this._keys[key + 1].value;
|
|
|
|
|
|
+ var startValue = this._getKeyValue(this._keys[key].value);
|
|
|
|
+ var endValue = this._getKeyValue(this._keys[key + 1].value);
|
|
|
|
|
|
// gradient : percent of currentFrame between the frame inf and the frame sup
|
|
// gradient : percent of currentFrame between the frame inf and the frame sup
|
|
var gradient = (currentFrame - this._keys[key].frame) / (this._keys[key + 1].frame - this._keys[key].frame);
|
|
var gradient = (currentFrame - this._keys[key].frame) / (this._keys[key + 1].frame - this._keys[key].frame);
|
|
@@ -192,7 +198,7 @@
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- return this._keys[this._keys.length - 1].value;
|
|
|
|
|
|
+ return this._getKeyValue(this._keys[this._keys.length - 1].value);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -204,7 +210,7 @@
|
|
var returnValue = true;
|
|
var returnValue = true;
|
|
|
|
|
|
// Adding a start key at frame 0 if missing
|
|
// Adding a start key at frame 0 if missing
|
|
- if (this._keys[0].frame != 0) {
|
|
|
|
|
|
+ if (this._keys[0].frame !== 0) {
|
|
var newKey = { frame: 0, value: this._keys[0].value };
|
|
var newKey = { frame: 0, value: this._keys[0].value };
|
|
this._keys.splice(0, 0, newKey);
|
|
this._keys.splice(0, 0, newKey);
|
|
}
|
|
}
|
|
@@ -222,15 +228,15 @@
|
|
var offsetValue;
|
|
var offsetValue;
|
|
// ratio represents the frame delta between from and to
|
|
// ratio represents the frame delta between from and to
|
|
var ratio = delay * (this.framePerSecond * speedRatio) / 1000.0;
|
|
var ratio = delay * (this.framePerSecond * speedRatio) / 1000.0;
|
|
|
|
+ var highLimitValue = 0;
|
|
|
|
|
|
if (ratio > range && !loop) { // If we are out of range and not looping get back to caller
|
|
if (ratio > range && !loop) { // If we are out of range and not looping get back to caller
|
|
returnValue = false;
|
|
returnValue = false;
|
|
- highLimitValue = this._keys[this._keys.length - 1].value;
|
|
|
|
|
|
+ highLimitValue = this._getKeyValue(this._keys[this._keys.length - 1].value);
|
|
} else {
|
|
} else {
|
|
// Get max value if required
|
|
// Get max value if required
|
|
- var highLimitValue = 0;
|
|
|
|
|
|
|
|
- if (this.loopMode != Animation.ANIMATIONLOOPMODE_CYCLE) {
|
|
|
|
|
|
+ if (this.loopMode !== Animation.ANIMATIONLOOPMODE_CYCLE) {
|
|
|
|
|
|
var keyOffset = to.toString() + from.toString();
|
|
var keyOffset = to.toString() + from.toString();
|
|
if (!this._offsetsCache[keyOffset]) {
|
|
if (!this._offsetsCache[keyOffset]) {
|