Three.js export SkinnedMesh with position

536 views Asked by At

I'm trying to export a model from a Three.js scene using https://github.com/mrdoob/three.js/blob/master/examples/jsm/exporters/OBJExporter.js

Some mesh are base meshes and some other are SkinnedMesh, so I've edited line 250 from

if ( child instanceof Mesh ) {

to

if ( child instanceof Mesh || child instanceof SkinnedMesh ) {

and I can see all the meshes in the exported file, but the SkinnedMeshes are in the origin with wrong position and orientation. How can I edit the exporter to also get the SkinnedMeshes right, and why is this happening?

EDIT: I tried with the STL exporter proposed in the answers, but it still fails to export the pose because the three properties that it checks:

if(typeof object.obj.geometry.attributes.skinIndex !== 'undefined' && typeof object.obj.geometry.attributes.skinWeight !== 'undefined' && typeof object.obj.skeleton !== 'undefined')

are all undefined except for "object.obj.skeleton". The properties that I can see in the SkinnedMesh objects are "instanceIndex", "normal", "position" and "uv"

EDIT 2:

Sorry for the confusion, but I misread the output log. There are some meshes with quite-said properties, meaning that the actual names are "skinWeight0" and "skinIndex0". I tried to change the name to that in the code and I can succesfully print those arrays, but the exported model is a total mess:

enter image description here

1

There are 1 answers

3
Mugen87 On

That's happening since the transformation of skinned meshes does not only depend on Object3D.position, Object3D.rotation and Object3D.scale and its position in the object hierarchy. It also depends on its skeleton.

The change you have made so far is not sufficient to honor skeleton information. If you want to ensure that the export actually reflects the transformation and shape of the skinned mesh, you need similar code like from this PR:

https://github.com/mrdoob/three.js/pull/16942

So the idea is to actually take the bone transformation into account when computing the final position of vertices (which are going to be defined in the OBJ file).