Hi!
I am exporting a 4x4 matrix from an other 3D software to XML format. Then I am reading the XML file into Unity and generate a new 4x4 matrix based on the values I exported from the other 3D Software because I want to use the rotations, transformations, etc. so I can put them on GameObjects in Unity.
The problem I have (and I think I am just having problems with Math) is, that the other 3D Software uses a different orientation concerning the X,Y and Z axis:
3D Software:
X = Right
Y = Forward
Z = Up
Unity:
X = Right
Z = Forward
Y = Up
I read a lot of posts on Google and this forum, but I am not able to get the right results. This is basically the code which converts the string of the XML to a 4x4 matrix:
private Matrix4x4 GetMatrix(string input)
{
var transMatrixValues = new float[16];
input = input.Replace("(", "");
input = input.Replace(")", "");
var values = input.Split(',');
for (var i = 0; i <= values.Length - 1; i++)
{
transMatrixValues[i] = (float)Math.Round(double.Parse(values[i]), 3);
}
var newMatrix = new Matrix4x4();
newMatrix.SetColumn(0, new Vector4(transMatrixValues[0], transMatrixValues[4], transMatrixValues[8], transMatrixValues[12]));
newMatrix.SetColumn(1, new Vector4(transMatrixValues[1], transMatrixValues[5], transMatrixValues[9], transMatrixValues[13]));
newMatrix.SetColumn(2, new Vector4(transMatrixValues[2], transMatrixValues[6], transMatrixValues[10], transMatrixValues[14]));
newMatrix.SetColumn(3, new Vector4(transMatrixValues[3], transMatrixValues[7], transMatrixValues[11], transMatrixValues[15]));
return newMatrix;
}
So how can I convert this matrix to a matrix I can use in Unity?
Thanks in advance.