Fix bug in IFC2X3 where updating style colours didn't work.

This commit is contained in:
Dion Moult
2021-11-10 16:45:16 +11:00
parent 0dac56dbdf
commit a7b3b5261f
5 changed files with 24 additions and 3 deletions
+2 -1
View File
@@ -32,6 +32,7 @@ import blenderbim.core.aggregate
import blenderbim.core.spatial
import blenderbim.core.style
from blenderbim.bim.ifc import IfcStore
from mathutils import Vector
class IfcExporter:
@@ -133,7 +134,7 @@ class IfcExporter:
def sync_object_placement(self, obj):
blender_matrix = np.array(obj.matrix_world)
element = self.file.by_id(obj.BIMObjectProperties.ifc_definition_id)
if list(obj.scale) != [1.0, 1.0, 1.0]:
if (obj.scale - Vector((1., 1.,1.))).length > 1e-4:
bpy.ops.bim.update_representation(obj=obj.name)
return element
if element.is_a("IfcGridAxis"):
+1 -1
View File
@@ -45,7 +45,7 @@ class Geometry(blenderbim.core.tool.Geometry):
@classmethod
def clear_scale(cls, obj):
if obj.scale != Vector((1.0, 1.0, 1.0)):
if (obj.scale - Vector((1., 1.,1.))).length > 1e-4:
if obj.data.users == 1:
context_override = {}
context_override["object"] = context_override["active_object"] = obj
+4 -1
View File
@@ -83,7 +83,7 @@ class Style(blenderbim.core.tool.Style):
@classmethod
def get_surface_shading_attributes(cls, obj):
return {
data = {
"SurfaceColour": {
"Name": None,
"Red": obj.diffuse_color[0],
@@ -92,6 +92,9 @@ class Style(blenderbim.core.tool.Style):
},
"Transparency": 1 - obj.diffuse_color[3],
}
if tool.Ifc.get_schema() == "IFC2X3":
del data["Transparency"]
return data
@classmethod
def get_surface_shading_style(cls, obj):
+14
View File
@@ -131,6 +131,7 @@ class TestGetSurfaceRenderingStyle(NewFile):
class TestGetSurfaceShadingAttributes(NewFile):
def test_get_colours_from_a_basic_material(self):
tool.Ifc.set(ifcopenshell.file())
obj = bpy.data.materials.new("Material")
obj.diffuse_color = [1, 1, 1, 1]
assert subject.get_surface_shading_attributes(obj) == {
@@ -143,6 +144,19 @@ class TestGetSurfaceShadingAttributes(NewFile):
"Transparency": 0,
}
def test_get_colours_from_a_basic_material_ifc2x3(self):
tool.Ifc.set(ifcopenshell.file(schema="IFC2X3"))
obj = bpy.data.materials.new("Material")
obj.diffuse_color = [1, 1, 1, 1]
assert subject.get_surface_shading_attributes(obj) == {
"SurfaceColour": {
"Name": None,
"Red": 1,
"Green": 1,
"Blue": 1,
},
}
class TestGetSurfaceShadingStyle(NewFile):
def test_run(self):
@@ -1,12 +1,15 @@
import pytest
import ifcopenshell
import ifcopenshell.api
import ifcopenshell.api.owner.settings
class IFC4:
@pytest.fixture(autouse=True)
def setup(self):
self.file = ifcopenshell.api.run("project.create_file")
ifcopenshell.api.owner.settings.get_user = lambda ifc: (ifc.by_type("IfcPersonAndOrganization") or [None])[0]
ifcopenshell.api.owner.settings.get_application = lambda ifc: (ifc.by_type("IfcApplication") or [None])[0]
class IFC2X3: