|
@@ -171,54 +171,87 @@
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
- public translate (vec: Vector3): void {
|
|
|
+ public translate (vec: Vector3, space = Space.LOCAL, mesh?: AbstractMesh): void {
|
|
|
|
|
|
var lm = this.getLocalMatrix();
|
|
|
|
|
|
- lm.m[12] += vec.x;
|
|
|
- lm.m[13] += vec.y;
|
|
|
- lm.m[14] += vec.z;
|
|
|
+ if(space == Space.LOCAL){
|
|
|
+
|
|
|
+ lm.m[12] += vec.x;
|
|
|
+ lm.m[13] += vec.y;
|
|
|
+ lm.m[14] += vec.z;
|
|
|
+
|
|
|
+ }else{
|
|
|
+
|
|
|
+ this._skeleton.computeAbsoluteTransforms();
|
|
|
+ var tmat = Tmp.Matrix[0];
|
|
|
+ var tvec = Tmp.Vector3[0];
|
|
|
+
|
|
|
+ if (mesh) {
|
|
|
+ tmat.copyFrom(this._parent.getAbsoluteTransform());
|
|
|
+ tmat.multiplyToRef(mesh.getWorldMatrix(), tmat);
|
|
|
+ }else {
|
|
|
+ tmat.copyFrom(this._parent.getAbsoluteTransform());
|
|
|
+ }
|
|
|
+
|
|
|
+ tmat.m[12] = 0;
|
|
|
+ tmat.m[13] = 0;
|
|
|
+ tmat.m[14] = 0;
|
|
|
+
|
|
|
+ tmat.invert();
|
|
|
+ Vector3.TransformCoordinatesToRef(vec, tmat, tvec);
|
|
|
+
|
|
|
+ lm.m[12] += tvec.x;
|
|
|
+ lm.m[13] += tvec.y;
|
|
|
+ lm.m[14] += tvec.z;
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
this.markAsDirty();
|
|
|
|
|
|
}
|
|
|
|
|
|
- public setPosition (position: Vector3): void {
|
|
|
+ public setPosition (position: Vector3, space = Space.LOCAL, mesh?: AbstractMesh): void {
|
|
|
|
|
|
var lm = this.getLocalMatrix();
|
|
|
|
|
|
- lm.m[12] = position.x;
|
|
|
- lm.m[13] = position.y;
|
|
|
- lm.m[14] = position.z;
|
|
|
+ if(space == Space.LOCAL){
|
|
|
|
|
|
- this.markAsDirty();
|
|
|
-
|
|
|
- }
|
|
|
+ lm.m[12] = position.x;
|
|
|
+ lm.m[13] = position.y;
|
|
|
+ lm.m[14] = position.z;
|
|
|
|
|
|
- public setAbsolutePosition (position: Vector3, mesh: AbstractMesh = null): void {
|
|
|
+ }else{
|
|
|
|
|
|
- this._skeleton.computeAbsoluteTransforms();
|
|
|
+ this._skeleton.computeAbsoluteTransforms();
|
|
|
|
|
|
- var tmat = Tmp.Matrix[0];
|
|
|
- var vec = Tmp.Vector3[0];
|
|
|
+ var tmat = Tmp.Matrix[0];
|
|
|
+ var vec = Tmp.Vector3[0];
|
|
|
|
|
|
- if (mesh) {
|
|
|
- tmat.copyFrom(this._parent.getAbsoluteTransform());
|
|
|
- tmat.multiplyToRef(mesh.getWorldMatrix(), tmat);
|
|
|
- }else {
|
|
|
- tmat.copyFrom(this._parent.getAbsoluteTransform());
|
|
|
- }
|
|
|
+ if (mesh) {
|
|
|
+ tmat.copyFrom(this._parent.getAbsoluteTransform());
|
|
|
+ tmat.multiplyToRef(mesh.getWorldMatrix(), tmat);
|
|
|
+ }else {
|
|
|
+ tmat.copyFrom(this._parent.getAbsoluteTransform());
|
|
|
+ }
|
|
|
|
|
|
- tmat.invert();
|
|
|
- Vector3.TransformCoordinatesToRef(position, tmat, vec);
|
|
|
+ tmat.invert();
|
|
|
+ Vector3.TransformCoordinatesToRef(position, tmat, vec);
|
|
|
|
|
|
- var lm = this.getLocalMatrix();
|
|
|
- lm.m[12] = vec.x;
|
|
|
- lm.m[13] = vec.y;
|
|
|
- lm.m[14] = vec.z;
|
|
|
+ lm.m[12] = vec.x;
|
|
|
+ lm.m[13] = vec.y;
|
|
|
+ lm.m[14] = vec.z;
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
this.markAsDirty();
|
|
|
-
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public setAbsolutePosition(position:Vector3, mesh?: AbstractMesh){
|
|
|
+
|
|
|
+ this.setPosition(position, Space.WORLD, mesh);
|
|
|
+
|
|
|
}
|
|
|
|
|
|
public setScale (x: number, y: number, z: number, scaleChildren = false): void {
|
|
@@ -291,7 +324,7 @@
|
|
|
|
|
|
}
|
|
|
|
|
|
- public setYawPitchRoll (yaw: number, pitch: number, roll: number, space = Space.LOCAL, mesh: AbstractMesh = null): void {
|
|
|
+ public setYawPitchRoll (yaw: number, pitch: number, roll: number, space = Space.LOCAL, mesh?: AbstractMesh): void {
|
|
|
|
|
|
var rotMat = Tmp.Matrix[0];
|
|
|
Matrix.RotationYawPitchRollToRef(yaw, pitch, roll, rotMat);
|
|
@@ -306,7 +339,7 @@
|
|
|
|
|
|
}
|
|
|
|
|
|
- public rotate (axis: Vector3, amount: number, space = Space.LOCAL, mesh: AbstractMesh = null): void {
|
|
|
+ public rotate (axis: Vector3, amount: number, space = Space.LOCAL, mesh?: AbstractMesh): void {
|
|
|
|
|
|
var rmat = Tmp.Matrix[0];
|
|
|
rmat.m[12] = 0;
|
|
@@ -319,7 +352,7 @@
|
|
|
|
|
|
}
|
|
|
|
|
|
- public setAxisAngle (axis: Vector3, angle: number, space = Space.LOCAL, mesh: AbstractMesh = null): void {
|
|
|
+ public setAxisAngle (axis: Vector3, angle: number, space = Space.LOCAL, mesh?: AbstractMesh): void {
|
|
|
|
|
|
var rotMat = Tmp.Matrix[0];
|
|
|
Matrix.RotationAxisToRef(axis, angle, rotMat);
|
|
@@ -332,7 +365,7 @@
|
|
|
|
|
|
}
|
|
|
|
|
|
- public setRotationMatrix (rotMat: Matrix, space = Space.LOCAL, mesh: AbstractMesh = null): void {
|
|
|
+ public setRotationMatrix (rotMat: Matrix, space = Space.LOCAL, mesh?: AbstractMesh): void {
|
|
|
|
|
|
var rotMatInv = Tmp.Matrix[0];
|
|
|
|
|
@@ -347,7 +380,7 @@
|
|
|
|
|
|
}
|
|
|
|
|
|
- private _rotateWithMatrix (rmat: Matrix, space = Space.LOCAL, mesh: AbstractMesh = null): void {
|
|
|
+ private _rotateWithMatrix (rmat: Matrix, space = Space.LOCAL, mesh?: AbstractMesh): void {
|
|
|
|
|
|
var lmat = this.getLocalMatrix();
|
|
|
var lx = lmat.m[12];
|
|
@@ -396,7 +429,7 @@
|
|
|
|
|
|
}
|
|
|
|
|
|
- private _getNegativeRotationToRef(rotMatInv: Matrix, space = Space.LOCAL, mesh: AbstractMesh = null): void {
|
|
|
+ private _getNegativeRotationToRef(rotMatInv: Matrix, space = Space.LOCAL, mesh?: AbstractMesh): void {
|
|
|
|
|
|
if (space == Space.WORLD) {
|
|
|
var scaleMatrix = Tmp.Matrix[2];
|
|
@@ -445,32 +478,60 @@
|
|
|
|
|
|
}
|
|
|
|
|
|
- public getAbsolutePosition (mesh: AbstractMesh = null): Vector3 {
|
|
|
+ public getPosition (space = Space.LOCAL, mesh?: AbstractMesh): Vector3 {
|
|
|
|
|
|
var pos = Vector3.Zero();
|
|
|
|
|
|
- this.getAbsolutePositionToRef(mesh, pos);
|
|
|
+ this.getPositionToRef(space, mesh, pos);
|
|
|
|
|
|
return pos;
|
|
|
|
|
|
}
|
|
|
|
|
|
- public getAbsolutePositionToRef (mesh: AbstractMesh = null, result: Vector3): void {
|
|
|
+ public getPositionToRef (space = Space.LOCAL, mesh: AbstractMesh, result: Vector3): void {
|
|
|
|
|
|
- this._skeleton.computeAbsoluteTransforms();
|
|
|
-
|
|
|
- var tmat = Tmp.Matrix[0];
|
|
|
+ if(space == Space.LOCAL){
|
|
|
+
|
|
|
+ var lm = this.getLocalMatrix();
|
|
|
+
|
|
|
+ result.x = lm.m[12];
|
|
|
+ result.y = lm.m[13];
|
|
|
+ result.z = lm.m[14];
|
|
|
|
|
|
- if (mesh) {
|
|
|
- tmat.copyFrom(this.getAbsoluteTransform());
|
|
|
- tmat.multiplyToRef(mesh.getWorldMatrix(), tmat);
|
|
|
}else{
|
|
|
- tmat = this.getAbsoluteTransform();
|
|
|
+
|
|
|
+ this._skeleton.computeAbsoluteTransforms();
|
|
|
+
|
|
|
+ var tmat = Tmp.Matrix[0];
|
|
|
+
|
|
|
+ if (mesh) {
|
|
|
+ tmat.copyFrom(this.getAbsoluteTransform());
|
|
|
+ tmat.multiplyToRef(mesh.getWorldMatrix(), tmat);
|
|
|
+ }else{
|
|
|
+ tmat = this.getAbsoluteTransform();
|
|
|
+ }
|
|
|
+
|
|
|
+ result.x = tmat.m[12];
|
|
|
+ result.y = tmat.m[13];
|
|
|
+ result.z = tmat.m[14];
|
|
|
+
|
|
|
}
|
|
|
|
|
|
- result.x = tmat.m[12];
|
|
|
- result.y = tmat.m[13];
|
|
|
- result.z = tmat.m[14];
|
|
|
+ }
|
|
|
+
|
|
|
+ public getAbsolutePosition (mesh?: AbstractMesh): Vector3 {
|
|
|
+
|
|
|
+ var pos = Vector3.Zero();
|
|
|
+
|
|
|
+ this.getPositionToRef(Space.WORLD, mesh, pos);
|
|
|
+
|
|
|
+ return pos;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public getAbsolutePositionToRef (mesh: AbstractMesh, result: Vector3) {
|
|
|
+
|
|
|
+ this.getPositionToRef(Space.WORLD, mesh, result);
|
|
|
|
|
|
}
|
|
|
|
|
@@ -527,7 +588,7 @@
|
|
|
|
|
|
var result = Vector3.Zero();
|
|
|
|
|
|
- this.getDirectionToRef(localAxis, result, mesh);
|
|
|
+ this.getDirectionToRef(localAxis, result, mesh);
|
|
|
|
|
|
return result;
|
|
|
|
|
@@ -551,26 +612,41 @@
|
|
|
|
|
|
}
|
|
|
|
|
|
- public getRotation(mesh: AbstractMesh): Quaternion {
|
|
|
+ public getRotation(space = Space.LOCAL, mesh?: AbstractMesh): Quaternion {
|
|
|
|
|
|
var result = Quaternion.Identity();
|
|
|
|
|
|
- this.getRotationToRef(mesh, result);
|
|
|
+ this.getRotationToRef(space, mesh, result);
|
|
|
|
|
|
return result;
|
|
|
|
|
|
}
|
|
|
|
|
|
- public getRotationToRef(mesh: AbstractMesh, result: Quaternion): void{
|
|
|
+ public getRotationToRef( space = Space.LOCAL, mesh: AbstractMesh, result: Quaternion): void{
|
|
|
+
|
|
|
+ if(space == Space.LOCAL){
|
|
|
|
|
|
- var mat = Tmp.Matrix[0];
|
|
|
- var amat = this.getAbsoluteTransform();
|
|
|
- var wmat = mesh.getWorldMatrix();
|
|
|
+ this.getLocalMatrix().decompose(Tmp.Vector3[0], result, Tmp.Vector3[1]);
|
|
|
+
|
|
|
+ }else{
|
|
|
|
|
|
- amat.multiplyToRef(wmat, mat);
|
|
|
+ var mat = Tmp.Matrix[0];
|
|
|
+ var amat = this.getAbsoluteTransform();
|
|
|
|
|
|
- mat.decompose(Tmp.Vector3[0], result, Tmp.Vector3[1]);
|
|
|
+ if(mesh){
|
|
|
|
|
|
+ var wmat = mesh.getWorldMatrix();
|
|
|
+ amat.multiplyToRef(wmat, mat);
|
|
|
+
|
|
|
+ mat.decompose(Tmp.Vector3[0], result, Tmp.Vector3[1]);
|
|
|
+
|
|
|
+ }else{
|
|
|
+
|
|
|
+ amat.decompose(Tmp.Vector3[0], result, Tmp.Vector3[1]);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
}
|