From c8a3ca5221549e23dfe5c8cbbf3780483c6191c3 Mon Sep 17 00:00:00 2001 From: Rami Tabbara Date: Fri, 29 Sep 2023 15:18:16 +0200 Subject: [PATCH] Getting CI tests working again --- mitsuba-blender/engine/properties.py | 5 +++-- mitsuba-blender/io/exporter/export_context.py | 2 +- mitsuba-blender/io/exporter/materials.py | 22 +++++++++++++------ .../io/importer/mi_spectra_utils.py | 2 +- tests/fixtures/__init__.py | 6 +++-- 5 files changed, 24 insertions(+), 13 deletions(-) diff --git a/mitsuba-blender/engine/properties.py b/mitsuba-blender/engine/properties.py index 4eb6194..d956c66 100644 --- a/mitsuba-blender/engine/properties.py +++ b/mitsuba-blender/engine/properties.py @@ -235,7 +235,7 @@ def draw(self, layout): def to_dict(self): ''' - Function that converts the plugin into a dict that can be loaded or savec by mitsuba's API + Function that converts the plugin into a dict that can be loaded or saved by mitsuba's API ''' plugin_params = {'type' : name} if 'parameters' in self.args: @@ -249,7 +249,8 @@ def to_dict(self): list_type = param['values_type'] if list_type == 'integrator': for integrator in self.integrators.collection: - plugin_params[integrator.name] = getattr(integrator.available_integrators, integrator.active_integrator).to_dict() + # Make sure we don't have any leading underscores for names - Mitsuba will otherwise complain! + plugin_params[integrator.name.lstrip('_')] = getattr(integrator.available_integrators, integrator.active_integrator).to_dict() elif list_type == 'string': selected_items = [] for choice in param['choices']: diff --git a/mitsuba-blender/io/exporter/export_context.py b/mitsuba-blender/io/exporter/export_context.py index 6863750..602c21f 100644 --- a/mitsuba-blender/io/exporter/export_context.py +++ b/mitsuba-blender/io/exporter/export_context.py @@ -98,7 +98,7 @@ def data_add(self, mts_dict, name=''): del mts_dict['id'] except KeyError: - name = '__elm__%i' % self.counter + name = 'elm__%i' % self.counter self.scene_data.update([(name, mts_dict)]) self.counter += 1 diff --git a/mitsuba-blender/io/exporter/materials.py b/mitsuba-blender/io/exporter/materials.py index b3e5a15..11a5ca2 100644 --- a/mitsuba-blender/io/exporter/materials.py +++ b/mitsuba-blender/io/exporter/materials.py @@ -32,10 +32,7 @@ def convert_float_texture_node(export_ctx, socket): raise NotImplementedError( "Node type %s is not supported. Only texture nodes are supported for float inputs" % node.type) else: - if socket.name == 'Roughness':#roughness values in blender are remapped with a square root - params = pow(socket.default_value, 2) - else: - params = socket.default_value + params = socket.default_value return params @@ -103,6 +100,11 @@ def convert_glossy_materials_cycles(export_ctx, current_node): roughness = convert_float_texture_node(export_ctx, current_node.inputs['Roughness']) + # Re-mapping to space in Mitsuba + # TODO: Handle when roughness is texture + if type(roughness) is float: + roughness = pow(roughness, 2) + if roughness and current_node.distribution != 'SHARP': params.update({ 'type': 'roughconductor', @@ -134,6 +136,11 @@ def convert_glass_materials_cycles(export_ctx, current_node): roughness = convert_float_texture_node(export_ctx, current_node.inputs['Roughness']) + # Re-mapping to space in Mitsuba + # TODO: Handle when roughness is texture + if type(roughness) is float: + roughness = pow(roughness, 2) + if roughness and current_node.distribution != 'SHARP': params.update({ 'type': 'roughdielectric', @@ -272,11 +279,12 @@ def convert_principled_materials_cycles(export_ctx, current_node): clearcoat = convert_float_texture_node(export_ctx, current_node.inputs['Clearcoat']) clearcoat_roughness = convert_float_texture_node(export_ctx, current_node.inputs['Clearcoat Roughness']) - # Undo default roughness transform done by the exporter + # Re-mapping to space in Mitsuba + # TODO: Handle when roughness is texture if type(roughness) is float: - roughness = np.sqrt(roughness) + roughness = pow(roughness, 2) if type(clearcoat_roughness) is float: - clearcoat_roughness = np.sqrt(clearcoat_roughness) + clearcoat_roughness = pow(clearcoat_roughness, 2) params.update({ 'type': 'principled', diff --git a/mitsuba-blender/io/importer/mi_spectra_utils.py b/mitsuba-blender/io/importer/mi_spectra_utils.py index 615d2f3..6224913 100644 --- a/mitsuba-blender/io/importer/mi_spectra_utils.py +++ b/mitsuba-blender/io/importer/mi_spectra_utils.py @@ -30,7 +30,7 @@ def convert_mi_srgb_reflectance_spectrum(mi_obj, default): ####################### def convert_mi_srgb_emitter_spectrum(mi_obj, default): - assert mi_obj.class_().name() == 'SRGBEmitterSpectrum' + assert mi_obj.class_().name() == 'SRGBReflectanceSpectrum' obj_props = _get_mi_obj_properties(mi_obj) radiance = list(obj_props.get('value', default)) return get_color_strength_from_radiance(radiance) \ No newline at end of file diff --git a/tests/fixtures/__init__.py b/tests/fixtures/__init__.py index 0ebdeff..e1dc2a1 100644 --- a/tests/fixtures/__init__.py +++ b/tests/fixtures/__init__.py @@ -66,8 +66,10 @@ def _bitmap_extract(self, bmp, require_variance=True): b_root = b_root.convert(Bitmap.PixelFormat.XYZ, Struct.Type.Float32, False) return np.array(b_root, copy=True), None else: - img = np.array(split[1][1], copy=False) - img_m2 = np.array(split[2][1], copy=False) + # Check which split contains moments - it may not be the first one after root + m2_index = 1 if split[1][0].startswith('m2_') else 2 + img = np.array(split[m2_index][1], copy=False) + img_m2 = np.array(split[m2_index][1], copy=False) return img, img_m2 - img * img def render_scene(self, scene_file, **kwargs):