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

FBXLoader doesn't support transformed pivot points #11895

Closed
looeee opened this issue Aug 6, 2017 · 18 comments
Closed

FBXLoader doesn't support transformed pivot points #11895

looeee opened this issue Aug 6, 2017 · 18 comments
Labels

Comments

@looeee
Copy link
Collaborator

looeee commented Aug 6, 2017

Simplified from #11697 since I've figured out the issue.

Here is a simple animation i created in 3ds max:

3dsmax

You can see the pivot point of the red bar has been moved to one end, and it is animated to swing around the pivot.

Loading this in Clara.io:

clara

The animation plays correctly, and the pivot point is displayed in the correct place.

Loading in Paint3D in windows - animations are not played, but the bar is in the correct place:

paint3d

Finally, loading in three.js and I get this:

three

The loader has assumed that the pivot point is at the centre of the bar and moved it accordingly - the animation plays around this new pivot.

Here's the FBX file:

simple joint.zip

@looeee
Copy link
Collaborator Author

looeee commented Aug 6, 2017

/ping @takahirox

@Mugen87 Mugen87 added the Bug label Aug 6, 2017
@roccapl
Copy link

roccapl commented Aug 6, 2017

see #11878 maybe it's not a problem with the exporter, because I have a similar issue with the JSON format

@looeee
Copy link
Collaborator Author

looeee commented Aug 6, 2017

@roccapl I investigated a bit and yes, transformed pivots are not supported by three.js. However Clara.io is built on three.js and the model loads fine there.

The obvious solution (to me) is that when loaders detect a transformed pivot, they create an empty Object3D to represent the pivot and make the mesh a child of that. Then all animations and transforms must be applied to the pivot object instead. I'll look into this tomorrow to get an idea of how complicated it would be to implement.

@roccapl
Copy link

roccapl commented Aug 7, 2017

Could someone explain to me why this is unsupported and what do people do as a common practice to circumvent this limitation? I've seen plenty of complex skinned animations with complicated bone chains playing back with no problems in three, why is this case different?

@looeee
Copy link
Collaborator Author

looeee commented Aug 7, 2017

I found a solution! 🍾 🎆
For this very simple jointed example anyway - it's not a fix for the FBXLoader so I'll keep it short here and any further discussion of this solution / workaround should take place on the forum.

But it seems the GLTF2Loader does support transformed pivots. So the process goes like this:

  1. Install the blender gltf2 exporter
  2. Export the file as FBX
  3. Load the FBX file in blender ( needs to be binary format 2015 or earlier)
  4. Export as GLTF2 ( I used .glb binary format)
  5. import in three.js and the results for this simple example look like this, and the animations play correctly (with a bit of tweaking of exporter settings)

three-gltf

Forum topic is here:
https://discourse.threejs.org/t/issue-fbx-model-shows-abnormal/693/6

@looeee
Copy link
Collaborator Author

looeee commented Aug 7, 2017

What this shows for this issue (and the related #11878 for JSON format issue), is that transformed pivots can be supported. So we need to find out how the GLTF2Loader (or exporter) supports them and see whether that will work of other loaders too.

@roccapl
Copy link

roccapl commented Aug 7, 2017

That's great news, I'll dig into the code on Thursday and see if I can come up with a patch. In the meantime if GLTF2 is a mature format I can try to use that instead of the JSON one.

@mrdoob
Copy link
Owner

mrdoob commented Aug 8, 2017

Wouldn't know how to solve it. For your specific model this patch does the trick:

diff --git a/examples/js/loaders/FBXLoader.js b/examples/js/loaders/FBXLoader.js
index 9c2a64c..491c82b 100644
--- a/examples/js/loaders/FBXLoader.js
+++ b/examples/js/loaders/FBXLoader.js
@@ -1509,6 +1509,13 @@
 
 			}
 
