Jump to content

Mesh rotated 180° in Unity, vs. Blender & game


Recommended Posts

I'm learning about how to make models for KSP parts using Blender and PartTools, using this "cheat sheet" by RoverDude as a reference for how things should be oriented, and I'm a bit confused because the orientation of my meshes doesn't entirely match what I'd expect based on that diagram.

For the sake of example, here's a simple mesh in Blender:

DZ4Vvo6.png

Notice the axes in the corner: I made it in what I think of as the typical orientation in Blender, with the X-axis pointing to the right and the Y-axis pointing upward when the model is viewed from the top.  But RoverDude's cheat sheet shows the opposite orientation, with the X-axis pointing left and Y-axis pointing down when viewed from the top, so here's another view of the same model with the camera in a different position:

jlELKAk.png

The axes here match the ones shown for Blender on the cheat sheet.

Now I import into Unity, which applies an automatic default rotation of -90 degrees around the X-axis to turn Blender's Z-up convention into Unity's Y-up:

yoZxQGg.png

…but the object looks like this:

Uz6729Q.png

The axes match what's shown for Unity on RoverDude's cheat sheet, but the model appears to be rotated 180° around the Y-axis compared to the second Blender image above, which confuses me: I'd expect them to match, based on the axes in the diagram.

Then I export this model to a .mu file using PartTools.  I have an empty GameObject with the PartTools component attached, with the cube model as a child object.  I add a simple .cfg file to load the .mu, start the game, and get this:

DVUJsmg.png

Now we're looking at the back of the cube again.  Based on the cheat sheet, this is consistent with the second Blender image above, but not with how it's displayed in the Unity editor.

I'm left wondering two things:

  • FIrst, why does the part appear with a different orientation in the Unity editor than it does in Blender and the VAB?  Are the axes in RoverDude's diagram incorrect, or am I misunderstanding something, or maybe importing my model incorrectly?
  • Second, how should I orient my mesh in Blender?  If I want the VAB image above to show the cube's front face instead of its back, is it OK to just put a 180° Y-axis rotation in the Transform block in Unity, or is it preferable to actually turn the whole thing around in Blender?  How do experienced modelers do this?
Link to comment
Share on other sites

Easy way: just model everything in blender with z up and y back (the normal mode in blender).

Then export to fbx with the following

exporta7xia.png

As you can see. the exporter already addresses the problem with the Forward: -z forward and UP: Y Up setting (this is even selected by default). This way your model will be imported fine with the correct orientation in unity. Only thing where you need to think is when setting up empty transforms in blender and want to align thrust axis, and smoke/exhaust fx axis.

One tip: make an empty transform and set all your meshes and empty transforms (for said exhaust fx, nodes, etc) as children of this empty. This way the said empty will define the origin of your model, so you don't even need to centre it around the actual origin in blender and unity but can freely position it in your scene. For example:

exportexamplexkxbb.png

All the objects that form the capsule with all its antennas etc are children of the empty named "va_capsule_origin".

EDIT: and yes, if you want your model rotated in the vab, rotate it in blender or unity (i usually try to set up as much as possible in blender).

Edited by InsaneDruid
Link to comment
Share on other sites

I'd been importing the .blend file directly to Unity (which automatically runs it through Blender's FBX exporter), but I tried manually exporting to FBX instead and the result is the same — the model is still rotated 180° in the Unity editor compared to how the "cheat sheet" indicates it's supposed to be.

Also interestingly, if I import the .mu file back into Blender using taniwha's Blender .mu importer, it's rotated 180° (around Blender's Z-axis) compared to the original.

Link to comment
Share on other sites

Unity works fine with blender models, I see no need to export as .fbx

The pros side is that you can tweak your model anytime during the workflow without extra steps. I always adjust the rotation of my prefabs in Unity rather than in Blender.

Link to comment
Share on other sites

I tried to implement the idea of just importing blender models directly into unity. The reasons why I did not stick with it are:

Version control. I like to save early, save often keeping older versions of the blend files.

I tend to work with big blend files that contain all the parts of a project. The whole Proton with every part is just one file. I tried importing it in unity -> took ages. Reasoning for this is that it allows me to model a project as a whole, then splitting it up and exporting the single models out of it. Especially during the initial development I carry a lot of helper structures, shrinkwrap targets, baking sources and a metric ton of image empties with me. Combined with the first point -> current folder size of my blend files for the TKS is 5GB that i would carry around in unity.

Another level of backup due to the presence of the fbx files on another drive.

Link to comment
Share on other sites

Following up, I found this image that shows the actual coordinate system orientation in Unity and in KSP.  The X-axis actually points toward the launchpad, not away from it as RoverDude's "cheat sheet" shows.  Seems like the cheat sheet is incorrect (which surprises me, since RoverDude generally knows what he's doing).

The actual relationship between the Blender and Unity coordinate systems seems to be that the handedness conversion flips the X-axis, and the 90-degree rotation around X, automatically applied to Blender models imported in Unity, transforms Blender's Z-up convention to Unity's Y-up.  If you orient the camera in Blender so that Z points up and X points to the left, you're facing toward the flag wall in the VAB.

