Jump to content

Blender to babylon.js issue


ozRocker
 Share

Recommended Posts

I get that we can't export armature to .babylon from Blender if some of the meshes attached don't have transformations applied.  I'm trying to find the best way to solve this issue.

I have a separate head and body attached to the same armature.  When I try to export to .babylon it will complain about the head mesh not having transformations applied.  When I check the mesh properties I see location, rotation all zero and scale all 1. Applying transformations to that mesh does nothing.  However, when I clear parent I notice Rotation X goes from 0 to -0.  I can then apply rotation and it'll set that back to 0.  Then I can parent mesh back to armature and export works fine.  However, I used "automatic weighting" so now I've lost all the weighting that was important to me. 

This isn't a Babylon.js problem but I didn't know where to ask.  Does anyone know how to stop that nonsense that results in a -0?  Or does anyone know how I can clear parent then re-attach to parent using the same weighting as before?  Or is it possible to edit the plugin to treat -0 as 0?

Link to comment
Share on other sites

I produced a workaround with the Blender exporter.

In json_exporter.py I commented out the lines that check for unapplied transformations:

#if mesh.hasUnappliedTransforms and hasattr(mesh, '#    self.fatalError = 'Mesh: ' + mesh.name + ' has un-applied transformations.  This will never work for a mesh with an armature.  Export cancelled'
#    Logger.log(self.fatalError)
#    return

 

Link to comment
Share on other sites

  • ozRocker changed the title to [SOLVED] Blender to babylon.js issue

A better place to change would be where hasUnAppliedTransforms is determined.  I did quite follow all that work flow.  An armature modifier can be on a mesh & exported where the parent is not also the armature, but I do not know how to get automatic weights that way.

Perhaps, abs() could be used in the check to mitigate this -0 stuff. 

# ensure no unapplied rotation or scale, when there is an armature
self.hasUnappliedTransforms = (self.scaling.x != 1 or self.scaling.y != 1 or self.scaling.z != 1 or
        (hasattr(self, 'rotation'          ) and (abs(self.rotation          .x) != 0 or abs(self.rotation          .y) != 0 or abs(self.rotation          .z) != 0)) or 
        (hasattr(self, 'rotationQuaternion') and (abs(self.rotationQuaternion.x) != 0 or abs(self.rotationQuaternion.y) != 0 or abs(self.rotationQuaternion.z) != 0 or self.rotationQuaternion.w != 1))
        )

 

Link to comment
Share on other sites

  • 3 weeks later...
On 2/18/2018 at 9:22 AM, JCPalmer said:

A better place to change would be where hasUnAppliedTransforms is determined.  I did quite follow all that work flow.  An armature modifier can be on a mesh & exported where the parent is not also the armature, but I do not know how to get automatic weights that way.

Perhaps, abs() could be used in the check to mitigate this -0 stuff. 

Holy moly. I had been having problems with this as well. I un-parented everything, cleared all transformations, confirmed that everything was indeed 0 and W was 1. Re-parented, re-weighted, tried the abs() solution and STILL got this error.

Finally, I logged the actual rotation data stored in the mesh in question. Simply logging self.rotation showed nothing of note: 0, 0, 0. THEN I decided to get specific and log each component (x, y, z) by themselves. Here's what I got when I hit Y:

3.552713678800501e-15

That's right; 0.0000000000000035527blahblahblah.

Ridiculous! So, Blender has a rounding problem when it comes to clearing transformations, and clearing them is no guarantee of anything, apparently.

SO, in addition to the abs() solution that JCPalmer proposed, I added round(n, 3) to each one of them, and it finally worked. I'll issue a pull request when I get a chance.

Edit: Actually, I don't think abs() is entirely necessary. Every Python version I have access to throws True when I compare -0 to 0. Maybe it's best to be on the safe side?

Link to comment
Share on other sites

3 hours ago, JCPalmer said:

Try Blender exporter 5.6 released last Friday.  I round to the precision that rotation is rounded to when exported.  This is even better than my first thought above.  No need to PM.  You could test it, since I did not have a real world example though.

Oh, great; I'll do that!

Edit: Works perfectly!

Link to comment
Share on other sites

  • RaananW changed the title to Blender to babylon.js issue

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.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...