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>2020-09-17 20:00:16 +0300
committerJulien Duroure <julien.duroure@gmail.com>2020-09-17 20:00:24 +0300
commit9db2451888a5f5a67d3d3d0fc2a967c208a3a801 (patch)
tree238533f0cdd2b4b287b96f54ed6c43a7dc0a1e8e /io_scene_gltf2/blender
parentec4ad081e564781230e3a9b31ef48f1f8fb71899 (diff)
glTF exporter: fix UVMap export when ORM are using different maps
Diffstat (limited to 'io_scene_gltf2/blender')
-rwxr-xr-xio_scene_gltf2/blender/exp/gltf2_blender_gather_materials.py32
-rwxr-xr-xio_scene_gltf2/blender/exp/gltf2_blender_gather_materials_pbr_metallic_roughness.py45
-rwxr-xr-xio_scene_gltf2/blender/exp/gltf2_blender_gather_texture_info.py51
3 files changed, 74 insertions, 54 deletions
diff --git a/io_scene_gltf2/blender/exp/gltf2_blender_gather_materials.py b/io_scene_gltf2/blender/exp/gltf2_blender_gather_materials.py
index 8dc5896f..c346a831 100755
--- a/io_scene_gltf2/blender/exp/gltf2_blender_gather_materials.py
+++ b/io_scene_gltf2/blender/exp/gltf2_blender_gather_materials.py
@@ -146,7 +146,7 @@ def __gather_emissive_texture(blender_material, export_settings):
emissive = gltf2_blender_get.get_socket(blender_material, "Emissive")
if emissive is None:
emissive = gltf2_blender_get.get_socket_old(blender_material, "Emissive")
- return gltf2_blender_gather_texture_info.gather_texture_info((emissive,), export_settings)
+ return gltf2_blender_gather_texture_info.gather_texture_info(emissive, (emissive,), export_settings)
def __gather_extensions(blender_material, export_settings):
@@ -187,6 +187,7 @@ def __gather_normal_texture(blender_material, export_settings):
if normal is None:
normal = gltf2_blender_get.get_socket_old(blender_material, "Normal")
return gltf2_blender_gather_texture_info.gather_material_normal_texture_info_class(
+ normal,
(normal,),
export_settings)
@@ -226,22 +227,19 @@ def __gather_orm_texture(blender_material, export_settings):
return None
# Double-check this will past the filter in texture_info
- info = gltf2_blender_gather_texture_info.gather_texture_info(result, export_settings)
+ info = gltf2_blender_gather_texture_info.gather_texture_info(result[0], result, export_settings)
if info is None:
return None
return result
def __gather_occlusion_texture(blender_material, orm_texture, export_settings):
- if orm_texture is not None:
- return gltf2_blender_gather_texture_info.gather_material_occlusion_texture_info_class(
- orm_texture,
- export_settings)
occlusion = gltf2_blender_get.get_socket(blender_material, "Occlusion")
if occlusion is None:
occlusion = gltf2_blender_get.get_socket_old(blender_material, "Occlusion")
return gltf2_blender_gather_texture_info.gather_material_occlusion_texture_info_class(
- (occlusion,),
+ occlusion,
+ orm_texture or (occlusion,),
export_settings)
@@ -297,14 +295,22 @@ def __gather_clearcoat_extension(blender_material, export_settings):
clearcoat_roughness_slots = (clearcoat_roughness_socket,)
if len(clearcoat_roughness_slots) > 0:
- combined_texture = gltf2_blender_gather_texture_info.gather_texture_info(clearcoat_roughness_slots, export_settings)
if has_clearcoat_texture:
- clearcoat_extension['clearcoatTexture'] = combined_texture
+ clearcoat_extension['clearcoatTexture'] = gltf2_blender_gather_texture_info.gather_texture_info(
+ clearcoat_socket,
+ clearcoat_roughness_slots,
+ export_settings,
+ )
if has_clearcoat_roughness_texture:
- clearcoat_extension['clearcoatRoughnessTexture'] = combined_texture
+ clearcoat_extension['clearcoatRoughnessTexture'] = gltf2_blender_gather_texture_info.gather_texture_info(
+ clearcoat_roughness_socket,
+ clearcoat_roughness_slots,
+ export_settings,
+ )
if __has_image_node_from_socket(clearcoat_normal_socket):
clearcoat_extension['clearcoatNormalTexture'] = gltf2_blender_gather_texture_info.gather_material_normal_texture_info_class(
+ clearcoat_normal_socket,
(clearcoat_normal_socket,),
export_settings
)
@@ -336,7 +342,11 @@ def __gather_transmission_extension(blender_material, export_settings):
transmission_slots = (transmission_socket,)
if len(transmission_slots) > 0:
- combined_texture = gltf2_blender_gather_texture_info.gather_texture_info(transmission_slots, export_settings)
+ combined_texture = gltf2_blender_gather_texture_info.gather_texture_info(
+ transmission_socket,
+ transmission_slots,
+ export_settings,
+ )
if has_transmission_texture:
transmission_extension['transmissionTexture'] = combined_texture
diff --git a/io_scene_gltf2/blender/exp/gltf2_blender_gather_materials_pbr_metallic_roughness.py b/io_scene_gltf2/blender/exp/gltf2_blender_gather_materials_pbr_metallic_roughness.py
index d0cf4517..a89b0ca1 100755
--- a/io_scene_gltf2/blender/exp/gltf2_blender_gather_materials_pbr_metallic_roughness.py
+++ b/io_scene_gltf2/blender/exp/gltf2_blender_gather_materials_pbr_metallic_roughness.py
@@ -90,7 +90,7 @@ def __gather_base_color_texture(blender_material, export_settings):
else:
inputs = (base_color_socket,)
- return gltf2_blender_gather_texture_info.gather_texture_info(inputs, export_settings)
+ return gltf2_blender_gather_texture_info.gather_texture_info(base_color_socket, inputs, export_settings)
def __gather_extensions(blender_material, export_settings):
@@ -115,28 +115,29 @@ def __gather_metallic_factor(blender_material, export_settings):
def __gather_metallic_roughness_texture(blender_material, orm_texture, export_settings):
- if orm_texture is not None:
- texture_input = orm_texture
+ metallic_socket = gltf2_blender_get.get_socket(blender_material, "Metallic")
+ roughness_socket = gltf2_blender_get.get_socket(blender_material, "Roughness")
+
+ hasMetal = metallic_socket is not None and __has_image_node_from_socket(metallic_socket)
+ hasRough = roughness_socket is not None and __has_image_node_from_socket(roughness_socket)
+
+ if not hasMetal and not hasRough:
+ metallic_roughness = gltf2_blender_get.get_socket_old(blender_material, "MetallicRoughness")
+ if metallic_roughness is None or not __has_image_node_from_socket(metallic_roughness):
+ return None
+ texture_input = (metallic_roughness,)
+ elif not hasMetal:
+ texture_input = (roughness_socket,)
+ elif not hasRough:
+ texture_input = (metallic_socket,)
else:
- metallic_socket = gltf2_blender_get.get_socket(blender_material, "Metallic")
- roughness_socket = gltf2_blender_get.get_socket(blender_material, "Roughness")
-
- hasMetal = metallic_socket is not None and __has_image_node_from_socket(metallic_socket)
- hasRough = roughness_socket is not None and __has_image_node_from_socket(roughness_socket)
-
- if not hasMetal and not hasRough:
- metallic_roughness = gltf2_blender_get.get_socket_old(blender_material, "MetallicRoughness")
- if metallic_roughness is None or not __has_image_node_from_socket(metallic_roughness):
- return None
- texture_input = (metallic_roughness,)
- elif not hasMetal:
- texture_input = (roughness_socket,)
- elif not hasRough:
- texture_input = (metallic_socket,)
- else:
- texture_input = (metallic_socket, roughness_socket)
-
- return gltf2_blender_gather_texture_info.gather_texture_info(texture_input, export_settings)
+ texture_input = (metallic_socket, roughness_socket)
+
+ return gltf2_blender_gather_texture_info.gather_texture_info(
+ texture_input[0],
+ orm_texture or texture_input,
+ export_settings,
+ )
def __gather_roughness_factor(blender_material, export_settings):
diff --git a/io_scene_gltf2/blender/exp/gltf2_blender_gather_texture_info.py b/io_scene_gltf2/blender/exp/gltf2_blender_gather_texture_info.py
index e8cc7c58..59cd5614 100755
--- a/io_scene_gltf2/blender/exp/gltf2_blender_gather_texture_info.py
+++ b/io_scene_gltf2/blender/exp/gltf2_blender_gather_texture_info.py
@@ -23,40 +23,46 @@ from io_scene_gltf2.io.com.gltf2_io_extensions import Extension
from io_scene_gltf2.io.exp.gltf2_io_user_extensions import export_user_extensions
-def gather_texture_info(blender_shader_sockets, export_settings):
- return __gather_texture_info_helper(blender_shader_sockets, 'DEFAULT', export_settings)
+# blender_shader_sockets determine the texture and primary_socket determines
+# the textranform and UVMap. Ex: when combining an ORM texture, for
+# occlusion the primary_socket would be the occlusion socket, and
+# blender_shader_sockets would be the (O,R,M) sockets.
-def gather_material_normal_texture_info_class(blender_shader_sockets, export_settings):
- return __gather_texture_info_helper(blender_shader_sockets, 'NORMAL', export_settings)
+def gather_texture_info(primary_socket, blender_shader_sockets, export_settings):
+ return __gather_texture_info_helper(primary_socket, blender_shader_sockets, 'DEFAULT', export_settings)
-def gather_material_occlusion_texture_info_class(blender_shader_sockets, export_settings):
- return __gather_texture_info_helper(blender_shader_sockets, 'OCCLUSION', export_settings)
+def gather_material_normal_texture_info_class(primary_socket, blender_shader_sockets, export_settings):
+ return __gather_texture_info_helper(primary_socket, blender_shader_sockets, 'NORMAL', export_settings)
+
+def gather_material_occlusion_texture_info_class(primary_socket, blender_shader_sockets, export_settings):
+ return __gather_texture_info_helper(primary_socket, blender_shader_sockets, 'OCCLUSION', export_settings)
@cached
def __gather_texture_info_helper(
+ primary_socket: bpy.types.NodeSocket,
blender_shader_sockets: typing.Tuple[bpy.types.NodeSocket],
kind: str,
export_settings):
- if not __filter_texture_info(blender_shader_sockets, export_settings):
+ if not __filter_texture_info(primary_socket, blender_shader_sockets, export_settings):
return None
fields = {
- 'extensions': __gather_extensions(blender_shader_sockets, export_settings),
+ 'extensions': __gather_extensions(primary_socket, export_settings),
'extras': __gather_extras(blender_shader_sockets, export_settings),
'index': __gather_index(blender_shader_sockets, export_settings),
- 'tex_coord': __gather_tex_coord(blender_shader_sockets, export_settings),
+ 'tex_coord': __gather_tex_coord(primary_socket, export_settings),
}
if kind == 'DEFAULT':
texture_info = gltf2_io.TextureInfo(**fields)
elif kind == 'NORMAL':
- fields['scale'] = __gather_normal_scale(blender_shader_sockets, export_settings)
+ fields['scale'] = __gather_normal_scale(primary_socket, export_settings)
texture_info = gltf2_io.MaterialNormalTextureInfoClass(**fields)
elif kind == 'OCCLUSION':
- fields['strength'] = __gather_occlusion_strength(blender_shader_sockets, export_settings)
+ fields['strength'] = __gather_occlusion_strength(primary_socket, export_settings)
texture_info = gltf2_io.MaterialOcclusionTextureInfoClass(**fields)
if texture_info.index is None:
@@ -67,7 +73,11 @@ def __gather_texture_info_helper(
return texture_info
-def __filter_texture_info(blender_shader_sockets, export_settings):
+def __filter_texture_info(primary_socket, blender_shader_sockets, export_settings):
+ if primary_socket is None:
+ return False
+ if __get_tex_from_socket(primary_socket) is None:
+ return False
if not blender_shader_sockets:
return False
if not all([elem is not None for elem in blender_shader_sockets]):
@@ -79,12 +89,11 @@ def __filter_texture_info(blender_shader_sockets, export_settings):
return True
-def __gather_extensions(blender_shader_sockets, export_settings):
- if not hasattr(blender_shader_sockets[0], 'links'):
+def __gather_extensions(primary_socket, export_settings):
+ if not hasattr(primary_socket, 'links'):
return None
- tex_nodes = [__get_tex_from_socket(socket).shader_node for socket in blender_shader_sockets]
- texture_node = tex_nodes[0] if (tex_nodes is not None and len(tex_nodes) > 0) else None
+ texture_node = __get_tex_from_socket(primary_socket).shader_node
if texture_node is None:
return None
texture_transform = gltf2_blender_get.get_texture_transform_from_texture_node(texture_node)
@@ -100,9 +109,9 @@ def __gather_extras(blender_shader_sockets, export_settings):
# MaterialNormalTextureInfo only
-def __gather_normal_scale(blender_shader_sockets, export_settings):
+def __gather_normal_scale(primary_socket, export_settings):
result = gltf2_blender_search_node_tree.from_socket(
- blender_shader_sockets[0],
+ primary_socket,
gltf2_blender_search_node_tree.FilterByType(bpy.types.ShaderNodeNormalMap))
if not result:
return None
@@ -113,7 +122,7 @@ def __gather_normal_scale(blender_shader_sockets, export_settings):
# MaterialOcclusionTextureInfo only
-def __gather_occlusion_strength(blender_shader_sockets, export_settings):
+def __gather_occlusion_strength(primary_socket, export_settings):
return None
@@ -122,8 +131,8 @@ def __gather_index(blender_shader_sockets, export_settings):
return gltf2_blender_gather_texture.gather_texture(blender_shader_sockets, export_settings)
-def __gather_tex_coord(blender_shader_sockets, export_settings):
- blender_shader_node = __get_tex_from_socket(blender_shader_sockets[0]).shader_node
+def __gather_tex_coord(primary_socket, export_settings):
+ blender_shader_node = __get_tex_from_socket(primary_socket).shader_node
if len(blender_shader_node.inputs['Vector'].links) == 0:
return 0