Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exporting from Blender: Y and Z axes are flipped #31

Closed
cyle opened this issue Aug 27, 2013 · 11 comments
Closed

Exporting from Blender: Y and Z axes are flipped #31

cyle opened this issue Aug 27, 2013 · 11 comments
Labels

Comments

@cyle
Copy link
Contributor

cyle commented Aug 27, 2013

Hello again. I'm having a weird issue exporting models from Blender into Babylon.js -- it seems that the axes get flipped around. For example, if I make a cone in Blender and point it upwards along the Z axis, it imports into Babylon as pointing along the Y axis. Putting a sphere at (x = 0, y = 0, z = 1) in Blender results in the item importing as (x = 0, y = 1, z = 0) in Babylon.js. Is this something that could be fixed in the exporter? It looks like line 66 of io_export_babylon.py is flipping the Y and Z coordinate -- is that intentional? It seems to also be the case on lines 435 and 436, as well. Any help would be appreciated! Thanks.

@deltakosh
Copy link
Contributor

This Is intentional because Babylon.js uses a system with y up. My blender uses a system with z up so I flip them to keep a visual continuity.

Does your blender use a y up coordinates system?

@cyle
Copy link
Contributor Author

cyle commented Aug 27, 2013

No, my blender (default install of the latest version on either Mac or Windows) uses a Z-up coordinate system. In the default 3D view, there's an X and Y grid with Z going up and down. So when I make a model that, for example, stays on Z = 0 but has objects along the X and Y axis, importing it into Babylon flips it on its side (since Z = Y in Babylon). I'll try changing the exporter code around to see if it fixes the issue. Or is there a way to change the coordinate system to be Y-up in Blender?

@cyle
Copy link
Contributor Author

cyle commented Aug 27, 2013

So when I change lines 66, 435, and 436 to flip Z and Y, for example changing this:

file_handler.write(",\""+name+"\":[" + "%.4f,%.4f,%.4f"%(vector.x,vector.z,vector.y) + "]")

to this:

file_handler.write(",\""+name+"\":[" + "%.4f,%.4f,%.4f"%(vector.x,vector.y,vector.z) + "]")

It works, but the model's textures seem to render inverted somehow. Here's an image of the way the existing export plugin renders in Babylon. The three cubes are the X (red), Y (green), and Z (blue) axes.

screen shot 2013-08-27 at 6 19 47 pm

Here's the way my adaptation renders it:

screen shot 2013-08-27 at 6 19 33 pm

The model should be pointing along the Y axis, which it does in my version of the exporter.

@deltakosh
Copy link
Contributor

It is cool that you can have what you want but there is something I do nor understand here:) Could you share a blender scene you created? I would like to test because for me the y/z inversion is required

@cyle
Copy link
Contributor Author

cyle commented Aug 29, 2013

Definitely -- here's the files I've used to demo the issue: https://github.com/cyle/babylonjs-model-test

Just want to say that this project is amazing. I'm extremely impressed with how quickly I've been able to rig up a good-looking 3D game in no time with Javascript in the browser. This is an excellent project and I'm super excited to see it get even better. Thank you for all of your work!

@deltakosh
Copy link
Contributor

Thank you :) I will have a look :)

@deltakosh
Copy link
Contributor

According to the scene you sent, the object should point along the z axis of babylon.js (which is the Y axis of blender):
capture

So I think the exporter behave well:
original

@cyle
Copy link
Contributor Author

cyle commented Aug 29, 2013

Okay, so that's how it should work between Blender and Babylon.js. So if we make models in Blender that we want to use in Babylon.js, we just need to make them along the Y axis if we expect them to be oriented correctly in Babylon.js. Is there any way Babylon.js could be changed so it works the other way, or is it required for the engine?

@deltakosh
Copy link
Contributor

It is required by the fact that in this way, the image produced by blender is the same in babylon.js :)

@cyle
Copy link
Contributor Author

cyle commented Aug 29, 2013

Okay, cool. Just wanted to make sure that was the case. Thanks for your help!

@cyle cyle closed this as completed Aug 29, 2013
@marcusdiy
Copy link

Yep. Seems like this problem was not solved. Exporting with "Preserve Z-up right-handed" doesnt work eighter. I tried to export using Blender 2.91.2 and for preview https://sandbox.babylonjs.com/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants