From 59853058f0e1fc7ba8af841c8697b017a54f2572 Mon Sep 17 00:00:00 2001 From: Dorian Ros Date: Tue, 22 Nov 2022 18:30:35 +0100 Subject: [PATCH 1/4] Importer: Fix y-axis UV flip with the PLY object importer (#51) Mitsuba flips the UVs on the y-axis when exporting as PLY. We now flip them back when importing. Fixes #50. --- mitsuba-blender/io/importer/bl_import_ply.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mitsuba-blender/io/importer/bl_import_ply.py b/mitsuba-blender/io/importer/bl_import_ply.py index ef73672..18271d5 100644 --- a/mitsuba-blender/io/importer/bl_import_ply.py +++ b/mitsuba-blender/io/importer/bl_import_ply.py @@ -300,7 +300,9 @@ def load_ply_mesh(filepath, ply_name): def add_face(vertices, indices, uvindices, colindices): mesh_faces.append(indices) if uvindices: - mesh_uvs.extend([(vertices[index][uvindices[0]], vertices[index][uvindices[1]]) for index in indices]) + # Mitsuba seems to flip the UVS on the y-axis when exporting. We account for this here by flipping them + # back to the original coordinates. + mesh_uvs.extend([(vertices[index][uvindices[0]], 1-vertices[index][uvindices[1]]) for index in indices]) if colindices: if len(colindices) == 3: mesh_colors.extend([ From 15181c15b507321ed2bafc775fdcd00c5d649dbd Mon Sep 17 00:00:00 2001 From: Baptiste Nicolet Date: Fri, 28 Apr 2023 11:08:14 +0200 Subject: [PATCH 2/4] Mention stable versions of blender in README --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 0cf7b82..4020c8c 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,8 @@ More in-depth information about the features of the add-on are available on the You can refer to the [Installation & Update Guide](https://github.com/mitsuba-renderer/mitsuba-blender/wiki/Installation-&-Update-Guide) on the wiki for more detailed instructions. -### Requirements +### Supported versions -* `Blender >= 2.93` +Blender version should be at least `2.93`. The addon has been extensively tested +on LTS versions of blender (2.93, 3.3). We recommend using those whenever +possible. From 155a1f0b25f7368c5caf8161d6a662b87fc69c45 Mon Sep 17 00:00:00 2001 From: Baptiste Nicolet Date: Fri, 28 Apr 2023 11:11:59 +0200 Subject: [PATCH 3/4] formatting --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4020c8c..a515129 100644 --- a/README.md +++ b/README.md @@ -27,5 +27,5 @@ You can refer to the [Installation & Update Guide](https://github.com/mitsuba-re ### Supported versions Blender version should be at least `2.93`. The addon has been extensively tested -on LTS versions of blender (2.93, 3.3). We recommend using those whenever +on LTS versions of blender (`2.93`, `3.3`). We recommend using those whenever possible. From 3336eeca316fe617689bd1020c53a442acd5221c Mon Sep 17 00:00:00 2001 From: Merlin Nimier-David Date: Wed, 12 Jul 2023 13:22:58 +0200 Subject: [PATCH 4/4] Geometry export: use unique names for repeated materials (#67) When a user assigns the same material to multiple material slots, the previous logic would use the same name for all of them, and therefore overwrite the exported mesh file repeatedly. Only the mesh part that appeared last in the materials slot list would remain. This PR ensures that unique names are used for the output meshes. --- mitsuba-blender/io/exporter/geometry.py | 54 ++++++++++++++++--------- 1 file changed, 34 insertions(+), 20 deletions(-) diff --git a/mitsuba-blender/io/exporter/geometry.py b/mitsuba-blender/io/exporter/geometry.py index 0f3b2e1..07a1336 100644 --- a/mitsuba-blender/io/exporter/geometry.py +++ b/mitsuba-blender/io/exporter/geometry.py @@ -1,9 +1,10 @@ -from .materials import export_material -from .export_context import Files -from mathutils import Matrix import os import bpy +from .materials import export_material +from .export_context import Files + + def convert_mesh(export_ctx, b_mesh, matrix_world, name, mat_nr): ''' This method creates a mitsuba mesh from a blender mesh and returns it. @@ -86,27 +87,44 @@ def export_object(deg_instance, export_ctx, is_particle): else: transform = b_object.matrix_world + if mat_count == 0: # No assigned material - converted_parts.append((-1, convert_mesh(export_ctx, - b_mesh, - transform, - name_clean, - 0))) - for mat_nr in range(mat_count): - if b_mesh.materials[mat_nr]: + converted_parts.append(( + name_clean, + -1, + convert_mesh(export_ctx, b_mesh, transform, name_clean, 0) + )) + else: + refs_per_mat = {} + for mat_nr in range(mat_count): + mat = b_mesh.materials[mat_nr] + if not mat: + continue + + # Ensures that the exported mesh parts have unique names, + # even if multiple material slots refer to the same material. + n_mat_refs = refs_per_mat.get(mat.name, 0) + name = f'{name_clean}-{mat.name}' + + if n_mat_refs >= 1: + name += f'-{n_mat_refs:03d}' + mts_mesh = convert_mesh(export_ctx, b_mesh, transform, - f"{name_clean}-{b_mesh.materials[mat_nr].name}", + name, mat_nr) if mts_mesh is not None and mts_mesh.face_count() > 0: - converted_parts.append((mat_nr, mts_mesh)) - export_material(export_ctx, b_mesh.materials[mat_nr]) + converted_parts.append((name, mat_nr, mts_mesh)) + refs_per_mat[mat.name] = n_mat_refs + 1 + + if n_mat_refs == 0: + # Only export this material once + export_material(export_ctx, mat) if b_object.type != 'MESH': b_object.to_mesh_clear() - part_count = len(converted_parts) # Use a ShapeGroup for instances and split meshes use_shapegroup = is_instance or is_instance_emitter or is_particle # TODO: Check if shapegroups for split meshes is worth it @@ -115,12 +133,8 @@ def export_object(deg_instance, export_ctx, is_particle): 'type': 'shapegroup' } - for (mat_nr, mts_mesh) in converted_parts: - # Determine the file name - if part_count == 1: - name = f"{name_clean}" - else: - name = f"{name_clean}-{b_mesh.materials[mat_nr].name}" + for (name, mat_nr, mts_mesh) in converted_parts: + name = name_clean if len(converted_parts) == 1 else name mesh_id = f"mesh-{name}" # Save as binary ply