diff --git a/src/blenderbim/blenderbim/bim/module/drawing/operator.py b/src/blenderbim/blenderbim/bim/module/drawing/operator.py index 81e3985cbb..2a9552f456 100644 --- a/src/blenderbim/blenderbim/bim/module/drawing/operator.py +++ b/src/blenderbim/blenderbim/bim/module/drawing/operator.py @@ -2643,8 +2643,33 @@ class AddReferenceImage(bpy.types.Operator, Operator): style = ifc_file.by_id(material.BIMMaterialProperties.ifc_style_id) tool.Style.assign_style_to_object(style, obj) - tool.Geometry.record_object_materials(obj) - material.BIMStyleProperties.diffuse_path = image_filepath.as_posix() - material.BIMStyleProperties.uv_mode = "Generated" - bpy.ops.bim.update_style_colours() + # TODO: IfcSurfaceStyleRendering is unnecessary here, added it only because + # we don't support IfcSurfaceStyleWithTextures without Rendering yet + shading_attributes = { + "SurfaceColour": { + "Red": 1.0, + "Green": 1.0, + "Blue": 1.0, + }, + "Transparency": 0.0, + "ReflectanceMethod": "NOTDEFINED", + } + ifcopenshell.api.run( + "style.add_surface_style", + tool.Ifc.get(), + style=style, + ifc_class="IfcSurfaceStyleRendering", + attributes=shading_attributes, + ) + texture = ifc_file.create_entity("IfcImageTexture", Mode="DIFFUSE", URLReference=image_filepath.as_posix()) + textures = [texture] + ifc_file.create_entity("IfcTextureCoordinateGenerator", Maps=textures, Mode="COORD") # UV map + tool.Ifc.run( + "style.add_surface_style", + style=style, + ifc_class="IfcSurfaceStyleWithTextures", + attributes={"Textures": textures}, + ) + tool.Style.reload_material_from_ifc(material) + tool.Geometry.record_object_materials(obj) diff --git a/src/blenderbim/blenderbim/bim/module/style/operator.py b/src/blenderbim/blenderbim/bim/module/style/operator.py index 9b3acf720c..dc4c2f7019 100644 --- a/src/blenderbim/blenderbim/bim/module/style/operator.py +++ b/src/blenderbim/blenderbim/bim/module/style/operator.py @@ -124,9 +124,7 @@ class DisableEditingStyle(bpy.types.Operator, tool.Ifc.Operator): style = tool.Ifc.get().by_id(props.is_editing_style) material = tool.Ifc.get_object(style) - # just to trigger style update - material.BIMStyleProperties.active_style_type = material.BIMStyleProperties.active_style_type - + tool.Style.reload_material_from_ifc(material) props.is_editing_style = 0 @@ -652,7 +650,7 @@ class EditSurfaceStyle(bpy.types.Operator, tool.Ifc.Operator): # TODO: provide `uv_maps` - need to rework .get_uv_maps not to depend on a single representation material = tool.Ifc.get_object(self.style) shading_style = self.rendering_style or self.shading_style - # TODO: support creating texture styles without defining shading style first + # TODO: support creating texture styles without defining rendering style first if self.rendering_style is None: self.report( {"ERROR"}, diff --git a/src/blenderbim/blenderbim/tool/style.py b/src/blenderbim/blenderbim/tool/style.py index 082e768556..bbf8bb194b 100644 --- a/src/blenderbim/blenderbim/tool/style.py +++ b/src/blenderbim/blenderbim/tool/style.py @@ -538,3 +538,7 @@ class Style(blenderbim.core.tool.Style): """assigns `style` to `object` current representation""" representation = tool.Geometry.get_active_representation(obj) tool.Ifc.run("style.assign_representation_styles", shape_representation=representation, styles=[style]) + + @classmethod + def reload_material_from_ifc(cls, blender_material): + blender_material.BIMStyleProperties.active_style_type = blender_material.BIMStyleProperties.active_style_type diff --git a/src/blenderbim/test/tool/test_drawing.py b/src/blenderbim/test/tool/test_drawing.py index 0cce6e1ede..84e63b0d75 100644 --- a/src/blenderbim/test/tool/test_drawing.py +++ b/src/blenderbim/test/tool/test_drawing.py @@ -872,5 +872,10 @@ class TestAddReferenceImage(NewFile): representation_items = set(tool.Geometry.get_active_representation(obj).Items) assert styled_items == representation_items - assert Path(material.BIMStyleProperties.diffuse_path) == filepath - assert material.BIMStyleProperties.uv_mode == "Generated" + material_nodes = material.node_tree.nodes + texture_filepath = material_nodes["Image Texture"].image.filepath + texture_filepath = Path(tool.Blender.blender_path_to_posix(texture_filepath)) + assert texture_filepath == filepath + + uv_node = material_nodes["Texture Coordinate"] + assert len(uv_node.outputs["Generated"].links[:]) == 1