From 74a27a787ab4b79c90cff0275fee8c2a50cf3496 Mon Sep 17 00:00:00 2001 From: rizzntine <143769073+rizzntine@users.noreply.github.com> Date: Sat, 25 Nov 2023 17:30:50 +0100 Subject: [PATCH 01/17] __init__.py: blend_mode fixed to blend_method Renamed from blend_mode to blend_method in accordance with blender internals --- io_mesh_w3d/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/io_mesh_w3d/__init__.py b/io_mesh_w3d/__init__.py index f9ede95b..6712208d 100644 --- a/io_mesh_w3d/__init__.py +++ b/io_mesh_w3d/__init__.py @@ -298,7 +298,7 @@ def draw(self, context): col = layout.column() col.prop(mat, 'surface_type') col = layout.column() - col.prop(mat, 'blend_mode') + col.prop(mat, 'blend_method') col = layout.column() col.prop(mat, 'ambient') @@ -370,7 +370,7 @@ def draw(self, context): col = layout.column() col.prop(mat, 'damaged_texture') col = layout.column() - col.prop(mat, 'secondary_texture_blend_mode') + col.prop(mat, 'secondary_texture_blend_method') col = layout.column() col.prop(mat, 'tex_coord_mapper_0') col = layout.column() From 71e43081637046a86028e5e62de81aba305b8662 Mon Sep 17 00:00:00 2001 From: rizzntine <143769073+rizzntine@users.noreply.github.com> Date: Sun, 3 Dec 2023 02:30:05 +0100 Subject: [PATCH 02/17] material_import.py: Alpha Clip blend method for working transparency --- io_mesh_w3d/common/utils/material_import.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/io_mesh_w3d/common/utils/material_import.py b/io_mesh_w3d/common/utils/material_import.py index 5e7730c9..56cc696b 100644 --- a/io_mesh_w3d/common/utils/material_import.py +++ b/io_mesh_w3d/common/utils/material_import.py @@ -43,7 +43,6 @@ def create_material_from_vertex_material(name, vert_mat): material = bpy.data.materials.new(name) material.material_type = 'VERTEX_MATERIAL' material.use_nodes = True - material.blend_method = 'BLEND' material.show_transparent_back = False attributes = {'DEFAULT'} @@ -91,7 +90,6 @@ def create_material_from_shader_material(context, name, shader_mat): material = bpy.data.materials.new(name) material.material_type = 'SHADER_MATERIAL' material.use_nodes = True - material.blend_method = 'BLEND' material.show_transparent_back = False material.technique = shader_mat.header.technique @@ -209,6 +207,8 @@ def create_material_from_shader_material(context, name, shader_mat): def set_shader_properties(material, shader): + material.blend_method = 'CLIP' + #this works for transparency until i get around to streamlining this better material.shader.depth_compare = str(shader.depth_compare) material.shader.depth_mask = str(shader.depth_mask) material.shader.color_mask = shader.color_mask From c6c7e851d6fea2ad8aeaeb84e47c4fad668b3890 Mon Sep 17 00:00:00 2001 From: rizzntine <143769073+rizzntine@users.noreply.github.com> Date: Sun, 3 Dec 2023 06:23:29 +0100 Subject: [PATCH 03/17] material_import.py: Added support for Multiple Materials per Mesh Object Based on makarenk0's implementation, now with alpha transparency support. --- io_mesh_w3d/common/utils/material_import.py | 60 +++++++++++++++------ 1 file changed, 43 insertions(+), 17 deletions(-) diff --git a/io_mesh_w3d/common/utils/material_import.py b/io_mesh_w3d/common/utils/material_import.py index 56cc696b..8abe9ac4 100644 --- a/io_mesh_w3d/common/utils/material_import.py +++ b/io_mesh_w3d/common/utils/material_import.py @@ -13,24 +13,50 @@ # vertex material ########################################################################## -def create_vertex_material(context, principleds, structure, mesh, b_mesh, name, triangles): - for vertMat in structure.vert_materials: - (material, principled) = create_material_from_vertex_material(name, vertMat) - mesh.materials.append(material) - principleds.append(principled) - - for mat_pass in structure.material_passes: - create_uvlayer(context, mesh, b_mesh, triangles, mat_pass) - create_uvlayer_2(context, mesh, b_mesh, triangles, mat_pass) - - if mat_pass.tx_stages: - tx_stage = mat_pass.tx_stages[0] - mat_id = mat_pass.vertex_material_ids[0] - tex_id = tx_stage.tx_ids[0][0] +def create_vertex_material(context, principleds, structure, mesh, b_mesh, name, triangles, mesh_ob): + + if len(structure.material_passes) == 1 and len(structure.textures) > 1: # condition for multiple materials per single mesh object + # Create the same amount of materials as textures used for this mesh + source_mat = structure.vert_materials[0] + for texture in structure.textures: + source_mat.vm_name = texture.id + (material, principled) = create_material_from_vertex_material(name, source_mat) + mesh.materials.append(material) + principleds.append(principled) + + create_uvlayer(context, mesh, b_mesh, triangles, structure.material_passes[0]) + + # Load textures + for tex_id, texture in enumerate(structure.textures): texture = structure.textures[tex_id] - tex = find_texture(context, texture.file, texture.id) - principleds[mat_id].base_color_texture.image = tex - principleds[mat_id].base_color_texture.image.name = texture.file + tex = find_texture(context, texture.file, texture.id) + principleds[tex_id].base_color_texture.image = tex + principleds[tex_id].alpha_texture.image = tex + + # Assign material to appropriate object faces + bpy.ops.object.mode_set(mode = 'EDIT') + bm = bmesh.from_edit_mesh(mesh_ob.data) + bm.faces.ensure_lookup_table() + for i, face in enumerate(bm.faces): + bm.faces[i].material_index = structure.material_passes[0].tx_stages[0].tx_ids[0][i] + bpy.ops.object.mode_set(mode = 'OBJECT') + else: + for vertMat in structure.vert_materials: + (material, principled) = create_material_from_vertex_material(name, vertMat) + mesh.materials.append(material) + principleds.append(principled) + + for mat_pass in structure.material_passes: + create_uvlayer(context, mesh, b_mesh, triangles, mat_pass) + + if mat_pass.tx_stages: + tx_stage = mat_pass.tx_stages[0] + mat_id = mat_pass.vertex_material_ids[0] + tex_id = tx_stage.tx_ids[0][0] + texture = structure.textures[tex_id] + tex = find_texture(context, texture.file, texture.id) + principleds[mat_id].base_color_texture.image = tex + principleds[mat_id].alpha_texture.image = tex def create_material_from_vertex_material(name, vert_mat): From 847c3a27d05ca463e2174938d7a8f79109c099d3 Mon Sep 17 00:00:00 2001 From: rizzntine <143769073+rizzntine@users.noreply.github.com> Date: Sun, 3 Dec 2023 06:25:15 +0100 Subject: [PATCH 04/17] Update mesh_import.py: Multiple Material per Mesh Object support +1 Argument to create_vertex_material in \material_import.py --- io_mesh_w3d/common/utils/mesh_import.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/io_mesh_w3d/common/utils/mesh_import.py b/io_mesh_w3d/common/utils/mesh_import.py index 915ac671..12573f37 100644 --- a/io_mesh_w3d/common/utils/mesh_import.py +++ b/io_mesh_w3d/common/utils/mesh_import.py @@ -74,14 +74,14 @@ def create_mesh(context, mesh_struct, coll): if mesh_struct.vert_materials: create_vertex_material( - context, principleds, mesh_struct, mesh, b_mesh, actual_mesh_name, triangles) + context, principleds, mesh_struct, mesh, b_mesh, actual_mesh_name, triangles, mesh_ob) for i, shader in enumerate(mesh_struct.shaders): set_shader_properties(mesh.materials[min(i, len(mesh.materials) - 1)], shader) elif mesh_struct.prelit_vertex: create_vertex_material(context, principleds, mesh_struct.prelit_vertex, - mesh, b_mesh, actual_mesh_name, triangles) + mesh, b_mesh, actual_mesh_name, triangles, mesh_ob) for i, shader in enumerate(mesh_struct.prelit_vertex.shaders): set_shader_properties(mesh.materials[i], shader) From 3f743b4f04ab6ddffff60545be2a7e36fff2188e Mon Sep 17 00:00:00 2001 From: rizzntine <143769073+rizzntine@users.noreply.github.com> Date: Sun, 3 Dec 2023 06:56:17 +0100 Subject: [PATCH 05/17] material_import.py: alpha clip blend mode for multiple material meshes --- io_mesh_w3d/common/utils/material_import.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/io_mesh_w3d/common/utils/material_import.py b/io_mesh_w3d/common/utils/material_import.py index 8abe9ac4..12c6101b 100644 --- a/io_mesh_w3d/common/utils/material_import.py +++ b/io_mesh_w3d/common/utils/material_import.py @@ -57,6 +57,11 @@ def create_vertex_material(context, principleds, structure, mesh, b_mesh, name, tex = find_texture(context, texture.file, texture.id) principleds[mat_id].base_color_texture.image = tex principleds[mat_id].alpha_texture.image = tex + + #Iterate through all materials and set their blend mode to Alpha Clip for transparency + for material in mesh.materials: + if material: + material.blend_method = 'CLIP' def create_material_from_vertex_material(name, vert_mat): @@ -233,8 +238,6 @@ def create_material_from_shader_material(context, name, shader_mat): def set_shader_properties(material, shader): - material.blend_method = 'CLIP' - #this works for transparency until i get around to streamlining this better material.shader.depth_compare = str(shader.depth_compare) material.shader.depth_mask = str(shader.depth_mask) material.shader.color_mask = shader.color_mask From 20c44e41b118edd7b712eaf2634bcf6ab11d18b8 Mon Sep 17 00:00:00 2001 From: rizzntine <143769073+rizzntine@users.noreply.github.com> Date: Tue, 5 Dec 2023 04:11:55 +0100 Subject: [PATCH 06/17] Create an empty UV Map on early return This is to ensure no export errors due to empty object data in certain formats. (One example would be an error thrown on Airfield Imports due to the HOUSECOLOR01 material not having an UV Map attached.) --- io_mesh_w3d/common/utils/helpers.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/io_mesh_w3d/common/utils/helpers.py b/io_mesh_w3d/common/utils/helpers.py index 66360bd8..b0dbcccb 100644 --- a/io_mesh_w3d/common/utils/helpers.py +++ b/io_mesh_w3d/common/utils/helpers.py @@ -82,6 +82,7 @@ def create_uvlayer(context, mesh, b_mesh, tris, mat_pass): context.warning('only one texture stage per material pass supported') if tx_coords is None: + uv_layer = mesh.uv_layers.new(do_init=False) return uv_layer = mesh.uv_layers.new(do_init=False) @@ -96,6 +97,7 @@ def create_uvlayer_2(context, mesh, b_mesh, tris, mat_pass): if mat_pass.tx_coords_2: tx_coords_2 = mat_pass.tx_coords_2 else: + uv_layer = mesh.uv_layers.new(do_init=False) return uv_layer = mesh.uv_layers.new(do_init=False) From 63bada3a1e2b78bfe7158b3cf4bb19e06e9e7c7a Mon Sep 17 00:00:00 2001 From: Rizzntine <143769073+rizzntine@users.noreply.github.com> Date: Sun, 28 Jan 2024 14:03:41 +0100 Subject: [PATCH 07/17] material_import.py: Fixed material duplication, node_tree manipulation --- io_mesh_w3d/common/utils/material_import.py | 22 ++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/io_mesh_w3d/common/utils/material_import.py b/io_mesh_w3d/common/utils/material_import.py index 12c6101b..8405863d 100644 --- a/io_mesh_w3d/common/utils/material_import.py +++ b/io_mesh_w3d/common/utils/material_import.py @@ -29,9 +29,15 @@ def create_vertex_material(context, principleds, structure, mesh, b_mesh, name, # Load textures for tex_id, texture in enumerate(structure.textures): texture = structure.textures[tex_id] - tex = find_texture(context, texture.file, texture.id) - principleds[tex_id].base_color_texture.image = tex - principleds[tex_id].alpha_texture.image = tex + tex = find_texture(context, texture.file, texture.id) + node_tree = mesh.materials[tex_id].node_tree + bsdf_node = node_tree.nodes.get('Principled BSDF') + texture_node = node_tree.nodes.new('ShaderNodeTexImage') + texture_node.image = tex + texture_node.location = (-350, 300) + links = node_tree.links + links.new(texture_node.outputs['Color'], bsdf_node.inputs['Base Color']) + links.new(texture_node.outputs['Alpha'], bsdf_node.inputs['Alpha']) # Assign material to appropriate object faces bpy.ops.object.mode_set(mode = 'EDIT') @@ -55,8 +61,14 @@ def create_vertex_material(context, principleds, structure, mesh, b_mesh, name, tex_id = tx_stage.tx_ids[0][0] texture = structure.textures[tex_id] tex = find_texture(context, texture.file, texture.id) - principleds[mat_id].base_color_texture.image = tex - principleds[mat_id].alpha_texture.image = tex + node_tree = mesh.materials[tex_id].node_tree + bsdf_node = node_tree.nodes.get('Principled BSDF') + texture_node = node_tree.nodes.new('ShaderNodeTexImage') + texture_node.image = tex + texture_node.location = (-350, 300) + links = node_tree.links + links.new(texture_node.outputs['Color'], bsdf_node.inputs['Base Color']) + links.new(texture_node.outputs['Alpha'], bsdf_node.inputs['Alpha']) #Iterate through all materials and set their blend mode to Alpha Clip for transparency for material in mesh.materials: From d123178b7aaf818b8bcd9dffc26d8f0e502dabfd Mon Sep 17 00:00:00 2001 From: rizzntine Date: Sun, 28 Jan 2024 13:04:16 +0000 Subject: [PATCH 08/17] autopep8 action fixes --- io_mesh_w3d/common/utils/material_import.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/io_mesh_w3d/common/utils/material_import.py b/io_mesh_w3d/common/utils/material_import.py index 8405863d..d414a26b 100644 --- a/io_mesh_w3d/common/utils/material_import.py +++ b/io_mesh_w3d/common/utils/material_import.py @@ -15,7 +15,8 @@ def create_vertex_material(context, principleds, structure, mesh, b_mesh, name, triangles, mesh_ob): - if len(structure.material_passes) == 1 and len(structure.textures) > 1: # condition for multiple materials per single mesh object + if len(structure.material_passes) == 1 and len( + structure.textures) > 1: # condition for multiple materials per single mesh object # Create the same amount of materials as textures used for this mesh source_mat = structure.vert_materials[0] for texture in structure.textures: @@ -29,7 +30,7 @@ def create_vertex_material(context, principleds, structure, mesh, b_mesh, name, # Load textures for tex_id, texture in enumerate(structure.textures): texture = structure.textures[tex_id] - tex = find_texture(context, texture.file, texture.id) + tex = find_texture(context, texture.file, texture.id) node_tree = mesh.materials[tex_id].node_tree bsdf_node = node_tree.nodes.get('Principled BSDF') texture_node = node_tree.nodes.new('ShaderNodeTexImage') @@ -40,12 +41,12 @@ def create_vertex_material(context, principleds, structure, mesh, b_mesh, name, links.new(texture_node.outputs['Alpha'], bsdf_node.inputs['Alpha']) # Assign material to appropriate object faces - bpy.ops.object.mode_set(mode = 'EDIT') + bpy.ops.object.mode_set(mode='EDIT') bm = bmesh.from_edit_mesh(mesh_ob.data) bm.faces.ensure_lookup_table() for i, face in enumerate(bm.faces): bm.faces[i].material_index = structure.material_passes[0].tx_stages[0].tx_ids[0][i] - bpy.ops.object.mode_set(mode = 'OBJECT') + bpy.ops.object.mode_set(mode='OBJECT') else: for vertMat in structure.vert_materials: (material, principled) = create_material_from_vertex_material(name, vertMat) @@ -69,8 +70,8 @@ def create_vertex_material(context, principleds, structure, mesh, b_mesh, name, links = node_tree.links links.new(texture_node.outputs['Color'], bsdf_node.inputs['Base Color']) links.new(texture_node.outputs['Alpha'], bsdf_node.inputs['Alpha']) - - #Iterate through all materials and set their blend mode to Alpha Clip for transparency + + # Iterate through all materials and set their blend mode to Alpha Clip for transparency for material in mesh.materials: if material: material.blend_method = 'CLIP' From 778c545a2b44e6bf84b5535e012acb75479f35d9 Mon Sep 17 00:00:00 2001 From: Rizzntine <143769073+rizzntine@users.noreply.github.com> Date: Mon, 29 Jan 2024 22:43:51 +0100 Subject: [PATCH 09/17] helpers.py : create_uvlayer, check if mesh exists --- io_mesh_w3d/common/utils/helpers.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/io_mesh_w3d/common/utils/helpers.py b/io_mesh_w3d/common/utils/helpers.py index b0dbcccb..3c422209 100644 --- a/io_mesh_w3d/common/utils/helpers.py +++ b/io_mesh_w3d/common/utils/helpers.py @@ -82,7 +82,8 @@ def create_uvlayer(context, mesh, b_mesh, tris, mat_pass): context.warning('only one texture stage per material pass supported') if tx_coords is None: - uv_layer = mesh.uv_layers.new(do_init=False) + if mesh is not None: + uv_layer = mesh.uv_layers.new(do_init=False) return uv_layer = mesh.uv_layers.new(do_init=False) From b9e12eb4b6776571991c0464b0b035200088bf4f Mon Sep 17 00:00:00 2001 From: Rizzntine <143769073+rizzntine@users.noreply.github.com> Date: Tue, 30 Jan 2024 01:43:03 +0100 Subject: [PATCH 10/17] Update material_pass.py --- tests/w3d/helpers/mesh_structs/material_pass.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/w3d/helpers/mesh_structs/material_pass.py b/tests/w3d/helpers/mesh_structs/material_pass.py index b4ec5bb9..f9aabdf7 100644 --- a/tests/w3d/helpers/mesh_structs/material_pass.py +++ b/tests/w3d/helpers/mesh_structs/material_pass.py @@ -30,7 +30,7 @@ def get_per_face_txcoords(): def get_texture_stage(index=0): return TextureStage( - tx_ids=[[index]], + tx_ids=[list(range(index))], per_face_tx_coords=[get_per_face_txcoords()], tx_coords=[get_uvs()]) From e2fb7a1a9a37f0036e7826d40002588d34997a58 Mon Sep 17 00:00:00 2001 From: Rizzntine <143769073+rizzntine@users.noreply.github.com> Date: Tue, 30 Jan 2024 01:49:40 +0100 Subject: [PATCH 11/17] Update material_pass.py --- tests/w3d/helpers/mesh_structs/material_pass.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/w3d/helpers/mesh_structs/material_pass.py b/tests/w3d/helpers/mesh_structs/material_pass.py index f9aabdf7..5a74f0a4 100644 --- a/tests/w3d/helpers/mesh_structs/material_pass.py +++ b/tests/w3d/helpers/mesh_structs/material_pass.py @@ -30,7 +30,7 @@ def get_per_face_txcoords(): def get_texture_stage(index=0): return TextureStage( - tx_ids=[list(range(index))], + tx_ids=[[index]*index], per_face_tx_coords=[get_per_face_txcoords()], tx_coords=[get_uvs()]) From c50bed36422950b2d243b66859074b5a313e60d2 Mon Sep 17 00:00:00 2001 From: Rizzntine <143769073+rizzntine@users.noreply.github.com> Date: Tue, 30 Jan 2024 02:05:59 +0100 Subject: [PATCH 12/17] tests/material_pass.py get_texture_stage() : attempt at per face texture id enumeration --- tests/w3d/helpers/mesh_structs/material_pass.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/w3d/helpers/mesh_structs/material_pass.py b/tests/w3d/helpers/mesh_structs/material_pass.py index 5a74f0a4..889b5b3a 100644 --- a/tests/w3d/helpers/mesh_structs/material_pass.py +++ b/tests/w3d/helpers/mesh_structs/material_pass.py @@ -30,7 +30,7 @@ def get_per_face_txcoords(): def get_texture_stage(index=0): return TextureStage( - tx_ids=[[index]*index], + tx_ids=[[index]+[index]*index], per_face_tx_coords=[get_per_face_txcoords()], tx_coords=[get_uvs()]) From c2b702d4b15d05d0b78828cbe69e57f731f46132 Mon Sep 17 00:00:00 2001 From: Rizzntine <143769073+rizzntine@users.noreply.github.com> Date: Tue, 30 Jan 2024 02:17:47 +0100 Subject: [PATCH 13/17] Update material_pass.py --- tests/w3d/helpers/mesh_structs/material_pass.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/w3d/helpers/mesh_structs/material_pass.py b/tests/w3d/helpers/mesh_structs/material_pass.py index 889b5b3a..0192c5b5 100644 --- a/tests/w3d/helpers/mesh_structs/material_pass.py +++ b/tests/w3d/helpers/mesh_structs/material_pass.py @@ -30,7 +30,7 @@ def get_per_face_txcoords(): def get_texture_stage(index=0): return TextureStage( - tx_ids=[[index]+[index]*index], + tx_ids=[[index]+[index]*max(0, index-1)], per_face_tx_coords=[get_per_face_txcoords()], tx_coords=[get_uvs()]) From 579b1b2553f2910e1fe41b7c80c59398f8e5f4ee Mon Sep 17 00:00:00 2001 From: Rizzntine <143769073+rizzntine@users.noreply.github.com> Date: Tue, 30 Jan 2024 03:28:06 +0100 Subject: [PATCH 14/17] Update material_import.py --- io_mesh_w3d/common/utils/material_import.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/io_mesh_w3d/common/utils/material_import.py b/io_mesh_w3d/common/utils/material_import.py index d414a26b..a1d3f08d 100644 --- a/io_mesh_w3d/common/utils/material_import.py +++ b/io_mesh_w3d/common/utils/material_import.py @@ -44,8 +44,9 @@ def create_vertex_material(context, principleds, structure, mesh, b_mesh, name, bpy.ops.object.mode_set(mode='EDIT') bm = bmesh.from_edit_mesh(mesh_ob.data) bm.faces.ensure_lookup_table() - for i, face in enumerate(bm.faces): - bm.faces[i].material_index = structure.material_passes[0].tx_stages[0].tx_ids[0][i] + if(bm.faces): + for i, face in enumerate(bm.faces): + bm.faces[i].material_index = structure.material_passes[0].tx_stages[0].tx_ids[0][i] bpy.ops.object.mode_set(mode='OBJECT') else: for vertMat in structure.vert_materials: From 58b0f30d83bfa423b6a11aa8d2adde7ddee74151 Mon Sep 17 00:00:00 2001 From: Rizzntine <143769073+rizzntine@users.noreply.github.com> Date: Tue, 30 Jan 2024 03:31:28 +0100 Subject: [PATCH 15/17] Update material_import.py --- io_mesh_w3d/common/utils/material_import.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/io_mesh_w3d/common/utils/material_import.py b/io_mesh_w3d/common/utils/material_import.py index a1d3f08d..0179c032 100644 --- a/io_mesh_w3d/common/utils/material_import.py +++ b/io_mesh_w3d/common/utils/material_import.py @@ -44,9 +44,11 @@ def create_vertex_material(context, principleds, structure, mesh, b_mesh, name, bpy.ops.object.mode_set(mode='EDIT') bm = bmesh.from_edit_mesh(mesh_ob.data) bm.faces.ensure_lookup_table() - if(bm.faces): - for i, face in enumerate(bm.faces): + for i, face in enumerate(bm.faces): + if(structure.material_passes[0].tx_stages[0].tx_ids[0][i]): bm.faces[i].material_index = structure.material_passes[0].tx_stages[0].tx_ids[0][i] + else: + bm.faces[i].material_index = structure.material_passes[0].tx_stages[0].tx_ids[0][0] bpy.ops.object.mode_set(mode='OBJECT') else: for vertMat in structure.vert_materials: From 90d94bb8463795ddd0a01c35ce953badfa1116ab Mon Sep 17 00:00:00 2001 From: Rizzntine <143769073+rizzntine@users.noreply.github.com> Date: Tue, 30 Jan 2024 03:39:12 +0100 Subject: [PATCH 16/17] Update material_import.py --- io_mesh_w3d/common/utils/material_import.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/io_mesh_w3d/common/utils/material_import.py b/io_mesh_w3d/common/utils/material_import.py index 0179c032..c93c9393 100644 --- a/io_mesh_w3d/common/utils/material_import.py +++ b/io_mesh_w3d/common/utils/material_import.py @@ -45,7 +45,7 @@ def create_vertex_material(context, principleds, structure, mesh, b_mesh, name, bm = bmesh.from_edit_mesh(mesh_ob.data) bm.faces.ensure_lookup_table() for i, face in enumerate(bm.faces): - if(structure.material_passes[0].tx_stages[0].tx_ids[0][i]): + if( i < len(structure.material_passes[0].tx_stages[0].tx_ids[0]) ): bm.faces[i].material_index = structure.material_passes[0].tx_stages[0].tx_ids[0][i] else: bm.faces[i].material_index = structure.material_passes[0].tx_stages[0].tx_ids[0][0] From 461f0d91f054493c01b3abf40840d9e9ae70408f Mon Sep 17 00:00:00 2001 From: rizzntine Date: Tue, 30 Jan 2024 02:39:45 +0000 Subject: [PATCH 17/17] autopep8 action fixes --- io_mesh_w3d/common/utils/material_import.py | 2 +- tests/w3d/helpers/mesh_structs/material_pass.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/io_mesh_w3d/common/utils/material_import.py b/io_mesh_w3d/common/utils/material_import.py index c93c9393..0f673f30 100644 --- a/io_mesh_w3d/common/utils/material_import.py +++ b/io_mesh_w3d/common/utils/material_import.py @@ -45,7 +45,7 @@ def create_vertex_material(context, principleds, structure, mesh, b_mesh, name, bm = bmesh.from_edit_mesh(mesh_ob.data) bm.faces.ensure_lookup_table() for i, face in enumerate(bm.faces): - if( i < len(structure.material_passes[0].tx_stages[0].tx_ids[0]) ): + if(i < len(structure.material_passes[0].tx_stages[0].tx_ids[0])): bm.faces[i].material_index = structure.material_passes[0].tx_stages[0].tx_ids[0][i] else: bm.faces[i].material_index = structure.material_passes[0].tx_stages[0].tx_ids[0][0] diff --git a/tests/w3d/helpers/mesh_structs/material_pass.py b/tests/w3d/helpers/mesh_structs/material_pass.py index 0192c5b5..e4541f2a 100644 --- a/tests/w3d/helpers/mesh_structs/material_pass.py +++ b/tests/w3d/helpers/mesh_structs/material_pass.py @@ -30,7 +30,7 @@ def get_per_face_txcoords(): def get_texture_stage(index=0): return TextureStage( - tx_ids=[[index]+[index]*max(0, index-1)], + tx_ids=[[index] + [index] * max(0, index - 1)], per_face_tx_coords=[get_per_face_txcoords()], tx_coords=[get_uvs()])