Kupoman / blendergltf

A glTF exporter for Blender
Apache License 2.0
319 stars 49 forks source link

Wrong nested rotations #152

Open hugoam opened 6 years ago

hugoam commented 6 years ago

Running the exporter on the following file: https://github.com/godotengine/tps-demo/blob/master/level/geometry/demolevel.blend With the default option: Y up, Z Forward

Will produce wrong nested transforms for meshes that are inside of a parent with identity transform inside of the blend file. The wrong output looks something like this: we have a root node with a rotation, and then the child node with an additional rotation:

        {
            "children": [
                374,
                375,
                376,
                377,
                378,
                379,
                393,
                394,
                395,
                396,
                397,
                398,
                399,
                400,
                401,
                402,
                403,
                404,
                405,
                406,
                407,
                408,
                409,
                410,
                411,
                412,
                413,
                414,
                415,
                416,
                417
            ],
            "name": "00ReactorInnerWall",
            "rotation": [
                0.0,
                0.7071068286895752,
                0.7071068286895752,
                0.0
            ],
            "scale": [
                1.0,
                1.0,
                1.0
            ],
            "translation": [
                0.0,
                0.0,
                0.0
            ]
        },

        {
            "mesh": 162,
            "name": "hallreactor_circ4500_ReactorOuterCeiling.001",
            "rotation": [
                0.0,
                0.049065735191106796,
                0.0,
                0.9987955689430237
            ],
            "scale": [
                1.0,
                1.0,
                1.0
            ],
            "translation": [
                0.0,
                0.0,
                0.0
            ]
        },

However, if we modify the blend file to remove the parent (which has identity transform, so the final transforms should be exactly the same after doing this operation), we don't get a parent node anymore, but the mesh node has exactly the same transform as in the previous excerpt:

        {
            "mesh": 162,
            "name": "hallreactor_circ4500_ReactorOuterCeiling.001",
            "rotation": [
                0.0,
                0.049065735191106796,
                0.0,
                0.9987955689430237
            ],
            "scale": [
                1.0,
                1.0,
                1.0
            ],
            "translation": [
                0.0,
                0.0,
                0.0
            ]
        },

We should end up with the same derived rotation in both case, however: