|
@@ -4,14 +4,15 @@ module BABYLON {
|
|
|
public targetMesh: AbstractMesh;
|
|
|
public poleTargetMesh: AbstractMesh;
|
|
|
public poleTargetBone: Bone;
|
|
|
-
|
|
|
public targetPosition = Vector3.Zero();
|
|
|
public poleTargetPosition = Vector3.Zero();
|
|
|
-
|
|
|
public poleTargetLocalOffset = Vector3.Zero();
|
|
|
public poleAngle = 0;
|
|
|
-
|
|
|
public mesh: AbstractMesh;
|
|
|
+ public slerpGradient = 1;
|
|
|
+
|
|
|
+ private _bone1Quat: Quaternion = Quaternion.Identity();
|
|
|
+ private _bone2Ang = Math.PI;
|
|
|
|
|
|
private _bone1: Bone;
|
|
|
private _bone2: Bone;
|
|
@@ -25,13 +26,14 @@ module BABYLON {
|
|
|
private _tmpVec3 = Vector3.Zero();
|
|
|
private _tmpVec4 = Vector3.Zero();
|
|
|
private _tmpVec5 = Vector3.Zero();
|
|
|
-
|
|
|
private _tmpMat1 = Matrix.Identity();
|
|
|
private _tmpMat2 = Matrix.Identity();
|
|
|
+ private _tmpQuat1 = Quaternion.Identity();
|
|
|
|
|
|
private _rightHandedSystem = false;
|
|
|
|
|
|
private _bendAxis = Vector3.Right();
|
|
|
+ private _slerping = false;
|
|
|
|
|
|
get maxAngle(): number {
|
|
|
|
|
@@ -45,7 +47,7 @@ module BABYLON {
|
|
|
|
|
|
}
|
|
|
|
|
|
- constructor(mesh: AbstractMesh, bone: Bone, options?: { targetMesh?: AbstractMesh, poleTargetMesh?: AbstractMesh, poleTargetBone?: Bone, poleTargetLocalOffset?:Vector3, poleAngle?: number, bendAxis?: Vector3, maxAngle?:number }){
|
|
|
+ constructor(mesh: AbstractMesh, bone: Bone, options?: { targetMesh?: AbstractMesh, poleTargetMesh?: AbstractMesh, poleTargetBone?: Bone, poleTargetLocalOffset?:Vector3, poleAngle?: number, bendAxis?: Vector3, maxAngle?:number, slerpGradient?:number }){
|
|
|
|
|
|
this._bone2 = bone;
|
|
|
this._bone1 = bone.getParent();
|
|
@@ -120,6 +122,10 @@ module BABYLON {
|
|
|
this.maxAngle = options.maxAngle;
|
|
|
}
|
|
|
|
|
|
+ if(options.slerpGradient){
|
|
|
+ this.slerpGradient = options.slerpGradient;
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
}
|
|
@@ -230,7 +236,7 @@ module BABYLON {
|
|
|
Matrix.RotationAxisToRef(this._bendAxis, angB, mat2);
|
|
|
mat2.multiplyToRef(mat1, mat1);
|
|
|
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
|
|
|
this._tmpVec1.copyFrom(this._bendAxis);
|
|
|
this._tmpVec1.x *= -1;
|
|
@@ -245,8 +251,22 @@ module BABYLON {
|
|
|
mat1.multiplyToRef(mat2, mat1);
|
|
|
}
|
|
|
|
|
|
- this._bone1.setRotationMatrix(mat1, Space.WORLD, this.mesh);
|
|
|
+ if(this.slerpGradient < 1){
|
|
|
+ if(!this._slerping){
|
|
|
+ this._bone1.getRotationQuaternionToRef(Space.WORLD, this.mesh, this._bone1Quat);
|
|
|
+ }
|
|
|
+ Quaternion.FromRotationMatrixToRef(mat1, this._tmpQuat1);
|
|
|
+ Quaternion.SlerpToRef(this._bone1Quat, this._tmpQuat1, this.slerpGradient, this._bone1Quat);
|
|
|
+ angC = this._bone2Ang * (1.0 - this.slerpGradient) + angC * this.slerpGradient;
|
|
|
+ this._bone1.setRotationQuaternion(this._bone1Quat, Space.WORLD, this.mesh);
|
|
|
+ this._slerping = true;
|
|
|
+ } else {
|
|
|
+ this._bone1.setRotationMatrix(mat1, Space.WORLD, this.mesh);
|
|
|
+ this._slerping = false;
|
|
|
+ }
|
|
|
+
|
|
|
this._bone2.setAxisAngle(this._bendAxis, angC, Space.LOCAL);
|
|
|
+ this._bone2Ang = angC;
|
|
|
|
|
|
}
|
|
|
|