Page 1 of 1

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

Posted: Wed Mar 25, 2020 10:00 am
by BadLuckBurt
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.

Re: Blender - Unity layout discrepancy

Posted: Wed Mar 25, 2020 11:15 am
by pango
Not using Blender myself, I don't know if this is of any use: https://relenting1.wixsite.com/nathanie ... and-tricks

Re: Blender - Unity layout discrepancy

Posted: Wed Mar 25, 2020 11:23 am
by BadLuckBurt
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

Re: Blender - Unity layout discrepancy

Posted: Thu Mar 26, 2020 6:23 am
by BadLuckBurt
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:

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

Posted: Thu Mar 26, 2020 1:42 pm
by King of Worms
Nice you solved it, that will be one epic room!!