Some trouble with the Blender exporter (rotations and unwanted Z/Y flip)

Hi there,

First, thanks for this excellent framework: currently migrating some hobby project from Three.js to Babylon and very happy with it!

Anyway, I have few troubles with the Blender exporter:

  • When the model have transformations, they are kept in the .babylon file. Is there an option to always convert positions to the world coordinate (like the glTF exporter does)?
  • Moreover, rotation do not work at all (except quaternions), it seems that the exporter doesn’t save the Euler order along with axis angles.
  • The exporter flip Z and Y, and I would like to prevent it from doing so, but can’t find how.

I can fix the first and second by “applying transforms” in Blender, however I can’t find an easy way to fix the last.

They said I should ping @JCPalmer for that! :wink:

Hi! And welcome to the forum!

Maybe @Drigax might be able to help as well.

The short answer to stop flipping is to change the source code, specifically format_vector in package_level.py.

Once done, you are “on your own”, not that you actually bought support in the first place though.

This exporter is designed to send data in native format to BJS. BJS is Y-Up, so everything is flipped, including rotations.

@Cedric @JCPalmer Thanks for the reply!

The project I’m migrating to Babylon is Z-up (and right-handed), so I have to make it work that way.
So far Babylon looks flexible enough, except rotation, so I will use quaternions everywhere, and I already coded few helpers to convert easily Z-up yaw/pitch/roll into quaternions.

For the Blender exporter, I decided (before reading your reply) to patch directly the .babylon output file (too much things to learn to patch the exporter itself, and I’m not enjoying Python programming). So far, for every mesh, my script swap Y/Z in the “positions” and “normals” arrays, and for the “indices” array, the first and the last of each group of three are swapped (to restore the correct face side). Is there anything else that need to be done for models? (UV?)

If there is too much work here, I would eventually prefer modifying the Python exporter, I just want to go with the shortest path. In package_level.py, if I change format_vector() and format_quaternion(), everything will be ok? Or is there other things to patch?

@JCPalmer BTW would you accept a PR for that? I got it working with an opt-in option inside the “world” tab.

Go ahead. One thing that will also need to change is the version. It should now be 6.3, since functionality has changed. This is in the initial.py at the highest level.

I can also change it prior to merge, though I don’t know how.

@JCPalmer Great! The PR is ready.

Ok, I will not get a look at till Monday.