Here are some sample files:
_test.zip (33.0 KB)
Both of the FBX files within the zip folder are located in the same place, the exception is one has no to geometric transforms/rotation, and the other one does.
Eevrything works as expected with the file that does not have any transforms applied.
Looking into the file which does have transforms further, all the nodes which contain geometry have the same node transforms as shown below:
var globalTransform = node.EvaluateGlobalTransform(true);
var globalRotation = node.Transform.GeometricRotation;
Console.WriteLine("Global Transform: " + globalTransform);
Console.WriteLine("Geometric Rotation: " + globalRotation);
globalTransform.Decompose(out Vector3 translation, out Vector3 scaling, out Quaternion rotation);
Console.WriteLine("Translation: " + translation);
Console.WriteLine("Scaling: " + scaling);
Console.WriteLine("Quaternion Rotation: " + rotation);
Console.WriteLine("Quaternion From Geometric Rotation Euler: " + Quaternion.FromEulerAngle(globalRotation));
Gives us:
Global Transform:
[ 0.9845965 -0.1748421 0.0000000 0.0000000;
0.1748421 0.9845965 0.0000000 0.0000000;
0.0000000 0.0000000 1.0000000 0.0000000;
1327029.5782806 1379847.3409376 0.0000000 1.0000000]
Geometric Rotation: (0 0 -10.069472)
Translation: (1327029.578281 1379847.340938 0)
Scaling: (1 1 1)
Quaternion Rotation: (0.996 -0.000 -0.000 -0.088)
Quaternion From Geometric Rotation Euler: (0.317 0.000 0.000 0.948)
Using the following:
rootNode.Accept(delegate (Node node)
{
var globalTransform = node.EvaluateGlobalTransform(true);
for (int i = 0; i < node.Entities.Count; i++)
{
if (node.Entities[i] is Aspose.ThreeD.Entities.Geometry geom)
{
for (int j = 0; j < geom.ControlPoints.Count; j++)
{
var v = globalTransform * geom.ControlPoints[j];
Console.WriteLine(v);
}
}
}
return true;
});
Here are the first few vectors from the file which does not have the transform, these are the correct values:
(1327066.373712 1379783.591349 370.013123 1)
(1327081.777634 1379782.888522 370.013123 1)
(1327066.725127 1379791.29331 370.013123 1)
(1327082.129049 1379790.590483 370.013123 1)
(1327066.373712 1379783.591349 370.505249 1)
And the vectors from the file which does have the transform:
(1327054.872962 1379778.217187 370.013123 1)
(1327069.927039 1379774.878091 370.013123 1)
(1327056.542512 1379785.744225 370.013123 1)
(1327071.596589 1379782.405129 370.013123 1)
(1327054.872962 1379778.217187 370.505249 1)
I would expect the above two files to match since we’re multiplying the points by the global transform matrix. To me it seems like a rotation issue, note the difference in euler angles above.
When I set node.Transform.GeometricRotation = Vector3.Origin;
prior to evaluating the global transform var globalTransform = node.EvaluateGlobalTransform(true);
, the vector values from from the file which does have the transform are now almost correct:
(1327066.56908 1379783.704513 370.013123 1)
(1327081.975085 1379783.048938 370.013123 1)
(1327066.896869 1379791.407516 370.013123 1)
(1327082.302875 1379790.751941 370.013123 1)
(1327066.56908 1379783.704513 370.505249 1)
Taking the first vector from the file I know is correct (no transforms applied to the original FBX, and the first vector from the above:
xDifference = 1327066.56908 - 1327066.373712 = 0.19536800007
yDifference = 1379783.704513 - 1379783.591349 = 0.11316399998
The above difference is in feet, converting this to meters we have:
xDifference = 0.059548166421336, or 5.95cm
yDifference = 0.034492387193904m, or 3.45cm
The above difference is small but still not acceptable for my requirements, especially since this is a small simple model and the differences will be larger on more complex models.
FYI, the reason I need the absolute correct values for each vector is because I will be converting them to latitude/longitude values and performing additional calculations on them.
As a side note, I not only have to set the transformation to the identity as you noted in the second step for exporting, I also have to set the GeometricTranslation to 0 also, and possibly the rotation:
node.Transform.TransformMatrix = Matrix4.Identity;
node.Transform.GeometricTranslation = Vector3.Origin;
node.Transform.GeometricRotation = Vector3.Origin;
Please advise how I can get the correct vector values when the input FBX file has a geometric transformation/rotation.
Note, performing the translation myself instead of using EvaluateGlobalTransform gets me the same values:
var globalRotation = node.Transform.GeometricRotation;
Matrix4 geometricMatrix = (new TransformBuilder(ComposeOrder.Append))
.Translate(node.Transform.GeometricTranslation)
.RotateEulerDegree(globalRotation.x, globalRotation.y, globalRotation.z)
.Scale(node.Transform.GeometricScaling).Matrix;
Images of the two files to show they have the same coordinates:
image.png (26.0 KB)
image.jpg (434.3 KB)
Thanks for your time