-def cv_draw():
- global cv_view_shader
- 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')
-
- verts = []
- colours = []
-
- #def drawbezier(p0,h0,p1,h1,c0,c1):
- # nonlocal verts, colours
-
- # verts += [p0]
- # verts += [h0]
- # colours += [(0.5,0.5,0.5,1.0),(0.5,0.5,0.5,1)]
- # verts += [p1]
- # verts += [h1]
- # colours += [(1.0,1.0,1,1),(1,1,1,1)]
- #
- # 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
- # verts += [(last[0],last[1],last[2])]
- # verts += [(p[0],p[1],p[2])]
- # colours += [c0*a0+c1*(1-a0),c0*a0+c1*(1-a0)]
- # last = p
-
- course_count = 0
-
- def drawbhandle(obj, direction, colour):
- nonlocal verts, colours
- p0 = obj.location
- h0 = obj.matrix_world @ Vector((0,direction,0))
- verts += [p0]
- verts += [h0]
- colours += [colour,colour]
-
- def drawbezier(p0,h0,p1,h1,c0,c1):
- nonlocal verts, 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
- verts += [(last[0],last[1],last[2])]
- verts += [(p[0],p[1],p[2])]
- colours += [c0*a0+c1*(1-a0),c0*a0+c1*(1-a0)]
- last = p
-
- def drawsbpath(o0,o1,c0,c1,s0,s1):
- nonlocal course_count
-
- offs = ((course_count % 2)*2-1) * course_count * 0.02
-
- p0 = o0.matrix_world @ Vector((offs, 0,0))
- h0 = o0.matrix_world @ Vector((offs, s0,0))
- p1 = o1.matrix_world @ Vector((offs, 0,0))
- h1 = o1.matrix_world @ Vector((offs,-s1,0))
- drawbezier(p0,h0,p1,h1,c0,c1)
-
- def drawbpath(o0,o1,c0,c1):
- drawsbpath(o0,o1,c0,c1,1.0,1.0)
-
- def drawbline(p0,p1,c0,c1):
- nonlocal verts, colours
- verts += [p0,p1]
- colours += [c0,c1]
-
- for obj in bpy.context.collection.objects:
- if obj.type == 'ARMATURE':
- for bone in obj.data.bones:
- if bone.cv_data.collider and obj.data.pose_position == 'REST':
- c = bone.head_local
- a = bone.cv_data.v0
- b = bone.cv_data.v1
-
- 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]]
- verts += [(v0[0],v0[1],v0[2])]
- verts += [(v1[0],v1[1],v1[2])]
- colours += [(0.5,0.5,0.5,0.5),(0.5,0.5,0.5,0.5)]
-
- center=obj.matrix_world@c
-
- def _angle_lim( major, minor, amin, amax, colour ):
- nonlocal verts, 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 = c + major*f*math.cos(a0) + minor*f*math.sin(a0)
- p1 = c + major*f*math.cos(a1) + minor*f*math.sin(a1)
-
- p0=obj.matrix_world @ p0
- p1=obj.matrix_world @ p1
- verts += [p0,p1]
- colours += [colour,colour]
-
- if x == 0:
- verts += [p0,c]
- colours += [colour,colour]
- if x == 15:
- verts += [p1,c]
- colours += [colour,colour]
-
- verts += [c+major*1.2*f,c+major*f*0.8]
- colours += [colour,colour]
-
- if bone.cv_data.con0:
- _angle_lim( Vector((0,1,0)),Vector((0,0,1)), \
- bone.cv_data.mins[0], bone.cv_data.maxs[0], \
- (1,0,0,1))
- _angle_lim( Vector((0,0,1)),Vector((1,0,0)), \
- bone.cv_data.mins[1], bone.cv_data.maxs[1], \
- (0,1,0,1))
- _angle_lim( Vector((1,0,0)),Vector((0,1,0)), \
- bone.cv_data.mins[2], bone.cv_data.maxs[2], \
- (0,0,1,1))
-
-
- if obj.cv_data.classtype == 'k_classtype_gate':
- if obj.type == 'MESH':
- dims = obj.data.cv_data.v0
- else:
- dims = obj.cv_data.v0
-
- vs = [None]*9
- c = Vector((0,0,dims[2]))