Link to comment
Share on other sites

  • 7 months later...
On 2/7/2017 at 9:28 PM, Wyzard said:

Following up, I found this image that shows the actual coordinate system orientation in Unity and in KSP.  The X-axis actually points toward the launchpad, not away from it as RoverDude's "cheat sheet" shows.  Seems like the cheat sheet is incorrect (which surprises me, since RoverDude generally knows what he's doing).

The actual relationship between the Blender and Unity coordinate systems seems to be that the handedness conversion flips the X-axis, and the 90-degree rotation around X, automatically applied to Blender models imported in Unity, transforms Blender's Z-up convention to Unity's Y-up.  If you orient the camera in Blender so that Z points up and X points to the left, you're facing toward the flag wall in the VAB.

Keywords, BLender, Unity, Axes, Axis (I am writing this because I seem to keep forgetting this and look up answer here on KSP forum, so I decided to create a mathematical definition of the problem).

This is what I have learned trying to position attachment nodes.

Blender X  become KSP - X. That means if you create a box of size 1 with one outward facing side on the x = 0  plane and another at x = 1 plane then any "attach_node" that is flush with the "x" walls will have x coordintates of x = 0 and x = -1

Blender Y becomes KSP -Z. That means if two more walls are y = 0 and y =1 then and "node_stack" that is flush will have z coordinates of z = 0 and z = -1

Blender Z becomes KSP Y.  That means if last two walls are z= 0 and z = 1 then they will become y = 0  and y = 1

So lets imaging a blender cube with 8  xyz  vertices. I have intentionally offset the center of the cube from the origin. the center of this cube in blender is 0.5, 0.5, 0.5

x,y,z vertices (in blender)

1. 0,0,0
2. 1,0,0
3. 0,1,0
4. 1,1,0
5. 0,0,1
6. 1,0,1
7. 0,1,1
8. 1,1,1

These vertices can form the 6 faces of a cube in blender. To make this cube set the 3D cursor in blender to xyz 0.5, 0.5, 0.5. The create a cube of radius 0.5.

face		plane(in Blender)		vertices (see above)
A			x = 0				1, 3, 5, and 7
B			y = 0 				1, 2, 5, and 6
C			z = 0				1, 2, 3, and 4
D 			x = 1				2, 4, 6, and 8
E			y = 1				3, 4, 7, and 8	
F			z = 1				5, 6, 7, and 8

 

Now if you are going to make nodes on the center of each face (A, B, C, D, E, F) you will  need to make the following script in your cfg file.

    node_stack_A = 0.00, 0.5, -0.5, 1.0, 0.0, 0.00, 1   \\-KSP x+ orientation faces east, '090 in VAB is derived from blender x-
    node_stack_B = -0.5, 0.5, 0.00, 0.0, 0.0, 1.0, 1   \\-KSP z+ orientation faces north, '000 in VAB is derived from blender y-
    node_stack_C = -0.5, 0.00, -0.5, 0.0, -1.0, 0, 1  \\-KSP y- orientation faces down, -'090 pitch in VAB is derived from blender z-
    node_stack_D = -1.00, 0.5, -0.5, -1.0, 0.0, 0.00, 1 \\-KSP x-negative orientation faces west '270 in VAB is derived from blender x+
    node_stack_E = -0.5, 0.5, -1.00, 0.0, 0.0, -1.0, 1 \\-KSP z-negative orientation faces south '180 in VAB is derived from blender y+
    node_stack_F = -0.5, 1.00, -0.5, 0.0, 1.0, 0, 1 \\-KSP y+ orientation faces up is derived from blender z+

Thus no direction in blender holds true in KSP. To put is simple the chirality of the axes in blender and Unity are mirror images and are not superimposable.  You cannot simply flip by -90 degrees on X axis to fix vertical usage problem because this does not change chirality. If unity does sign reverse one set of coordinates, the the model you produce in KSP will be a chiral image of the model created in blender.

The problem half lies in blender and unity, and is not due to the -90 rotation on the X-axis. There are two ways (chirality) of displaying X+, Y+ and Z+ orientations. When looking down from Z+ perspective X+ can be clockwise or counterclockwise of Y. In chemistry these are known as stereo isomers and each are valid (e.g. d-amino acids versus l-amino acids). To put is quite simply blender and unity coordinate systems is a mirror image of each and cannot be superimposed. Blender uses an x+ axis that is clockwise from y+ axis when viewed from a +z position, whereas blender uses a x+ axis that is counterclockwise of y+ axis when viewed from the z+ axis.  Therefore Unity could not just rotate around x axis by 90 degrees, it would actually have to invert an axis in order to fix the problem during the import and create a chirality representative in some dimension of blender. .

I hope this explains this. I agree its a major pain in the ___. I always seem to forget and have to go look it up.

 

 

 

 

 

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...