|
@@ -1279,88 +1279,87 @@
|
|
|
|
|
|
public setParent(mesh:AbstractMesh, keepWorldPositionRotation = false): void{
|
|
public setParent(mesh:AbstractMesh, keepWorldPositionRotation = false): void{
|
|
|
|
|
|
- mesh.addChild(this, keepWorldPositionRotation);
|
|
|
|
|
|
+ var child = this;
|
|
|
|
+ var parent = mesh;
|
|
|
|
|
|
- }
|
|
|
|
|
|
+ if(mesh == null){
|
|
|
|
|
|
- public addChild(mesh:AbstractMesh, keepWorldPositionRotation = false): void{
|
|
|
|
|
|
+ if(child.parent && keepWorldPositionRotation){
|
|
|
|
+
|
|
|
|
+ var rotation = Tmp.Quaternion[0];
|
|
|
|
+ var position = Tmp.Vector3[0];
|
|
|
|
+ var scale = Tmp.Vector3[1];
|
|
|
|
|
|
- var child = mesh;
|
|
|
|
- var parent = this;
|
|
|
|
|
|
+ child.getWorldMatrix().decompose(scale, rotation, position);
|
|
|
|
|
|
- if(keepWorldPositionRotation){
|
|
|
|
-
|
|
|
|
- var rotation = Tmp.Quaternion[0];
|
|
|
|
- var position = Tmp.Vector3[0];
|
|
|
|
- var scale = Tmp.Vector3[1];
|
|
|
|
- var m1 = Tmp.Matrix[0];
|
|
|
|
- var m2 = Tmp.Matrix[1];
|
|
|
|
|
|
+ if (child.rotationQuaternion) {
|
|
|
|
+ child.rotationQuaternion.copyFrom(rotation);
|
|
|
|
+ } else {
|
|
|
|
+ rotation.toEulerAnglesToRef(child.rotation);
|
|
|
|
+ }
|
|
|
|
|
|
- parent.getWorldMatrix().decompose(scale, rotation, position);
|
|
|
|
|
|
+ child.position.x = position.x;
|
|
|
|
+ child.position.y = position.y;
|
|
|
|
+ child.position.z = position.z;
|
|
|
|
|
|
- rotation.toRotationMatrix(m1);
|
|
|
|
- m2.setTranslation(position);
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- m2.multiplyToRef(m1, m1);
|
|
|
|
|
|
+ } else {
|
|
|
|
|
|
- var invParentMatrix = Matrix.Invert(m1);
|
|
|
|
|
|
+ if(keepWorldPositionRotation){
|
|
|
|
+
|
|
|
|
+ var rotation = Tmp.Quaternion[0];
|
|
|
|
+ var position = Tmp.Vector3[0];
|
|
|
|
+ var scale = Tmp.Vector3[1];
|
|
|
|
+ var m1 = Tmp.Matrix[0];
|
|
|
|
+ var m2 = Tmp.Matrix[1];
|
|
|
|
|
|
- var m = child.getWorldMatrix().multiply(invParentMatrix);
|
|
|
|
|
|
+ parent.getWorldMatrix().decompose(scale, rotation, position);
|
|
|
|
|
|
- m.decompose(scale, rotation, position);
|
|
|
|
|
|
+ rotation.toRotationMatrix(m1);
|
|
|
|
+ m2.setTranslation(position);
|
|
|
|
|
|
- if (child.rotationQuaternion) {
|
|
|
|
- child.rotationQuaternion.copyFrom(rotation);
|
|
|
|
- } else {
|
|
|
|
- rotation.toEulerAnglesToRef(child.rotation);
|
|
|
|
- }
|
|
|
|
|
|
+ m2.multiplyToRef(m1, m1);
|
|
|
|
|
|
- invParentMatrix = Matrix.Invert(parent.getWorldMatrix());
|
|
|
|
|
|
+ var invParentMatrix = Matrix.Invert(m1);
|
|
|
|
|
|
- var m = child.getWorldMatrix().multiply(invParentMatrix);
|
|
|
|
|
|
+ var m = child.getWorldMatrix().multiply(invParentMatrix);
|
|
|
|
|
|
- m.decompose(Vector3.Zero(), Quaternion.Identity(), position);
|
|
|
|
|
|
+ m.decompose(scale, rotation, position);
|
|
|
|
|
|
- child.position.x = position.x;
|
|
|
|
- child.position.y = position.y;
|
|
|
|
- child.position.z = position.z;
|
|
|
|
|
|
+ if (child.rotationQuaternion) {
|
|
|
|
+ child.rotationQuaternion.copyFrom(rotation);
|
|
|
|
+ } else {
|
|
|
|
+ rotation.toEulerAnglesToRef(child.rotation);
|
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
|
|
|
+ invParentMatrix = Matrix.Invert(parent.getWorldMatrix());
|
|
|
|
|
|
- child.parent = parent;
|
|
|
|
|
|
+ var m = child.getWorldMatrix().multiply(invParentMatrix);
|
|
|
|
|
|
- }
|
|
|
|
|
|
+ m.decompose(scale, rotation, position);
|
|
|
|
|
|
- public removeChild(mesh:AbstractMesh, keepWorldPositionRotation = false): void{
|
|
|
|
|
|
+ child.position.x = position.x;
|
|
|
|
+ child.position.y = position.y;
|
|
|
|
+ child.position.z = position.z;
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
|
|
- var child = mesh;
|
|
|
|
- var parent = this;
|
|
|
|
-
|
|
|
|
- if (!child.parent) {
|
|
|
|
- return;
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- if(keepWorldPositionRotation){
|
|
|
|
|
|
+ child.parent = parent;
|
|
|
|
|
|
- var rotation = Tmp.Quaternion[0];
|
|
|
|
- var position = Tmp.Vector3[0];
|
|
|
|
- var m1 = Tmp.Matrix[0];
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- child.getWorldMatrix().decompose(Vector3.Zero(), rotation, position);
|
|
|
|
|
|
+ public addChild(mesh:AbstractMesh, keepWorldPositionRotation = false): void{
|
|
|
|
|
|
- if (child.rotationQuaternion) {
|
|
|
|
- child.rotationQuaternion.copyFrom(rotation);
|
|
|
|
- } else {
|
|
|
|
- rotation.toEulerAnglesToRef(child.rotation);
|
|
|
|
- }
|
|
|
|
|
|
+ mesh.setParent(this, keepWorldPositionRotation);
|
|
|
|
|
|
- child.position.x = position.x;
|
|
|
|
- child.position.y = position.y;
|
|
|
|
- child.position.z = position.z;
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
|
|
|
+ public removeChild(mesh:AbstractMesh, keepWorldPositionRotation = false): void{
|
|
|
|
|
|
- child.parent = null;
|
|
|
|
|
|
+ mesh.setParent(null, keepWorldPositionRotation);
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|