mrdoob / three.js

JavaScript 3D Library.
https://threejs.org/
MIT License
102.02k stars 35.34k forks source link

Broken blender export with animation (demos and blends are provided) #8511

Closed rnixik closed 6 years ago

rnixik commented 8 years ago
Description of the problem

PR #8412 updated blender export and now there are no way to export mesh with skinned animation. I have tested with women model and with monster model, which is imported from collada examples/models/collada/monster/monster.dae. I have build demos with the same main.js but with different json files.

Demos

Settings for mesh export (Scene is unchecked, using THREE.JSONLoader):

Image of settings

Only mesh with new export - women (4MB)

Image of Women Mesh New

Only mesh with old export - women (4MB)

Image of Women Mesh Old

Only mesh with new export - monster (242KB)

Image of Monster Mesh New

There is another option and another problem: export with checked "Scene" and using THREE.ObjectLoader: Image of settings But with this option animation does not work correctly in both versions:

Scene with new export - monster (285KB) Scene with old export - monster (284KB) Image of Monster Scene

I have worked with old exporter and noticed that vertices values in json are bigger with Scene checked then with unchecked version. I have tried to replace this array in json file and animation becomes work properly. I can not figure out what is the problem with exporter with checked Scene.

Files

Exports have been done with reset transforms of bones before each export.

Three.js version
tschw commented 8 years ago

@rnixik

Which Three.js release is the "old" exporter?

[... Scene checked ... ] But with this option animation does not work correctly in both versions

I think this part is a known issue.

I have tried to replace this array in json file and animation becomes work properly

Replaced with ...? The array exported by the old or the current exporter?

rnixik commented 8 years ago

@tschw

Which Three.js release is the "old" exporter?

Old exporter is before PR #8412, it means r75, new is in dev.

Replaced with ...

Array of vertices in scene.json replaced with array of vertices from object.json (the same mesh).

The array exported by the old or the current exporter?

I've experimented with old exporter.

rnixik commented 8 years ago

A little more about replacing.

  1. I exported monster with unchecked Scene and got monster.json with these vertices: Image of object vertices
  2. Then I exported monster with checked Scene and got monster_scene.json with these vertices: Image of scene vertices
  3. Then I copied vertices from the first and put them into the second and got monster_scene_replaced.json with these vertices: Image of replaced vertices

Now I got correct animation, but with a little different scale of object. Demo with THREE.ObjectLoader and animation after replacement.

Files: replacing.zip (347KB)

tschw commented 8 years ago

@rnixik

Old exporter is before PR #8412, it means r75, new is in dev.

Since you already identified the breaking PR, let's first see whether the author is around, to save us some digging. /ping @phfatmonkey

If not around, we'll do exactly that.

Now I got correct animation, but with a little different scale of object.

Seems it should be able to make this one work too, then.

phfatmonkey commented 8 years ago

Hey guys. I did some work on the skinned mesh export recently because we couldn't get any skinned meshes to work at all.

