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 Exporting Animations - Rest Position toggle #5887

Closed
willyvvu opened this issue Jan 13, 2015 · 13 comments
Closed

Blender Exporting Animations - Rest Position toggle #5887

willyvvu opened this issue Jan 13, 2015 · 13 comments

Comments

@willyvvu
Copy link
Contributor

When exporting a multiple skeletal animations, I find myself needing to export the mesh in the rest position to avoid having three.js to take an already-skinned mesh and apply armature transforms on it again.

screen shot 2015-01-13 at 10 48 40 am

I created a separate animation consisting of the rest position just so I could switch to it before exporting, so I could export the rest position. I realized that there is a button in Blender that accomplishes the same task:

screen shot 2015-01-13 at 10 43 11 am

However, exporting in that way creates a slightly different, non-functional JSON. Here are the two output files:

https://www.diffchecker.com/qyxn4nxg

The file on the left is the one that works correctly. It was exported by creating a separate rest animation. The file on the right is exported by choosing "Rest Position", and appears to be missing animation data.

It would be nice for the rest position button to work - it would remove the need for a separate animation just for exporting. Visually in the editor, both methods have identical meshes displaying, but export differently.

Also, exporting skeletal animations changes the currently selected animation.

@crobi
Copy link
Contributor

crobi commented Jan 13, 2015

Note (ping @repsac): the Blender exporter is currently being rewritten in the dev branch. You may get very different results with it, maybe you could try the exporter from the dev branch?

[...] to avoid having three.js to take an already-skinned mesh and apply armature transforms on it again

Isn't this a bug with the exporter then? Can you describe this problem in detail?

The file on the right is exported by choosing "Rest Position", and appears to be missing animation data

The file on the right has a "Wiggle" animation that contains the rest pose for all keyframes. I guess if you tell Blender to display the rest pose for all time steps, then it will also export the rest pose for all time steps.

@repsac
Copy link
Contributor

repsac commented Jan 13, 2015

Actually there is another issue with animations I am trying to figure out with the new exporter. The dev branch does not export an array of animations. I had some issues with this, tho that was awhile ago and I can't recall what it was. Currently the logic I am using this logic to find the armature and action to use.

bpy.data.objects[<object_name>].find_armature().animation_data.action

It seemed more logical to directly query the target object of the mesh rather than blindly iterate over the actions in bpy.data.actions and assume each one contained animation data relevant to the geometry which is what the previous/current exporter does. But then again what is logical and what is actually needed aren't always the same thing...

But this is why the new exporter puts out a single object/dictionary and not an array. I could be wrong in this assumption but that is what we are trying to figure out.

@repsac
Copy link
Contributor

repsac commented Feb 11, 2015

After this PR #6052 is merged I suggest testing out the changes made specifically to skeletal animations in which you can choose to export either POSE or REST (your armature's pose position will have to match). It also puts out an array again.

@willyvvu
Copy link
Contributor Author

Thanks! I'll be sure to take it for a spin.

@willyvvu
Copy link
Contributor Author

All right. I've tried the new exporter (which is fantastic), and I'm back with results.
It seems that I get four different results by selecting different options from the exporter pose/rest menu and the armature pose/rest menu.

Armature ➡️ _________________ Exporter ⬇️
Mesh is exported in the pose position, and all animations magically become the animation selected during export, e.g. Selecting the Idle animation when exporting will cause the the other animations to magically become the Idle animation. Mesh is exported in rest position, and all animations consist of the resting position only. The mesh doesn't move, and stays in the rest position.
Mesh is exported in the pose position, and all animations work. However, the mesh is transformed twice. Mesh is exported in the rest position, and all the animations work properly! 👍

More notes:
✅ The exporter now does not change the currently selected animation. Great!
❔ Exporting takes much longer than it used to, causing blender to temporarily hang.
❌ Exporting with the armature selected instead of the mesh causes an error. Perhaps having the exporter check each object to see if it is a mesh while exporting?

@repsac
Copy link
Contributor

repsac commented Feb 15, 2015

It probably isn't wise to mix Pose/Rest. I considered throwing in a check for that but still on the fence about that one. Who knows if someone ever has a really odd scene that requires them to mix the two. I also played with the concept of setting the position based on the three exporter settings (if your scene's armature was set to Rest but the exporter was Pose it would set the position for you) but for some reason this didn't seem to work as expected. The code is still in place but commented out until I have more time to look at it.

