From ee97a4410ecee70837b46252ff945d3649419452 Mon Sep 17 00:00:00 2001 From: Sebastian Sille Date: Tue, 21 Feb 2023 12:34:05 +0100 Subject: [PATCH 1/4] Make sure there is a primary texture changed source of texture Signed-off-by: Sebastian Sille --- io_scene_3ds/export_3ds.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/io_scene_3ds/export_3ds.py b/io_scene_3ds/export_3ds.py index 422fc8c..71c55fc 100644 --- a/io_scene_3ds/export_3ds.py +++ b/io_scene_3ds/export_3ds.py @@ -731,8 +731,8 @@ def make_material_chunk(material, image): diffuse = [] for link in wrap.material.node_tree.links: - if link.from_node.type == 'TEX_IMAGE' and link.to_node.type != 'BSDF_PRINCIPLED': - diffuse = [link.from_node.image] if not wrap.normalmap_texture else None + if link.from_node.type == 'TEX_IMAGE' and link.to_node.type == 'MIX_RGB': + diffuse = [link.from_node.image] if diffuse: if primary_tex == False: -- 2.30.2 From cf96645043b121cdb1f03aaf60c29941d134d8ed Mon Sep 17 00:00:00 2001 From: Sebastian Sille Date: Tue, 21 Feb 2023 13:28:31 +0100 Subject: [PATCH 2/4] Texture Dict no longer needed removed TEXTURE_DICT, wich is no longer needed because textures will be processed individually Signed-off-by: Sebastian Sille --- io_scene_3ds/import_3ds.py | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/io_scene_3ds/import_3ds.py b/io_scene_3ds/import_3ds.py index 5ef0e7a..44a4fd2 100644 --- a/io_scene_3ds/import_3ds.py +++ b/io_scene_3ds/import_3ds.py @@ -323,7 +323,7 @@ def process_next_chunk(context, file, previous_chunk, imported_objects, IMAGE_SE contextMesh_smooth = None contextMeshUV = None - TEXTURE_DICT = {} + #TEXTURE_DICT = {} MATDICT = {} # Localspace variable names, faster. @@ -379,23 +379,19 @@ def process_next_chunk(context, file, previous_chunk, imported_objects, IMAGE_SE else: bmat = MATDICT.get(matName) # in rare cases no materials defined. - if bmat: - img = TEXTURE_DICT.get(bmat.name) - else: - print(" warning: material %r not defined!" % matName) - bmat = MATDICT[matName] = bpy.data.materials.new(matName) - img = None bmesh.materials.append(bmat) # can be None + for fidx in faces: + bmesh.polygons[fidx].material_index = mat_idx - if uv_faces and img: - for fidx in faces: - bmesh.polygons[fidx].material_index = mat_idx - # TODO: How to restore this? - # uv_faces[fidx].image = img - else: - for fidx in faces: - bmesh.polygons[fidx].material_index = mat_idx +# if uv_faces and img: +# for fidx in faces: +# bmesh.polygons[fidx].material_index = mat_idx +# # TODO: How to restore this? +# # uv_faces[fidx].image = img +# else: +# for fidx in faces: +# bmesh.polygons[fidx].material_index = mat_idx if uv_faces: uvl = bmesh.uv_layers.active.data[:] -- 2.30.2 From 616f47fd51ca4a2e609995dcba0a53246ebb612b Mon Sep 17 00:00:00 2001 From: Sebastian Sille Date: Wed, 22 Feb 2023 23:07:20 +0100 Subject: [PATCH 3/4] Connect alpha to main texture if they are equal double textures will be removed Signed-off-by: Sebastian Sille --- io_scene_3ds/import_3ds.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/io_scene_3ds/import_3ds.py b/io_scene_3ds/import_3ds.py index 44a4fd2..77382b6 100644 --- a/io_scene_3ds/import_3ds.py +++ b/io_scene_3ds/import_3ds.py @@ -302,7 +302,21 @@ def add_texture_to_material(image, contextWrapper, pct, extend, alpha, scale, of elif extend == 'noWrap': img_wrap.extension = 'CLIP' if alpha == 'alpha': - links.new(img_wrap.node_image.outputs['Alpha'], img_wrap.socket_dst) + for link in links: + if link.from_node.type == 'TEX_IMAGE' and link.to_node.type == 'MIX_RGB': + tex = link.from_node.image.name + own_node = img_wrap.node_image + own_map = img_wrap.node_mapping + if tex == image.name: + links.new(link.from_node.outputs['Alpha'], img_wrap.socket_dst) + nodes.remove(own_map) + nodes.remove(own_node) + for imgs in bpy.data.images: + if imgs.name[-3:].isdigit(): + if not img.users: + bpy.data.images.remove(imgs) + else: + links.new(img_wrap.node_image.outputs['Alpha'], img_wrap.socket_dst) shader.location = (300, 300) contextWrapper._grid_to_location(1, 0, dst_node=contextWrapper.node_out, ref_node=shader) -- 2.30.2 From 6b80a47e76f55bc2112d9ad834af8c69108404f1 Mon Sep 17 00:00:00 2001 From: Sebastian Sille Date: Wed, 22 Feb 2023 23:38:28 +0100 Subject: [PATCH 4/4] Connect alpha to main texture if they are equal missed a letter^^ --- io_scene_3ds/import_3ds.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/io_scene_3ds/import_3ds.py b/io_scene_3ds/import_3ds.py index 77382b6..a8d8e87 100644 --- a/io_scene_3ds/import_3ds.py +++ b/io_scene_3ds/import_3ds.py @@ -313,7 +313,7 @@ def add_texture_to_material(image, contextWrapper, pct, extend, alpha, scale, of nodes.remove(own_node) for imgs in bpy.data.images: if imgs.name[-3:].isdigit(): - if not img.users: + if not imgs.users: bpy.data.images.remove(imgs) else: links.new(img_wrap.node_image.outputs['Alpha'], img_wrap.socket_dst) -- 2.30.2