Skip to content

Commit

Permalink
Merge branch 'master' into feature/material-nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
ros-dorian committed Nov 12, 2023
2 parents 9c9d1c6 + 3336eec commit f487089
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 24 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
55 changes: 34 additions & 21 deletions mitsuba-blender/exporter/geometry.py
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -86,28 +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))
b_mat = b_mesh.materials[mat_nr]
export_material(export_ctx, b_mat)
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
Expand All @@ -116,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
Expand Down
4 changes: 3 additions & 1 deletion mitsuba-blender/importer/bl_import_ply.py
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down

0 comments on commit f487089

Please sign in to comment.