mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-10 14:07:43 +00:00
Support for loading face colors from ifc (IfcIndexedColourMap)
example - https://imgur.com/a/l8Yn4Rr
This commit is contained in:
@@ -391,12 +391,11 @@ class TestCreatingStyles(NewFile):
|
||||
), f"Failed to match pixels for {n_components}.\nBlender pixel_data: {image_node.image.pixels[:]}.\nExpected data: {expected_pixel_data}"
|
||||
|
||||
|
||||
class TestLoadingIndexedTextureMap(NewFile):
|
||||
def test_run(self):
|
||||
class TestLoadingIndexedMap(NewFile):
|
||||
def test_load_texture_map(self):
|
||||
bpy.context.scene.unit_settings.length_unit = "MILLIMETERS"
|
||||
bpy.ops.bim.create_project()
|
||||
|
||||
# TODO: replace with loading geometry from IFC
|
||||
# create a cube without uv and triangulate it
|
||||
mesh = bpy.data.meshes.new("Cube")
|
||||
bm = tool.Blender.get_bmesh_for_mesh(mesh, clean=True)
|
||||
@@ -408,31 +407,7 @@ class TestLoadingIndexedTextureMap(NewFile):
|
||||
builder = ShapeBuilder(ifc_file)
|
||||
|
||||
# tesselated cube
|
||||
points = (
|
||||
V(-1000, -1000, -1000),
|
||||
V(-1000, -1000, 1000),
|
||||
V(-1000, 1000, -1000),
|
||||
V(-1000, 1000, 1000),
|
||||
V(1000, -1000, -1000),
|
||||
V(1000, -1000, 1000),
|
||||
V(1000, 1000, -1000),
|
||||
V(1000, 1000, 1000),
|
||||
)
|
||||
faces = (
|
||||
(1, 2, 0),
|
||||
(3, 6, 2),
|
||||
(7, 4, 6),
|
||||
(5, 0, 4),
|
||||
(6, 0, 2),
|
||||
(3, 5, 7),
|
||||
(1, 3, 2),
|
||||
(3, 7, 6),
|
||||
(7, 5, 4),
|
||||
(5, 1, 0),
|
||||
(6, 4, 0),
|
||||
(3, 1, 5),
|
||||
)
|
||||
face_set = builder.polygonal_face_set(points, faces)
|
||||
face_set = builder.polygonal_face_set([v.co for v in mesh.vertices], [p.vertices[:] for p in mesh.polygons])
|
||||
|
||||
uv_indices = (
|
||||
(1, 2, 3),
|
||||
@@ -493,9 +468,45 @@ class TestLoadingIndexedTextureMap(NewFile):
|
||||
texture_coord.TexCoordIndex = uv_indices
|
||||
texture_coord.TexCoords = uv_verts_list
|
||||
|
||||
subject.load_indexed_texture_map(texture_coord, mesh)
|
||||
subject.load_indexed_map(texture_coord, mesh)
|
||||
|
||||
uv_layer = mesh.uv_layers.active
|
||||
assert uv_layer is not None
|
||||
for ifc_uv, blender_uv in zip(uv_verts, uv_layer.uv, strict=True):
|
||||
assert tool.Cad.are_vectors_equal(Vector(ifc_uv), blender_uv.vector)
|
||||
|
||||
def test_load_color_map(self):
|
||||
bpy.context.scene.unit_settings.length_unit = "MILLIMETERS"
|
||||
bpy.ops.bim.create_project()
|
||||
|
||||
# create a cube without uv and triangulate it
|
||||
mesh = bpy.data.meshes.new("Cube")
|
||||
bm = tool.Blender.get_bmesh_for_mesh(mesh, clean=True)
|
||||
bmesh.ops.create_cube(bm, size=2.0, calc_uvs=False)
|
||||
bmesh.ops.triangulate(bm, faces=bm.faces[:])
|
||||
tool.Blender.apply_bmesh(mesh, bm)
|
||||
|
||||
ifc_file = tool.Ifc.get()
|
||||
builder = ShapeBuilder(ifc_file)
|
||||
|
||||
# tesselated cube
|
||||
face_set = builder.polygonal_face_set([v.co for v in mesh.vertices], [p.vertices[:] for p in mesh.polygons])
|
||||
|
||||
colors = ((1.0, 0.0, 0.0), (0.0, 0.5, 0.0), (1.0, 1.0, 0.0))
|
||||
color_index = (0, 0, 0, 0, 2, 1, 0, 0, 0, 0, 2, 1)
|
||||
|
||||
ifc_colors_list = ifc_file.create_entity("IfcColourRgbList", colors)
|
||||
colour_map = ifc_file.create_entity("IfcIndexedColourMap")
|
||||
colour_map.MappedTo = face_set
|
||||
colour_map.Colours = ifc_colors_list
|
||||
colour_map.ColourIndex = [i + 1 for i in color_index]
|
||||
|
||||
subject.load_indexed_map(colour_map, mesh)
|
||||
|
||||
layer = mesh.color_attributes.active_color
|
||||
assert layer is not None
|
||||
for face_i, face in enumerate(mesh.polygons):
|
||||
for loop_i in face.loop_indices:
|
||||
blender_color = Vector(layer.data[loop_i].color)
|
||||
ifc_color = Vector(colors[color_index[face_i]] + (1.0,))
|
||||
assert tool.Cad.are_vectors_equal(blender_color, ifc_color)
|
||||
|
||||
Reference in New Issue
Block a user