Support solid line annotations using curve data

This commit is contained in:
Dion Moult
2020-05-09 16:38:05 +10:00
parent e270cf6989
commit 561009c330
3 changed files with 32 additions and 39 deletions
+22 -26
View File
@@ -867,33 +867,13 @@ class SvgWriter():
'dominant-baseline': 'middle'
}))
if self.ifc_cutter.hidden_obj:
matrix_world = self.ifc_cutter.hidden_obj.matrix_world
for edge in self.ifc_cutter.hidden_obj.data.edges:
classes = ['annotation', 'hidden']
v0_global = matrix_world @ self.ifc_cutter.hidden_obj.data.vertices[edge.vertices[0]].co.xyz
v1_global = matrix_world @ self.ifc_cutter.hidden_obj.data.vertices[edge.vertices[1]].co.xyz
v0 = self.project_point_onto_camera(v0_global)
v1 = self.project_point_onto_camera(v1_global)
start = Vector(((x_offset + v0.x), (y_offset - v0.y)))
end = Vector(((x_offset + v1.x), (y_offset - v1.y)))
vector = end - start
line = self.svg.add(self.svg.line(start=tuple(start * self.scale),
end=tuple(end * self.scale), class_=' '.join(classes)))
line['stroke-dasharray'] = '3, 2'
for obj in self.ifc_cutter.hidden_objs:
self.draw_line_annotation(obj, ['hidden'])
if self.ifc_cutter.leader_obj:
matrix_world = self.ifc_cutter.leader_obj.matrix_world
for spline in self.ifc_cutter.leader_obj.data.splines:
classes = ['annotation', 'leader']
points = self.get_spline_points(spline)
projected_points = [self.project_point_onto_camera(matrix_world @ p.co.xyz) for p in points]
d = ' '.join(['L {} {}'.format(
(x_offset + p.x) * self.scale, (y_offset - p.y) * self.scale)
for p in projected_points])
d = 'M{}'.format(d[1:])
path = self.svg.add(self.svg.path(d=d, class_=' '.join(classes)))
path['marker-end'] = 'url(#leader-marker)'
for obj in self.ifc_cutter.solid_objs:
self.draw_line_annotation(obj, ['solid'])
self.draw_line_annotation(self.ifc_cutter.leader_obj, ['leader'])
if self.ifc_cutter.plan_level_obj:
for spline in self.ifc_cutter.plan_level_obj.data.splines:
@@ -971,6 +951,22 @@ class SvgWriter():
self.draw_text_annotations()
def draw_line_annotation(self, obj, classes):
# TODO: properly scope these offsets
x_offset = self.raw_width / 2
y_offset = self.raw_height / 2
classes.extend(['annotation'])
matrix_world = obj.matrix_world
for spline in obj.data.splines:
points = self.get_spline_points(spline)
projected_points = [self.project_point_onto_camera(matrix_world @ p.co.xyz) for p in points]
d = ' '.join(['L {} {}'.format(
(x_offset + p.x) * self.scale, (y_offset - p.y) * self.scale)
for p in projected_points])
d = 'M{}'.format(d[1:])
path = self.svg.add(self.svg.path(d=d, class_=' '.join(classes)))
def draw_text_annotations(self):
x_offset = self.raw_width / 2
y_offset = self.raw_height / 2
@@ -1,3 +1,6 @@
.cut { fill: black; stroke: black; stroke-linecap: 'round'; stroke-width: 0.35; }
.background { fill: white; stroke: black; stroke-linecap: 'round'; stroke-width: 0.25; }
.annotation { fill: none; stroke: black; stroke-linecap: 'round'; stroke-width: 0.25; }
.hidden { stroke-dasharray: 3, 2; }
.leader { marker-end: url(#leader-marker); }
.solid {}
@@ -1580,7 +1580,8 @@ class CutSection(bpy.types.Operator):
ifc_cutter.stair_obj = None
ifc_cutter.dimension_obj = None
ifc_cutter.equal_obj = None
ifc_cutter.hidden_obj = None
ifc_cutter.hidden_objs = []
ifc_cutter.solid_objs = []
ifc_cutter.plan_level_obj = None
ifc_cutter.section_level_obj = None
ifc_cutter.grid_objs = []
@@ -1595,7 +1596,9 @@ class CutSection(bpy.types.Operator):
elif 'Dimension' in obj.name:
ifc_cutter.dimension_obj = obj
elif 'Hidden' in obj.name:
ifc_cutter.hidden_obj = obj
ifc_cutter.hidden_objs.append(obj)
elif 'Solid' in obj.name:
ifc_cutter.solid_objs.append(obj)
elif 'IfcGrid' in obj.name:
ifc_cutter.grid_objs.append(obj)
elif 'Plan Level' in obj.name:
@@ -1841,17 +1844,8 @@ class SetViewPreset2(bpy.types.Operator):
bpy.context.scene.display.shading.light = 'FLAT'
bpy.context.scene.display.shading.color_type = 'SINGLE'
bpy.context.scene.display.shading.single_color = (1, 1, 1)
bpy.context.scene.use_nodes = True
rgb_curves = bpy.context.scene.node_tree.nodes.new(type='CompositorNodeCurveRGB')
rgb_curves.mapping.curves[3].points.new(.4, 0) # Increase black contrast
rgb_curves.mapping.update()
for node in bpy.context.scene.node_tree.nodes:
if node.type == 'R_LAYERS':
render_layers = node
elif node.type == 'COMPOSITE':
composite = node
bpy.context.scene.node_tree.links.new(render_layers.outputs[0], rgb_curves.inputs[1])
bpy.context.scene.node_tree.links.new(rgb_curves.outputs[0], composite.inputs[0])
bpy.context.scene.view_settings.use_curve_mapping = True
bpy.context.scene.view_settings.curve_mapping.curves[3].points.new(.4, 0) # Increase black contrast
return {'FINISHED'}