+ cv_view_verts = []
+ cv_view_colours = []
+#}
+
+# I dont remember what this does exactly
+#
+def cv_draw_bpath( o0,o1,c0,c1 ):
+#{
+ cv_draw_sbpath( o0,o1,c0,c1,1.0,1.0 )
+#}
+
+# Semi circle to show the limit. and some lines
+#
+def draw_limit( obj, center, major, minor, amin, amax, colour ):
+#{
+ global cv_view_verts, cv_view_colours
+ f = 0.05
+ ay = major*f
+ ax = minor*f
+
+ for x in range(16):
+ #{
+ t0 = x/16
+ t1 = (x+1)/16
+ a0 = amin*(1.0-t0)+amax*t0
+ a1 = amin*(1.0-t1)+amax*t1
+
+ p0 = center + major*f*math.cos(a0) + minor*f*math.sin(a0)
+ p1 = center + major*f*math.cos(a1) + minor*f*math.sin(a1)
+
+ p0=obj.matrix_world @ p0
+ p1=obj.matrix_world @ p1
+ cv_view_verts += [p0,p1]
+ cv_view_colours += [colour,colour]
+
+ if x == 0:
+ #{
+ cv_view_verts += [p0,center]
+ cv_view_colours += [colour,colour]
+ #}
+ if x == 15:
+ #{
+ cv_view_verts += [p1,center]
+ cv_view_colours += [colour,colour]
+ #}
+ #}
+
+ cv_view_verts += [center+major*1.2*f,center+major*f*0.8]
+ cv_view_colours += [colour,colour]
+
+ cv_draw_lines()
+#}
+
+# Cone and twist limit
+#
+def draw_cone_twist( center, vx, vy, va ):
+#{
+ global cv_view_verts, cv_view_colours
+ axis = vy.cross( vx )
+ axis.normalize()
+
+ size = 0.12
+
+ cv_view_verts += [center, center+va*size]
+ cv_view_colours += [ (1,1,1,1), (1,1,1,1) ]
+
+ for x in range(32):
+ #{
+ t0 = (x/32) * math.tau
+ t1 = ((x+1)/32) * math.tau
+
+ c0 = math.cos(t0)
+ s0 = math.sin(t0)
+ c1 = math.cos(t1)
+ s1 = math.sin(t1)
+
+ p0 = center + (axis + vx*c0 + vy*s0).normalized() * size
+ p1 = center + (axis + vx*c1 + vy*s1).normalized() * size
+
+ col0 = ( abs(c0), abs(s0), 0.0, 1.0 )
+ col1 = ( abs(c1), abs(s1), 0.0, 1.0 )
+
+ cv_view_verts += [center, p0, p0, p1]
+ cv_view_colours += [ (0,0,0,0), col0, col0, col1 ]
+ #}
+
+ cv_draw_lines()
+#}
+
+# Draws constraints and stuff for the skeleton. This isnt documented and wont be
+#
+def draw_skeleton_helpers( obj ):
+#{
+ global cv_view_verts, cv_view_colours
+
+ if obj.data.pose_position != 'REST':
+ #{
+ return
+ #}
+
+ for bone in obj.data.bones:
+ #{
+ c = bone.head_local
+ a = Vector((bone.cv_data.v0[0], bone.cv_data.v0[1], bone.cv_data.v0[2]))
+ b = Vector((bone.cv_data.v1[0], bone.cv_data.v1[1], bone.cv_data.v1[2]))
+
+ if bone.cv_data.collider == 'collider_box':
+ #{
+
+ vs = [None]*8
+ vs[0]=obj.matrix_world@Vector((c[0]+a[0],c[1]+a[1],c[2]+a[2]))
+ vs[1]=obj.matrix_world@Vector((c[0]+a[0],c[1]+b[1],c[2]+a[2]))
+ vs[2]=obj.matrix_world@Vector((c[0]+b[0],c[1]+b[1],c[2]+a[2]))
+ vs[3]=obj.matrix_world@Vector((c[0]+b[0],c[1]+a[1],c[2]+a[2]))
+ vs[4]=obj.matrix_world@Vector((c[0]+a[0],c[1]+a[1],c[2]+b[2]))
+ vs[5]=obj.matrix_world@Vector((c[0]+a[0],c[1]+b[1],c[2]+b[2]))
+ vs[6]=obj.matrix_world@Vector((c[0]+b[0],c[1]+b[1],c[2]+b[2]))
+ vs[7]=obj.matrix_world@Vector((c[0]+b[0],c[1]+a[1],c[2]+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.5,0.5,0.5,0.5),(0.5,0.5,0.5,0.5)]
+ #}
+ #}
+ elif bone.cv_data.collider == 'collider_capsule':
+ #{
+ v0 = b-a
+ major_axis = 0
+ largest = -1.0
+
+ for i in range(3):
+ #{
+ if abs(v0[i]) > largest:
+ #{
+ largest = abs(v0[i])
+ major_axis = i
+ #}
+ #}
+
+ v1 = Vector((0,0,0))
+ v1[major_axis] = 1.0
+
+ tx = Vector((0,0,0))
+ ty = Vector((0,0,0))
+
+ cv_tangent_basis( v1, tx, ty )
+ r = (abs(tx.dot( v0 )) + abs(ty.dot( v0 ))) * 0.25
+ l = v0[ major_axis ] - r*2
+
+ p0 = obj.matrix_world@Vector( c + (a+b)*0.5 + v1*l*-0.5 )
+ p1 = obj.matrix_world@Vector( c + (a+b)*0.5 + v1*l* 0.5 )
+
+ colour = [0.2,0.2,0.2,1.0]
+ colour[major_axis] = 0.5
+
+ cv_draw_halfsphere( p0, -v1, ty, tx, r, colour )
+ cv_draw_halfsphere( p1, v1, ty, tx, r, colour )
+ cv_draw_line( p0+tx* r, p1+tx* r, colour )
+ cv_draw_line( p0+tx*-r, p1+tx*-r, colour )
+ cv_draw_line( p0+ty* r, p1+ty* r, colour )
+ cv_draw_line( p0+ty*-r, p1+ty*-r, colour )
+ #}
+ else:
+ #{
+ continue
+ #}
+
+ center = obj.matrix_world @ c
+ if bone.cv_data.con0:
+ #{
+ vx = Vector([bone.cv_data.conevx[_] for _ in range(3)])
+ vy = Vector([bone.cv_data.conevy[_] for _ in range(3)])
+ va = Vector([bone.cv_data.coneva[_] for _ in range(3)])
+ draw_cone_twist( center, vx, vy, va )
+
+ #draw_limit( obj, c, Vector((0,0,1)),Vector((0,-1,0)), \
+ # bone.cv_data.mins[0], bone.cv_data.maxs[0], \
+ # (1,0,0,1))
+ #draw_limit( obj, c, Vector((0,-1,0)),Vector((1,0,0)), \
+ # bone.cv_data.mins[1], bone.cv_data.maxs[1], \
+ # (0,1,0,1))
+ #draw_limit( obj, c, Vector((1,0,0)),Vector((0,0,1)), \
+ # bone.cv_data.mins[2], bone.cv_data.maxs[2], \
+ # (0,0,1,1))
+ #}
+ #}
+#}
+
+def cv_draw():
+#{
+ global cv_view_shader
+ global cv_view_verts
+ global cv_view_colours
+ global cv_view_course_i
+
+ cv_view_course_i = 0
+ cv_view_verts = []
+ cv_view_colours = []
+
+ cv_view_shader.bind()
+ gpu.state.depth_mask_set(False)
+ gpu.state.line_width_set(2.0)
+ gpu.state.face_culling_set('BACK')
+ gpu.state.depth_test_set('LESS')
+ gpu.state.blend_set('NONE')
+
+ for obj in bpy.context.collection.objects:
+ #{
+ if obj.type == 'ARMATURE':
+ #{
+ if obj.data.pose_position == 'REST':
+ draw_skeleton_helpers( obj )
+ #}
+ else:
+ #{
+ classtype = obj.cv_data.classtype
+ if (classtype != 'classtype_none') and (classtype in globals()):
+ #{
+ cl = globals()[ classtype ]
+
+ if getattr( cl, "draw_scene_helpers", None ):
+ #{
+ cl.draw_scene_helpers( obj )
+ #}
+ #}
+ #}
+ #}
+
+ cv_draw_lines()
+ return
+#}
+
+
+# ---------------------------------------------------------------------------- #
+# #
+# Blender #
+# #
+# ---------------------------------------------------------------------------- #
+
+# Checks whether this object has a classtype assigned. we can only target other
+# classes