+cv_view_verts = []
+cv_view_colours = []
+cv_view_course_i = 0
+
+# Draw axis alligned sphere at position with radius
+#
+def cv_draw_sphere( pos, radius, colour ):
+#{
+ global cv_view_verts, cv_view_colours
+
+ ly = pos + Vector((0,0,radius))
+ lx = pos + Vector((0,radius,0))
+ lz = pos + Vector((0,0,radius))
+
+ pi = 3.14159265358979323846264
+
+ for i in range(16):
+ #{
+ t = ((i+1.0) * 1.0/16.0) * pi * 2.0
+ s = math.sin(t)
+ c = math.cos(t)
+
+ py = pos + Vector((s*radius,0.0,c*radius))
+ px = pos + Vector((s*radius,c*radius,0.0))
+ pz = pos + Vector((0.0,s*radius,c*radius))
+
+ cv_view_verts += [ px, lx ]
+ cv_view_verts += [ py, ly ]
+ cv_view_verts += [ pz, lz ]
+
+ cv_view_colours += [ colour, colour, colour, colour, colour, colour ]
+
+ ly = py
+ lx = px
+ lz = pz
+ #}
+ cv_draw_lines()
+#}
+
+# Draw transformed -1 -> 1 cube
+#
+def cv_draw_ucube( transform, colour ):
+#{
+ global cv_view_verts, cv_view_colours
+
+ a = Vector((-1,-1,-1))
+ b = Vector((1,1,1))
+
+ vs = [None]*8
+ vs[0] = transform @ Vector((a[0], a[1], a[2]))
+ vs[1] = transform @ Vector((a[0], b[1], a[2]))
+ vs[2] = transform @ Vector((b[0], b[1], a[2]))
+ vs[3] = transform @ Vector((b[0], a[1], a[2]))
+ vs[4] = transform @ Vector((a[0], a[1], b[2]))
+ vs[5] = transform @ Vector((a[0], b[1], b[2]))
+ vs[6] = transform @ Vector((b[0], b[1], b[2]))
+ vs[7] = transform @ Vector((b[0], a[1], b[2]))
+
+ indices = [(0,1),(1,2),(2,3),(3,0),(4,5),(5,6),(6,7),(7,4),\
+ (0,4),(1,5),(2,6),(3,7)]
+
+ for l in indices:
+ #{
+ v0 = vs[l[0]]
+ v1 = vs[l[1]]
+ cv_view_verts += [(v0[0],v0[1],v0[2])]
+ cv_view_verts += [(v1[0],v1[1],v1[2])]
+ cv_view_colours += [(0,1,0,1),(0,1,0,1)]
+ #}
+ cv_draw_lines()
+#}
+
+# Draw line with colour
+#
+def cv_draw_line( p0, p1, colour ):
+#{
+ global cv_view_verts, cv_view_colours
+
+ cv_view_verts += [p0,p1]
+ cv_view_colours += [colour, colour]
+ cv_draw_lines()
+#}
+
+# Draw line with colour(s)
+#
+def cv_draw_line2( p0, p1, c0, c1 ):
+#{
+ global cv_view_verts, cv_view_colours
+
+ cv_view_verts += [p0,p1]
+ cv_view_colours += [c0,c1]
+ cv_draw_lines()
+#}
+
+# Just the tx because we dont really need ty for this app
+#
+def cv_tangent_basis_tx( n, tx ):
+#{
+ if abs( n[0] ) >= 0.57735027:
+ #{
+ tx[0] = n[1]
+ tx[1] = -n[0]
+ tx[2] = 0.0
+ #}
+ else:
+ #{
+ tx[0] = 0.0
+ tx[1] = n[2]
+ tx[2] = -n[1]
+ #}
+
+ tx.normalize()
+#}
+
+# Draw coloured arrow
+#
+def cv_draw_arrow( p0, p1, c0 ):
+#{
+ global cv_view_verts, cv_view_colours
+
+ n = p1-p0
+ midpt = p0 + n*0.5
+ n.normalize()
+
+ tx = Vector((1,0,0))
+ cv_tangent_basis_tx( n, tx )
+
+ cv_view_verts += [p0,p1, midpt+(tx-n)*0.15,midpt, midpt+(-tx-n)*0.15,midpt ]
+ cv_view_colours += [c0,c0,c0,c0,c0,c0]
+ cv_draw_lines()
+#}
+
+# Drawhandles of a bezier control point
+#
+def cv_draw_bhandle( obj, direction, colour ):
+#{
+ global cv_view_verts, cv_view_colours
+
+ p0 = obj.location
+ h0 = obj.matrix_world @ Vector((0,direction,0))
+
+ cv_view_verts += [p0]
+ cv_view_verts += [h0]
+ cv_view_colours += [colour,colour]
+ cv_draw_lines()
+#}
+
+# Draw a bezier curve (at fixed resolution 10)
+#
+def cv_draw_bezier( p0,h0,p1,h1,c0,c1 ):
+#{
+ global cv_view_verts, cv_view_colours
+
+ last = p0
+ for i in range(10):
+ #{
+ t = (i+1)/10
+ a0 = 1-t
+
+ tt = t*t
+ ttt = tt*t
+ p=ttt*p1+(3*tt-3*ttt)*h1+(3*ttt-6*tt+3*t)*h0+(3*tt-ttt-3*t+1)*p0
+
+ cv_view_verts += [(last[0],last[1],last[2])]
+ cv_view_verts += [(p[0],p[1],p[2])]
+ cv_view_colours += [c0*a0+c1*(1-a0),c0*a0+c1*(1-a0)]
+
+ last = p
+ #}
+ cv_draw_lines()
+#}
+
+# I think this one extends the handles of the bezier otwards......
+#
+def cv_draw_sbpath( o0,o1,c0,c1,s0,s1 ):
+#{
+ global cv_view_course_i
+
+ offs = ((cv_view_course_i % 2)*2-1) * cv_view_course_i * 0.02