mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-09 17:31:45 +00:00
Fixing tests after 2dc9dc200
This commit is contained in:
@@ -58,9 +58,8 @@ def update_style_colours(ifc, style, obj=None, verbose=False):
|
||||
element = style.get_style(obj)
|
||||
|
||||
if style.can_support_rendering_style(obj):
|
||||
style_elements = style.get_style_elements(obj)
|
||||
rendering_style = style_elements.get("IfcSurfaceStyleRendering", None)
|
||||
texture_style = style_elements.get("IfcSurfaceStyleWithTextures", None)
|
||||
rendering_style = style.get_surface_rendering_style(obj)
|
||||
texture_style = style.get_texture_style(obj)
|
||||
attributes = style.get_surface_rendering_attributes(obj, verbose)
|
||||
if rendering_style:
|
||||
ifc.run("style.edit_surface_style", style=rendering_style, attributes=attributes)
|
||||
@@ -122,7 +121,7 @@ def enable_editing_style(style, obj=None):
|
||||
|
||||
|
||||
def enable_editing_external_style(style, obj=None):
|
||||
external_style = style.get_style_elements(obj)["IfcExternallyDefinedSurfaceStyle"]
|
||||
external_style = style.get_external_style(obj)
|
||||
style.enable_editing_external_style(obj)
|
||||
style.import_external_style_attributes(external_style, obj)
|
||||
|
||||
|
||||
@@ -815,8 +815,11 @@ class Style:
|
||||
def get_elements_by_style(cls, style): pass
|
||||
def get_name(cls, obj): pass
|
||||
def get_style(cls, obj): pass
|
||||
def get_surface_rendering_attributes(cls, obj): pass
|
||||
def get_style_elements(cls, blender_material): pass
|
||||
def get_surface_rendering_attributes(cls, obj, verbose=True): pass
|
||||
def get_surface_rendering_style(cls, obj): pass
|
||||
def get_texture_style(cls, obj): pass
|
||||
def get_external_style(cls, obj): pass
|
||||
def get_surface_shading_attributes(cls, obj): pass
|
||||
def get_surface_shading_style(cls, obj): pass
|
||||
def get_surface_texture_style(cls, obj): pass
|
||||
|
||||
@@ -88,22 +88,22 @@ class Loader(blenderbim.core.tool.Loader):
|
||||
if surface_style["SurfaceColour"]:
|
||||
surface_style["SurfaceColour"] = color_to_tuple(surface_style["SurfaceColour"])
|
||||
|
||||
if surface_style["DiffuseColour"] and surface_style["DiffuseColour"].is_a("IfcColourRgb"):
|
||||
if surface_style.get("DiffuseColour", None) and surface_style["DiffuseColour"].is_a("IfcColourRgb"):
|
||||
surface_style["DiffuseColour"] = ("IfcColourRgb", color_to_tuple(surface_style["DiffuseColour"]))
|
||||
|
||||
elif surface_style["DiffuseColour"] and surface_style["DiffuseColour"].is_a("IfcNormalisedRatioMeasure"):
|
||||
elif surface_style.get("DiffuseColour", None) and surface_style["DiffuseColour"].is_a("IfcNormalisedRatioMeasure"):
|
||||
diffuse_color_value = surface_style["DiffuseColour"].wrappedValue
|
||||
diffuse_color = [v * diffuse_color_value for v in surface_style["SurfaceColor"][:3]] + [1]
|
||||
surface_style["DiffuseColour"] = ("IfcNormalisedRatioMeasure", diffuse_color)
|
||||
else:
|
||||
surface_style["DiffuseColour"] = None
|
||||
|
||||
if surface_style["SpecularColour"] and surface_style["SpecularColour"].is_a("IfcNormalisedRatioMeasure"):
|
||||
if surface_style.get("SpecularColour", None) and surface_style["SpecularColour"].is_a("IfcNormalisedRatioMeasure"):
|
||||
surface_style["SpecularColour"] = surface_style["SpecularColour"].wrappedValue
|
||||
else:
|
||||
surface_style["SpecularColour"] = None
|
||||
|
||||
if surface_style["SpecularHighlight"] and surface_style["SpecularHighlight"].is_a("IfcSpecularRoughness"):
|
||||
if surface_style.get("SpecularHighlight", None) and surface_style["SpecularHighlight"].is_a("IfcSpecularRoughness"):
|
||||
surface_style["SpecularHighlight"] = surface_style["SpecularHighlight"].wrappedValue
|
||||
else:
|
||||
surface_style["SpecularHighlight"] = None
|
||||
|
||||
@@ -163,9 +163,13 @@ class Style(blenderbim.core.tool.Style):
|
||||
props["update_graph"] = False
|
||||
|
||||
style_elements = tool.Style.get_style_elements(blender_material)
|
||||
surface_style = style_elements["IfcSurfaceStyleRendering"]
|
||||
surface_style = style_elements.get("IfcSurfaceStyleRendering", None)
|
||||
texture_style = style_elements.get("IfcSurfaceStyleWithTextures", None)
|
||||
|
||||
# in case we have just IfcSurfaceStyleShading
|
||||
if not surface_style:
|
||||
return
|
||||
|
||||
style_data = tool.Loader.surface_style_to_dict(surface_style)
|
||||
if style_data["ReflectanceMethod"] == "NOTDEFINED":
|
||||
style_data["ReflectanceMethod"] = "PHYSICAL"
|
||||
@@ -361,6 +365,16 @@ class Style(blenderbim.core.tool.Style):
|
||||
style_elements = cls.get_style_elements(obj)
|
||||
return style_elements.get("IfcSurfaceStyleRendering", None)
|
||||
|
||||
@classmethod
|
||||
def get_texture_style(cls, obj):
|
||||
style_elements = cls.get_style_elements(obj)
|
||||
return style_elements.get("IfcSurfaceStyleWithTextures", None)
|
||||
|
||||
@classmethod
|
||||
def get_external_style(cls, obj):
|
||||
style_elements = cls.get_style_elements(obj)
|
||||
return style_elements.get("IfcExternallyDefinedSurfaceStyle", None)
|
||||
|
||||
@classmethod
|
||||
def get_surface_shading_attributes(cls, obj):
|
||||
data = {
|
||||
|
||||
@@ -85,22 +85,39 @@ class TestUpdateStyleColours:
|
||||
def test_updating_rendering_style_if_available(self, ifc, style):
|
||||
style.get_style("obj").should_be_called().will_return("element")
|
||||
style.can_support_rendering_style("obj").should_be_called().will_return(True)
|
||||
style.get_surface_rendering_style("obj").should_be_called().will_return("style")
|
||||
style.get_surface_rendering_attributes("obj").should_be_called().will_return("attributes")
|
||||
ifc.run("style.edit_surface_style", style="style", attributes="attributes").should_be_called()
|
||||
|
||||
style.get_surface_rendering_style("obj").should_be_called().will_return("rendering_style")
|
||||
style.get_texture_style("obj").should_be_called().will_return("texture_style")
|
||||
style.get_surface_rendering_attributes("obj", "verbose").should_be_called().will_return("attributes")
|
||||
ifc.run("style.edit_surface_style", style="rendering_style", attributes="attributes").should_be_called()
|
||||
|
||||
ifc.run("style.add_surface_textures", material="obj").should_be_called().will_return("textures")
|
||||
ifc.run("style.edit_surface_style", style="texture_style", attributes={"Textures": "textures"}).should_be_called().will_return("textures")
|
||||
|
||||
style.record_shading("obj").should_be_called()
|
||||
subject.update_style_colours(ifc, style, obj="obj")
|
||||
subject.update_style_colours(ifc, style, obj="obj", verbose="verbose")
|
||||
|
||||
def test_adding_a_rendering_style_if_not_available(self, ifc, style):
|
||||
style.get_style("obj").should_be_called().will_return("element")
|
||||
style.can_support_rendering_style("obj").should_be_called().will_return(True)
|
||||
|
||||
style.get_surface_rendering_style("obj").should_be_called().will_return(None)
|
||||
style.get_surface_rendering_attributes("obj").should_be_called().will_return("attributes")
|
||||
style.get_texture_style("obj").should_be_called().will_return(None)
|
||||
style.get_surface_rendering_attributes("obj", "verbose").should_be_called().will_return("attributes")
|
||||
ifc.run(
|
||||
"style.add_surface_style", style="element", ifc_class="IfcSurfaceStyleRendering", attributes="attributes"
|
||||
).should_be_called()
|
||||
|
||||
ifc.run("style.add_surface_textures", material="obj").should_be_called().will_return("textures")
|
||||
ifc.run(
|
||||
"style.add_surface_style",
|
||||
style="element",
|
||||
ifc_class="IfcSurfaceStyleWithTextures",
|
||||
attributes={"Textures": "textures"},
|
||||
).should_be_called()
|
||||
|
||||
style.record_shading("obj").should_be_called()
|
||||
subject.update_style_colours(ifc, style, obj="obj")
|
||||
subject.update_style_colours(ifc, style, obj="obj", verbose="verbose")
|
||||
|
||||
def test_updating_shading_style_as_a_fallback_if_available(self, ifc, style):
|
||||
style.get_style("obj").should_be_called().will_return("element")
|
||||
|
||||
@@ -163,11 +163,15 @@ class TestGetSurfaceRenderingAttributes(NewFile):
|
||||
obj = bpy.data.materials.new("Material")
|
||||
obj.diffuse_color = [1, 1, 1, 1]
|
||||
obj.use_nodes = True
|
||||
output = tool.Blender.get_material_node(obj, "OUTPUT_MATERIAL")
|
||||
node = tool.Blender.get_material_node(obj, "BSDF_PRINCIPLED")
|
||||
obj.node_tree.nodes.remove(node)
|
||||
|
||||
node = obj.node_tree.nodes.new(type="ShaderNodeBsdfGlossy")
|
||||
node.inputs["Color"].default_value = [0.5, 0.5, 0.5, 0.5]
|
||||
node.inputs["Roughness"].default_value = 0.2
|
||||
obj.node_tree.links.new(node.outputs[0], output.inputs[0])
|
||||
|
||||
assert subject.get_surface_rendering_attributes(obj) == {
|
||||
"SurfaceColour": {
|
||||
"Name": None,
|
||||
@@ -190,11 +194,15 @@ class TestGetSurfaceRenderingAttributes(NewFile):
|
||||
obj = bpy.data.materials.new("Material")
|
||||
obj.diffuse_color = [1, 1, 1, 1]
|
||||
obj.use_nodes = True
|
||||
output = tool.Blender.get_material_node(obj, "OUTPUT_MATERIAL")
|
||||
node = tool.Blender.get_material_node(obj, "BSDF_PRINCIPLED")
|
||||
obj.node_tree.nodes.remove(node)
|
||||
|
||||
node = obj.node_tree.nodes.new(type="ShaderNodeBsdfDiffuse")
|
||||
node.inputs["Color"].default_value = [0.5, 0.5, 0.5, 0.5]
|
||||
node.inputs["Roughness"].default_value = 0.2
|
||||
obj.node_tree.links.new(node.outputs[0], output.inputs[0])
|
||||
|
||||
assert subject.get_surface_rendering_attributes(obj) == {
|
||||
"SurfaceColour": {
|
||||
"Name": None,
|
||||
@@ -217,11 +225,15 @@ class TestGetSurfaceRenderingAttributes(NewFile):
|
||||
obj = bpy.data.materials.new("Material")
|
||||
obj.diffuse_color = [1, 1, 1, 1]
|
||||
obj.use_nodes = True
|
||||
output = tool.Blender.get_material_node(obj, "OUTPUT_MATERIAL")
|
||||
node = tool.Blender.get_material_node(obj, "BSDF_PRINCIPLED")
|
||||
obj.node_tree.nodes.remove(node)
|
||||
|
||||
node = obj.node_tree.nodes.new(type="ShaderNodeBsdfGlass")
|
||||
node.inputs["Color"].default_value = [0.5, 0.5, 0.5, 0.5]
|
||||
node.inputs["Roughness"].default_value = 0.2
|
||||
obj.node_tree.links.new(node.outputs[0], output.inputs[0])
|
||||
|
||||
assert subject.get_surface_rendering_attributes(obj) == {
|
||||
"SurfaceColour": {
|
||||
"Name": None,
|
||||
@@ -244,10 +256,14 @@ class TestGetSurfaceRenderingAttributes(NewFile):
|
||||
obj = bpy.data.materials.new("Material")
|
||||
obj.diffuse_color = [1, 1, 1, 1]
|
||||
obj.use_nodes = True
|
||||
output = tool.Blender.get_material_node(obj, "OUTPUT_MATERIAL")
|
||||
node = tool.Blender.get_material_node(obj, "BSDF_PRINCIPLED")
|
||||
obj.node_tree.nodes.remove(node)
|
||||
|
||||
node = obj.node_tree.nodes.new(type="ShaderNodeEmission")
|
||||
node.inputs["Color"].default_value = [0.5, 0.5, 0.5, 0.5]
|
||||
obj.node_tree.links.new(node.outputs[0], output.inputs[0])
|
||||
|
||||
assert subject.get_surface_rendering_attributes(obj) == {
|
||||
"SurfaceColour": {
|
||||
"Name": None,
|
||||
@@ -270,10 +286,14 @@ class TestGetSurfaceRenderingAttributes(NewFile):
|
||||
obj = bpy.data.materials.new("Material")
|
||||
obj.diffuse_color = [1, 1, 1, 1]
|
||||
obj.use_nodes = True
|
||||
output = tool.Blender.get_material_node(obj, "OUTPUT_MATERIAL")
|
||||
node = tool.Blender.get_material_node(obj, "BSDF_PRINCIPLED")
|
||||
obj.node_tree.nodes.remove(node)
|
||||
|
||||
node = obj.node_tree.nodes.new(type="ShaderNodeVolumePrincipled")
|
||||
node.inputs["Color"].default_value = [0.5, 0.5, 0.5, 0.5]
|
||||
obj.node_tree.links.new(node.outputs[0], output.inputs[0])
|
||||
|
||||
assert subject.get_surface_rendering_attributes(obj) == {
|
||||
"SurfaceColour": {
|
||||
"Name": None,
|
||||
|
||||
Reference in New Issue
Block a user