Skip to content

Commit 52f18fe

Browse files
committed
Viewport preview for batting annotation
Currently it's always set to the same thickness and doesn't update from pset value. It's currently using zigzag pattern to indicate batting because some techincal limitation of the shader (Error: C6033: Hardware limitation reached, can only emit 256 vertices of this size) Also added batting to the annotation tool panel.
1 parent d5ecb9b commit 52f18fe

3 files changed

Lines changed: 103 additions & 2 deletions

File tree

src/blenderbim/blenderbim/bim/module/drawing/decoration.py

Lines changed: 96 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,15 @@ def decorate(self, context, object):
313313
raise NotImplementedError()
314314

315315
def draw_lines(
316-
self, context, obj, vertices, indices, topology=None, is_scale_dependant=True, fill_next_vertices=False
316+
self,
317+
context,
318+
obj,
319+
vertices,
320+
indices,
321+
topology=None,
322+
is_scale_dependant=True,
323+
fill_next_vertices=False,
324+
extra_float_kwargs={},
317325
):
318326
# use is_scale_dependant = False if shader is not using uniform viewportDrawingScale
319327
# otherwise uniform will be discarded during the optimization process
@@ -364,6 +372,9 @@ def draw_lines(
364372
viewport_drawing_scale = 0.00025 * mm_to_px
365373
self.shader.uniform_float("viewportDrawingScale", viewport_drawing_scale)
366374

375+
for kwarg, value in extra_float_kwargs.items():
376+
self.shader.uniform_float(kwarg, value)
377+
367378
batch.draw(self.shader)
368379

369380
def draw_label(self, context, text, pos, dir, gap=4, center=True, vcenter=False):
@@ -1332,6 +1343,89 @@ def decorate(self, context, obj):
13321343
self.draw_lines(context, obj, verts, idxs)
13331344

13341345

1346+
class BattingDecorator(BaseDecorator):
1347+
"""Decorator for batting objects
1348+
1349+
Uses first two vertices in verts list.
1350+
"""
1351+
1352+
objecttype = "BATTING"
1353+
1354+
DEF_GLSL = (
1355+
BaseDecorator.DEF_GLSL
1356+
+ """
1357+
#define BREAK_LENGTH 32.0
1358+
#define BREAK_WIDTH 16.0
1359+
#define PATTERN_SEGMENT_LENGTH 2
1360+
"""
1361+
)
1362+
1363+
GEOM_GLSL = """
1364+
uniform vec2 winsize;
1365+
uniform float viewportDrawingScale;
1366+
uniform float batting_thickness;
1367+
1368+
layout(lines) in;
1369+
layout(line_strip, max_vertices=256) out;
1370+
1371+
void main() {
1372+
vec4 clip2win = matCLIP2WIN();
1373+
vec4 win2clip = matWIN2CLIP();
1374+
1375+
vec4 p0 = gl_in[0].gl_Position, p1 = gl_in[1].gl_Position;
1376+
1377+
vec4 p0w = CLIP2WIN(p0), p1w = CLIP2WIN(p1), pmw = (p0w + p1w) * .5;
1378+
vec4 edge = p1w - p0w, dir = normalize(edge);
1379+
1380+
vec4 gap = dir * 16.0; // TODO: never used?
1381+
1382+
float segment_width = batting_thickness / 2.5;
1383+
vec2 batting_dimensions = vec2(segment_width, batting_thickness);
1384+
// make sure to multiply by viewportDrawingScale
1385+
// so the drawing will stay consistent on zoom in / zoom out
1386+
mat2 m_edge_space = mat2( dir.xy, dir.yx*vec2(1,-1) ) * viewportDrawingScale;
1387+
1388+
vec2 pattern_segment_data[PATTERN_SEGMENT_LENGTH];
1389+
// simplified insulation pattern
1390+
// pattern_segment_data[0] = vec2(0, 1);
1391+
// pattern_segment_data[1] = vec2(0.5, 0.8);
1392+
// pattern_segment_data[2] = vec2(0, 0.2);
1393+
// pattern_segment_data[3] = vec2(0.5, 0);
1394+
// pattern_segment_data[4] = vec2(1.0, 0.2);
1395+
// pattern_segment_data[5] = vec2(0.5, 0.8);
1396+
// pattern_segment_data[6] = vec2(1.0, 1.0);
1397+
// zigzag pattern
1398+
pattern_segment_data[0] = vec2(0, 1);
1399+
pattern_segment_data[1] = vec2(0, 0);
1400+
1401+
int segs = int( ceil( length(edge) / (batting_dimensions.x * viewportDrawingScale) ) ); // amount of segments
1402+
vec4 p;
1403+
vec2 p_base, p_cur_ver;
1404+
1405+
for (int i = 0; i < segs; i++) {
1406+
p_base = m_edge_space * (vec2(i, -0.5) * batting_dimensions);
1407+
for(int j=0; j<PATTERN_SEGMENT_LENGTH; j++) {
1408+
p_cur_ver = p_base + m_edge_space * (pattern_segment_data[j] * batting_dimensions);
1409+
p = p0w + vec4(p_cur_ver, 0, 0);
1410+
gl_Position = WIN2CLIP(p);
1411+
EmitVertex();
1412+
}
1413+
}
1414+
1415+
gl_Position = p1;
1416+
EmitVertex();
1417+
EndPrimitive();
1418+
}
1419+
"""
1420+
1421+
def decorate(self, context, obj):
1422+
if obj.data.is_editmode:
1423+
verts, idxs = self.get_editmesh_geom(obj)
1424+
else:
1425+
verts, idxs = self.get_mesh_geom(obj)
1426+
self.draw_lines(context, obj, verts[:2], idxs, extra_float_kwargs={"batting_thickness": 32.0})
1427+
1428+
13351429
class GridDecorator(BaseDecorator):
13361430
objecttype = "GRID"
13371431

@@ -1788,6 +1882,7 @@ class DecorationsHandler:
17881882
SectionDecorator,
17891883
ElevationDecorator,
17901884
TextDecorator,
1885+
BattingDecorator,
17911886
]
17921887

