Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulien Duroure <julien.duroure@gmail.com>2018-12-15 08:30:27 +0300
committerJulien Duroure <julien.duroure@gmail.com>2018-12-15 08:30:27 +0300
commit6d933c0e3ac8048e8a04f2b42bcd21a667818c2e (patch)
tree95799aa9467fc4bdfa69e7a5192411fd312e7e8a /io_scene_gltf2/blender/imp/gltf2_blender_material.py
parentb55002b7c33154d2b66166aaf0c2a0b287ec9e42 (diff)
glTF importer: fix material import / vertex color
Fixed a bug when a same material sometimes uses vertex color, sometimes doesn't
Diffstat (limited to 'io_scene_gltf2/blender/imp/gltf2_blender_material.py')
-rwxr-xr-xio_scene_gltf2/blender/imp/gltf2_blender_material.py30
1 files changed, 18 insertions, 12 deletions
diff --git a/io_scene_gltf2/blender/imp/gltf2_blender_material.py b/io_scene_gltf2/blender/imp/gltf2_blender_material.py
index c9fa6927..c910b7f8 100755
--- a/io_scene_gltf2/blender/imp/gltf2_blender_material.py
+++ b/io_scene_gltf2/blender/imp/gltf2_blender_material.py
@@ -34,13 +34,19 @@ class BlenderMaterial():
"""Material creation."""
pymaterial = gltf.data.materials[material_idx]
- if pymaterial.name is not None:
- name = pymaterial.name
+ if vertex_color is None:
+ if pymaterial.name is not None:
+ name = pymaterial.name
+ else:
+ name = "Material_" + str(material_idx)
else:
- name = "Material_" + str(material_idx)
+ if pymaterial.name is not None:
+ name = pymaterial.name + "_" + vertex_color
+ else:
+ name = "Material_" + str(material_idx) + "_" + vertex_color
mat = bpy.data.materials.new(name)
- pymaterial.blender_material = mat.name
+ pymaterial.blender_material[vertex_color] = mat.name
if pymaterial.extensions is not None and 'KHR_materials_pbrSpecularGlossiness' in pymaterial.extensions.keys():
BlenderKHR_materials_pbrSpecularGlossiness.create(
@@ -62,36 +68,36 @@ class BlenderMaterial():
# add emission map if needed
if pymaterial.emissive_texture is not None:
- BlenderEmissiveMap.create(gltf, material_idx)
+ BlenderEmissiveMap.create(gltf, material_idx, vertex_color)
# add normal map if needed
if pymaterial.normal_texture is not None:
- BlenderNormalMap.create(gltf, material_idx)
+ BlenderNormalMap.create(gltf, material_idx, vertex_color)
# add occlusion map if needed
# will be pack, but not used
if pymaterial.occlusion_texture is not None:
- BlenderOcclusionMap.create(gltf, material_idx)
+ BlenderOcclusionMap.create(gltf, material_idx, vertex_color)
if pymaterial.alpha_mode is not None and pymaterial.alpha_mode != 'OPAQUE':
- BlenderMaterial.blender_alpha(gltf, material_idx)
+ BlenderMaterial.blender_alpha(gltf, material_idx, vertex_color)
@staticmethod
- def set_uvmap(gltf, material_idx, prim, obj):
+ def set_uvmap(gltf, material_idx, prim, obj, vertex_color):
"""Set UV Map."""
pymaterial = gltf.data.materials[material_idx]
- node_tree = bpy.data.materials[pymaterial.blender_material].node_tree
+ node_tree = bpy.data.materials[pymaterial.blender_material[vertex_color]].node_tree
uvmap_nodes = [node for node in node_tree.nodes if node.type in ['UVMAP', 'NORMAL_MAP']]
for uvmap_node in uvmap_nodes:
if uvmap_node["gltf2_texcoord"] in prim.blender_texcoord.keys():
uvmap_node.uv_map = prim.blender_texcoord[uvmap_node["gltf2_texcoord"]]
@staticmethod
- def blender_alpha(gltf, material_idx):
+ def blender_alpha(gltf, material_idx, vertex_color):
"""Set alpha."""
pymaterial = gltf.data.materials[material_idx]
- material = bpy.data.materials[pymaterial.blender_material]
+ material = bpy.data.materials[pymaterial.blender_material[vertex_color]]
node_tree = material.node_tree
# Add nodes for basic transparency