Wrong quaternion on export

Rotation is invalid on specific angles on export. For example ( 0, 0, PI ) gives wrong rotation. But if we add some epsilon on Z euler angle - the rotation is totally fine.

Scene scene = new Scene();
        
Node node1 = scene.RootNode.CreateChildNode("Node1");
node1.Transform.Rotation = Quaternion.FromEulerAngle( 0, 0, Math.PI );
node1.Entity = new Pyramid();
        
Node node2 = scene.RootNode.CreateChildNode("Node2");
node2.Transform.Rotation = Quaternion.FromEulerAngle( 0, 0, Math.PI + 0.001 );
node2.Entity = new Pyramid();
        
scene.Save( "model.fbx", FileFormat.FBX7400Binary );

Resulting fbx: model.fbx.zip (3.2 KB)

@Anton.Akzhigitov

We have logged an issue as THREEDNET-983 in our issue management system for this case. We will further look into its details and keep you posted with the status of its rectification. Please be patient and spare us some time.

We are sorry for the inconvenience.

I see that status of the issue changed to “Won’t fix”. Can you please explain

@Anton.Akzhigitov

If you use Rotation(Quaternion type), the transform’s internal implementation will uses quaternion to represent it’s rotation, but FBX uses Euler angles, the conversion will cause a gimbal lock at Pi.

A work around is uses Transform.EulerAngles, this will ensure Transform uses Euler angles internally, and make sure it outputs the exactly the same value in file types that uses euler angles.

Scene scene = new Scene();

Node node1 = scene.RootNode.CreateChildNode("Node1");
node1.Transform.EulerAngles = new Vector3(0, 0, 180);
node1.Entity = new Pyramid();

scene.Save( "model.fbx", FileFormat.FBX7400ASCII ); 
1 Like