Skip to content
This repository was archived by the owner on Nov 24, 2024. It is now read-only.

Commit 48de2f7

Browse files
qwiglydeeMoult
authored andcommitted
fix arrows heads
1 parent f37283f commit 48de2f7

1 file changed

Lines changed: 31 additions & 11 deletions

File tree

src/ifcblenderexport/blenderbim/bim/decoration.py

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,15 @@ class DimensionDecorator(ViewDecorator):
4747
"""
4848
GEOM_GLSL = """
4949
layout(lines) in;
50-
layout(line_strip, max_vertices=8) out;
50+
layout(line_strip, max_vertices=10) out;
5151
5252
uniform float angle;
5353
uniform float length;
54+
uniform float aspect;
5455
5556
void main() {
57+
/** generates arrows from lines */
58+
5659
vec4 p0 = gl_in[0].gl_Position, p1 = gl_in[1].gl_Position;
5760
float c = cos(angle), s = sin(angle);
5861
mat4 rot_a = mat4( c, -s, 0, 0,
@@ -64,32 +67,46 @@ class DimensionDecorator(ViewDecorator):
6467
0, 0, 1, 0,
6568
0, 0, 0, 1);
6669
67-
vec4 dir = normalize(p1 - p0);
68-
69-
vec4 arr_a = rot_a * dir * length;
70-
vec4 arr_b = rot_b * dir * length;
70+
// converting to and from square-space coordinates to calculate arrows
71+
mat4 clip2square = mat4(aspect, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
72+
mat4 square2clip = mat4(1/aspect, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
73+
vec4 dir = normalize((p1 - p0) * clip2square) * length;
74+
vec4 head = dir * square2clip;
75+
vec4 arr_a = dir * rot_a * square2clip;
76+
vec4 arr_b = dir * rot_b * square2clip;
7177
72-
gl_Position = p0;
78+
gl_Position = p0 + head;
7379
EmitVertex();
74-
gl_Position = p1;
80+
gl_Position = p1 - head;
7581
EmitVertex();
7682
EndPrimitive();
7783
78-
gl_Position = p0 + arr_a;
79-
EmitVertex();
8084
gl_Position = p0;
8185
EmitVertex();
86+
gl_Position = p0 + arr_a;
87+
EmitVertex();
8288
gl_Position = p0 + arr_b;
8389
EmitVertex();
90+
gl_Position = p0;
91+
EmitVertex();
8492
EndPrimitive();
8593
94+
gl_Position = p1;
95+
EmitVertex();
96+
gl_Position = p1 - arr_b;
97+
EmitVertex();
8698
gl_Position = p1 - arr_a;
8799
EmitVertex();
88100
gl_Position = p1;
89101
EmitVertex();
90-
gl_Position = p1 - arr_b;
102+
EndPrimitive();
103+
/*
104+
gl_Position = vec4(0, 0, 0, 1) * square2clip;
105+
EmitVertex();
106+
gl_Position = vec4(0.25, 0.25, 0, 1) * square2clip;
91107
EmitVertex();
92108
EndPrimitive();
109+
*/
93110
}
94111
"""
95112
FRAG_GLSL = """
@@ -189,10 +206,13 @@ def coords(segm):
189206
segments, []))
190207
batch = batch_for_shader(self.shader, 'LINES', {'pos': points})
191208
self.shader.bind()
209+
192210
matrix = self.context.region_data.perspective_matrix
211+
aspect = self.context.region.width / self.context.region.height
193212
self.shader.uniform_float("viewMatrix", matrix)
194213
# TODO: get everything from styles
214+
self.shader.uniform_float('aspect', aspect)
195215
self.shader.uniform_float('color', (1.0, 1.0, 1.0))
196216
self.shader.uniform_float('angle', math.pi / 12)
197-
self.shader.uniform_float('length', 0.05)
217+
self.shader.uniform_float('length', 32 / self.context.region.height)
198218
batch.draw(self.shader)

0 commit comments

Comments
 (0)