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.48k stars 317 forks source link

add_alpha is false even if vertex color has alpha component #2235

Closed msparkles closed 4 months ago

msparkles commented 4 months ago

Describe the bug add_alpha = mat is not None and add_alpha and not (mat.blend_method is None or mat.blend_method == 'OPAQUE') This expression gives False with our pipeline-

# ...
        if not obj.data.color_attributes and obj.active_material:
            obj.data.color_attributes.new(name='Col', type='FLOAT_COLOR', domain='CORNER')

            color = obj.active_material.diffuse_color

            for datum in obj.data.attributes.active_color.data:
                datum.color = color

            obj.data.materials.clear()
# ...

This pipeline of ours may be a bit of a legacy, but bear with us- because we only use vertex colors in our models, we turn a material on an object with only the base diffuse color into vertex color.

PS: Whether or not we clear the materials and whether or not we assign Alpha Blend does not seem to affect the result.

Expected behavior What we expect is that the alpha component of the vertex colors also get picked up and exported.

.blend file/.gltf (mandatory) prism.zip

Our export scripts are at https://github.com/automancy/automancy

Version

msparkles commented 4 months ago

Forgot to mention: vc_alpha_name is not None.

mat = get_material_from_idx(material_idx, self.materials, self.export_settings) mat here is of course None.

julienduroure commented 4 months ago

Hello, Seems your materials have "OPAQUE" blend_method, so no alpha will be exported.

Can you please upload a test file when you already apply all your modification done by your eporter, just before calling the bpy.ops.export_scene.gltf?

Edit: Your VC will be exported only when used as base color multiplier of the base color, as described in glTF specification. See #2233 (not merged yet)

Edit2: We should probably chek gather_alpha_info instead of blend_method here...

The0Dev commented 4 months ago

I'm also experiencing this bug again #2206

msparkles commented 4 months ago

Seems your materials have "OPAQUE" blend_method, so no alpha will be exported.

There shouldn't even be a material- not in our case. And indeed there isn't

Can you please upload a test file when you already apply all your modification done by your eporter, just before calling the bpy.ops.export_scene.gltf?

Here: a.zip

Your VC will be exported only when used as base color multiplier of the base color, as described in glTF specification.

That's weird- we haven't read the spec, but shouldn't you be able to simply have vertex colors?

julienduroure commented 4 months ago

@The0Dev

I'm also experiencing this bug again https://github.com/KhronosGroup/glTF-Blender-IO/issues/2206

Will be fixed in #2237

@msparkles

This will be fixed in #2233