mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-29 00:03:17 +00:00
UV coordinates for triangulated face sets are now saved in IFC.
This commit is contained in:
@@ -188,8 +188,9 @@ class UpdateRepresentation(bpy.types.Operator):
|
||||
"geometry": obj.data,
|
||||
"coordinate_offset": coordinate_offset,
|
||||
"total_items": max(1, len(obj.material_slots)),
|
||||
"should_force_faceted_brep": context.scene.BIMGeometryProperties.should_force_faceted_brep,
|
||||
"should_force_triangulation": context.scene.BIMGeometryProperties.should_force_triangulation,
|
||||
"should_force_faceted_brep": tool.Geometry.should_force_faceted_brep(),
|
||||
"should_force_triangulation": tool.Geometry.should_force_triangulation(),
|
||||
"should_generate_uvs": tool.Geometry.should_generate_uvs(obj),
|
||||
"ifc_representation_class": self.ifc_representation_class,
|
||||
}
|
||||
|
||||
|
||||
@@ -50,6 +50,7 @@ def add_representation(
|
||||
total_items=geometry.get_total_representation_items(obj),
|
||||
should_force_faceted_brep=geometry.should_force_faceted_brep(),
|
||||
should_force_triangulation=geometry.should_force_triangulation(),
|
||||
should_generate_uvs=geometry.should_generate_uvs(obj),
|
||||
ifc_representation_class=ifc_representation_class,
|
||||
profile_set_usage=profile_set_usage,
|
||||
)
|
||||
|
||||
@@ -217,6 +217,7 @@ class Geometry:
|
||||
def run_style_add_style(cls, obj=None): pass
|
||||
def should_force_faceted_brep(cls): pass
|
||||
def should_force_triangulation(cls): pass
|
||||
def should_generate_uvs(cls, obj): pass
|
||||
def should_use_presentation_style_assignment(cls): pass
|
||||
|
||||
|
||||
|
||||
@@ -298,6 +298,15 @@ class Geometry(blenderbim.core.tool.Geometry):
|
||||
def should_force_triangulation(cls):
|
||||
return bpy.context.scene.BIMGeometryProperties.should_force_triangulation
|
||||
|
||||
@classmethod
|
||||
def should_generate_uvs(cls, obj):
|
||||
for slot in obj.material_slots:
|
||||
if slot.material and slot.material.use_nodes:
|
||||
for node in slot.material.node_tree.nodes:
|
||||
if node.type == "TEX_COORD" and node.outputs['UV'].links:
|
||||
return True
|
||||
return False
|
||||
|
||||
@classmethod
|
||||
def should_use_presentation_style_assignment(cls):
|
||||
return bpy.context.scene.BIMGeometryProperties.should_use_presentation_style_assignment
|
||||
|
||||
@@ -45,6 +45,7 @@ class TestAddRepresentation:
|
||||
geometry.get_total_representation_items("obj").should_be_called().will_return(1)
|
||||
geometry.should_force_faceted_brep().should_be_called().will_return(False)
|
||||
geometry.should_force_triangulation().should_be_called().will_return(True)
|
||||
geometry.should_generate_uvs("obj").should_be_called().will_return(True)
|
||||
ifc.run(
|
||||
"geometry.add_representation",
|
||||
context="context",
|
||||
@@ -54,6 +55,7 @@ class TestAddRepresentation:
|
||||
total_items=1,
|
||||
should_force_faceted_brep=False,
|
||||
should_force_triangulation=True,
|
||||
should_generate_uvs=True,
|
||||
ifc_representation_class="ifc_representation_class",
|
||||
profile_set_usage="profile_set_usage",
|
||||
).should_be_called().will_return("representation")
|
||||
@@ -109,6 +111,7 @@ class TestAddRepresentation:
|
||||
geometry.get_total_representation_items("obj").should_be_called().will_return(1)
|
||||
geometry.should_force_faceted_brep().should_be_called().will_return(False)
|
||||
geometry.should_force_triangulation().should_be_called().will_return(True)
|
||||
geometry.should_generate_uvs("obj").should_be_called().will_return(True)
|
||||
ifc.run(
|
||||
"geometry.add_representation",
|
||||
context="context",
|
||||
@@ -118,6 +121,7 @@ class TestAddRepresentation:
|
||||
total_items=1,
|
||||
should_force_faceted_brep=False,
|
||||
should_force_triangulation=True,
|
||||
should_generate_uvs=True,
|
||||
ifc_representation_class="ifc_representation_class",
|
||||
profile_set_usage="profile_set_usage",
|
||||
).should_be_called().will_return("representation")
|
||||
|
||||
@@ -462,6 +462,33 @@ class TestShouldForceTriangulation(NewFile):
|
||||
assert subject.should_force_triangulation() is result
|
||||
|
||||
|
||||
class TestShouldGenerateUVs(NewFile):
|
||||
def test_needs_mesh_data(self):
|
||||
obj = bpy.data.objects.new("Object", None)
|
||||
assert subject.should_generate_uvs(obj) is False
|
||||
|
||||
def test_needs_nodes(self):
|
||||
obj = bpy.data.objects.new("Object", bpy.data.meshes.new("Mesh"))
|
||||
material = bpy.data.materials.new("Material")
|
||||
obj.data.materials.append(material)
|
||||
material.use_nodes = False
|
||||
assert subject.should_generate_uvs(obj) is False
|
||||
|
||||
def test_needs_texture_coordinates_with_a_uv_output(self):
|
||||
obj = bpy.data.objects.new("Object", bpy.data.meshes.new("Mesh"))
|
||||
material = bpy.data.materials.new("Material")
|
||||
obj.data.materials.append(material)
|
||||
material.use_nodes = True
|
||||
|
||||
bsdf = material.node_tree.nodes["Principled BSDF"]
|
||||
node = material.node_tree.nodes.new(type="ShaderNodeTexImage")
|
||||
material.node_tree.links.new(bsdf.inputs["Base Color"], node.outputs["Color"])
|
||||
|
||||
coords = material.node_tree.nodes.new(type="ShaderNodeTexCoord")
|
||||
material.node_tree.links.new(node.inputs["Vector"], coords.outputs["UV"])
|
||||
assert subject.should_generate_uvs(obj) is True
|
||||
|
||||
|
||||
class TestShouldUsePresentationStyleAssignment(NewFile):
|
||||
def test_run(self):
|
||||
result = bpy.context.scene.BIMGeometryProperties.should_use_presentation_style_assignment
|
||||
|
||||
Reference in New Issue
Block a user