❔ Exporting takes much longer than it used to, causing blender to temporarily hang.

Speed improvements have been addressed (#6031) and there are a couple more parts of the exporter that have yet to be optimized. One thing that is unavoidable is that now the exporter actually uses json to serialize (this is one place where I have noticed slower performance). Previously string blocks like this

'''
{
    "key1": "%(value)s"
}
'''

were used in the exporter and built JSON entries into a large string that only needed to be written to file. The customized json serializing is slower but allows other features:

  • proper JSON formatted documents (handles all the indents) , for a developer having things like animation key values with pretty indents makes debugging soooooooooooooo much easier
  • allows for non-indented documents (See the Indent option which is recommended on exporting animations to save size)
  • value parsing that supports the new floating point precision export option

Also because the exporter builds real Python dictionaries under the hood it gives me a data format that can use for other formats like msgpack or like in production scenario I setup where the output dictionary is actually checked into a database directly.

❌ Exporting with the armature selected instead of the mesh causes an error. Perhaps having the exporter check each object to see if it is a mesh while exporting?

Is this the error you're seeing #6050 (comment)? If so then the exporter is indeed checking (#6050 (comment)) and reporting, it just isn't a wrapped into a dialog at this time.
https://github.com/mrdoob/three.js/blob/dev/utils/exporters/blender/addons/io_three/exporter/__init__.py#L65

If the traceback is something else then it would be an actual error because the exporter would have been trying to parse an armature like its a mesh. I will be adding utilizing something like this
http://community.cgcookie.com/t/code-snippet-easy-error-messages/203
for creating message/error dialogs for the exporter now that it seems like we are through the major kinks.

It seems like you have a working animation export now.

@willyvvu
Copy link
Contributor Author

All right. I still don't quite understand exactly what is changed by the two Rest/Pose toggles (for Armature and Exporter). At least there is one option that works for me - and many thanks for a re-write!

I'm also experiencing strange artifacts on importing these animations on the client side, using the latest dev version of three.js. Some animations will rotate/scale randomly when played, but that's probably best left to another issue.

@willyvvu
Copy link
Contributor Author

Hmm... It seems to come with non-normalized quaternions coming from Blender - apparently Blender allows quaternions have x, y, z, and w values greater than 1!

@willyvvu
Copy link
Contributor Author

These non-normalized quaternions are also exported! Note the 18.577 I was able to set. Sometimes blender will accidentally set these.

"hierarchy": [{
            "keys": [{
                "rot": [0.0,0.0,-0.0,1.0],
                "time": 0.0,
                "pos": [0.0,0.856348,-0.0],
                "scl": [1,1,1]
            },{
                "rot": [1.0,0.0,-0.0,0.963587],
                "time": 0.133333
            },{
                "rot": [1.0,0.0,-0.0,18.577267],
                "time": 0.283333
            },{
                "rot": [1.0,0.0,-0.0,0.999611],
                "time": 0.483333,
                "pos": [0.0,0.856348,-0.0],
                "scl": [1,1,1]
            }],
            "parent": -1
        }

@willyvvu
Copy link
Contributor Author

The rest belongs in #6082

@repsac
Copy link
Contributor

repsac commented Feb 16, 2015

I still don't quite understand exactly what is changed by the two Rest/Pose toggles

Well if you're so inclined you could diff the exporter modules from r66 and r67 (that is when the changed happened). You could also read what was said here #5582 (comment) and here #5582 (comment) and see if that makes sense for you. Or just be happy that you have a way to get working animations out ;)

@titansoftime
Copy link
Contributor

Good catch on the non-normalized quaternions.

All right. I still don't quite understand exactly what is changed by the two Rest/Pose toggles (for Armature and Exporter)

I believe the reason for this is that exporting in pose mode positions the bones to the selected pose. Applying a different animation to these already set bone positions creates distortions.

@willyvvu
Copy link
Contributor Author

Thanks, @repsac and thanks again @titansoftime.

Through playing around and studying code, I can hope to develop a clearer understanding of the ins and outs of the exporter over time.

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

No branches or pull requests

5 participants