+			if ( 'GeometricTranslation' in node.properties ) {
+
+				var array = node.properties.GeometricTranslation.value;
+				model.geometry.translate( array[ 0 ], array[ 1 ], array[ 2 ] );
+
+			}
+
 			var conns = connections.get( model.FBX_ID );
 			for ( var parentIndex = 0; parentIndex < conns.parents.length; parentIndex ++ ) {
 

screen shot 2017-08-08 at 9 01 45 am

However, this is modifying the geometry directly, so if other scene nodes use this same geometry things will break.

@looeee
Copy link
Collaborator Author

looeee commented Aug 9, 2017

I created a simple rectangle in 3DS Max. By default the pivot is placed at the centre of the bottom face of the object. Then I centred the pivot to the object, and created two FBX files:

Pivot test.zip

Running these through a diff checker, aside from time stamps and IDs the only differences are

pivot_default.fbx

Objects:  { 
  ...
	Model: 2247454960, "Model::Box001", "Mesh" {
		Version: 232
		Properties70:  {
			P: "PreRotation", "Vector3D", "Vector", "",-90,-0,0
			P: "RotationActive", "bool", "", "",1
			P: "InheritType", "enum", "", "",1
			P: "ScalingMax", "Vector3D", "Vector", "",0,0,0
			P: "DefaultAttributeIndex", "int", "Integer", "",0
			P: "MaxHandle", "int", "Integer", "UH",1
		}
    ...
	}
  ...
}

pivot_centered.fbx

Objects:  { 
  ...
  Model: 2247454960, "Model::Box001", "Mesh" {
      Version: 232
      Properties70:  {
        P: "PreRotation", "Vector3D", "Vector", "",-90,-0,0
        P: "RotationActive", "bool", "", "",1
        P: "InheritType", "enum", "", "",1
        P: "ScalingMax", "Vector3D", "Vector", "",0,0,0
        P: "GeometricTranslation", "Vector3D", "Vector", "",0,0,-1.5
        P: "DefaultAttributeIndex", "int", "Integer", "",0
        P: "Lcl Translation", "Lcl Translation", "", "A",0,1.5,-0
        P: "MaxHandle", "int", "Integer", "UH",1
      }
    ...
	}
  ...
}

Specifically, centring the pivot adds the lines:

P: "GeometricTranslation", "Vector3D", "Vector", "",0,0,-1.5
P: "Lcl Translation", "Lcl Translation", "", "A",0,1.5,-0

Both of these files loaded in three.js display correctly, since it seems these lines are ignored and the pivot is assumed to be at the centre of the object.

The problem arises when any animation is applied - animations will only be correct for pivot_centered.fbx, as all transformations will be applied around the centre of the object.

@looeee
Copy link
Collaborator Author

looeee commented Aug 9, 2017

@mrdoob I can confirm that your solution works in my simple test case. For more complex examples though the model may be a Group or Object3D and this is required:

if ( 'GeometricTranslation' in node.properties ) {

   var array = node.properties.GeometricTranslation.value;
    model.traverse( function( child ) {

        if( child.geometry ) {

           child.geometry.translate( array[ 0 ], array[ 1 ], array[ 2 ] );

       }

   } );
}

This looks better (unfortunately I can't share my model, but here is a before and after screenshot).

Without fix:
pre_fix

With fix:
post_fix

The only part of this model that is currently animated are the legs which just swing back and forth, and as you can see some strange transform is applied to the left leg, while the right seems to be OK.

Aside from that it looks like normals are inverted on the right leg and right arm.

So, still a lot of problems - but this gives me hope that most of them can be fixed in Max before exporting.

However, this is modifying the geometry directly, so if other scene nodes use this same geometry things will break.

At the moment, we are faced with a situation where nearly all complex animated or rigged models are broken. It might be the case that supporting these models is more useful than supporting models with reused geometry. But certainly more testing is in order before making that decision - and ideally a solution that suits both cases can be found.

@mrdoob
Copy link
Owner

mrdoob commented Aug 10, 2017

Hmm... Would loading the file in Blender and exporting as gltf be an option?

@looeee
Copy link
Collaborator Author

looeee commented Aug 10, 2017

Theoretically, yes - and it worked well for the person who made the linked forum post. However this is what happens when I try to load the FBX file in blender:

blender

and I have even less luck exporting it as collada instead of fbx. I'm in the process of trying other formats now though.

@looeee
Copy link
Collaborator Author

looeee commented Aug 10, 2017

I found that exporting as .abc (alembic) format works , kind of. Materials are not exported, but the object does load in blender at least. However try as I might I cannot get my animations to export with the gltf2 exporter. Aside from this, gltf seems to have the same issue with winding order as #11911

gltf

@looeee
Copy link
Collaborator Author

looeee commented Aug 14, 2017

Just wanna come back to this - it got a bit off topic, but as I understand it the issue at the moment is that we can either support animation using transformed pivot, or instanced geometry with non-centred pivots. And at the moment we are supporting instanced geometry.

I think that supporting animations with transformed pivots is a much higher priority, given that its one of the most basic animation techniques. There's basically no way to get something as simple as a hinge joint working without this fix, let alone a complex rigged mesh.

Instanced geometry with centred pivots will still work in any case, and if there is no way to deal with the instanced geometries with non-centred pivots, then that's a small price to pay for fixing animations.

@FishOrBear
Copy link
Contributor

FishOrBear commented Aug 16, 2017

I thought I had the same problem

3dmax before exporting
image
After import

image

test.zip

tv.zip

@looeee
Copy link
Collaborator Author

looeee commented Aug 16, 2017

@FishOrBear can you try implementing the fix mentioned above to see if this fixes your error?

@FishOrBear
Copy link
Contributor

Thank you, I tried it.
Solved my question.
@looeee

@looeee
Copy link
Collaborator Author

looeee commented Oct 9, 2017

Closed via #11963

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

No branches or pull requests

5 participants