Skip to content

Commit 635aa6a

Browse files
authored
Blender 4.0 fixes (#88)
* Need to bump Mitsuba dependency to 3.5.0 to benefit from version check fix * Renaming of some principled BSDF slots * Also some principled BSDF slots changed from float to color types
1 parent 7289f14 commit 635aa6a

File tree

5 files changed

+74
-18
lines changed

5 files changed

+74
-18
lines changed

.github/workflows/test.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ jobs:
2525
environment:
2626
- {
2727
os: "ubuntu-latest",
28-
mitsuba-version: "3.4.1"
28+
mitsuba-version: "3.5.0"
2929
}
3030
- {
3131
os: "windows-latest",
32-
mitsuba-version: "3.4.1"
32+
mitsuba-version: "3.5.0"
3333
}
3434
blender:
3535
- {
@@ -38,6 +38,9 @@ jobs:
3838
- {
3939
version: "3.6"
4040
}
41+
- {
42+
version: "4.0"
43+
}
4144

4245
steps:
4346
- name: Git checkout

mitsuba-blender/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
from . import io, engine
2424

25-
DEPS_MITSUBA_VERSION = '3.4.1'
25+
DEPS_MITSUBA_VERSION = '3.5.0'
2626

2727
def get_addon_preferences(context):
2828
return context.preferences.addons[__name__].preferences

mitsuba-blender/io/exporter/geometry.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ def convert_mesh(export_ctx, b_mesh, matrix_world, name, mat_nr):
2626
'type': 'blender',
2727
'version': ".".join(map(str,bpy.app.version))
2828
}
29-
b_mesh.calc_normals()
29+
30+
if bpy.app.version < (4, 0, 0):
31+
b_mesh.calc_normals()
3032
# Compute the triangle tesselation
3133
b_mesh.calc_loop_triangles()
3234

mitsuba-blender/io/exporter/materials.py

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import bpy
12
import numpy as np
23
from mathutils import Matrix
34
from .export_context import Files
@@ -260,18 +261,38 @@ def convert_mix_materials_cycles(export_ctx, current_node):#TODO: test and fix t
260261

261262
def convert_principled_materials_cycles(export_ctx, current_node):
262263
params = {}
264+
265+
if bpy.app.version >= (4, 0, 0):
266+
specular_key = 'Specular IOR Level'
267+
transmission_key = 'Transmission Weight'
268+
sheen_key = 'Sheen Weight'
269+
clearcoat_key = 'Coat Weight'
270+
clearcoat_roughness_key = 'Coat Roughness'
271+
else:
272+
specular_key = 'Specular'
273+
transmission_key = 'Transmission'
274+
sheen_key = 'Sheen'
275+
clearcoat_key = 'Clearcoat'
276+
clearcoat_roughness_key = 'Clearcoat Roughness'
277+
263278
base_color = convert_color_texture_node(export_ctx, current_node.inputs['Base Color'])
264-
specular = current_node.inputs['Specular'].default_value
265-
specular_tint = convert_float_texture_node(export_ctx, current_node.inputs['Specular Tint'])
266-
specular_trans = convert_float_texture_node(export_ctx, current_node.inputs['Transmission'])
279+
specular = current_node.inputs[specular_key].default_value
280+
if bpy.app.version >= (4, 0, 0):
281+
specular_tint = convert_color_texture_node(export_ctx, current_node.inputs['Specular Tint'])
282+
else:
283+
specular_tint = convert_float_texture_node(export_ctx, current_node.inputs['Specular Tint'])
284+
specular_trans = convert_float_texture_node(export_ctx, current_node.inputs[transmission_key])
267285
ior = current_node.inputs['IOR'].default_value
268286
roughness = convert_float_texture_node(export_ctx, current_node.inputs['Roughness'])
269287
metallic = convert_float_texture_node(export_ctx, current_node.inputs['Metallic'])
270288
anisotropic = convert_float_texture_node(export_ctx, current_node.inputs['Anisotropic'])
271-
sheen = convert_float_texture_node(export_ctx, current_node.inputs['Sheen'])
272-
sheen_tint = convert_float_texture_node(export_ctx, current_node.inputs['Sheen Tint'])
273-
clearcoat = convert_float_texture_node(export_ctx, current_node.inputs['Clearcoat'])
274-
clearcoat_roughness = convert_float_texture_node(export_ctx, current_node.inputs['Clearcoat Roughness'])
289+
sheen = convert_float_texture_node(export_ctx, current_node.inputs[sheen_key])
290+
if bpy.app.version >= (4, 0, 0):
291+
sheen_tint = convert_color_texture_node(export_ctx, current_node.inputs['Sheen Tint'])
292+
else:
293+
sheen_tint = convert_float_texture_node(export_ctx, current_node.inputs['Sheen Tint'])
294+
clearcoat = convert_float_texture_node(export_ctx, current_node.inputs[clearcoat_key])
295+
clearcoat_roughness = convert_float_texture_node(export_ctx, current_node.inputs[clearcoat_roughness_key])
275296

276297
params.update({
277298
'type': 'principled',

mitsuba-blender/io/importer/materials.py

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,13 @@ def write_mi_rgb_property(mi_context, mi_mat, mi_prop_name, bl_mat_wrap, out_soc
247247
mi_prop_type = mi_mat.type(mi_prop_name)
248248
if mi_prop_type == Properties.Type.Color:
249249
write_mi_rgb_value(mi_context, list(mi_mat.get(mi_prop_name, default)), bl_mat_wrap, out_socket_id)
250+
if mi_prop_type == Properties.Type.Float:
251+
if mi_prop_name in mi_mat:
252+
col_val = mi_mat.get(mi_prop_name)
253+
col = [col_val, col_val, col_val]
254+
else:
255+
col = default
256+
write_mi_rgb_value(mi_context, list(col), bl_mat_wrap, out_socket_id)
250257
elif mi_prop_type == Properties.Type.NamedReference:
251258
mi_texture_ref_id = mi_mat.get(mi_prop_name)
252259
mi_texture = mi_context.mi_scene_props.get_with_id_and_class(mi_texture_ref_id, 'Texture')
@@ -331,19 +338,42 @@ def write_mi_emitter_bsdf(mi_context, bl_mat_wrap, out_socket_id, mi_emitter):
331338
######################
332339

333340
def write_mi_principled_bsdf(mi_context, mi_mat, bl_mat_wrap, out_socket_id, mi_bump=None, mi_normal=None):
341+
if bpy.app.version >= (4, 0, 0):
342+
specular_key = 'Specular IOR Level'
343+
transmission_key = 'Transmission Weight'
344+
sheen_key = 'Sheen Weight'
345+
clearcoat_key = 'Coat Weight'
346+
clearcoat_roughness_key = 'Coat Roughness'
347+
else:
348+
specular_key = 'Specular'
349+
transmission_key = 'Transmission'
350+
sheen_key = 'Sheen'
351+
clearcoat_key = 'Clearcoat'
352+
clearcoat_roughness_key = 'Clearcoat Roughness'
353+
354+
334355
bl_principled = bl_mat_wrap.ensure_node_type([out_socket_id], 'ShaderNodeBsdfPrincipled', 'BSDF')
335356
bl_principled_wrap = bl_shader_utils.NodeMaterialWrapper(bl_mat_wrap.bl_mat, out_node=bl_principled)
336357
write_mi_rgb_property(mi_context, mi_mat, 'base_color', bl_principled_wrap, 'Base Color', [0.8, 0.8, 0.8])
337-
write_mi_float_property(mi_context, mi_mat, 'specular', bl_principled_wrap, 'Specular', 0.5)
338-
write_mi_float_property(mi_context, mi_mat, 'spec_tint', bl_principled_wrap, 'Specular Tint', 0.0)
339-
write_mi_float_property(mi_context, mi_mat, 'spec_trans', bl_principled_wrap, 'Transmission', 0.0)
358+
write_mi_float_property(mi_context, mi_mat, 'specular', bl_principled_wrap, specular_key, 0.5)
359+
if bpy.app.version >= (4, 0, 0):
360+
write_mi_rgb_property(mi_context, mi_mat, 'spec_tint', bl_principled_wrap, 'Specular Tint', [0.0, 0.0, 0.0])
361+
else:
362+
write_mi_float_property(mi_context, mi_mat, 'spec_tint', bl_principled_wrap, 'Specular Tint', 0.0)
363+
364+
write_mi_float_property(mi_context, mi_mat, 'spec_trans', bl_principled_wrap, transmission_key, 0.0)
340365
write_mi_float_property(mi_context, mi_mat, 'metallic', bl_principled_wrap, 'Metallic', 0.0)
341366
write_mi_float_property(mi_context, mi_mat, 'anisotropic', bl_principled_wrap, 'Anisotropic', 0.0)
342367
write_mi_roughness_property(mi_context, mi_mat, 'roughness', bl_principled_wrap, 'Roughness', 0.4)
343-
write_mi_float_property(mi_context, mi_mat, 'sheen', bl_principled_wrap, 'Sheen', 0.0)
344-
write_mi_float_property(mi_context, mi_mat, 'sheen_tint', bl_principled_wrap, 'Sheen Tint', 0.5)
345-
write_mi_float_property(mi_context, mi_mat, 'clearcoat', bl_principled_wrap, 'Clearcoat', 0.0)
346-
write_mi_roughness_property(mi_context, mi_mat, 'clearcoat_gloss', bl_principled_wrap, 'Clearcoat Roughness', 0.03)
368+
write_mi_float_property(mi_context, mi_mat, 'sheen', bl_principled_wrap, sheen_key, 0.0)
369+
370+
if bpy.app.version >= (4, 0, 0):
371+
write_mi_rgb_property(mi_context, mi_mat, 'sheen_tint', bl_principled_wrap, 'Sheen Tint', [0.5, 0.5, 0.5])
372+
else:
373+
write_mi_float_property(mi_context, mi_mat, 'sheen_tint', bl_principled_wrap, 'Sheen Tint', 0.5)
374+
375+
write_mi_float_property(mi_context, mi_mat, 'clearcoat', bl_principled_wrap, clearcoat_key, 0.0)
376+
write_mi_roughness_property(mi_context, mi_mat, 'clearcoat_gloss', bl_principled_wrap, clearcoat_roughness_key, 0.03)
347377
# Write normal and bump maps
348378
write_mi_bump_and_normal_maps(mi_context, bl_principled_wrap, 'Normal', mi_bump=mi_bump, mi_normal=mi_normal)
349379
return True

0 commit comments

Comments
 (0)