FBX: Coordinate system axes exported incorrectly, resulting in a 180 degree rotation of meshes. #43935
Labels
No Label
Interest
Animation & Rigging
Interest
Blender Cloud
Interest
Collada
Interest
Core
Interest
Documentation
Interest
Eevee & Viewport
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
Import and Export
Interest
Modeling
Interest
Modifiers
Interest
Nodes & Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds, Tests & Devices
Interest
Python API
Interest
Rendering & Cycles
Interest
Sculpt, Paint & Texture
Interest
Translations
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Meta
Good First Issue
Meta
Papercut
Module
Add-ons (BF-Blender)
Module
Add-ons (Community)
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
3 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender-addons#43935
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Blender version: 2.73a
(FBX binary exporter)
When exporting a binary FBX, the coordinate system properties [UpAxis, UpAxisSign, FrontAxis, FrontAxisSign, CoordAxis and CoordAxisSign] are chosen incorrectly.
This error arises when mapping via the look-up table RIGHT_HAND_AXES. This table is correct as documented in the comments, in that it correctly maps tuples of (Up, Front) to the corresponding FBX properties. The error arises because everywhere in the FBX exporter/importer code, the value used to index into the table is actually (Up, Forward), not (Up, Front). Note that FBX considers the "front" vector as being the vector describing the normal direction of the visible faces of the model, i.e. a vector pointing toward the camera, not away from it. Basically, the front vector is the negation of the forward vector, so the result is a coordinate system that is rotated 180 degrees to what we actually wanted.
Because of this, while the actual mesh data is correctly exported, any importer that makes use of the coordinate system properties will, on converting the mesh data, rotate it 180 degrees. (This does not affect the Blender FBX importer because it uses the same look-up table on import, so the error is reversed.)
This bug is easily illustrated by exporting any mesh and then loading it into an external viewer such as the Visual Studio 2013 built-in viewer. You will see that the mesh is rotated 180 degrees.
The fix for this is trivial: simply convert RIGHT_HAND_AXES to be indexed by (Up, Forward) instead of (Up, Front) by negating the front vectors in the table indices. I have attached before and after versions of the relevant file*. This simple change fixes the problem 100%.
Bonus info: I haven't looked too far into it but it sounds like bug #42110 may be caused by this, since it is using an external importer.
^* Hmm. My browser is giving me no indication that these files have actually been uploaded. In case they haven't, here is the before and after version of the table as text.
BEFORE:
And AFTER:
Changed status to: 'Open'
Added subscriber: @ib_rod
I just noticed that my change screwed up the formatting of the code, since I made the minimal possible change and didn't adjust the whitespace. Here's a tidier version with whitespace adjusted:
AFTER:
Added subscriber: @mont29
Hrmmm… already changed that table a few times in the past. :/
Do you have a good reference link explaining what exactly FBX expects here? I never could fine one, so just tried guessing so far.
The best I have is from the comments in the FBX SDK source code. The following lines are of interest (included again with more context below):
From fbxsdk_2015.1\include\fbxsdk\scene\FbxAxisSystem.h:
[Line 61] There still needs a parameter to denote the direction of the EFrontVector just as the EUpVector. And the sign of the
[Line 62] EFrontVector represents the direction (1 is front and -1 is back relative to observer).
...
[Line 110] EFrontVector Vector with origin at the screen pointing toward the camera.
As you can see, while it may not be the clearest of descriptions, they definitely specify that the vector points toward the camera. I believe this is why they prefer the term "front" (as in front-facing polygons) rather than, say, "forward".
I can also tell you from my own experience that this is consistent with what I've seen from Autodesk's own exporters for Maya, Max, etc. Our import code works fine with files generated by those exporters. Only with Blender (2.73a) do I see the mesh rotated 180 degrees. On investigation I found that the mesh data itself is correct, but that the coordinate system conversion (converting from the system used by the data in the file to the system used internally by our renderer) was rotating it. This occurred even if I export the mesh in the same coordinate system as our renderer uses internally, which means that the conversion should be skipped altogether. Eventually I tracked this down to the coordinate system properties, which were flipped compared to what they should be for those files according to the comments above. This change fixed it for us. I can now export with anycoordinate system axes and have the data import correctly, and the same code works for FBX files generated by the other exporters. I also verified it by viewing the files in the FBX viewer in Visual Studio 2013. Prior to the change the mesh is rotated 180 degrees no matter which coordinate system axes I export as. With the change the mesh appears correctly oriented.
.....
As promised here are those comments with more surrounding context:
fbxsdk_2015.1\include\fbxsdk\scene\FbxAxisSystem.h, beginning at line 53:
fbxsdk_2015.1\include\fbxsdk\scene\FbxAxisSystem.h, beginning at line 110:
Yeah, that kind of documentation can pretty much be understood in both directions :|
But still, think your explanations make sense, and quick check indeed shows rotated issue with UE4 (much easier to test it myself now that UE4 can be built on Linux!).
Will commit, a huge thanks for finding and fixing this!
This issue was referenced by
660f2dd8bb
Changed status from 'Open' to: 'Resolved'
Closed by commit
660f2dd8bb
.No problem. :)