[Solved] Blender Y coord <-> Unity Z coord conversion for layouts

Discuss modding questions and implementation details.
Post Reply
User avatar
BadLuckBurt
Posts: 554
Joined: Sun Nov 05, 2017 8:30 pm

[Solved] Blender Y coord <-> Unity Z coord conversion for layouts

Post by BadLuckBurt » Wed Mar 25, 2020 10:00 am

Hi everyone,

While working on the Hall of Champions easter egg, I have found a bit of a strange problem that I'm not sure how to fix yet:

The first image is the layout in Blender, I have placed the start marker in that hallway in the south part so you're supposed to enter there, facing north.

Image

The second image is what happens when I load this layout into Unity, it somehow gets reversed so you start from the north, facing south.

Image

I think it has to do with left-handed vs right-handed coordinate systems. Left-handed is Unity's, right-handed is what Blender uses. I usually run away when matrix math gets involved but I don't think I can escape it this time. I didn't notice it with this particular mesh since the hallway is dead center in relation to the cylinder's origin so even when rotating, the start marker is in the right place.

I have two other variations of this mesh for testing purposes where the hallway is slight off-center and that's where I ran into the problem that the start marker is placed outside of the mesh in Unity, causing you to spawn in the void.

Please note that this is not the rotation 'error' that people run into when importing single meshes into Unity but more of an issue with the translation of complete scene coordinates from Blender to Unity.

I'll try to figure this out today to create a workable solution for myself but if anyone has any input or a solution, that would be greatly appreciated. I can supply source files if needed, including the script I use to export the layouts from Blender to Daggerfall Unity but as far as I know, I'm the only person who has dabbled in this so far. My Google-fu has not yielded any results yet, other than wordy explanations of what's going on so I'm letting that sink in atm.
Last edited by BadLuckBurt on Thu Mar 26, 2020 7:51 am, edited 1 time in total.
Daggerfall Unity on UESP: https://en.uesp.net/w/index.php?title=T ... fall_Unity
Daggerfall Unity on Nexus Mods: https://www.nexusmods.com/daggerfallunity
My github repositories with mostly DFU related stuff: https://github.com/BadLuckBurt

User avatar
pango
Posts: 2411
Joined: Wed Jul 18, 2018 6:14 pm
Location: France
Contact:

Re: Blender - Unity layout discrepancy

Post by pango » Wed Mar 25, 2020 11:15 am

Not using Blender myself, I don't know if this is of any use: https://relenting1.wixsite.com/nathanie ... and-tricks
When a measure becomes a target, it ceases to be a good measure.
-- Charles Goodhart

User avatar
BadLuckBurt
Posts: 554
Joined: Sun Nov 05, 2017 8:30 pm

Re: Blender - Unity layout discrepancy

Post by BadLuckBurt » Wed Mar 25, 2020 11:23 am

pango wrote:
Wed Mar 25, 2020 11:15 am
Not using Blender myself, I don't know if this is of any use: https://relenting1.wixsite.com/nathanie ... and-tricks
Thanks, that page does touch briefly on single models but not scene coordinates. After Googling a bit last night, I realised its not a regular occurance as most people probably build their scenes in Unity directly. I suspect the eventual solution will be deceptively simple as is often the case with these problems :D

Bookmarked the page anyway since it may come in handy for other things, thank you
Daggerfall Unity on UESP: https://en.uesp.net/w/index.php?title=T ... fall_Unity
Daggerfall Unity on Nexus Mods: https://www.nexusmods.com/daggerfallunity
My github repositories with mostly DFU related stuff: https://github.com/BadLuckBurt

User avatar
BadLuckBurt
Posts: 554
Joined: Sun Nov 05, 2017 8:30 pm

Re: Blender - Unity layout discrepancy

Post by BadLuckBurt » Thu Mar 26, 2020 6:23 am

I figured out a solution to the problem, just need to test it. Tested and it works.

For custom models to appear facing the same direction in Unity as they are in Blender, the model needs to be rotated 180 degrees around Blender's Z-axis and it's rotation needs to be applied. After that the 90 degrees X-axis fix needs to be reapplied. The model can then be exported properly to FBX and will appear correctly in Unity.

To work with the model again in Blender, the Z-axis rotation needs to be reversed back.

The Daggerfall models I exported from Daggerfall Modeling are already oriented correctly so I dont need to worry about those. I suspect this is because Blender imported the .DAE objects into it's own coordinate system and DFU builds the meshes in Unity's coordinate system so as long as the position coordinates are correct, they'll appear the same in both Blender and Unity.

When exporting the layout from Blender, I will need to take into account the entire scene's bounding box and substract the bounding box length on the Y-axis from the objects Y-coordinate to get the correct Z-coordinate for DFU.

Glad to have this solved and written out, I was afraid it was going to do my head in :lol:
Daggerfall Unity on UESP: https://en.uesp.net/w/index.php?title=T ... fall_Unity
Daggerfall Unity on Nexus Mods: https://www.nexusmods.com/daggerfallunity
My github repositories with mostly DFU related stuff: https://github.com/BadLuckBurt

User avatar
King of Worms
Posts: 3212
Joined: Mon Oct 17, 2016 11:18 pm
Location: Scourg Barrow (CZ)
Contact:

Re: [Solved] Blender Y coord <-> Unity Z coord conversion for layouts

Post by King of Worms » Thu Mar 26, 2020 1:42 pm

Nice you solved it, that will be one epic room!!

Post Reply