Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blender 4.0 fixes #88

Merged
merged 1 commit into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ jobs:
environment:
- {
os: "ubuntu-latest",
mitsuba-version: "3.4.1"
mitsuba-version: "3.5.0"
}
- {
os: "windows-latest",
mitsuba-version: "3.4.1"
mitsuba-version: "3.5.0"
}
blender:
- {
Expand All @@ -38,6 +38,9 @@ jobs:
- {
version: "3.6"
}
- {
version: "4.0"
}

steps:
- name: Git checkout
Expand Down
2 changes: 1 addition & 1 deletion mitsuba-blender/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

from . import io, engine

DEPS_MITSUBA_VERSION = '3.4.1'
DEPS_MITSUBA_VERSION = '3.5.0'

def get_addon_preferences(context):
return context.preferences.addons[__name__].preferences
Expand Down
4 changes: 3 additions & 1 deletion mitsuba-blender/io/exporter/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ def convert_mesh(export_ctx, b_mesh, matrix_world, name, mat_nr):
'type': 'blender',
'version': ".".join(map(str,bpy.app.version))
}
b_mesh.calc_normals()

if bpy.app.version < (4, 0, 0):
b_mesh.calc_normals()
# Compute the triangle tesselation
b_mesh.calc_loop_triangles()

Expand Down
35 changes: 28 additions & 7 deletions mitsuba-blender/io/exporter/materials.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import bpy
import numpy as np
from mathutils import Matrix
from .export_context import Files
Expand Down Expand Up @@ -260,18 +261,38 @@ def convert_mix_materials_cycles(export_ctx, current_node):#TODO: test and fix t

def convert_principled_materials_cycles(export_ctx, current_node):
params = {}

if bpy.app.version >= (4, 0, 0):
specular_key = 'Specular IOR Level'
transmission_key = 'Transmission Weight'
sheen_key = 'Sheen Weight'
clearcoat_key = 'Coat Weight'
clearcoat_roughness_key = 'Coat Roughness'
else:
specular_key = 'Specular'
transmission_key = 'Transmission'
sheen_key = 'Sheen'
clearcoat_key = 'Clearcoat'
clearcoat_roughness_key = 'Clearcoat Roughness'

base_color = convert_color_texture_node(export_ctx, current_node.inputs['Base Color'])
specular = current_node.inputs['Specular'].default_value
specular_tint = convert_float_texture_node(export_ctx, current_node.inputs['Specular Tint'])
specular_trans = convert_float_texture_node(export_ctx, current_node.inputs['Transmission'])
specular = current_node.inputs[specular_key].default_value
if bpy.app.version >= (4, 0, 0):
specular_tint = convert_color_texture_node(export_ctx, current_node.inputs['Specular Tint'])
else:
specular_tint = convert_float_texture_node(export_ctx, current_node.inputs['Specular Tint'])
specular_trans = convert_float_texture_node(export_ctx, current_node.inputs[transmission_key])
ior = current_node.inputs['IOR'].default_value
roughness = convert_float_texture_node(export_ctx, current_node.inputs['Roughness'])
metallic = convert_float_texture_node(export_ctx, current_node.inputs['Metallic'])
anisotropic = convert_float_texture_node(export_ctx, current_node.inputs['Anisotropic'])
sheen = convert_float_texture_node(export_ctx, current_node.inputs['Sheen'])
sheen_tint = convert_float_texture_node(export_ctx, current_node.inputs['Sheen Tint'])
clearcoat = convert_float_texture_node(export_ctx, current_node.inputs['Clearcoat'])
clearcoat_roughness = convert_float_texture_node(export_ctx, current_node.inputs['Clearcoat Roughness'])
sheen = convert_float_texture_node(export_ctx, current_node.inputs[sheen_key])
if bpy.app.version >= (4, 0, 0):
sheen_tint = convert_color_texture_node(export_ctx, current_node.inputs['Sheen Tint'])
else:
sheen_tint = convert_float_texture_node(export_ctx, current_node.inputs['Sheen Tint'])
clearcoat = convert_float_texture_node(export_ctx, current_node.inputs[clearcoat_key])
clearcoat_roughness = convert_float_texture_node(export_ctx, current_node.inputs[clearcoat_roughness_key])

