Describe the bug
If you import the model which use vertex color, you'll get that annoying "_COLOR0" - everytime you import it! So if you export/import it multiple times, you'll end with something like
And don't forget about material name limit in Blender...
MyMaterialName_COLOR0_COLOR0_<...>_COLO
And what if material name is very long initially?
Looooooooooooooooooooooooooo<...>oongName_CO
Is this a normal behavior? Why do we need that "_COLOR0" in material name?
The reason its added is that you can have a glTF material named M used by two meshes, one with vertex colors and one without. In Blender you can't have a material that works for both meshes with and without vertex colors, so we need to make two materials for M. The one that doesn't use vertex colors is called M and the one that does is called M_COLOR0.
We could just call them both M. Then if two materials do get created one would get named M and one M.001, as usual in Blender.
Or we could detect if the material needs to be split into two materials. If only one is needed we could call it M whether or not it uses colors. Only if two are needed would we use M and M_COLOR0.
Either of these would fix the _COLOR0_COLOR0_COLOR0 issue.
We could just call them both M. Then if two materials do get created one would get named M and one M.001, as usual in Blender.
This sounds OK to me, and is probably the easiest? As Blender has this convention for incrementing material names it shouldn't surprise users too much.
Or we could just not append it if it already ends with _COLOR0 of course.
@donmccurdy It's definitely the easiest. The only bad thing is you'd no longer be able to tell by looking which one uses vertex colors and which one doesn't I guess.
I'd be fine with it though.
Is that the only reason we have to duplicate materials in Blender import? In three.js there is a much longer list of causes: skinning, vertex colors, vertex normals, vertex tangents, shape key positions, shape key normals, different draw modes... we definitely don't bother to specify why the material got cloned. But I'm happy either way here.
Is that the only reason we have to duplicate materials in Blender import?
Yes. (It sounds like in Three.js a material corresponds to a unique shader/pipeline.)
Let's ask @julienduroure's opinion. This got added as part of the initial fix for materials not being duplicated in #30.
Hello,
We could just call them both M. Then if two materials do get created one would get named M and one M.001, as usual in Blender.
I'm totally fine with the proposition. It was only a naming convention, and with the new proposition, we will avoid the reported issue.
Okay, cool. Patch is just
--- a/addons/io_scene_gltf2/blender/imp/gltf2_blender_material.py
+++ b/addons/io_scene_gltf2/blender/imp/gltf2_blender_material.py
@@ -33,8 +33,6 @@ class BlenderMaterial():
name = pymaterial.name
if name is None:
name = "Material_" + str(material_idx)
- if vertex_color is not None:
- name += "_" + vertex_color
mat = bpy.data.materials.new(name)
pymaterial.blender_material[vertex_color] = mat.name