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

Blender export bones rotation pivot #10273

Closed
hesselbom opened this issue Dec 2, 2016 · 5 comments
Closed

Blender export bones rotation pivot #10273

hesselbom opened this issue Dec 2, 2016 · 5 comments

Comments

@hesselbom
Copy link

Description of the problem

In Blender I've created a mesh, attached armature and a simple rotation animation on one of the bones, called "head" (connected to another, named "stomach").

When exporting to Three.js I get two issues. The first is that for position yz are flipped, similar for rotation. This was easy to solve by hacking the exported animationKeys to flip them to work with threejs. How I did that was inside the parseAnimation function, under the comment // ...assume skeletal animation I added this:

for (let i = 0; i < animationKeys.length; i++) {
  let keys = animationKeys[i]
  let diff = [keys.pos[0] - bones[h].pos[0], keys.pos[1] - bones[h].pos[1], keys.pos[2] - bones[h].pos[2]]
  keys.pos = bones[h].pos.slice()
  keys.pos[0] += diff[0]
  keys.pos[1] += -diff[2]
  keys.pos[2] += diff[1]

  diff = [keys.rot[0] - bones[h].rotq[0], keys.rot[1] - bones[h].rotq[1], keys.rot[2] - bones[h].rotq[2], keys.rot[3] - bones[h].rotq[3]]
  keys.rot = bones[h].rotq.slice()
  keys.rot[0] += diff[0]
  keys.rot[1] += -diff[2]
  keys.rot[2] += diff[1]
  keys.rot[3] += diff[3]
}

I suppose that is mostly a hack to get it to work for me, it should really be in the exporter python script, I'll look into that later. That was just the context, the second issue is what this post is about.

When running the animation the pivot point for the "head" bone's rotation looks to be at 0,0,0 while in Blender it's relative to it's position (parent?). The result is the following:

blender1

blender2

real1

real2

I tried to "hack" in a way to set pivot point myself, just to see if I could get it to work, but I couldn't find how.

The export settings I use are the following (although I've tried pretty much every variation of settings I could think of):
exportsettings

This is an issue but I'm not 100% sure how it's supposed to work (regarding pivot points for bones).

Three.js version

0.82.1 (latest from npm at time of writing)

@HiZhaoxiaoyang
Copy link

HiZhaoxiaoyang commented Dec 2, 2016

skeletal sounds cool ...

@mrdoob
Copy link
Owner

mrdoob commented Dec 2, 2016

/ping @arturitu

@arturitu
Copy link
Contributor

arturitu commented Dec 3, 2016

@hesselbom

About the yz are flipped perhaps you need to reset all of these data before export your model >
image

And about pivot point, I use this settings to export timeline based animation (where Morph animation isn't selected, is selected 'Keyframe animation' and on 'Skeletal animation' is selected 'Pose' not 'Rest'>
image

Anyway, this is a link with a tutorial step by step to export a bone animated model with all the source code and blender files if you want to compare >http://unboring.net/workflows/animation.html

I hope with this you don't have any problem.

@hesselbom
Copy link
Author

Interesting! Looks like both animations and flipped values work well when just exporting the model and not the scene.

That's good enough for me. I would still consider it a bug that it gets wrong when exporting scene/hierarchy but for my purposes I can get it to work like this.

Thanks!

@Mugen87
Copy link
Collaborator

Mugen87 commented May 31, 2018

The JSON Blender exporter has been removed with R93 (#14117).

Also see: https://threejs.org/docs/#manual/introduction/Loading-3D-models

@Mugen87 Mugen87 closed this as completed May 31, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants