KhronosGroup / glTF

glTF – Runtime 3D Asset Delivery
Other
7.18k stars 1.14k forks source link

COLLADA2GLTF can't convert Maya's moved group pivot information correctly. #551

Closed emadurandal closed 8 years ago

emadurandal commented 8 years ago

Hi there.

I tried latest COLLADA2GLTF, but I found a little weird covert result.

Look at this maya scene file (group_pivot.mb in attached zip file). In this scene, there is a group whose pivot position is moved to (0, 5, 0). You can see this animation scene at https://youtu.be/-BME5VZRDUQ

I exported this scene to collada file (group_pivot.dae) using ColladaMaya exporter. I checked that this collada file is correct. Because MacOS preview function showed correct animation. https://youtu.be/NwhLpZD2gBM

Then, I converted this collada file to gltf file (group_pivot_original.gltf, group_pivot.bin, group_pivot0FS.glsl and group_pivot0VS.glsl) using COLLADA2GLTF. But Its data (group_pivot_original.gltf) seem wrong.

This video is the result of group_pivot_original.gltf using my original WebGL library, GLBoost. It’s wrong animation as you can see. https://youtu.be/ZapNp3LNB6A

I think that the cause is the following part (in group_pivot_original.gltf).

    "nodes": {
        "_group1": {
            "children": [
                "_group1_pCube1"
            ],
            "name": "group1",
            "rotation": [
                0,
                0,
                0.707107,
                0.707107
            ],
            "scale": [
                1,
                1,
                1
            ],
            "translation": [       <- ?
                5,
                5,
                0
            ]
        },
        "_group1_pCube1": {
            "children": [],
            "matrix": [       <- ?
                1,
                0,
                0,
                0,
                0,
                1,
                0,
                0,
                0,
                0,
                1,
                0,
                0,
                0,
                0,
                1
            ],

So, I fixed the data (group_pivot_fixed.gltf) as following.

    "nodes": {
        "_group1": {
            "children": [
                "_group1_pCube1"
            ],
            "name": "group1",
            "rotation": [
                0,
                0,
                0.707107,
                0.707107
            ],
            "scale": [
                1,
                1,
                1
            ],
            "translation": [
                0,
                5,
                0
            ]
        },
        "_group1_pCube1": {
            "children": [],
            "matrix": [
                1,
                0,
                0,
                0,
                0,
                1,
                0,
                0,
                0,
                0,
                1,
                0,
                0,
                -5,
                0,
                1
            ],

Then, My GLBoost Renderer showed correct Animation. https://youtu.be/zyV3JKvEZqE

In conclusion, I think that COLLADA2GLTF should export like group_pivot_fixed.gltf, not group_pivot_original.gltf. Or, If there is a pivot infomation in glTF spec. COLLADA2GLTF should export it. I guess that this problem is caused by COLLADA2GLTF’s bug, not my GLBoost library’s bug.

group_pivot.zip

pjcozzi commented 8 years ago

@emadurandal wow, thanks for the carefully written issue. I agree this sounds like a bug in COLLADA2GLTF so I labeled this issue accordingly.

In the meantime, you could try converting this model with Cesium's converter, which does some extra processing that may help, or the Autodesk FBX to glTF converter, which also works with COLLADA, but I have not tested myself, or Assimp.

Let me know if you try any of these.

Also, let me know when glTF support in GLBoost is in a state you are happy with and we'll list GLBoost here: https://github.com/KhronosGroup/glTF#webgl-engines

emadurandal commented 8 years ago

@pjcozzi Thank you for your reply. I'll check those other tools and report the results :smile:

Also, let me know when glTF support in GLBoost is in a state you are happy with and we'll list GLBoost here: https://github.com/KhronosGroup/glTF#webgl-engines

Wow! It's my great pleasure for GLBoost to could be listed there! my friends and I are making the library better gradually. and we are going to try human skinning animations support using glTF. When we get the progress, I'll let you know that. Thank you!

emadurandal commented 8 years ago

@pjcozzi I tried Cesium's converter, but the same problem happened. I posted feedback to Cesium's forum. http://cesiumjs.org/forum.html Next, I'm now trying Autodesk FBX to glTF converter. but the build steps are a little too much work. :sweat_smile:

pjcozzi commented 8 years ago

@cyrillef are there pre-built binaries for your FBX to glTF converter?

@emadurandal I suspect Cesium's converter issue is the same bug as COLLADA2GLTF.

cyrillef commented 8 years ago

@pjcozzi - I'll post them asap - I am just back from the trip to Montreal

lasalvavida commented 8 years ago

@emadurandal When I open your attached COLLADA file in Blender I see this: maya_pivot

Is the file you attached correct?

pjcozzi commented 8 years ago

@lasalvavida also try Visual Studio or Mac preview incase the Blender importer has an issue.

lasalvavida commented 8 years ago

@pjcozzi I'm not sure if Visual Studio can play animations, either way I opened it in this viewer and it displayed correctly, so it must be an issue in Blender. It is interesting that Blender and COLLADA2GLTF have a similar issue, so the culprit may be OpenCOLLADA.

emadurandal commented 8 years ago

@lasalvavida @pjcozzi I apologize for the late reply. I'm relieved that my attached COLLADA file appears to be correct.

lasalvavida commented 8 years ago

I've been playing with this a bit, and I think I understand what's happening, but I don't have a fix yet.

Maya is pivoting around a point by translating, rotating and then translating back

COLLADA2GLTF flattens these transformations to make the node matrix latex_1346dd360b023d6ec0e289556d73e22e

However, the animation targets latex_693a5af43d7d7bf270b32f27a10bf0a6, which just gets naively applied to the node matrix

It should be fairly obvious that latex_573d55a2d07a5f87243526b37432de72

One possible avenue would be to force animations in situations like this to be in matrix form and apply the proper transformation to each keyframe as shown for this example latex_9fdc7de28bb62c48914975e37b638fcb

lasalvavida commented 8 years ago

@emadurandal Sorry for the long wait. This should get fixed by #684.