KhronosGroup / glTF-Blender-IO

Blender glTF 2.0 importer and exporter
https://docs.blender.org/manual/en/latest/addons/import_export/scene_gltf2.html
Apache License 2.0
1.45k stars 306 forks source link

__manage_extension_declaration - removes user extensions #2259

Closed ronh991 closed 1 month ago

ronh991 commented 1 month ago

Describe the bug user extensions is in the list of json data - in gltf2_blender_export.py - function export and into manage_extension_declaration. however the __manage_extension_declaration code removes all user_extensions. there is a "gltf_need_to_keep_extension_declaration" export_setting however I don't see that available in the export dialogue

To Reproduce Steps to reproduce the behavior: create an addon the uses gltf2 and adds user extensions to the userextensions list. - similar to KHR*

Expected behavior does not delete the user extensions.

Screenshots If applicable, add screenshots to help explain your problem.

.blend file/ .gltf (mandatory) test_42_error_03 (2).zip

Version

Additional context adding print statements to __manage_extension_declaration

json dec before ['ASOBO_normal_map_convention', 'ASOBO_unique_id', 'KHR_materials_clearcoat', 'KHR_materials_transmission', 'KHR_materials_specular', 'KHR_materials_anisotropy', 'KHR_materials_ior', 'ASOBO_material_draw_order', 'ASOBO_material_detail_map', 'ASOBO_material_windshield']

json dec after []

def __manage_extension_declaration(json, export_settings):
    if 'extensionsUsed' in json.keys():
        print("json dec before", json['extensionsUsed'])
        new_ext_used = []
        for ext in json['extensionsUsed']:
            if ext not in export_settings['gltf_need_to_keep_extension_declaration']:
                continue
            new_ext_used.append(ext)
        json['extensionsUsed'] = new_ext_used
        print("json dec after", json['extensionsUsed'])
    if 'extensionsRequired' in json.keys():
        new_ext_required = []
        for ext in json['extensionsRequired']:
            if ext not in export_settings['gltf_need_to_keep_extension_declaration']:
                continue
            new_ext_required.append(ext)
        json['extensionsRequired'] = new_ext_required

EDIT am I suppose to add gltf_need_to_keep_extension_declaration, I assumed it would already be in the Khronos exportsettings property list. I would then add my ASOBO* extension names to that property

julienduroure commented 1 month ago

Hello, Except if you are using animation pointer, you shouldn't take care of this. Investigation in progress about this regression

julienduroure commented 1 month ago

I am not able to reproduce with this hook:

    def gather_asset_hook(self, asset, export_settings):
        asset.extensions = {}
        asset.extensions["EXT_julien_test"] = self.Extension(
            name="EXT_julien_test",
            extension={"hello": "hello"},
            required=True
        )

This give me

{
    "asset":{
        "extensions":{
            "EXT_julien_test":{
                "hello":"hello"
            }
        },
        "generator":"Khronos glTF Blender I/O v4.2.44",
        "version":"2.0"
    },
    "extensionsUsed":[
        "EXT_julien_test"
    ],
    "extensionsRequired":[
        "EXT_julien_test"
    ],
    "scene":0,
    "scenes":[
        {
            "name":"Scene"
        }
    ]
}

Can you please provide me a single hook addon that shows the issue?

ronh991 commented 1 month ago

The extensions are basically material extensions.

loop through all the material extensions


    @staticmethod
    def export(gltf2_material, blender_material, export_settings):
        for extension in MSFSMaterial.extensions:
            extension.to_extension(blender_material, gltf2_material, export_settings)

and then something like this is done.


    @staticmethod
    def to_extension(blender_material, gltf2_material, export_settings):
        from ..io.msfs_material import MSFSMaterial

        result = {}
        if blender_material.msfs_material_type == "msfs_windshield":
            result["rainDropScale"] = blender_material.msfs_rain_drop_scale
            result["wiper1State"] = blender_material.msfs_wiper_1_state
            result["wiper2State"] = blender_material.msfs_wiper_2_state
            result["wiper3State"] = blender_material.msfs_wiper_3_state
            result["wiper4State"] = blender_material.msfs_wiper_4_state
            if blender_material.msfs_extra_slot1_texture is not None:
                result["wiperMaskTexture"] = MSFSMaterial.export_image(
                    blender_material,
                    blender_material.msfs_extra_slot1_texture,
                    "DEFAULT",
                    export_settings,
                )

            gltf2_material.extensions[AsoboWindshield.SerializedName] = Extension(
                name=AsoboWindshield.SerializedName, extension=result, required=False
            )

this used to work fine, now they disappear as I said initially.

The extensions appear in the material data, however the extensions_used is forced to nothing.

    "materials":[
        {
            "alphaMode":"BLEND",
            "emissiveFactor":[
                0,
                0,
                0
            ],
            "emissiveTexture":{
                "index":0
            },
            "extensions":{
                "ASOBO_material_draw_order":{
                    "drawOrderOffset":2
                },
                "ASOBO_material_detail_map":{
                    "detailColorTexture":{
                        "index":1
                    },
                    "detailNormalTexture":{
                        "index":2
                    },
                    "UVScale":6,
                    "blendThreshold":0.10000000149011612
                },
                "ASOBO_material_windshield":{
                    "rainDropScale":1,
                    "wiper1State":0,
                    "wiper2State":0,
                    "wiper3State":0,
                    "wiper4State":0
                }
            },
            "extras":{
                "ASOBO_material_code":"Windshield"
            },
            "name":"WINDSHIELD BUCKER BBB_int",
            "pbrMetallicRoughness":{
                "baseColorFactor":[
                    1,
                    1,
                    1,
                    0.009999999776482582
                ],
                "metallicFactor":0,
                "roughnessFactor":0.07000000029802322
            }
        },

there is no extensions_used

    "asset":{
        "extensions":{
            "ASOBO_normal_map_convention":{
                "tangent_space_convention":"DirectX"
            }
        },
        "generator":"Khronos glTF Blender I/O v4.2.44 and Asobo Studio MSFS Blender I/O v2.2.4",
        "version":"2.0"
    },
    "scene":0,
    "scenes":[
        {
            "name":"Scene",
            "nodes":[
                0,
                1
            ]
        }
    ],

It used to look like this

{
    "asset":{
        "extensions":{
            "ASOBO_normal_map_convention":{
                "tangent_space_convention":"DirectX"
            }
        },
        "generator":"Khronos glTF Blender I/O v3.6.28 and Asobo Studio MSFS Blender I/O v1.3.3",
        "version":"2.0"
    },
    "extensionsUsed":[
        "ASOBO_normal_map_convention",
        "ASOBO_unique_id"
    ],
    "scene":0,
    "scenes":[
        {
            "name":"Scene",
            "nodes":[
                0
            ]
        }
    ],
ronh991 commented 1 month ago

fixed with 22e5e39 code manually added to own Bleneder download.

    "asset":{
        "extensions":{
            "ASOBO_normal_map_convention":{
                "tangent_space_convention":"DirectX"
            }
        },
        "generator":"Khronos glTF Blender I/O v4.2.44 and Asobo Studio MSFS Blender I/O v2.2.4",
        "version":"2.0"
    },
    "extensionsUsed":[
        "ASOBO_normal_map_convention",
        "ASOBO_unique_id",
        "ASOBO_material_draw_order",
        "ASOBO_material_detail_map",
        "ASOBO_material_windshield"
    ],
    "scene":0,
    "scenes":[
        {
            "name":"Scene",
            "nodes":[
                0,
                1
            ]
        }
    ],