+ lines = batch_for_shader(\
+ cv_view_shader, 'LINES', \
+ { "pos":cv_view_verts, "color":cv_view_colours })
+
+ lines.draw( cv_view_shader )
+
+ 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.SR_data.collider_min[0],
+ bone.SR_data.collider_min[1],
+ bone.SR_data.collider_min[2]))
+ b = Vector((bone.SR_data.collider_max[0],
+ bone.SR_data.collider_max[1],
+ bone.SR_data.collider_max[2]))
+
+ if bone.SR_data.collider == '1':#{
+ 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.SR_data.collider == '2':#{
+ 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.SR_data.cone_constraint:#{
+ vx = Vector([bone.SR_data.conevx[_] for _ in range(3)])
+ vy = Vector([bone.SR_data.conevy[_] for _ in range(3)])
+ va = Vector([bone.SR_data.coneva[_] for _ in range(3)])
+ draw_cone_twist( center, vx, vy, va )
+ #}
+ #}
+#}
+
+def cv_ent_gate( obj ):
+#{
+ global cv_view_verts, cv_view_colours
+
+ if obj.type != 'MESH': return
+
+ mesh_data = obj.data.SR_data.ent_gate[0]
+ data = obj.SR_data.ent_gate[0]
+ dims = mesh_data.dimensions
+
+ vs = [None]*9
+ c = Vector((0,0,dims[2]))
+
+ vs[0] = obj.matrix_world @ Vector((-dims[0],0.0,-dims[1]+dims[2]))
+ vs[1] = obj.matrix_world @ Vector((-dims[0],0.0, dims[1]+dims[2]))
+ vs[2] = obj.matrix_world @ Vector(( dims[0],0.0, dims[1]+dims[2]))
+ vs[3] = obj.matrix_world @ Vector(( dims[0],0.0,-dims[1]+dims[2]))
+ vs[4] = obj.matrix_world @ (c+Vector((-1,0,-2)))
+ vs[5] = obj.matrix_world @ (c+Vector((-1,0, 2)))
+ vs[6] = obj.matrix_world @ (c+Vector(( 1,0, 2)))
+ vs[7] = obj.matrix_world @ (c+Vector((-1,0, 0)))
+ vs[8] = obj.matrix_world @ (c+Vector(( 1,0, 0)))
+
+ indices = [(0,1),(1,2),(2,3),(3,0),(4,5),(5,6),(7,8)]
+
+ 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 += [(1,1,0,1),(1,1,0,1)]
+ #}
+
+ sw = (0.4,0.4,0.4,0.2)
+ if data.target != None:
+ cv_draw_arrow( obj.location, data.target.location, sw )
+#}
+
+def dijkstra( graph, start_node, target_node ):
+#{
+ unvisited = [_ for _ in graph]
+ shortest_path = {}
+ previous_nodes = {}
+
+ for n in unvisited:
+ shortest_path[n] = 9999999.999999
+ shortest_path[start_node] = 0
+
+ while unvisited:#{
+ current_min_node = None
+ for n in unvisited:#{
+ if current_min_node == None:
+ current_min_node = n
+ elif shortest_path[n] < shortest_path[current_min_node]:
+ current_min_node = n
+ #}
+
+ for branch in graph[current_min_node]:#{
+ tentative_value = shortest_path[current_min_node]
+ tentative_value += graph[current_min_node][branch]
+ if tentative_value < shortest_path[branch]:#{
+ shortest_path[branch] = tentative_value
+ previous_nodes[branch] = current_min_node
+ #}
+ #}
+
+ unvisited.remove(current_min_node)
+ #}
+
+ path = []
+ node = target_node
+ while node != start_node:#{
+ path.append(node)
+
+ if node not in previous_nodes: return None
+ node = previous_nodes[node]
+ #}
+
+ # Add the start node manually
+ path.append(start_node)
+ return path
+#}
+
+def node_graph( route_nodes ):
+#{
+ graph = {}
+ for n in route_nodes:
+ graph[n.name] = {}
+
+ for i in range(len(route_nodes)-1):#{
+ for j in range(i+1, len(route_nodes)):#{
+ ni = route_nodes[i]
+ nj = route_nodes[j]
+
+ v0 = ni.location - nj.location
+
+ gate = None
+
+ if ni.SR_data.ent_type == 'ent_gate':
+ gate = ni
+
+ if nj.SR_data.ent_type == 'ent_gate':#{
+ if gate: continue
+ gate = nj
+ #}
+
+ if gate:#{
+ v1 = gate.matrix_world.to_3x3() @ Vector((0,-1,0))
+ if gate.SR_data.ent_gate[0].target:
+ if v1.dot(v0) > 0.0: continue
+ else:
+ if v1.dot(v0) < 0.0: continue
+ #}
+
+ dist = v0.magnitude
+
+ if dist > 25.0: continue
+ graph[route_nodes[i].name][route_nodes[j].name] = dist
+ graph[route_nodes[j].name][route_nodes[i].name] = dist
+ #}
+ #}
+
+ return graph
+#}
+
+def cv_draw_route( route, route_nodes ):
+#{
+ pole = Vector((0.2,0.2,10))
+ hat = Vector((1,8,0.2))
+ cc = route.SR_data.ent_route[0].colour
+
+ cv_draw_ucube(route.matrix_world,cc,Vector((0.5,-7.5,6)),\
+ Vector((0,-6.5,5.5)))
+ cv_draw_ucube(route.matrix_world,cc,pole, Vector(( 0.5, 0.5,0)) )
+ cv_draw_ucube(route.matrix_world,cc,pole, Vector(( 0.5,-13.5,0)) )
+ cv_draw_ucube(route.matrix_world,cc,hat, Vector((-0.5,-6.5, 12)) )
+ cv_draw_ucube(route.matrix_world,cc,hat, Vector((-0.5,-6.5,-1)) )
+
+ checkpoints = route.SR_data.ent_route[0].gates
+ graph = node_graph( route_nodes )
+
+ for i in range(len(checkpoints)):#{
+ gi = checkpoints[i].target
+ gj = checkpoints[(i+1)%len(checkpoints)].target
+
+ if gi:#{
+ dest = gi.SR_data.ent_gate[0].target
+ if dest:
+ cv_draw_line_dotted( gi.location, dest.location, cc )
+ gi = dest
+ #}
+
+ if gi==gj: continue # error?
+ if not gi or not gj: continue
+
+ path = dijkstra( graph, gj.name, gi.name )
+
+ if path:#{
+ for sj in range(len(path)-1):#{
+ o0 = bpy.data.objects[ path[sj] ]
+ o1 = bpy.data.objects[ path[sj+1] ]
+ cv_draw_arrow(o0.location,o1.location,cc,1.5)
+ #}
+ #}
+ else:#{
+ cv_draw_line_dotted( gi.location, gj.location, cc )
+ #}
+ #}
+#}
+
+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 = []