mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-22 02:10:59 +00:00
Support IfcIndexedPolyCurve for more robust 2D representations
This commit is contained in:
@@ -2433,21 +2433,9 @@ class IfcExporter():
|
|||||||
return self.create_curves_from_curve(curve, is_2d=is_2d)
|
return self.create_curves_from_curve(curve, is_2d=is_2d)
|
||||||
|
|
||||||
def create_curves_from_mesh(self, mesh, is_2d=False):
|
def create_curves_from_mesh(self, mesh, is_2d=False):
|
||||||
self.create_vertices(mesh.vertices, is_2d=is_2d)
|
return [self.file.createIfcIndexedPolyCurve(
|
||||||
edges = list(mesh.edges)
|
self.create_cartesian_point_list_from_vertices(mesh.vertices, is_2d=is_2d),
|
||||||
loop_vertices = []
|
[self.file.createIfcLineIndex(tuple(e.vertices)) for e in mesh.edges])]
|
||||||
loops = []
|
|
||||||
# Not a fast algorithm, but easy
|
|
||||||
while edges:
|
|
||||||
for i, edge in enumerate(edges):
|
|
||||||
if edge.vertices[0] in loop_vertices \
|
|
||||||
and edge.vertices[1] in loop_vertices:
|
|
||||||
del edges[i]
|
|
||||||
loop_vertex_indices = self.get_loop_from_edges(edges)
|
|
||||||
loop_vertices.extend(loop_vertex_indices)
|
|
||||||
loops.append(self.file.createIfcPolyline([
|
|
||||||
self.ifc_vertices[i] for i in loop_vertex_indices]))
|
|
||||||
return loops
|
|
||||||
|
|
||||||
def create_curves_from_curve(self, curve, is_2d=False):
|
def create_curves_from_curve(self, curve, is_2d=False):
|
||||||
results = []
|
results = []
|
||||||
@@ -2690,6 +2678,11 @@ class IfcExporter():
|
|||||||
representation['target_view']]['ifc'],
|
representation['target_view']]['ifc'],
|
||||||
representation['subcontext'], 'Brep', items)
|
representation['subcontext'], 'Brep', items)
|
||||||
|
|
||||||
|
def create_cartesian_point_list_from_vertices(self, vertices, is_2d=False):
|
||||||
|
if is_2d:
|
||||||
|
return self.file.createIfcCartesianPointList2D([self.convert_si_to_unit(v.co.xy) for v in vertices])
|
||||||
|
return self.file.createIfcCartesianPointList3D([self.convert_si_to_unit(v.co) for v in vertices])
|
||||||
|
|
||||||
def create_vertices(self, vertices, is_2d=False):
|
def create_vertices(self, vertices, is_2d=False):
|
||||||
if is_2d:
|
if is_2d:
|
||||||
for v in vertices:
|
for v in vertices:
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ def add_object(self, context):
|
|||||||
]
|
]
|
||||||
edges = [[0, 1], [1, 2], [2, 3]]
|
edges = [[0, 1], [1, 2], [2, 3]]
|
||||||
faces = []
|
faces = []
|
||||||
mesh = bpy.data.meshes.new(name="IfcDoor/Dumb Door")
|
mesh = bpy.data.meshes.new(name="Dumb Door")
|
||||||
mesh.from_pydata(verts, edges, faces)
|
mesh.from_pydata(verts, edges, faces)
|
||||||
obj2 = object_data_add(context, mesh, operator=self)
|
obj2 = object_data_add(context, mesh, operator=self)
|
||||||
bpy.ops.object.convert(target='CURVE')
|
bpy.ops.object.convert(target='CURVE')
|
||||||
@@ -85,11 +85,13 @@ def add_object(self, context):
|
|||||||
obj4.display_type = 'WIRE'
|
obj4.display_type = 'WIRE'
|
||||||
obj4.parent = obj2
|
obj4.parent = obj2
|
||||||
obj4.matrix_parent_inverse = obj2.matrix_world.inverted()
|
obj4.matrix_parent_inverse = obj2.matrix_world.inverted()
|
||||||
|
obj4.hide_render = True
|
||||||
obj4.name = 'IfcOpeningElement/Dumb Door Opening'
|
obj4.name = 'IfcOpeningElement/Dumb Door Opening'
|
||||||
attribute = obj4.BIMObjectProperties.attributes.add()
|
attribute = obj4.BIMObjectProperties.attributes.add()
|
||||||
attribute.name = 'PredefinedType'
|
attribute.name = 'PredefinedType'
|
||||||
attribute.string_value = 'OPENING'
|
attribute.string_value = 'OPENING'
|
||||||
|
|
||||||
|
obj2.name = 'IfcDoor/Dumb Door'
|
||||||
attribute = obj2.BIMObjectProperties.attributes.add()
|
attribute = obj2.BIMObjectProperties.attributes.add()
|
||||||
attribute.name = 'PredefinedType'
|
attribute.name = 'PredefinedType'
|
||||||
attribute.string_value = 'DOOR'
|
attribute.string_value = 'DOOR'
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ def add_object(self, context):
|
|||||||
]
|
]
|
||||||
edges = [[0, 1], [1, 2], [2, 3]]
|
edges = [[0, 1], [1, 2], [2, 3]]
|
||||||
faces = []
|
faces = []
|
||||||
mesh = bpy.data.meshes.new(name="IfcWindow/Dumb Window")
|
mesh = bpy.data.meshes.new(name="Dumb Window")
|
||||||
mesh.from_pydata(verts, edges, faces)
|
mesh.from_pydata(verts, edges, faces)
|
||||||
obj2 = object_data_add(context, mesh, operator=self)
|
obj2 = object_data_add(context, mesh, operator=self)
|
||||||
bpy.ops.object.convert(target='CURVE')
|
bpy.ops.object.convert(target='CURVE')
|
||||||
@@ -84,11 +84,13 @@ def add_object(self, context):
|
|||||||
obj4.display_type = 'WIRE'
|
obj4.display_type = 'WIRE'
|
||||||
obj4.parent = obj2
|
obj4.parent = obj2
|
||||||
obj4.matrix_parent_inverse = obj2.matrix_world.inverted()
|
obj4.matrix_parent_inverse = obj2.matrix_world.inverted()
|
||||||
|
obj4.hide_render = True
|
||||||
obj4.name = 'IfcOpeningElement/Dumb Window Opening'
|
obj4.name = 'IfcOpeningElement/Dumb Window Opening'
|
||||||
attribute = obj4.BIMObjectProperties.attributes.add()
|
attribute = obj4.BIMObjectProperties.attributes.add()
|
||||||
attribute.name = 'PredefinedType'
|
attribute.name = 'PredefinedType'
|
||||||
attribute.string_value = 'OPENING'
|
attribute.string_value = 'OPENING'
|
||||||
|
|
||||||
|
obj2.name = 'IfcWindow/Dumb Window'
|
||||||
attribute = obj2.BIMObjectProperties.attributes.add()
|
attribute = obj2.BIMObjectProperties.attributes.add()
|
||||||
attribute.name = 'PredefinedType'
|
attribute.name = 'PredefinedType'
|
||||||
attribute.string_value = 'WINDOW'
|
attribute.string_value = 'WINDOW'
|
||||||
|
|||||||
@@ -2123,6 +2123,8 @@ class CutSection(bpy.types.Operator):
|
|||||||
elif obj.type == 'FONT':
|
elif obj.type == 'FONT':
|
||||||
ifc_cutter.text_objs.append(obj)
|
ifc_cutter.text_objs.append(obj)
|
||||||
|
|
||||||
|
# TODO: this should be detected from the IFC, not from Blender, and
|
||||||
|
# should use a bbox calculation to determine whether it is shown
|
||||||
for obj in bpy.context.visible_objects:
|
for obj in bpy.context.visible_objects:
|
||||||
for subcontext in obj.BIMObjectProperties.representation_contexts:
|
for subcontext in obj.BIMObjectProperties.representation_contexts:
|
||||||
if subcontext.context == 'Plan' \
|
if subcontext.context == 'Plan' \
|
||||||
|
|||||||
Reference in New Issue
Block a user