diff --git a/src/ifcblenderexport/blenderbim/bim/decoration.py b/src/ifcblenderexport/blenderbim/bim/decoration.py index 30c644008b..6f16e65c7e 100644 --- a/src/ifcblenderexport/blenderbim/bim/decoration.py +++ b/src/ifcblenderexport/blenderbim/bim/decoration.py @@ -62,13 +62,33 @@ class BaseDecorator(): head[2] = mat2(c, +s, -s, c) * nose; } - void circle_head(in vec2 p0, in vec2 p1, out vec2 head[CIRCLE_SEGS]) { + void circle_head(in vec2 p0, in vec2 p1, in float size, out vec2 head[CIRCLE_SEGS]) { float angle_d = PI * 2 / CIRCLE_SEGS; for(int i = 0; i DASH_RATIO) { + float t = fract(dist / DASH1_SIZE); + if (t > 0.5) { discard; } else { fragColor = vec4(1.0, 1.0, 1.0, 1.0); @@ -548,3 +570,168 @@ class HiddenDecorator(BaseDecorator): else: verts, idxs = self.get_mesh_geom(obj) self.draw_lines(obj, verts, idxs) + + +class LevelDecorator(BaseDecorator): + + def get_splines(self, obj): + """Iterates through splines + Args: + obj: Blender object with Curve data + + Yields: + verts: points of each spline, world coords + """ + for spline in obj.data.splines: + spline_points = spline.bezier_points if spline.bezier_points else spline.points + yield [obj.matrix_world @ p.co for p in spline_points] + + def decorate(self, obj): + verts, idxs, topo = self.get_path_geom(obj) + self.draw_lines(obj, verts, idxs, topo) + splines = self.get_splines(obj) + self.draw_labels(obj, splines) + + +class PlanDecorator(LevelDecorator): + basename = "IfcAnnotation/Plan Level" + installed = None + + GEOM_GLSL = """ + uniform vec2 winsize; + + layout(lines) in; + layout(line_strip, max_vertices=MAX_POINTS) out; + in uint type[]; + + void main() { + vec4 p0 = gl_in[0].gl_Position, p1 = gl_in[1].gl_Position; + uint t0 = type[0], t1 = type[1]; + + mat4 windowMatrix = mat4(winsize.x/2, 0, 0, 0, 0, winsize.y/2, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); + mat4 unwindowMatrix = inverse(windowMatrix); + + vec2 p0w = (windowMatrix * (p0 / p0.w)).xy, p1w = (windowMatrix * (p1 / p1.w)).xy; + + vec4 gap1 = vec4(0); + + // end edge cross+circle for last segment + if (t1 == 2u) { + vec2 head_o[CIRCLE_SEGS]; + + circle_head(p0w, p1w, CIRCLE2_SIZE, head_o); + for(int i=0; i 0.875 || (t > 0.25 && t < 0.375)) { + discard; + } else { + fragColor = vec4(1.0, 1.0, 1.0, 1.0); + } + } + """ + + def draw_labels(self, obj, splines): + region = self.context.region + region3d = self.context.region_data + for verts in splines: + v0 = verts[0] + v1 = verts[1] + p0 = location_3d_to_region_2d(region, region3d, v0) + p1 = location_3d_to_region_2d(region, region3d, v1) + dir = p1 - p0 + elev = verts[-1].z + text = f"RL {elev:.2f}" + self.draw_label(text, p0 + dir.normalized() * 16, -dir, gap=16, center=False) diff --git a/src/ifcblenderexport/blenderbim/bim/prop.py b/src/ifcblenderexport/blenderbim/bim/prop.py index 4b83aa25bd..09a7d8e10f 100644 --- a/src/ifcblenderexport/blenderbim/bim/prop.py +++ b/src/ifcblenderexport/blenderbim/bim/prop.py @@ -366,12 +366,16 @@ def toggleDecorations(self, context): decoration.LeaderDecorator.install(self, context) decoration.StairDecorator.install(self, context) decoration.HiddenDecorator.install(self, context) + decoration.PlanDecorator.install(self, context) + decoration.SectionDecorator.install(self, context) else: decoration.DimensionDecorator.uninstall() decoration.EqualityDecorator.uninstall() decoration.LeaderDecorator.uninstall() decoration.StairDecorator.uninstall() decoration.HiddenDecorator.uninstall() + decoration.PlanDecorator.uninstall() + decoration.SectionDecorator.uninstall() def getScenarios(self, context):