17931888
installed = None

src/blenderbim/blenderbim/bim/module/drawing/ui.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,9 @@ def draw(self, context):
174174
col.alignment = "LEFT"
175175
row2 = col.row(align=True)
176176
row2.operator("bim.remove_drawing", icon="X", text="").drawing = active_drawing.ifc_definition_id
177-
row2.operator("bim.duplicate_drawing", icon="COPYDOWN", text="").drawing = active_drawing.ifc_definition_id
177+
row2.operator(
178+
"bim.duplicate_drawing", icon="COPYDOWN", text=""
179+
).drawing = active_drawing.ifc_definition_id
178180
col = row.column()
179181
col.alignment = "RIGHT"
180182
op = row.operator("bim.open_view", icon="URL", text="")
@@ -417,6 +419,9 @@ def draw(self, context):
417419
op.data_type = "mesh"
418420

419421
row = layout.row(align=True)
422+
op = row.operator("bim.add_annotation", text="Batting", icon="FORCE_FORCE")
423+
op.object_type = "BATTING"
424+
op.data_type = "mesh"
420425
op = row.operator("bim.add_annotation", text="Fill Area", icon="NODE_TEXTURE")
421426
op.object_type = "FILL_AREA"
422427

src/blenderbim/blenderbim/tool/drawing.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ def copy_representation(cls, source, dest):
4949
def create_annotation_object(cls, drawing, object_type):
5050
data_type = {
5151
"ANGLE": "curve",
52+
"BATTING": "mesh",
5253
"BREAKLINE": "mesh",
5354
"DIAMETER": "curve",
5455
"DIMENSION": "curve",

0 commit comments

Comments
 (0)