|
@@ -162,8 +162,8 @@ module BABYLON {
|
|
|
public set rotationQuaternion(quaternion: Nullable<Quaternion>) {
|
|
|
this._rotationQuaternion = quaternion;
|
|
|
//reset the rotation vector.
|
|
|
- if (quaternion && this.rotation.length()) {
|
|
|
- this.rotation.copyFromFloats(0.0, 0.0, 0.0);
|
|
|
+ if (quaternion) {
|
|
|
+ this.rotation.setAll(0.0);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -222,7 +222,7 @@ module BABYLON {
|
|
|
}
|
|
|
|
|
|
if (this.billboardMode !== this._cache.billboardMode || this.billboardMode !== TransformNode.BILLBOARDMODE_NONE) {
|
|
|
- return false;
|
|
|
+ return false;
|
|
|
}
|
|
|
|
|
|
if (this._cache.pivotMatrixUpdated) {
|
|
@@ -234,21 +234,21 @@ module BABYLON {
|
|
|
}
|
|
|
|
|
|
if (!this._cache.position.equals(this._position)) {
|
|
|
- return false;
|
|
|
+ return false;
|
|
|
}
|
|
|
|
|
|
if (this._rotationQuaternion) {
|
|
|
if (!this._cache.rotationQuaternion.equals(this._rotationQuaternion)) {
|
|
|
- return false;
|
|
|
+ return false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (!this._cache.rotation.equals(this._rotation)) {
|
|
|
- return false;
|
|
|
+ return false;
|
|
|
}
|
|
|
|
|
|
if (!this._cache.scaling.equals(this._scaling)) {
|
|
|
- return false;
|
|
|
+ return false;
|
|
|
}
|
|
|
|
|
|
return true;
|
|
@@ -304,7 +304,7 @@ module BABYLON {
|
|
|
* @returns the current TransformNode
|
|
|
*/
|
|
|
public setPivotMatrix(matrix: Matrix, postMultiplyPivotMatrix = true): TransformNode {
|
|
|
- this._pivotMatrix = matrix.clone();
|
|
|
+ this._pivotMatrix.copyFrom(matrix);
|
|
|
this._cache.pivotMatrixUpdated = true;
|
|
|
this._postMultiplyPivotMatrix = postMultiplyPivotMatrix;
|
|
|
|
|
@@ -391,10 +391,9 @@ module BABYLON {
|
|
|
absolutePositionZ = absolutePosition.z;
|
|
|
}
|
|
|
if (this.parent) {
|
|
|
- var invertParentWorldMatrix = this.parent.getWorldMatrix().clone();
|
|
|
- invertParentWorldMatrix.invert();
|
|
|
- var worldPosition = new Vector3(absolutePositionX, absolutePositionY, absolutePositionZ);
|
|
|
- this.position = Vector3.TransformCoordinates(worldPosition, invertParentWorldMatrix);
|
|
|
+ const invertParentWorldMatrix = Tmp.Matrix[0];
|
|
|
+ this.parent.getWorldMatrix().invertToRef(invertParentWorldMatrix);
|
|
|
+ Vector3.TransformCoordinatesFromFloatsToRef(absolutePositionX, absolutePositionY, absolutePositionZ, invertParentWorldMatrix, this.position);
|
|
|
} else {
|
|
|
this.position.x = absolutePositionX;
|
|
|
this.position.y = absolutePositionY;
|
|
@@ -420,9 +419,8 @@ module BABYLON {
|
|
|
*/
|
|
|
public getPositionExpressedInLocalSpace(): Vector3 {
|
|
|
this.computeWorldMatrix();
|
|
|
- var invLocalWorldMatrix = this._localWorld.clone();
|
|
|
- invLocalWorldMatrix.invert();
|
|
|
-
|
|
|
+ const invLocalWorldMatrix = Tmp.Matrix[0];
|
|
|
+ this._localWorld.invertToRef(invLocalWorldMatrix);
|
|
|
return Vector3.TransformNormal(this.position, invLocalWorldMatrix);
|
|
|
}
|
|
|
|
|
@@ -571,34 +569,18 @@ module BABYLON {
|
|
|
if (!node && !this.parent) {
|
|
|
return this;
|
|
|
}
|
|
|
- if (!node) {
|
|
|
- var rotation = Tmp.Quaternion[0];
|
|
|
- var position = Tmp.Vector3[0];
|
|
|
- var scale = Tmp.Vector3[1];
|
|
|
|
|
|
+ var quatRotation = Tmp.Quaternion[0];
|
|
|
+ var position = Tmp.Vector3[0];
|
|
|
+ var scale = Tmp.Vector3[1];
|
|
|
+
|
|
|
+ if (!node) {
|
|
|
if (this.parent && this.parent.computeWorldMatrix) {
|
|
|
this.parent.computeWorldMatrix(true);
|
|
|
}
|
|
|
this.computeWorldMatrix(true);
|
|
|
- this.getWorldMatrix().decompose(scale, rotation, position);
|
|
|
-
|
|
|
- if (this.rotationQuaternion) {
|
|
|
- this.rotationQuaternion.copyFrom(rotation);
|
|
|
- } else {
|
|
|
- rotation.toEulerAnglesToRef(this.rotation);
|
|
|
- }
|
|
|
-
|
|
|
- this.scaling.x = scale.x;
|
|
|
- this.scaling.y = scale.y;
|
|
|
- this.scaling.z = scale.z;
|
|
|
-
|
|
|
- this.position.x = position.x;
|
|
|
- this.position.y = position.y;
|
|
|
- this.position.z = position.z;
|
|
|
+ this.getWorldMatrix().decompose(scale, quatRotation, position);
|
|
|
} else {
|
|
|
- var rotation = Tmp.Quaternion[0];
|
|
|
- var position = Tmp.Vector3[0];
|
|
|
- var scale = Tmp.Vector3[1];
|
|
|
var diffMatrix = Tmp.Matrix[0];
|
|
|
var invParentMatrix = Tmp.Matrix[1];
|
|
|
|
|
@@ -607,23 +589,18 @@ module BABYLON {
|
|
|
|
|
|
node.getWorldMatrix().invertToRef(invParentMatrix);
|
|
|
this.getWorldMatrix().multiplyToRef(invParentMatrix, diffMatrix);
|
|
|
- diffMatrix.decompose(scale, rotation, position);
|
|
|
-
|
|
|
- if (this.rotationQuaternion) {
|
|
|
- this.rotationQuaternion.copyFrom(rotation);
|
|
|
- } else {
|
|
|
- rotation.toEulerAnglesToRef(this.rotation);
|
|
|
- }
|
|
|
-
|
|
|
- this.position.x = position.x;
|
|
|
- this.position.y = position.y;
|
|
|
- this.position.z = position.z;
|
|
|
+ diffMatrix.decompose(scale, quatRotation, position);
|
|
|
+ }
|
|
|
|
|
|
- this.scaling.x = scale.x;
|
|
|
- this.scaling.y = scale.y;
|
|
|
- this.scaling.z = scale.z;
|
|
|
+ if (this.rotationQuaternion) {
|
|
|
+ this.rotationQuaternion.copyFrom(quatRotation);
|
|
|
+ } else {
|
|
|
+ quatRotation.toEulerAnglesToRef(this.rotation);
|
|
|
}
|
|
|
|
|
|
+ this.scaling.copyFrom(scale);
|
|
|
+ this.position.copyFrom(position);
|
|
|
+
|
|
|
this.parent = node;
|
|
|
return this;
|
|
|
}
|
|
@@ -693,8 +670,8 @@ module BABYLON {
|
|
|
public rotate(axis: Vector3, amount: number, space?: Space): TransformNode {
|
|
|
axis.normalize();
|
|
|
if (!this.rotationQuaternion) {
|
|
|
- this.rotationQuaternion = Quaternion.RotationYawPitchRoll(this.rotation.y, this.rotation.x, this.rotation.z);
|
|
|
- this.rotation = Vector3.Zero();
|
|
|
+ this.rotationQuaternion = this.rotation.toQuaternion();
|
|
|
+ this.rotation.setAll(0);
|
|
|
}
|
|
|
var rotationQuaternion: Quaternion;
|
|
|
if (!space || (space as any) === Space.LOCAL) {
|
|
@@ -703,8 +680,8 @@ module BABYLON {
|
|
|
}
|
|
|
else {
|
|
|
if (this.parent) {
|
|
|
- var invertParentWorldMatrix = this.parent.getWorldMatrix().clone();
|
|
|
- invertParentWorldMatrix.invert();
|
|
|
+ const invertParentWorldMatrix = Tmp.Matrix[0];
|
|
|
+ this.parent.getWorldMatrix().invertToRef(invertParentWorldMatrix);
|
|
|
axis = Vector3.TransformNormal(axis, invertParentWorldMatrix);
|
|
|
}
|
|
|
rotationQuaternion = Quaternion.RotationAxisToRef(axis, amount, TransformNode._rotationAxisCache);
|
|
@@ -727,19 +704,32 @@ module BABYLON {
|
|
|
axis.normalize();
|
|
|
if (!this.rotationQuaternion) {
|
|
|
this.rotationQuaternion = Quaternion.RotationYawPitchRoll(this.rotation.y, this.rotation.x, this.rotation.z);
|
|
|
- this.rotation.copyFromFloats(0, 0, 0);
|
|
|
+ this.rotation.setAll(0);
|
|
|
}
|
|
|
- point.subtractToRef(this.position, Tmp.Vector3[0]);
|
|
|
- Matrix.TranslationToRef(Tmp.Vector3[0].x, Tmp.Vector3[0].y, Tmp.Vector3[0].z, Tmp.Matrix[0]);
|
|
|
- Tmp.Matrix[0].invertToRef(Tmp.Matrix[2]);
|
|
|
- Matrix.RotationAxisToRef(axis, amount, Tmp.Matrix[1]);
|
|
|
- Tmp.Matrix[2].multiplyToRef(Tmp.Matrix[1], Tmp.Matrix[2]);
|
|
|
- Tmp.Matrix[2].multiplyToRef(Tmp.Matrix[0], Tmp.Matrix[2]);
|
|
|
|
|
|
- Tmp.Matrix[2].decompose(Tmp.Vector3[0], Tmp.Quaternion[0], Tmp.Vector3[1]);
|
|
|
+ const tmpVector = Tmp.Vector3[0];
|
|
|
+ const finalScale = Tmp.Vector3[1];
|
|
|
+ const finalTranslation = Tmp.Vector3[2];
|
|
|
+
|
|
|
+ const finalRotation = Tmp.Quaternion[0];
|
|
|
+
|
|
|
+ const translationMatrix = Tmp.Matrix[0]; // T
|
|
|
+ const translationMatrixInv = Tmp.Matrix[1]; // T'
|
|
|
+ const rotationMatrix = Tmp.Matrix[2]; // R
|
|
|
+ const finalMatrix = Tmp.Matrix[3]; // T' x R x T
|
|
|
+
|
|
|
+ point.subtractToRef(this.position, tmpVector);
|
|
|
+ Matrix.TranslationToRef(tmpVector.x, tmpVector.y, tmpVector.z, translationMatrix); // T
|
|
|
+ Matrix.TranslationToRef(-tmpVector.x, -tmpVector.y, -tmpVector.z, translationMatrixInv); // T'
|
|
|
+ Matrix.RotationAxisToRef(axis, amount, rotationMatrix); // R
|
|
|
+
|
|
|
+ translationMatrixInv.multiplyToRef(rotationMatrix, finalMatrix); // T' x R
|
|
|
+ finalMatrix.multiplyToRef(translationMatrix, finalMatrix); // T' x R x T
|
|
|
+
|
|
|
+ finalMatrix.decompose(finalScale, finalRotation, finalTranslation);
|
|
|
|
|
|
- this.position.addInPlace(Tmp.Vector3[1]);
|
|
|
- Tmp.Quaternion[0].multiplyToRef(this.rotationQuaternion, this.rotationQuaternion);
|
|
|
+ this.position.addInPlace(finalTranslation);
|
|
|
+ finalRotation.multiplyToRef(this.rotationQuaternion, this.rotationQuaternion);
|
|
|
|
|
|
return this;
|
|
|
}
|