params.update({
'type': 'principled',
Expand Down
44 changes: 37 additions & 7 deletions mitsuba-blender/io/importer/materials.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,13 @@ def write_mi_rgb_property(mi_context, mi_mat, mi_prop_name, bl_mat_wrap, out_soc
mi_prop_type = mi_mat.type(mi_prop_name)
if mi_prop_type == Properties.Type.Color:
write_mi_rgb_value(mi_context, list(mi_mat.get(mi_prop_name, default)), bl_mat_wrap, out_socket_id)
if mi_prop_type == Properties.Type.Float:
if mi_prop_name in mi_mat:
col_val = mi_mat.get(mi_prop_name)
col = [col_val, col_val, col_val]
else:
col = default
write_mi_rgb_value(mi_context, list(col), bl_mat_wrap, out_socket_id)
elif mi_prop_type == Properties.Type.NamedReference:
mi_texture_ref_id = mi_mat.get(mi_prop_name)
mi_texture = mi_context.mi_scene_props.get_with_id_and_class(mi_texture_ref_id, 'Texture')
Expand Down Expand Up @@ -331,19 +338,42 @@ def write_mi_emitter_bsdf(mi_context, bl_mat_wrap, out_socket_id, mi_emitter):
######################

def write_mi_principled_bsdf(mi_context, mi_mat, bl_mat_wrap, out_socket_id, mi_bump=None, mi_normal=None):
if bpy.app.version >= (4, 0, 0):
specular_key = 'Specular IOR Level'
transmission_key = 'Transmission Weight'
sheen_key = 'Sheen Weight'
clearcoat_key = 'Coat Weight'
clearcoat_roughness_key = 'Coat Roughness'
else:
specular_key = 'Specular'
transmission_key = 'Transmission'
sheen_key = 'Sheen'
clearcoat_key = 'Clearcoat'
clearcoat_roughness_key = 'Clearcoat Roughness'


bl_principled = bl_mat_wrap.ensure_node_type([out_socket_id], 'ShaderNodeBsdfPrincipled', 'BSDF')
bl_principled_wrap = bl_shader_utils.NodeMaterialWrapper(bl_mat_wrap.bl_mat, out_node=bl_principled)
write_mi_rgb_property(mi_context, mi_mat, 'base_color', bl_principled_wrap, 'Base Color', [0.8, 0.8, 0.8])
write_mi_float_property(mi_context, mi_mat, 'specular', bl_principled_wrap, 'Specular', 0.5)
write_mi_float_property(mi_context, mi_mat, 'spec_tint', bl_principled_wrap, 'Specular Tint', 0.0)
write_mi_float_property(mi_context, mi_mat, 'spec_trans', bl_principled_wrap, 'Transmission', 0.0)
write_mi_float_property(mi_context, mi_mat, 'specular', bl_principled_wrap, specular_key, 0.5)
if bpy.app.version >= (4, 0, 0):
write_mi_rgb_property(mi_context, mi_mat, 'spec_tint', bl_principled_wrap, 'Specular Tint', [0.0, 0.0, 0.0])
else:
write_mi_float_property(mi_context, mi_mat, 'spec_tint', bl_principled_wrap, 'Specular Tint', 0.0)

write_mi_float_property(mi_context, mi_mat, 'spec_trans', bl_principled_wrap, transmission_key, 0.0)
write_mi_float_property(mi_context, mi_mat, 'metallic', bl_principled_wrap, 'Metallic', 0.0)
write_mi_float_property(mi_context, mi_mat, 'anisotropic', bl_principled_wrap, 'Anisotropic', 0.0)
write_mi_roughness_property(mi_context, mi_mat, 'roughness', bl_principled_wrap, 'Roughness', 0.4)
write_mi_float_property(mi_context, mi_mat, 'sheen', bl_principled_wrap, 'Sheen', 0.0)
write_mi_float_property(mi_context, mi_mat, 'sheen_tint', bl_principled_wrap, 'Sheen Tint', 0.5)
write_mi_float_property(mi_context, mi_mat, 'clearcoat', bl_principled_wrap, 'Clearcoat', 0.0)
write_mi_roughness_property(mi_context, mi_mat, 'clearcoat_gloss', bl_principled_wrap, 'Clearcoat Roughness', 0.03)
write_mi_float_property(mi_context, mi_mat, 'sheen', bl_principled_wrap, sheen_key, 0.0)

if bpy.app.version >= (4, 0, 0):
write_mi_rgb_property(mi_context, mi_mat, 'sheen_tint', bl_principled_wrap, 'Sheen Tint', [0.5, 0.5, 0.5])
else:
write_mi_float_property(mi_context, mi_mat, 'sheen_tint', bl_principled_wrap, 'Sheen Tint', 0.5)

write_mi_float_property(mi_context, mi_mat, 'clearcoat', bl_principled_wrap, clearcoat_key, 0.0)
write_mi_roughness_property(mi_context, mi_mat, 'clearcoat_gloss', bl_principled_wrap, clearcoat_roughness_key, 0.03)
# Write normal and bump maps
write_mi_bump_and_normal_maps(mi_context, bl_principled_wrap, 'Normal', mi_bump=mi_bump, mi_normal=mi_normal)
return True
Expand Down
Loading