-
Notifications
You must be signed in to change notification settings - Fork 1
/
common_drawing_view.py
128 lines (117 loc) · 3.74 KB
/
common_drawing_view.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
'''
Re-Created on Feb 13, 2018 for D3Splint
Created on Jul 11, 2015 for Retopoflow CGCookie
@author: Patrick
'''
import bpy
import bgl
import blf
#bgl.glDepthRange(0.0, 0.5)
def draw3d_polyline(context, points, color, thickness, LINE_TYPE):
if context.region_data.view_perspective == 'ORTHO':
bias = 0.9997
else:
bias = 0.997
if LINE_TYPE == "GL_LINE_STIPPLE":
bgl.glLineStipple(4, 0x5555) #play with this later
bgl.glEnable(bgl.GL_LINE_STIPPLE)
bgl.glEnable(bgl.GL_BLEND)
bgl.glColor4f(*color)
bgl.glLineWidth(thickness)
bgl.glDepthRange(0.0, bias)
bgl.glBegin(bgl.GL_LINE_STRIP)
for coord in points: bgl.glVertex3f(*coord)
bgl.glEnd()
bgl.glLineWidth(1)
if LINE_TYPE == "GL_LINE_STIPPLE":
bgl.glDisable(bgl.GL_LINE_STIPPLE)
bgl.glEnable(bgl.GL_BLEND) # back to uninterrupted lines
def draw3d_closed_polylines(context, lpoints, color, thickness, LINE_TYPE):
if context.space_data.region_3d.view_perspective == 'ORTHO':
bias = 0.9997
else:
bias = 0.997
if LINE_TYPE == "GL_LINE_STIPPLE":
bgl.glLineStipple(4, 0x5555) #play with this later
bgl.glEnable(bgl.GL_LINE_STIPPLE)
bgl.glEnable(bgl.GL_BLEND)
bgl.glColor4f(*color)
bgl.glLineWidth(thickness)
bgl.glDepthRange(0.0, bias)
for points in lpoints:
bgl.glBegin(bgl.GL_LINE_STRIP)
for coord in points:
bgl.glVertex3f(*coord)
bgl.glVertex3f(*points[0])
bgl.glEnd()
bgl.glLineWidth(1)
if LINE_TYPE == "GL_LINE_STIPPLE":
bgl.glDisable(bgl.GL_LINE_STIPPLE)
bgl.glEnable(bgl.GL_BLEND) # back to uninterrupted lines
def draw3d_arrow(context, pfrom, pto, normal, color, thickness, LINE_TYPE):
pdiff = pto - pfrom
l = pdiff.length
hd = l * 0.10
hw = l * 0.05
pdir = pdiff / l
portho = pdir.cross(normal).normalized()
pto0 = pto - pdir * hd + portho * hw
pto1 = pto - pdir * hd - portho * hw
if context.space_data.region_3d.view_perspective == 'ORTHO':
bias = 0.9997
else:
bias = 0.997
if LINE_TYPE == "GL_LINE_STIPPLE":
bgl.glLineStipple(4, 0x5555) #play with this later
bgl.glEnable(bgl.GL_LINE_STIPPLE)
bgl.glEnable(bgl.GL_BLEND)
bgl.glColor4f(*color)
bgl.glLineWidth(thickness)
bgl.glDepthRange(0.0, bias)
bgl.glBegin(bgl.GL_LINES)
bgl.glVertex3f(*pfrom)
bgl.glVertex3f(*pto)
bgl.glVertex3f(*pto0)
bgl.glVertex3f(*pto)
bgl.glVertex3f(*pto1)
bgl.glVertex3f(*pto)
bgl.glEnd()
bgl.glLineWidth(1)
if LINE_TYPE == "GL_LINE_STIPPLE":
bgl.glDisable(bgl.GL_LINE_STIPPLE)
def draw3d_quad(context, points, color):
if context.space_data.region_3d.view_perspective == 'ORTHO':
bias = 0.9999
else:
bias = 0.999
bgl.glEnable(bgl.GL_BLEND)
bgl.glColor4f(*color)
bgl.glDepthRange(0.0, bias)
bgl.glBegin(bgl.GL_QUADS)
for coord in points: bgl.glVertex3f(*coord)
bgl.glEnd()
def draw3d_quads(context, lpoints, color):
if context.space_data.region_3d.view_perspective == 'ORTHO':
bias = 0.9999
else:
bias = 0.999
bgl.glEnable(bgl.GL_BLEND)
bgl.glColor4f(*color)
bgl.glDepthRange(0.0, bias)
bgl.glBegin(bgl.GL_QUADS)
for points in lpoints:
for coord in points:
bgl.glVertex3f(*coord)
bgl.glEnd()
def draw3d_points(context, points, color, size):
if context.space_data.region_3d.view_perspective == 'ORTHO':
bias = 0.9999
else:
bias = 0.999
bgl.glColor4f(*color)
bgl.glPointSize(size)
bgl.glDepthRange(0.0, bias)
bgl.glBegin(bgl.GL_POINTS)
for coord in points: bgl.glVertex3f(*coord)
bgl.glEnd()
bgl.glPointSize(1.0)