Is your skinned mesh scaled in Blender? If so, try Applying the Transformations of both Rotation and Scale. That usually fixes the "nightmare dragon" problem (that's what we call it when the mesh distorts like that.

tschw commented 8 years ago

@rnixik Did the suggestion above solve your problems?

@phfatmonkey Please correct me if I'm wrong, but your PR seems to have broken it - at least in OP's case. Is there any way to get rid of the quirk?

rnixik commented 8 years ago

Is your skinned mesh scaled in Blender? If so, try Applying the Transformations of both Rotation and Scale.

Applied, but does not help. Tested with scene and without scene Image of applying

phfatmonkey commented 8 years ago

@rnixik Are you exporting the model when the mesh is in the bind pose? If not, add an action with just one keyframe where all the bones are in their default position (cleared transform).

Please correct me if I'm wrong, but your PR seems to have broken it - at least in OP's case. Is there any way to get rid of the quirk?

@tschw With the new THREE, we weren't able to get any skinned meshes loaded properly at all when using the last version of the exporter (r73). The PR I did got us to a point where we can export and display skinned meshes as expected.

I'll take a look at your scene and examples and see if I can identify the issue.

rnixik commented 8 years ago

@phfatmonkey Yes, in the bind pose

tschw commented 8 years ago

@phfatmonkey

With the new THREE, we weren't able to get any skinned meshes loaded properly at all when using the last version of the exporter (r73). The PR I did got us to a point where we can export and display skinned meshes as expected.

You said so in your previous post. Else reverting the changes until the issues are resolved would have been a short-termed solution, but I figured that it would probably break the export in a dozen of other cases.

I'll take a look at your scene and examples and see if I can identify the issue.

Thanks a lot! That's what I had hoped for.

If not, add an action with just one keyframe where all the bones are in their default position (cleared transform).

It'd be super awesome if we could automate these steps somehow. I don't think we should settle with having a secret science of model export.

phfatmonkey commented 8 years ago

Ok, I looked at your files and here's what I found.

The Armature and the Mesh in both scenes (women.blend and monster.blend) have scale applied. It's easy to fix the mesh, but applying transforms on the Armature causes the mesh to be horribly distorted. As a general rule, make sure you don't scale or rotate your rig or bones. It's just a good best practice for rigging in general to do this.

Now, on to the exporter issues...

I'm fairly certain this issue existed before my pull request. I just tried r75 with the newest marine model included in pull request #8410 and I got this:

image

Similar results with the exporter on the dev branch just before my PR:

image

Then I tried the newest dev exporter with my change:

image

After r69 the exporter was completely changed and the way it's grabbing vert transforms is a little different. Previously transforms seemed to be using world space, but now they're transformed using a matrix. Perhaps when a model or armature is scaled the transform matrix doesn't take that into account, and since skinned verts need the bone transforms to be transformed correctly, it might explain the results. Maybe ping @repsac, one of the original authors, to see if he has any thoughts.

It'd be super awesome if we could automate these steps somehow. I don't think we should settle with having a secret science of model export.

Agreed. I suspect that's what the 'Rest' option was for in the previous exporter. However, that wasn't working either so I removed it until that feature can be added.

@rnixik I'm still curious to know which version of the exporter was used to get accurate results. Were you using the JSONLoader? With the newest exporter we were able to use the newest THREE with the ObjectLoader for skinned meshes. I agree it still needs some work, but it was unusable before.

rnixik commented 8 years ago

Ok. I will play with marine model.

I'm still curious to know which version of the exporter was used to get accurate results. Were you using the JSONLoader?

THREE.JSONLoader + exporter from r74 (I guess it has not changed in r75)

phfatmonkey commented 8 years ago

THREE.JSONLoader + exporter from r74 (I guess it has not changed in r75)

From what I understand, The JSONLoader is deprecated. If you still want to use it you'll have to use an older exporter.

rnixik commented 8 years ago

The JSONLoader is deprecated

What I should use instead? Even ObjectLoader depends on JSONLoader: https://github.com/mrdoob/three.js/blob/dev/src/loaders/ObjectLoader.js#L84

rnixik commented 8 years ago

I have tried marine model. It works fine with new exporter with scene checked and THREE.ObjectLoader. But can't even find the model on the scene with scene unchecked and THREE.JSONLoader (no any errors; tried different scale, camera positions, different materials, fov, orbit controls, new exporter, old exporter).

phfatmonkey commented 8 years ago

I think only static meshes are supported if Scene is unchecked. I noticed with the new exporter it wouldn't let me even export skinned meshes with scene unchecked. I got this error:

image

and a JSON wasn't even created. My impression is that with the new version of THREE they're moving to scene exports and you have to use the Object Loader. Take a look at examples/webgl_animation_skinning_blending.html for a demo.

rnixik commented 8 years ago

I haven't noticed this error. I got json and it loads. I did console.log and got a geometry. May be this geometry was not geometry of marine.

daniel-nth commented 8 years ago

@phfatmonkey Exporting a skinned mesh without a scene works by selecting the mesh, not the armature. The exporter will find the corresponding bones and animations. At least it used to at the time I wrote 5c72366a949e8b8a1f4a8d251c7fd1f7a3c9b107 to fix REST animations. We leave everything in the scene section of the exporter unchecked and load via JSONLoader. Since I never got a reply to https://github.com/mrdoob/three.js/issues/6050#issuecomment-150026481 and we were horribly busy I never created a PR for that. For our models this commit still works with an up-to-date dev-branch (apart from model orientation, that broke somewhere down the line). We never tried to use the scene export for skinned meshes, so no idea if things are handled differently there.

Admittedly, it does not work at all with marine_anims_core.blend. With 5c72366a949e8b8a1f4a8d251c7fd1f7a3c9b107 and a current dev branch I get similar results to the screenshots above (REST, no scene, mesh selected).

One of the main problems with Blender and three.js seems to be that there is no canonical way to create animations and everybody ends up with very different results. Our Blender guys have some rough documentation on on how they create animated models . I'll try to get them to figure out what is different in the marine.

manthrax commented 8 years ago

@phfatmonkey In your screenshot, I don't see a mesh object. When exporting skinned meshes, I usually need to have the mesh itself selected... the exporter then grabs the parent armature for export I believe.

trumanus commented 7 years ago

@phfatmonkey Hi, i have tried to export with last version on dev now, but the "nightmare dragon" problem is not solved. My human is not traslated or scaled..

What can i do ?

cropped

phfatmonkey commented 7 years ago

Hi, @trumanus. I haven't looked at this project for a while so things may be different from what I remember. But here's what could be going wrong.

Is your skinned mesh scaled? Try applying the scale to your mesh to see if that fixes it.

Is your Armature scaled? Try applying the scale on the Armature. At this point you may need to re-weight.

Are your individual bones scaled? Try applying the scale on the bones. This will also likely destroy your skin weights.

Try selecting your mesh when you export, not the armature.

If that doesn't work, you may need to go back to the older exporter. The last time I looked at this project the newest exporter was reverted back to the broken version that flips the Y and Z axis, so that might be causing the "nightmare dragon" scenario.

Sorry I can't be of more assistance. Good luck with it.

trumanus commented 7 years ago

i have applied all but nothing changed... i'm using a model create with makehuman and motion from bvh

marine is exported in right way so.. i don't think is a problem of the exporter...

i don't understand why i have to export the model in bind pose , can you give me some info on that ?

phfatmonkey commented 7 years ago

@trumanus If you haven't been exporting from the bind pose that's another reason you get the Nightmare Dragon. Make sure you try that.

The bind pose is important because there has to be a starting transform for all verts and bones from which to transform. For example, if you move the right arm up, what does that mean? It needs to know what the starting point of the verts are so it can know where to move them when the arm goes up.

So If the bind pose is wrong, the starting point for your animation is wrong.

trumanus commented 7 years ago

Hi where i can find tutorials on that specific actions in blender ? sorry i'm a programmer and not a 3d modeller

phfatmonkey commented 7 years ago

There's a ton of Blender Tutorials out there, a simple Google search yields pages of them. However, I understand it's hard to know what to search for sometimes if your'e not familiar with the terms.

What you'll want to look for are tutorials that cover the following:

I usually have an animation with just the bind pose (typically the character in a T-pose, arms up parallel to the ground plane). Then I have that as the active action when I export.

Good luck.

trumanus commented 7 years ago

:D yes tons.. and i tried each ... but nothing is changed...

the process is very simple makehuman---> blender --> bvh --> threejs... but there is no way to do that..: 4 night of deep studing no solution... :(

trumanus commented 7 years ago

I found the problem... The exporter on dev is not correct.. i clone r82 and i made all the changes by hand.. i suppose.. will be a good idea to push the correction again on dev..

mrdoob commented 7 years ago

I don't think the exporter in dev has had any change since r82... https://github.com/mrdoob/three.js/commits/dev/utils/exporters/blender

trumanus commented 7 years ago

Hi the 82 has no the correction for yz swap, i just used your suggestions last night and now the exporter works fine ;)

vertices_.extend((vertex.co.x, vertex.co.y, vertex.co.z))

raptor3d commented 7 years ago

Hi, i still have the same problem, can u please write a short tutorial about what you did to fix it and in wich file ? I think the biggest problems in Threejs is exactly this: it is impossible to import models and create character animations in a "simple" way.

Very important: a lot of animators are using different 3d programs then Blender, so I think could be very interesting for them a detailed tutorial "using FBX" like an interchange file format and then from Blender to ThreeJs using JSON or GLTF, then a simple javascript code to see the objects finally moving !

I think that a lot of users are starting to user ThreeJs very seriously and not just to experiment some code or 3d effects. Last week I was working with a team , their animators are using Maya and we were wasting 4 days without find a solution. Was very difficult to understand where was the problem, exporter ? model ? bones-skeleton setup ? And we still have no solution ! At the end of the week another user wrote us that the Maya exporter seems not support animations... one week late ! This lack in the documentations and tutorials is killing their need to use ThreeJs for their game's idea.

In attach the json file of my "dragon" test

Thanks and sorry for my English.

test_but_dragon.zip

Mauro

avallintine commented 7 years ago

I've also been struggling to get animations working when exported from Blender. The lastest version (r84) does not work for me. I get the dreaded "nightmare dragon" animations and my objects face the wrong direction. I started testing previous releases and r76 is the latest version that works as expected. So, I compared the exported json from r76 to r84 and discovered that the ordering of the vertices and normals is different. Also, the object matrix is different. I copied this data from the r76 export to the r84 export and everything worked as expected. Now my objects are facing the right direction and my animations are correct.

It looks like https://github.com/mrdoob/three.js/pull/8781 introduced some changes that are now causing problems for a lot of people. Unfortunately I'm not familiar enough with the problem it was trying to solve to suggest a solution.

astrolope commented 7 years ago

@avallintine I've been dealing with the nightmare dragon export issues for the last couple days. So if I'm correct you exported with r76 and then copied the associated vertices into your r84 exported file. Are you rendering with the r84 renderer? Trying to reproduce a fix to this issue.

Here's the JSON that I'm getting from the r84 exporter. rigged2.json.zip

avallintine commented 7 years ago

@astrolope

That's correct. I exported two json files, one with r76 and the other with r84. I then copied the geometry vertices and normals, and the object matrix values, from r76 to r84. Rendered with r84. That seemed to fix my problem.

However, I've since discovered that exporting just a single object (uncheck "Scene" in the exporter), rather than the whole scene, using r84 and then loading with JSONLoader rather than ObjectLoader, seems to avoid these issues. You might try that also/instead. Exporting just a single object also avoided another quirk I was seeing. In Blender the resting rotation of my bones is zero. However, when I exported the entire scene and loaded in Three the resting rotations of my bones became some non-zero value. On the other hand, when I export my mesh as a single object, the rotations in Three and Blender match, which makes my life easier. Also, when you export the entire scene, the orientation of individual objects in that scene differ from the scene itself. So, if you were to change the position of an object along the x-axis in Three, it ends up moving along y or z (I forget which) relative to the scene.

In short, it appears that there's currently something funky with scene export which has caused various issues and in general complicated matters for me. I plan to avoid using it and export individual objects instead until the problem gets sorted, or someone can explain what I'm doing wrong.

avallintine commented 7 years ago

Welp, I thought I had it working but just encountered another setback. Exporting a rigged mesh as a single object (i.e. not as a scene) seems to work OK, but when I also tried to export a shape key along with it (by checking "Blend Shape animation") everything fell apart. The model came out rotated 90 deg and bone movement gives me nightmare dragon again. Looking at the JSON I see that the geometry vertices have changed compared to exporting without blend shapes (I'm not talking about the blend shape vertices, but the base model). So, for some reason, just enabling that single option "Blend Shape animation" changes the exported base geometry. Going to look into this further and hopefully come up with a solution.

manthrax commented 7 years ago

I just want to throw some advice to people having animation export probs... Generally try to keep all your objects in identity transforms as much as possible.. i.e. no rotation , position set to 0 and scaling to 1....

Then do your armature binding/skinning..

then with the skin selected, do the export.

Another tip, when you hit the save settings button at the bottom of the export pane, you then also have to save the blend file, or the settings wont actually save.

xbeat commented 7 years ago

Hi, by exporting the marine model from Blender: (examples/models/skinned/marine/marine_anims_core.blend folder) there are no errors but nothing appears (the original json works perfectly), so after a little compare of the two files I modified the json file in the material section like below. I exported the model with the parameters as in the image and the model in 'TPOSE' position and the export has been successful. Hope it may be useful.

Parameter modified: "materials":[{ ... "blending":"NormalBlending", (removed this line) "color":16777215, (was 8947848) "transparent":false, (was true) ... }],

three r85 master blender 2.78c safari / chrome browser

threejs_export_params

chuckhacker commented 7 years ago

Also affected by this bug

donmccurdy commented 6 years ago

FYI I've tested both of the OP models (monster.blend and women.blend) with the glTF Blender exporter and the results work in THREE.GLTFLoader correctly. Might need some tweaks on your materials to match the PBR workflow glTF uses, but the animation looks right.

001a1cdf-9a58-4844-a1af-0f5761897d39-92650-0000f3cdeeca3115

Mugen87 commented 6 years ago

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

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