Plugins mamagement
This commit is contained in:
parent
9ecee93b43
commit
c27151ec62
38 changed files with 3934 additions and 550 deletions
706
plugins/VJing/bank0.py
Normal file
706
plugins/VJing/bank0.py
Normal file
|
|
@ -0,0 +1,706 @@
|
|||
#!/usr/bin/python2.7
|
||||
# -*- coding: utf-8 -*-
|
||||
# -*- mode: Python -*-
|
||||
|
||||
'''
|
||||
VJing Bank 0
|
||||
|
||||
was Franken for compo laser at coockie 2018 demoparty
|
||||
|
||||
0 : many Starfields
|
||||
1 : generic pose animations
|
||||
2 : Faces
|
||||
3 : Dancers
|
||||
|
||||
LICENCE : CC
|
||||
Sam Neurohack, Loloster,
|
||||
|
||||
'''
|
||||
|
||||
|
||||
import math
|
||||
#import gstt
|
||||
#from globalVars import *
|
||||
import numpy as np
|
||||
import pdb
|
||||
from datetime import datetime
|
||||
from random import randrange
|
||||
import redis
|
||||
import lj3
|
||||
import sys,time
|
||||
|
||||
from osc4py3.as_eventloop import *
|
||||
from osc4py3 import oscbuildparse
|
||||
#from osc4py3 import oscmethod as osm
|
||||
from osc4py3.oscmethod import *
|
||||
import argparse
|
||||
|
||||
#f_sine = 0
|
||||
|
||||
|
||||
screen_size = [400,400]
|
||||
xy_center = [screen_size[0]/2,screen_size[1]/2]
|
||||
|
||||
message = "Hello"
|
||||
OSCinPort = 8010
|
||||
|
||||
redisIP = '127.0.0.1'
|
||||
ljclient = 0
|
||||
|
||||
print ("")
|
||||
print ("Arguments parsing if needed...")
|
||||
argsparser = argparse.ArgumentParser(description="VJ Bank 0 for LJ")
|
||||
argsparser.add_argument("-r","--redisIP",help="IP of the Redis server used by LJ (127.0.0.1 by default) ",type=str)
|
||||
argsparser.add_argument("-c","--client",help="LJ client number (0 by default)",type=int)
|
||||
argsparser.add_argument("-v","--verbose",help="Verbosity level (0 by default)",type=int)
|
||||
|
||||
args = argsparser.parse_args()
|
||||
|
||||
|
||||
if args.verbose:
|
||||
debug = args.verbose
|
||||
else:
|
||||
debug = 0
|
||||
|
||||
if args.client:
|
||||
ljclient = args.client
|
||||
else:
|
||||
ljclient = 0
|
||||
|
||||
# Redis Computer IP
|
||||
if args.redisIP != None:
|
||||
redisIP = args.redisIP
|
||||
else:
|
||||
redisIP = '127.0.0.1'
|
||||
|
||||
|
||||
lj3.Config(redisIP,ljclient)
|
||||
|
||||
def OSCljclient(value):
|
||||
# Will receive message address, and message data flattened in s, x, y
|
||||
print("I got /bank0/ljclient with value", value)
|
||||
ljclient = value
|
||||
lj3.LjClient(ljclient)
|
||||
|
||||
def hex2rgb(hexcode):
|
||||
return tuple(map(ord,hexcode[1:].decode('hex')))
|
||||
|
||||
|
||||
def rgb2hex(rgb):
|
||||
return int('0x%02x%02x%02x' % tuple(rgb),0)
|
||||
|
||||
|
||||
|
||||
# Curve 0 many starfields
|
||||
def prepareSTARFIELD():
|
||||
global star, stars0, stars1, stars2, starfieldcount, starspeed, displayedstars, displayedstars, num_stars, max_depth
|
||||
|
||||
stars0=[]
|
||||
stars1=[]
|
||||
stars2=[]
|
||||
#stars3=[]
|
||||
num_stars = 50
|
||||
max_depth = 20
|
||||
stars = []
|
||||
starfieldcount = 0
|
||||
displayedstars = 5
|
||||
starspeed = 0.05
|
||||
|
||||
for i in range(num_stars):
|
||||
# A star is represented as a list with this format: [X,Y,Z]
|
||||
star = [randrange(-25,25), randrange(-25,25), randrange(1, max_depth)]
|
||||
stars0.append(star)
|
||||
star = [randrange(-25,25), randrange(-25,25), randrange(1, max_depth)]
|
||||
stars1.append(star)
|
||||
star = [randrange(-25,25), randrange(-25,25), randrange(1, max_depth)]
|
||||
stars2.append(star)
|
||||
|
||||
def Starfield(hori=0,verti=0):
|
||||
global star, stars0, stars1, stars2, starfieldcount, starspeed, displayedstars, displayedstars, num_stars, max_depth
|
||||
|
||||
starfieldcount += 1
|
||||
#print starfieldcount
|
||||
starpoints = []
|
||||
|
||||
# Move starfield according to joypads. Not used in the demo
|
||||
'''
|
||||
# Tflight joystick :
|
||||
# y axis 1 top -1 bottom 1
|
||||
# x axis 0 left -1 right 1
|
||||
# Main fire button 5
|
||||
# hat (x,y) x -1 left x 1 right y -1 bottom y 1 top
|
||||
# speed axis 3 backward 1 forward -1
|
||||
|
||||
if Nbpads > 0:
|
||||
# Move center on X axis according to pad
|
||||
if pad1.get_axis(0)<-0.1 or pad1.get_axis(0)>0.1:
|
||||
hori = pad1.get_axis(0)
|
||||
#print hori
|
||||
# Move center on Y axis according to pad
|
||||
if pad1.get_axis(1)<-0.1 or pad1.get_axis(1)>0.1:
|
||||
verti= pad1.get_axis(1)
|
||||
#print verti
|
||||
'''
|
||||
|
||||
#print displayedstars, 'stars displayed'
|
||||
|
||||
# Increase number of
|
||||
if displayedstars < num_stars and starfieldcount % 15 == 0:
|
||||
displayedstars += 1
|
||||
|
||||
if displayedstars == num_stars and starfieldcount % 10 == 0:
|
||||
starspeed += 0.005
|
||||
|
||||
#if Nbpads > 0:
|
||||
# starspeed = (1-pad1.get_axis(3))
|
||||
|
||||
#print starspeed
|
||||
|
||||
for starnumber in range(0,displayedstars):
|
||||
|
||||
# The Z component is decreased on each frame.
|
||||
stars0[starnumber][2] -= starspeed * 3
|
||||
stars1[starnumber][2] -= starspeed * 3
|
||||
stars2[starnumber][2] -= starspeed * 3
|
||||
|
||||
# If the star has past the screen (I mean Z<=0) then we
|
||||
# reposition it far away from the screen (Z=max_depth)
|
||||
# with random X and Y coordinates.
|
||||
if stars0[starnumber][2] <= 0:
|
||||
stars0[starnumber][0] = randrange(-25,25)
|
||||
stars0[starnumber][1] = randrange(-25,25)
|
||||
stars0[starnumber][2] = max_depth
|
||||
|
||||
if stars1[starnumber][2] <= 0:
|
||||
stars1[starnumber][0] = randrange(-25,25)
|
||||
stars1[starnumber][1] = randrange(-25,25)
|
||||
stars1[starnumber][2] = max_depth
|
||||
|
||||
if stars2[starnumber][2] <= 0:
|
||||
stars2[starnumber][0] = randrange(-25,25)
|
||||
stars2[starnumber][1] = randrange(-25,25)
|
||||
stars2[starnumber][2] = max_depth
|
||||
|
||||
|
||||
# Convert the 3D coordinates to 2D using perspective projection.
|
||||
k0 = 128.0 / stars0[starnumber][2]
|
||||
k1 = 128.0 / stars1[starnumber][2]
|
||||
k2 = 128.0 / stars2[starnumber][2]
|
||||
|
||||
# Move Starfield origin.
|
||||
# if stars xpos/ypos is same sign (i.e left stars xpos is <0) than (joystick or code) acceleration (hori and verti moves the star field origin)
|
||||
if np.sign(stars0[starnumber][0]) == np.sign(hori):
|
||||
x0 = int(stars0[starnumber][0] * k0 + xy_center[0] + (hori*600))
|
||||
else:
|
||||
x0 = int(stars0[starnumber][0] * k0 + xy_center[0] + (hori*300))
|
||||
|
||||
if np.sign(stars0[starnumber][1]) == np.sign(verti):
|
||||
y0 = int(stars0[starnumber][1] * k0 + xy_center[1] + (verti*600))
|
||||
else:
|
||||
y0 = int(stars0[starnumber][1] * k0 + xy_center[1] + (verti*300))
|
||||
|
||||
|
||||
if np.sign(stars1[starnumber][0]) == np.sign(hori):
|
||||
x1 = int(stars1[starnumber][0] * k1 + xy_center[0] + (hori*600))
|
||||
else:
|
||||
x1 = int(stars1[starnumber][0] * k1 + xy_center[0] + (hori*300))
|
||||
|
||||
if np.sign(stars1[starnumber][1]) == np.sign(verti):
|
||||
y1 = int(stars1[starnumber][1] * k1 + xy_center[1] + (verti*600))
|
||||
else:
|
||||
y1 = int(stars1[starnumber][1] * k1 + xy_center[1] + (verti*300))
|
||||
|
||||
|
||||
if np.sign(stars2[starnumber][0]) == np.sign(hori):
|
||||
x2 = int(stars2[starnumber][0] * k2 + xy_center[0] + (hori*600))
|
||||
else:
|
||||
x2 = int(stars2[starnumber][0] * k2 + xy_center[0] + (hori*300))
|
||||
|
||||
if np.sign(stars2[starnumber][1]) == np.sign(verti):
|
||||
y2 = int(stars2[starnumber][1] * k2 + xy_center[1] + (verti*600))
|
||||
else:
|
||||
y2 = int(stars2[starnumber][1] * k2 + xy_center[1] + (verti*300))
|
||||
|
||||
|
||||
# Add star to pointlist PL 0
|
||||
if 0 <= x0 < screen_size[0] - 2 and 0 <= y0 < screen_size[1] - 2:
|
||||
#f.LineTo((x,y), 0x80000000)
|
||||
lj3.PolyLineOneColor([(x0,y0),((x0+1),(y0+1))], c = rgb2hex([255,255,255]), PL = 0, closed = False)
|
||||
#fwork.PolyLineOneColor([(x0,y0),((x0+1),(y0+1))], c=rgb2hex([255,255,255]), PL = 0, closed = False)
|
||||
|
||||
# Add star to pointlist PL 1
|
||||
if 0 <= x1 < screen_size[0] - 2 and 0 <= y1 < screen_size[1] - 2:
|
||||
lj3.PolyLineOneColor([(x1,y1),((x1+1),(y1+1))], c = rgb2hex([255,255,255]), PL = 0, closed = False)
|
||||
|
||||
#fwork.PolyLineOneColor([(x1,y1),((x1+1),(y1+1))], c=rgb2hex([255,255,255]), PL = 1, closed = False)
|
||||
|
||||
# Add star to pointlist PL 2
|
||||
#if 0 <= x2 < screen_size[0] - 2 and 0 <= y2 < screen_size[1] - 2:
|
||||
# fwork.PolyLineOneColor([(x2,y2),((x2+1),(y2+1))], c=colorify.rgb2hex([255,255,255]), PL = 2, closed = False)
|
||||
# #f.PolyLineOneColor([(x,y),((x+2),(y+2))], COLOR_WHITE)
|
||||
|
||||
'''
|
||||
if starfieldcount < 200:
|
||||
|
||||
if 0 <= x3 < screen_size[0] - 2 and 0 <= y3 < screen_size[1] - 2:
|
||||
fwork.PolyLineOneColor([(x3,y3),((x3+2),(y3+2))], c=colorify.rgb2hex([255,255,255]), PL = 3, closed = False)
|
||||
'''
|
||||
|
||||
|
||||
lj3.Text(message, color, PL = 2, xpos = 300, ypos = 300, resize = 1, rotx =0, roty =0 , rotz=0)
|
||||
lj3.DrawPL(0)
|
||||
lj3.DrawPL(1)
|
||||
lj3.DrawPL(2)
|
||||
#lj3.DrawPL(3)
|
||||
|
||||
|
||||
# Curve 1 : generic pose animations
|
||||
import json
|
||||
CurrentPose = 1
|
||||
|
||||
# get absolute body position points
|
||||
def getCOCO(pose_json,pose_points, people):
|
||||
|
||||
dots = []
|
||||
for dot in pose_points:
|
||||
if len(pose_json['part_candidates'][people][str(dot)]) != 0:
|
||||
dots.append((pose_json['part_candidates'][people][str(dot)][0], pose_json['part_candidates'][people][str(dot)][1]))
|
||||
return dots
|
||||
|
||||
|
||||
# get relative (-1 0 1) body position points. a position -1, -1 means doesn't exist
|
||||
def getBODY(pose_json,pose_points, people):
|
||||
|
||||
dots = []
|
||||
for dot in pose_points:
|
||||
#print pose_points
|
||||
if len(pose_json['people'][people]['pose_keypoints_2d']) != 0:
|
||||
#print "people 0"
|
||||
if pose_json['people'][people]['pose_keypoints_2d'][dot * 3] != -1 and pose_json['people'][people]['pose_keypoints_2d'][(dot * 3)+1] != -1:
|
||||
dots.append((pose_json['people'][people]['pose_keypoints_2d'][dot * 3], pose_json['people'][people]['pose_keypoints_2d'][(dot * 3)+1]))
|
||||
return dots
|
||||
|
||||
|
||||
# get absolute face position points
|
||||
def getFACE(pose_json,pose_points, people):
|
||||
|
||||
dots = []
|
||||
for dot in pose_points:
|
||||
|
||||
if len(pose_json['people'][people]['face_keypoints_2d']) != 0:
|
||||
#print "people 0"
|
||||
if pose_json['people'][people]['face_keypoints_2d'][dot * 3] != -1 and pose_json['people'][people]['face_keypoints_2d'][(dot * 3)+1] != -1:
|
||||
dots.append((pose_json['people'][people]['face_keypoints_2d'][dot * 3], pose_json['people'][people]['face_keypoints_2d'][(dot * 3)+1]))
|
||||
|
||||
return dots
|
||||
|
||||
|
||||
# Body parts
|
||||
def bodyCOCO(pose_json, people):
|
||||
pose_points = [10,9,8,1,11,12,13]
|
||||
return getBODY(pose_json,pose_points, people)
|
||||
|
||||
def armCOCO(pose_json, people):
|
||||
pose_points = [7,6,5,1,2,3,4]
|
||||
return getBODY(pose_json,pose_points, people)
|
||||
|
||||
def headCOCO(pose_json, people):
|
||||
pose_points = [1,0]
|
||||
return getBODY(pose_json,pose_points, people)
|
||||
|
||||
|
||||
# Face keypoints
|
||||
def face(pose_json, people):
|
||||
pose_points = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]
|
||||
return getFACE(pose_json,pose_points, people)
|
||||
|
||||
def browL(pose_json, people):
|
||||
pose_points = [26,25,24,23,22]
|
||||
return getFACE(pose_json,pose_points, people)
|
||||
|
||||
def browR(pose_json, people):
|
||||
pose_points = [21,20,19,18,17]
|
||||
return getFACE(pose_json,pose_points, people)
|
||||
|
||||
def eyeR(pose_json, people):
|
||||
pose_points = [36,37,38,39,40,41,36]
|
||||
return getFACE(pose_json,pose_points, people)
|
||||
|
||||
def eyeL(pose_json, people):
|
||||
pose_points = [42,43,44,45,46,47,42]
|
||||
return getFACE(pose_json,pose_points, people)
|
||||
|
||||
def nose(pose_json, people):
|
||||
pose_points = [27,28,29,30]
|
||||
return getFACE(pose_json,pose_points, people)
|
||||
|
||||
def mouth(pose_json, people):
|
||||
pose_points = [48,59,58,57,56,55,54,53,52,51,50,49,48,60,67,66,65,64,63,62,61,60]
|
||||
return getFACE(pose_json,pose_points, people)
|
||||
|
||||
import os
|
||||
|
||||
|
||||
# Get frame number for pose path describe in PoseDir
|
||||
def lengthPOSE(pose_dir):
|
||||
|
||||
if debug > 0:
|
||||
print("Check directory",'poses/' + pose_dir)
|
||||
if os.path.exists('poses/' + pose_dir):
|
||||
numfiles = sum(1 for f in os.listdir('poses/' + pose_dir) if os.path.isfile(os.path.join('poses/' + pose_dir + '/', f)) and f[0] != '.')
|
||||
if debug > 0:
|
||||
print(numfiles,"images")
|
||||
return numfiles
|
||||
else:
|
||||
if debug > 0:
|
||||
print("but it doesn't even exist!")
|
||||
return 0
|
||||
|
||||
def preparePOSE():
|
||||
global anims0, anims1, anims2
|
||||
|
||||
# anim format (name, xpos,ypos, resize, currentframe, totalframe, count, speed)
|
||||
# total frames is fetched from directory file count
|
||||
|
||||
anims1 = [['sky',50,100,300,0,0,0,1],['2dancer1', 400,100, 300,0,0,0,1],['1dancer', 400,100, 300,0,0,0,1],['window1',100,100,300,0,0,0,1]]
|
||||
anims2 = [['window1', 400,200, 300,0,0,0,1],['2dancer1',100,200,300,0,0,0,1]]
|
||||
|
||||
for anim in anims1:
|
||||
anim[5]= lengthPOSE(anim[0])
|
||||
anims0 = anims1
|
||||
|
||||
|
||||
# display n pose animations on Laser 0
|
||||
def Pose():
|
||||
global anims0, anims1, anims2
|
||||
|
||||
for anim in anims0:
|
||||
PL = 0
|
||||
dots = []
|
||||
print(anim, anim[5])
|
||||
# repeat anim[7] time the same frame
|
||||
anim[6] +=1
|
||||
if anim[6] == anim[7]:
|
||||
|
||||
anim[6] = 0
|
||||
# increase current frame and compare to total frame
|
||||
anim[4] += 1
|
||||
if anim[4] == anim[5]:
|
||||
anim[4] = 0
|
||||
|
||||
|
||||
posename = 'poses/' + anim[0] + '/' + anim[0] +'-'+str("%05d"%anim[4])+'.json'
|
||||
posefile = open(posename , 'r')
|
||||
posedatas = posefile.read()
|
||||
pose_json = json.loads(posedatas)
|
||||
|
||||
for people in range(len(pose_json['people'])):
|
||||
|
||||
lj3.rPolyLineOneColor(bodyCOCO(pose_json, people), c=color, PL = 0, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3])
|
||||
lj3.rPolyLineOneColor(armCOCO(pose_json, people), c=color, PL = 0, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3])
|
||||
lj3.rPolyLineOneColor(headCOCO(pose_json, people), c=color, PL = 0, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3])
|
||||
|
||||
# Face
|
||||
'''
|
||||
#lj3.rPolyLineOneColor(face(pose_json, people), c=color, PL = 0, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3])
|
||||
lj3.rPolyLineOneColor(browL(pose_json, people), c=color, PL = 0, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3])
|
||||
lj3.rPolyLineOneColor(browR(pose_json, people), c=color, PL = 0, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3])
|
||||
lj3.rPolyLineOneColor(eyeR(pose_json, people), c=color, PL = 0, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3])
|
||||
lj3.rPolyLineOneColor(eyeL(pose_json, people), c=color, PL = 0, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3])
|
||||
lj3.rPolyLineOneColor(nose(pose_json, people), c=color, PL = 0, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3])
|
||||
lj3.rPolyLineOneColor(mouth(pose_json, people), c=color, PL = 0, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3])
|
||||
'''
|
||||
|
||||
lj3.DrawPL(PL)
|
||||
time.sleep(0.02)
|
||||
|
||||
|
||||
# decrease current frame
|
||||
if keystates[pygame.K_w]: # and not keystates_prev[pygame.K_w]:
|
||||
CurrentPose -= 1
|
||||
if CurrentPose < 2:
|
||||
CurrentPose = numfiles -1
|
||||
#time.sleep(0.033)
|
||||
print("Frame : ",CurrentPose)
|
||||
|
||||
# increaser current frame
|
||||
if keystates[pygame.K_x]: # and not keystates_prev[pygame.K_x]:
|
||||
CurrentPose += 1
|
||||
if CurrentPose > numfiles -1:
|
||||
CurrentPose = 1
|
||||
#time.sleep(0.033)
|
||||
print("Frame : ",CurrentPose)
|
||||
|
||||
|
||||
|
||||
# Curve 2 Faces
|
||||
import json
|
||||
CurrentPose = 1
|
||||
|
||||
def prepareFACES():
|
||||
|
||||
|
||||
# anim format (name, xpos,ypos, resize, currentframe, totalframe, count, speed)
|
||||
# total frame is fetched from directory file count
|
||||
|
||||
anims[0] = [['detroit1', 300,300, 100,0,0,0,1]]
|
||||
anims[1] = [['detroit1', 400,200, 200,0,0,0,1]]
|
||||
anims[2] = [['detroit1', 500,200, 300,0,0,0,1]]
|
||||
|
||||
'''
|
||||
# read anims number of frames from disk.
|
||||
for anim in range(len(anims0)):
|
||||
anims0[anim][5]= lengthPOSE(anims0[anim][0])
|
||||
for anim in range(len(anims1)):
|
||||
anims1[anim][5]= lengthPOSE(anims1[anim][0])
|
||||
for anim in range(len(anims2)):
|
||||
anims2[anim][5]= lengthPOSE(anims2[anim][0])
|
||||
'''
|
||||
|
||||
#replace code below
|
||||
'''
|
||||
for laseranims in range(3):
|
||||
if debug > 0:
|
||||
print "anims:",anims[laseranims],
|
||||
for anim in range(len(anims[laseranims])):
|
||||
anims[laseranims][anim][5]= lengthPOSE(anims[laseranims][anim][0])
|
||||
if debug > 1:
|
||||
print anims[laseranims][anim][5]
|
||||
'''
|
||||
#by this one
|
||||
#thanks to https://stackoverflow.com/questions/19184335/is-there-a-need-for-rangelena
|
||||
|
||||
for laseranims in anims:
|
||||
if debug > 1:
|
||||
print("anims:",laseranims)
|
||||
for anim in laseranims:
|
||||
anim[5]=lengthPOSE(anim[0])
|
||||
if debug > 1:
|
||||
print(anim[5])
|
||||
|
||||
|
||||
|
||||
# display the face animation describe in PoseDir
|
||||
def Faces():
|
||||
|
||||
for laseranims in range(3):
|
||||
for anim in anims[laseranims]:
|
||||
PL = laseranims
|
||||
#print PL, anim
|
||||
dots = []
|
||||
#print anim, anim[5]
|
||||
# repeat anim[7] time the same frame
|
||||
anim[6] +=1
|
||||
if anim[6] == anim[7]:
|
||||
|
||||
anim[6] = 0
|
||||
# increase current frame and compare to total frame
|
||||
anim[4] += 1
|
||||
if anim[4] == anim[5]:
|
||||
anim[4] = 0
|
||||
|
||||
|
||||
posename = 'poses/' + anim[0] + '/' + anim[0] +'-'+str("%05d"%anim[4])+'.json'
|
||||
posefile = open(posename , 'r')
|
||||
posedatas = posefile.read()
|
||||
pose_json = json.loads(posedatas)
|
||||
|
||||
# Face
|
||||
|
||||
for people in range(len(pose_json['people'])):
|
||||
|
||||
#lj3.PolyLineOneColor(face(pose), c=color, PL = 0, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3])
|
||||
lj3.rPolyLineOneColor(browL(pose_json, people), c=color, PL = laseranims, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3])
|
||||
lj3.rPolyLineOneColor(browR(pose_json, people), c=color, PL = laseranims, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3])
|
||||
lj3.rPolyLineOneColor(eyeR(pose_json, people), c=color, PL = laseranims, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3])
|
||||
lj3.rPolyLineOneColor(eyeL(pose_json, people), c=color, PL = laseranims, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3])
|
||||
lj3.rPolyLineOneColor(nose(pose_json, people), c=color, PL = laseranims, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3])
|
||||
lj3.rPolyLineOneColor(mouth(pose_json, people), c=color, PL = laseranims, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3])
|
||||
|
||||
lj3.DrawPL(PL)
|
||||
time.sleep(0.02)
|
||||
|
||||
# Curve 3
|
||||
# Dancers
|
||||
import json
|
||||
CurrentPose = 1
|
||||
|
||||
def prepareDANCERS():
|
||||
|
||||
# anim format (name, xpos,ypos, resize, currentframe, totalframe, count, speed)
|
||||
# total frame is fetched from directory file count
|
||||
|
||||
anims[0] = [['1dancer',500,200,300,0,0,0,10]]
|
||||
anims[1] = [['2dancer1',500,200,300,0,0,0,10]]
|
||||
anims[2] = [['window1',500,200,300,0,0,0,10]]
|
||||
#anims[1] = [['2dancer1',100,200,300,0,0,0,10]]
|
||||
#anims[2] = [['window1',400,200, 300,0,0,0,10]]
|
||||
# read anims number of frames from disk.
|
||||
|
||||
for laseranims in range(3):
|
||||
for anim in range(len(anims[laseranims])):
|
||||
anims[laseranims][anim][5]= lengthPOSE(anims[laseranims][anim][0])
|
||||
|
||||
# display the pose animation describe in PoseDir
|
||||
def Dancers():
|
||||
|
||||
for laseranims in range(3):
|
||||
|
||||
for anim in anims[laseranims]:
|
||||
PL = laseranims
|
||||
#print PL, anim
|
||||
dots = []
|
||||
#print anim, anim[5]
|
||||
# repeat anim[7] time the same frame
|
||||
anim[6] +=1
|
||||
if anim[6] == anim[7]:
|
||||
|
||||
anim[6] = 0
|
||||
# increase current frame and compare to total frame
|
||||
anim[4] += 1
|
||||
if anim[4] == anim[5]:
|
||||
anim[4] = 0
|
||||
|
||||
|
||||
#bhorosc.sendresol("/layer1/clip1/connect",1)
|
||||
#bhorosc.sendresol("/layer1/clip1/connect",0)
|
||||
|
||||
posename = 'poses/' + anim[0] + '/' + anim[0] +'-'+str("%05d"%anim[4])+'.json'
|
||||
posefile = open(posename , 'r')
|
||||
posedatas = posefile.read()
|
||||
pose_json = json.loads(posedatas)
|
||||
|
||||
|
||||
for people in range(len(pose_json['people'])):
|
||||
lj3.rPolyLineOneColor(bodyCOCO(pose_json, people), c=color, PL = laseranims, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3])
|
||||
lj3.rPolyLineOneColor(armCOCO(pose_json, people), c=color, PL = laseranims, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3])
|
||||
|
||||
lj3.rPolyLineOneColor(browL(pose_json, people), c=color, PL = laseranims, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3])
|
||||
lj3.rPolyLineOneColor(browR(pose_json, people), c=color, PL = laseranims, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3])
|
||||
lj3.rPolyLineOneColor(eyeR(pose_json, people), c=color, PL = laseranims, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3])
|
||||
lj3.rPolyLineOneColor(eyeL(pose_json, people), c=color, PL = laseranims, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3])
|
||||
lj3.rPolyLineOneColor(nose(pose_json, people), c=color, PL = laseranims, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3])
|
||||
lj3.rPolyLineOneColor(mouth(pose_json, people), c=color, PL = laseranims, closed = False,xpos = anim[1], ypos = anim[2], resize = anim[3])
|
||||
|
||||
|
||||
lj3.DrawPL(PL)
|
||||
|
||||
'''
|
||||
lj3.PolyLineOneColor(bodyCOCO(pose_json), c=color, PL = 0, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3])
|
||||
lj3.PolyLineOneColor(armCOCO(pose_json), c=color, PL = 0, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3])
|
||||
lj3.PolyLineOneColor(headCOCO(pose_json), c=color, PL = 0, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3])
|
||||
|
||||
|
||||
PL[PL] = fwork.LinesPL(PL)
|
||||
'''
|
||||
|
||||
def OSCljclient(value):
|
||||
# Will receive message address, and message data flattened in s, x, y
|
||||
print("I got /bank0/ljclient with value", value)
|
||||
ljclient = value
|
||||
lj3.LjClient(ljclient)
|
||||
|
||||
|
||||
# Dancers, Starfield, Pose, Face
|
||||
def OSCrun(value):
|
||||
# Will receive message address, and message data flattened in s, x, y
|
||||
print("I got /run with value", value)
|
||||
doit = value
|
||||
|
||||
|
||||
def WebStatus(message):
|
||||
lj3.Send("/status",message)
|
||||
|
||||
|
||||
#doit = Starfield
|
||||
doit = Pose
|
||||
#doit = Faces
|
||||
#doit = Dancers
|
||||
|
||||
print('Loading Bank0...')
|
||||
|
||||
WebStatus("Load Bank0")
|
||||
|
||||
# OSC Server callbacks
|
||||
print("Starting OSC at 127.0.0.1 port",OSCinPort,"...")
|
||||
osc_startup()
|
||||
osc_udp_server("127.0.0.1", OSCinPort, "InPort")
|
||||
|
||||
osc_method("/bank0/run*", OSCrun)
|
||||
osc_method("/bank0/ping*", lj3.OSCping)
|
||||
osc_method("/bank0/ljclient", OSCljclient)
|
||||
|
||||
|
||||
import pygame
|
||||
pygame.init()
|
||||
Nbpads = pygame.joystick.get_count()
|
||||
print ("Joypads : ", str(Nbpads))
|
||||
|
||||
'''
|
||||
if Nbpads != 2:
|
||||
|
||||
print ('')
|
||||
print ('')
|
||||
print ("THIS VERSION NEEDS 2 PADS. PLEASE CONNECT THEM.")
|
||||
print ('')
|
||||
sys.exit()
|
||||
'''
|
||||
|
||||
|
||||
if Nbpads > 1:
|
||||
|
||||
pad2 = pygame.joystick.Joystick(1)
|
||||
pad2.init()
|
||||
print ("Pad2 :", pad2.get_name())
|
||||
numButtons = pad2.get_numbuttons()
|
||||
#print ("Axis Pad 2 :", str(pad2.get_numaxes()))
|
||||
#print ("Buttons Pad 2 :" , str(numButtons))
|
||||
|
||||
# joy is pad abstraction to handle many different devices.
|
||||
joy2 = lj3.setup_controls(pad2)
|
||||
|
||||
if Nbpads > 0:
|
||||
|
||||
pad1 = pygame.joystick.Joystick(0)
|
||||
pad1.init()
|
||||
print ("Pad1 :",pad1.get_name())
|
||||
numButtons = pad1.get_numbuttons()
|
||||
joy1 = lj3.setup_controls(pad1)
|
||||
#print ("Axis Pad 1 :", str(pad1.get_numaxes()))
|
||||
#print ("Buttons Pad 1 :" , str(numButtons))
|
||||
|
||||
|
||||
|
||||
|
||||
anims =[[],[],[],[]]
|
||||
color = lj3.rgb2int(255,255,255)
|
||||
|
||||
prepareSTARFIELD()
|
||||
preparePOSE()
|
||||
prepareDANCERS()
|
||||
prepareFACES()
|
||||
|
||||
WebStatus("Bank0 ready.")
|
||||
print("Bank0 ready")
|
||||
|
||||
def Run():
|
||||
|
||||
try:
|
||||
while 1:
|
||||
#Starfield(hori=0,verti=0)
|
||||
doit()
|
||||
|
||||
except KeyboardInterrupt:
|
||||
pass
|
||||
|
||||
# Gently stop on CTRL C
|
||||
|
||||
finally:
|
||||
|
||||
WebStatus("Bank0 Exit")
|
||||
print("Stopping OSC...")
|
||||
lj3.OSCstop()
|
||||
|
||||
print ("Bank0 Stopped.")
|
||||
|
||||
Run()
|
||||
618
plugins/VJing/lj3.py
Normal file
618
plugins/VJing/lj3.py
Normal file
|
|
@ -0,0 +1,618 @@
|
|||
# coding=UTF-8
|
||||
|
||||
'''
|
||||
LJ v0.8.1 in python3
|
||||
Some LJ functions useful for python clients (was framy.py)
|
||||
|
||||
OSC functions commented, waiting working on OSC in python3
|
||||
|
||||
Config(redisIP, client number)
|
||||
PolyLineOneColor
|
||||
rPolyLineOneColor
|
||||
|
||||
Text(word, color, PL, xpos, ypos, resize, rotx, roty, rotz) : Display a word
|
||||
Send(adress,message) : remote control. See commands.py
|
||||
WebStatus(message) : display message on webui
|
||||
DrawPL(point list number) : once you stacked all wanted elements, like 2 polylines, send them to lasers.
|
||||
rgb2int(r,g,b)
|
||||
|
||||
OSCstart(): Start the OSC system.
|
||||
OSCframe():
|
||||
OSCstop(): Properly close the OSC system
|
||||
OSCping(value): Answer to LJ pings
|
||||
|
||||
setup_controls(joystick)
|
||||
|
||||
XboxController : getLeftHori, getLeftVert, getRightHori, getRightVert, getLeftTrigger, getRightTrigger
|
||||
Ps3Controller : getLeftHori, getLeftVert, getRightHori, getRightVert, getLeftTrigger, getRightTrigger, getUp, getDown, getLeft, getRight, getFire1, getFire2(self):
|
||||
MySaitekController : getLeftHori,getLeftVert, getRightHori,getRightVert, getLeftTrigger,getRightTrigger
|
||||
MyThrustController : getLeftHori, getLeftVert, getRightHori, getRightVert, getLeftTrigger, getRightTrigger
|
||||
CSLController : getLeftHori,getLeftVert,getRightHori, getRightVert,getLeftTrigger,getRightTrigger,getFire1,getFire2
|
||||
my USB Joystick : getUp,getDown,getLeft,getRight,etLeftTrigger, getRightTrigger,getFire1, getFire2
|
||||
|
||||
|
||||
LICENCE : CC
|
||||
Sam Neurohack
|
||||
|
||||
'''
|
||||
|
||||
import math
|
||||
import redis
|
||||
|
||||
# Import needed modules from osc4py3
|
||||
from osc4py3.as_eventloop import *
|
||||
from osc4py3 import oscbuildparse
|
||||
|
||||
|
||||
redisIP = '127.0.0.1'
|
||||
r = redis.StrictRedis(host=redisIP, port=6379, db=0)
|
||||
|
||||
ClientNumber = 0
|
||||
|
||||
point_list = []
|
||||
pl = [[],[],[],[]]
|
||||
|
||||
#
|
||||
# OSC interaction with LJ
|
||||
#
|
||||
|
||||
def OSCstart():
|
||||
# Start the system.
|
||||
osc_startup()
|
||||
#osc_udp_client(redisIP, 8002, "LJ 8002")
|
||||
|
||||
def OSCframe():
|
||||
#print("OSCprocess")
|
||||
osc_process()
|
||||
|
||||
# Properly close the system. Todo
|
||||
def OSCstop():
|
||||
osc_terminate()
|
||||
|
||||
|
||||
# Answer to LJ pings
|
||||
def OSCping(value):
|
||||
# Will receive message address, and message data flattened in s, x, y
|
||||
print("I got /ping with value", value)
|
||||
Send("/pong",value)
|
||||
|
||||
|
||||
def Send(oscaddress,oscargs=''):
|
||||
|
||||
try:
|
||||
msg = oscbuildparse.OSCMessage(oscaddress, None, [oscargs])
|
||||
osc_send(msg, "LJ 8002")
|
||||
OSCframe()
|
||||
|
||||
except:
|
||||
print ('Connection to LJ refused : died ?')
|
||||
pass
|
||||
'''
|
||||
def handlerfunction(s, x, y):
|
||||
# Will receive message data unpacked in s, x, y
|
||||
pass
|
||||
|
||||
def handlerfunction2(address, s, x, y):
|
||||
# Will receive message address, and message data flattened in s, x, y
|
||||
pass
|
||||
|
||||
# Make server channels to receive packets.
|
||||
osc_udp_server("127.0.0.1", 3721, "localhost")
|
||||
osc_udp_server("0.0.0.0", 3724, "anotherserver")
|
||||
'''
|
||||
|
||||
|
||||
|
||||
ASCII_GRAPHICS = [
|
||||
|
||||
# caracteres corrects
|
||||
|
||||
[(-50,30), (-30,-30), (30,-30), (10,30), (-50,30)], #0
|
||||
[(-20,30), (0,-30), (-20,30)], #1
|
||||
[(-30,-10), (0,-30), (30,-10), (30,0), (-30,30), (30,30)], #2
|
||||
[(-30,-30), (0,-30), (30,-10), (0,0), (30,10), (0,30), (-30,30)], #3
|
||||
[(30,10), (-30,10), (0,-30), (0,30)], #4
|
||||
[(30,-30), (-30,-30), (-30,0), (0,0), (30,10), (0,30), (-30,30)], #5
|
||||
[(30,-30), (0,-30), (-30,-10), (-30,30), (0,30), (30,10), (30,0), (-30,0)], #6
|
||||
[(-30,-30), (30,-30), (-30,30)], #7
|
||||
[(-30,30), (-30,-30), (30,-30), (30,30), (-30,30), (-30,0), (30,0)], #8
|
||||
[(30,0), (-30,0), (-30,-10), (0,-30), (30,-30), (30,10), (0,30), (-30,30)], #9
|
||||
|
||||
# caracteres a implementer
|
||||
[(-30,10), (30,-10), (30,10), (0,30), (-30,10), (-30,-10), (0,-30), (30,-10)], #:
|
||||
[(-30,-10), (0,-30), (0,30)], [(-30,30), (30,30)], #;
|
||||
[(-30,-10), (0,-30), (30,-10), (30,0), (-30,30), (30,30)], #<
|
||||
[(-30,-30), (0,-30), (30,-10), (0,0), (30,10), (0,30), (-30,30)], #=
|
||||
[(30,10), (-30,10), (0,-30), (0,30)], #>
|
||||
[(30,-30), (-30,-30), (-30,0), (0,0), (30,10), (0,30), (-30,30)], #?
|
||||
[(30,-30), (0,-30), (-30,-10), (-30,30), (0,30), (30,10), (30,0), (-30,0)], #@
|
||||
|
||||
# Caracteres corrects
|
||||
|
||||
|
||||
[(-30,30), (-30,-30), (30,-30), (30,30), (30,0), (-30,0)], #A
|
||||
[(-30,30), (-30,-30), (30,-30), (30,30), (30,0), (-30,0)], #A
|
||||
[(-30,30), (-30,-30), (30,-30), (30,30), (-30,30), (-30,0), (30,0)], #B
|
||||
[(30,30), (-30,30), (-30,-30), (30,-30)], #C
|
||||
[(-30,30), (-30,-30), (30,-30), (30,30), (-30,30)], #D
|
||||
[(30,30), (-30,30), (-30,-0), (30,0), (-30,0), (-30,-30), (30,-30)], #E
|
||||
[(-30,30), (-30,-0), (30,0), (-30,0), (-30,-30), (30,-30)], #F
|
||||
[(0,0), (30,0), (30,30), (-30,30), (-30,-30),(30,-30)], #G
|
||||
[(-30,-30), (-30,30), (-30,0), (30,0), (30,30), (30,-30)], #H
|
||||
[(0,30), (0,-30)], #I
|
||||
[(-30,30), (0,-30), (0,-30), (-30,-30), (30,-30)], #J
|
||||
[(-30,-30), (-30,30), (-30,0), (30,-30), (-30,0), (30,30)], #K
|
||||
[(30,30), (-30,30), (-30,-30)], #L
|
||||
[(-30,30), (-30,-30), (0,0), (30,-30), (30,30)], #M
|
||||
[(-30,30), (-30,-30), (30,30), (30,-30)], #N
|
||||
[(-30,30), (-30,-30), (30,-30), (30,30), (-30,30)], #O
|
||||
[(-30,0), (30,0), (30,-30), (-30,-30), (-30,30)], #P
|
||||
[(30,30), (30,-30), (-30,-30), (-30,30), (30,30),(35,35)], #Q
|
||||
[(-30,30), (-30,-30), (30,-30), (30,0), (-30,0), (30,30)], #R
|
||||
[(30,-30), (-30,-30), (-30,0), (30,0), (30,30), (-30,30)], #S
|
||||
[(0,30), (0,-30), (-30,-30), (30,-30)], #T
|
||||
[(-30,-30), (-30,30), (30,30), (30,-30)], #U
|
||||
[(-30,-30), (0,30), (30,-30)], #V
|
||||
[(-30,-30), (-30,30), (0,0), (30,30), (30,-30)], #W
|
||||
[(-30,30), (30,-30)], [(-30,-30), (30,30)], #X
|
||||
[(0,30), (0,0), (30,-30), (0,0), (-30,-30)], #Y
|
||||
[(30,30), (-30,30), (30,-30), (-30,-30)], #Z
|
||||
|
||||
# A implementer
|
||||
|
||||
[(-30,-10), (0,-30), (0,30)], [(-30,30), (30,30)], #[
|
||||
[(-30,-10), (0,-30), (30,-10), (30,0), (-30,30), (30,30)], #\
|
||||
[(-30,-30), (0,-30), (30,-10), (0,0), (30,10), (0,30), (-30,30)], #]
|
||||
[(30,10), (-30,10), (0,-30), (0,30)], #^
|
||||
[(30,-30), (-30,-30), (-30,0), (0,0), (30,10), (0,30), (-30,30)], #_
|
||||
[(30,-30), (0,-30), (-30,-10), (-30,30), (0,30), (30,10), (30,0), (-30,0)], #`
|
||||
|
||||
# Implementé
|
||||
|
||||
[(-20,20), (-20,-20), (20,-20), (20,20), (20,0), (-20,0)], #a
|
||||
[(-20,20), (-20,-20), (20,-20), (20,20), (-20,20), (-20,0), (20,0)], #b
|
||||
[(20,20), (-20,20), (-20,-20), (20,-20)], #c
|
||||
[(-20,20), (-20,-20), (20,-20), (20,20), (-20,20)], #d
|
||||
[(20,20), (-20,20), (-20,-0), (20,0), (-20,0), (-20,-20), (20,-20)], #e
|
||||
[(-20,20), (-20,-0), (20,0), (-20,0), (-20,-20), (20,-20)], #f
|
||||
[(0,0), (20,0), (20,20), (-20,20), (-20,-20),(20,-20)], #g
|
||||
[(-20,-20), (-20,20), (-20,0), (20,0), (20,20), (20,-20)], #H
|
||||
[(0,20), (0,-20)], #I
|
||||
[(-20,20), (0,-20), (0,-20), (-20,-20), (20,-20)], #J
|
||||
[(-20,-20), (-20,20), (-20,0), (20,-20), (-20,0), (20,20)], #K
|
||||
[(20,20), (-20,20), (-20,-20)], #L
|
||||
[(-20,20), (-20,-20), (0,0), (20,-20), (20,20)], #M
|
||||
[(-20,20), (-20,-20), (20,20), (20,-20)], #N
|
||||
[(-20,20), (-20,-20), (20,-20), (20,20), (-20,20)], #O
|
||||
[(-20,0), (20,0), (20,-20), (-20,-20), (-20,20)], #P
|
||||
[(20,20), (20,-20), (-20,-20), (-20,20), (20,20),(25,25)], #Q
|
||||
[(-20,20), (-20,-20), (20,-20), (20,0), (-20,0), (20,20)], #R
|
||||
[(20,-20), (-20,-20), (-20,0), (20,0), (20,20), (-20,20)], #S
|
||||
[(0,20), (0,-20), (-20,-20), (20,-20)], #T
|
||||
[(-20,-20), (-20,20), (20,20), (20,-20)], #U
|
||||
[(-20,-20), (0,20), (20,-20)], #V
|
||||
[(-20,-20), (-20,20), (0,0), (20,20), (20,-20)], #W
|
||||
[(-20,20), (20,-20)], [(-20,-20), (20,20)], #X
|
||||
[(0,20), (0,0), (20,-20), (0,0), (-20,-20)], #Y
|
||||
[(20,20), (-20,20), (20,-20), (-20,-20)], #Z
|
||||
|
||||
[(-2,15), (2,15)] # Point a la place de {
|
||||
]
|
||||
|
||||
def rgb2int(r,g,b):
|
||||
return int('0x%02x%02x%02x' % (r,g,b),0)
|
||||
|
||||
|
||||
def Config(redisIP,client):
|
||||
global ClientNumber
|
||||
|
||||
r = redis.StrictRedis(host=redisIP, port=6379, db=0)
|
||||
ClientNumber = client
|
||||
osc_udp_client(redisIP, 8002, "LJ 8002")
|
||||
|
||||
|
||||
def LjClient(client):
|
||||
global ClientNumber
|
||||
|
||||
ClientNumber = client
|
||||
|
||||
|
||||
|
||||
def LineTo(xy, c, PL):
|
||||
|
||||
pl[PL].append((xy + (c,)))
|
||||
|
||||
def Line(xy1, xy2, c, PL):
|
||||
LineTo(xy1, 0, PL)
|
||||
LineTo(xy2, c , PL)
|
||||
|
||||
|
||||
def PolyLineOneColor(xy_list, c, PL , closed ):
|
||||
#print "--"
|
||||
#print "c",c
|
||||
#print "xy_list",xy_list
|
||||
#print "--"
|
||||
xy0 = None
|
||||
for xy in xy_list:
|
||||
if xy0 is None:
|
||||
xy0 = xy
|
||||
#print "xy0:",xy0
|
||||
LineTo(xy0,0, PL)
|
||||
LineTo(xy0,c, PL)
|
||||
else:
|
||||
#print "xy:",xy
|
||||
LineTo(xy,c, PL)
|
||||
if closed:
|
||||
LineTo(xy0,c, PL)
|
||||
|
||||
|
||||
# Computing points coordinates for rPolyline function from 3D and around 0,0 to pygame coordinates
|
||||
def Pointransf(xy, xpos = 0, ypos =0, resize =1, rotx =0, roty =0 , rotz=0):
|
||||
|
||||
x = xy[0] * resize
|
||||
y = xy[1] * resize
|
||||
z = 0
|
||||
|
||||
rad = rotx * math.pi / 180
|
||||
cosaX = math.cos(rad)
|
||||
sinaX = math.sin(rad)
|
||||
|
||||
y2 = y
|
||||
y = y2 * cosaX - z * sinaX
|
||||
z = y2 * sinaX + z * cosaX
|
||||
|
||||
rad = roty * math.pi / 180
|
||||
cosaY = math.cos(rad)
|
||||
sinaY = math.sin(rad)
|
||||
|
||||
z2 = z
|
||||
z = z2 * cosaY - x * sinaY
|
||||
x = z2 * sinaY + x * cosaY
|
||||
|
||||
rad = rotz * math.pi / 180
|
||||
cosZ = math.cos(rad)
|
||||
sinZ = math.sin(rad)
|
||||
|
||||
x2 = x
|
||||
x = x2 * cosZ - y * sinZ
|
||||
y = x2 * sinZ + y * cosZ
|
||||
|
||||
#print xy, (x + xpos,y+ ypos)
|
||||
return (x + xpos,y+ ypos)
|
||||
'''
|
||||
to understand why it get negative Y
|
||||
|
||||
# 3D to 2D projection
|
||||
factor = 4 * gstt.cc[22] / ((gstt.cc[21] * 8) + z)
|
||||
print xy, (x * factor + xpos, - y * factor + ypos )
|
||||
return (x * factor + xpos, - y * factor + ypos )
|
||||
'''
|
||||
|
||||
# Send 2D point list around 0,0 with 3D rotation resizing and reposition around xpos ypos
|
||||
#def rPolyLineOneColor(self, xy_list, c, PL , closed, xpos = 0, ypos =0, resize =1, rotx =0, roty =0 , rotz=0):
|
||||
def rPolyLineOneColor(xy_list, c, PL , closed, xpos = 0, ypos =0, resize =0.7, rotx =0, roty =0 , rotz=0):
|
||||
xy0 = None
|
||||
for xy in xy_list:
|
||||
if xy0 is None:
|
||||
xy0 = xy
|
||||
LineTo(Pointransf(xy0, xpos, ypos, resize, rotx, roty, rotz),0, PL)
|
||||
LineTo(Pointransf(xy0, xpos, ypos, resize, rotx, roty, rotz),c, PL)
|
||||
else:
|
||||
LineTo(Pointransf(xy, xpos, ypos, resize, rotx, roty, rotz),c, PL)
|
||||
if closed:
|
||||
LineTo(Pointransf(xy0, xpos, ypos, resize, rotx, roty, rotz),c, PL)
|
||||
|
||||
|
||||
def LinesPL(PL):
|
||||
print ("Stupido !! your code is to old : use DrawPL() instead of LinesPL()")
|
||||
DrawPL(PL)
|
||||
|
||||
def DrawPL(PL):
|
||||
#print '/pl/0/'+str(PL), str(pl[PL])
|
||||
if r.set('/pl/'+str(ClientNumber)+'/'+str(PL), str(pl[PL])) == True:
|
||||
pl[PL] = []
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
def ResetPL(self, PL):
|
||||
pl[PL] = []
|
||||
|
||||
|
||||
|
||||
def DigitsDots(number,color):
|
||||
dots =[]
|
||||
for dot in ASCII_GRAPHICS[number]:
|
||||
#print dot
|
||||
dots.append((gstt.xy_center[0]+dot[0],gstt.xy_center[1]+dot[1],color))
|
||||
#self.point_list.append((xy + (c,)))
|
||||
return dots
|
||||
|
||||
def CharDots(char,color):
|
||||
|
||||
dots =[]
|
||||
for dot in ASCII_GRAPHICS[ord(char)-46]:
|
||||
dots.append((dot[0],dot[1],color))
|
||||
return dots
|
||||
|
||||
def Text(message,c, PL, xpos, ypos, resize, rotx, roty, rotz):
|
||||
|
||||
dots =[]
|
||||
|
||||
l = len(message)
|
||||
i= 0
|
||||
#print message
|
||||
|
||||
for ch in message:
|
||||
|
||||
#print ""
|
||||
# texte centre en x automatiquement selon le nombre de lettres l
|
||||
x_offset = 26 * (- (0.9*l) + 3*i)
|
||||
#print i,x_offset
|
||||
# if digit
|
||||
if ord(ch)<58:
|
||||
char_pl_list = ASCII_GRAPHICS[ord(ch) - 48]
|
||||
else:
|
||||
char_pl_list = ASCII_GRAPHICS[ord(ch) - 46 ]
|
||||
|
||||
char_draw = []
|
||||
#dots.append((char_pl_list[0][0] + x_offset,char_pl_list[0][1],0))
|
||||
|
||||
for xy in char_pl_list:
|
||||
char_draw.append((xy[0] + x_offset,xy[1],c))
|
||||
i +=1
|
||||
#print ch,char_pl_list,char_draw
|
||||
rPolyLineOneColor(char_draw, c, PL , False, xpos, ypos, resize, rotx, roty, rotz)
|
||||
#print ("laser",PL,"message",message)
|
||||
#dots.append(char_draw)
|
||||
|
||||
|
||||
|
||||
import re
|
||||
|
||||
def setup_controls(joystick):
|
||||
"""
|
||||
Joystick wrapper.
|
||||
"""
|
||||
if re.search('playstation', joystick.get_name(), re.I):
|
||||
return Ps3Controller(joystick)
|
||||
|
||||
elif re.search('X-box', joystick.get_name(), re.I):
|
||||
return XboxController(joystick)
|
||||
|
||||
elif re.search('Saitek', joystick.get_name(), re.I):
|
||||
return MySaitekController(joystick)
|
||||
|
||||
elif re.search('Thrustmaster dual analog 3.2', joystick.get_name(), re.I):
|
||||
return MyThrustController(joystick)
|
||||
|
||||
elif re.search('2n1 USB', joystick.get_name(), re.I):
|
||||
return CSLController(joystick)
|
||||
|
||||
elif re.search('Joystick', joystick.get_name(), re.I):
|
||||
return USBController(joystick)
|
||||
|
||||
return Controller(joystick)
|
||||
|
||||
class Controller(object):
|
||||
|
||||
def __init__(self, joystick):
|
||||
"""Pass a PyGame joystick instance."""
|
||||
self.js = joystick
|
||||
|
||||
def getLeftHori(self):
|
||||
return self.js.get_axis(2)
|
||||
|
||||
def getLeftVert(self):
|
||||
return self.js.get_axis(3)
|
||||
|
||||
def getRightHori(self):
|
||||
return self.js.get_axis(0)
|
||||
|
||||
def getRightVert(self):
|
||||
return self.js.get_axis(1)
|
||||
|
||||
def getLeftTrigger(self):
|
||||
return self.js.get_button(9)
|
||||
|
||||
def getRightTrigger(self):
|
||||
return self.js.get_button(2)
|
||||
|
||||
class XboxController(Controller):
|
||||
|
||||
def __init__(self, joystick):
|
||||
super(XboxController, self).__init__(joystick)
|
||||
|
||||
def getLeftHori(self):
|
||||
return self.js.get_axis(0)
|
||||
|
||||
def getLeftVert(self):
|
||||
return self.js.get_axis(1)
|
||||
|
||||
def getRightHori(self):
|
||||
return self.js.get_axis(3)
|
||||
|
||||
def getRightVert(self):
|
||||
return self.js.get_axis(4)
|
||||
|
||||
def getLeftTrigger(self):
|
||||
return self.js.get_axis(2)
|
||||
|
||||
def getRightTrigger(self):
|
||||
return self.js.get_button(11)
|
||||
|
||||
class Ps3Controller(Controller):
|
||||
|
||||
#up 4 _DOWN 6 left 7 right 5 croix 14 rond 13 triangle 12
|
||||
|
||||
def __init__(self, joystick):
|
||||
super(Ps3Controller, self).__init__(joystick)
|
||||
|
||||
def getLeftHori(self):
|
||||
return self.js.get_axis(0)
|
||||
|
||||
def getLeftVert(self):
|
||||
return self.js.get_axis(1)
|
||||
|
||||
def getRightHori(self):
|
||||
return self.js.get_axis(2)
|
||||
|
||||
def getRightVert(self):
|
||||
return self.js.get_axis(3)
|
||||
|
||||
def getLeftTrigger(self):
|
||||
# TODO: Verify
|
||||
return self.js.get_button(8)
|
||||
|
||||
def getRightTrigger(self):
|
||||
# TODO: Verify
|
||||
return self.js.get_button(9)
|
||||
|
||||
def getUp(self):
|
||||
return self.js.get_button(4)
|
||||
|
||||
def getDown(self):
|
||||
return self.js.get_button(6)
|
||||
|
||||
def getLeft(self):
|
||||
return self.js.get_button(7)
|
||||
|
||||
def getRight(self):
|
||||
return self.js.get_button(5)
|
||||
|
||||
def getFire1(self):
|
||||
return self.js.get_button(14)
|
||||
|
||||
def getFire2(self):
|
||||
return self.js.get_button(13)
|
||||
|
||||
|
||||
class MySaitekController(Controller):
|
||||
|
||||
def __init__(self, joystick):
|
||||
super(MySaitekController, self).__init__(joystick)
|
||||
|
||||
def getLeftHori(self):
|
||||
return self.js.get_axis(0)
|
||||
|
||||
def getLeftVert(self):
|
||||
return self.js.get_axis(1)
|
||||
|
||||
def getRightHori(self):
|
||||
return self.js.get_axis(3)
|
||||
|
||||
def getRightVert(self):
|
||||
return self.js.get_axis(2)
|
||||
|
||||
def getLeftTrigger(self):
|
||||
return self.js.get_button(6)
|
||||
|
||||
def getRightTrigger(self):
|
||||
return self.js.get_button(7)
|
||||
|
||||
class MyThrustController(Controller):
|
||||
|
||||
def __init__(self, joystick):
|
||||
super(MyThrustController, self).__init__(joystick)
|
||||
|
||||
def getLeftHori(self):
|
||||
return self.js.get_axis(0)
|
||||
|
||||
def getLeftVert(self):
|
||||
return self.js.get_axis(1)
|
||||
|
||||
def getRightHori(self):
|
||||
return self.js.get_axis(2)
|
||||
|
||||
def getRightVert(self):
|
||||
return self.js.get_axis(3)
|
||||
|
||||
def getLeftTrigger(self):
|
||||
return self.js.get_button(5)
|
||||
|
||||
def getRightTrigger(self):
|
||||
return self.js.get_button(7)
|
||||
|
||||
|
||||
class CSLController(Controller):
|
||||
|
||||
def __init__(self, joystick):
|
||||
super(CSLController, self).__init__(joystick)
|
||||
|
||||
def getLeftHori(self):
|
||||
return self.js.get_axis(2)
|
||||
|
||||
def getLeftVert(self):
|
||||
return self.js.get_axis(3)
|
||||
|
||||
def getRightHori(self):
|
||||
return self.js.get_axis(0)
|
||||
|
||||
def getRightVert(self):
|
||||
return self.js.get_axis(1)
|
||||
|
||||
def getLeftTrigger(self):
|
||||
return self.js.get_button(6)
|
||||
|
||||
def getRightTrigger(self):
|
||||
return self.js.get_button(7)
|
||||
|
||||
def getFire1(self):
|
||||
return self.js.get_button(2)
|
||||
|
||||
def getFire2(self):
|
||||
return self.js.get_button(1)
|
||||
|
||||
class USBController(Controller):
|
||||
|
||||
|
||||
# my USB Joystick
|
||||
#up axis 0 -1 DOWN axis 0 1 left axis 1 1 right axis 1 -1 bouton gauche 10 bouton droite 9
|
||||
|
||||
def __init__(self, joystick):
|
||||
super(USBController, self).__init__(joystick)
|
||||
|
||||
|
||||
def getUp(self):
|
||||
if self.js.get_axis(0) == -1:
|
||||
return 1
|
||||
else:
|
||||
return 0
|
||||
|
||||
def getDown(self):
|
||||
if self.js.get_axis(0) > 0.9:
|
||||
return 1
|
||||
else:
|
||||
return 0
|
||||
|
||||
def getLeft(self):
|
||||
if self.js.get_axis(1) == 1:
|
||||
return 1
|
||||
else:
|
||||
return 0
|
||||
|
||||
def getRight(self):
|
||||
if self.js.get_axis(1) == -1:
|
||||
return 1
|
||||
else:
|
||||
return 0
|
||||
|
||||
def getLeftTrigger(self):
|
||||
return self.js.get_button(10)
|
||||
|
||||
def getRightTrigger(self):
|
||||
return self.js.get_button(9)
|
||||
|
||||
def getFire1(self):
|
||||
if self.js.get_button(10) == 1:
|
||||
print ("fire 1")
|
||||
return self.js.get_button(10)
|
||||
|
||||
def getFire2(self):
|
||||
if self.js.get_button(9) == 1:
|
||||
print ("fire 2")
|
||||
return self.js.get_button(9)
|
||||
|
||||
|
||||
|
||||
|
||||
1
plugins/VJing/poses
Symbolic link
1
plugins/VJing/poses
Symbolic link
|
|
@ -0,0 +1 @@
|
|||
../../../LJay/poses
|
||||
598
plugins/VJing/poses.py
Normal file
598
plugins/VJing/poses.py
Normal file
|
|
@ -0,0 +1,598 @@
|
|||
#!/usr/bin/python2.7
|
||||
# -*- coding: utf-8 -*-
|
||||
# -*- mode: Python -*-
|
||||
|
||||
'''
|
||||
Laser Jaying
|
||||
|
||||
LICENCE : CC
|
||||
Sam Neurohack, Loloster,
|
||||
|
||||
Openpose json files animations
|
||||
|
||||
Set for amiral castle :
|
||||
|
||||
Curve 0 : Mapping
|
||||
Curve 1 : Pose align on Laser 0 for the moment
|
||||
Curve 2 : Faces
|
||||
Curve 3 : Dancers
|
||||
|
||||
'''
|
||||
|
||||
|
||||
import math
|
||||
import gstt
|
||||
from globalVars import *
|
||||
import bhoroscp
|
||||
import colorify
|
||||
import numpy as np
|
||||
import pdb
|
||||
import time
|
||||
from datetime import datetime
|
||||
import settings
|
||||
|
||||
|
||||
# For Mapping()
|
||||
# dedicated settings handler is in settings.py
|
||||
import pygame
|
||||
|
||||
f_sine = 0
|
||||
|
||||
|
||||
|
||||
# Curve 0
|
||||
# Edit shape mode / Run Mode
|
||||
|
||||
def MappingConf(section):
|
||||
global mouse_prev, sections
|
||||
|
||||
print ""
|
||||
print "For Mapping(), reading Architecture Points"
|
||||
gstt.EditStep = 0
|
||||
gstt.CurrentWindow = -1
|
||||
gstt.CurrentCorner = 0
|
||||
gstt.CurrentSection = section
|
||||
mouse_prev = ((405, 325), (0, 0, 0))
|
||||
|
||||
# Get all shapes points (="corners") for the given section of the conf file -> gstt.Windows
|
||||
gstt.Windows = []
|
||||
sections = settings.MappingSections()
|
||||
|
||||
print ""
|
||||
#print "Sections : ", sections
|
||||
print "Reading Section : ", sections[gstt.CurrentSection]
|
||||
|
||||
gstt.Laser = settings.MappingRead([sections[gstt.CurrentSection],'laser'])
|
||||
print "Laser : ", gstt.Laser
|
||||
gstt.simuPL = gstt.Laser
|
||||
|
||||
for Window in xrange(settings.Mapping(sections[gstt.CurrentSection])-1):
|
||||
print "Reading option : ", str(Window)
|
||||
shape = [sections[gstt.CurrentSection], str(Window)]
|
||||
WindowPoints = settings.MappingRead(shape)
|
||||
gstt.Windows.append(WindowPoints)
|
||||
|
||||
print "Section points : " ,gstt.Windows
|
||||
|
||||
|
||||
|
||||
|
||||
# section 0 is "General", then first screen shapes in section 1
|
||||
# Todo : Should search automatically first screen in settings file sections.
|
||||
# MappingConf(1) should be call only if curve 0 is selected
|
||||
|
||||
|
||||
def Mapping(fwork, keystates, keystates_prev):
|
||||
global mouse_prev, sections
|
||||
|
||||
PL = gstt.Laser
|
||||
dots = []
|
||||
|
||||
#switch to edit mode Key E ?
|
||||
if keystates[pygame.K_e] and not keystates_prev[pygame.K_e] and gstt.EditStep == 0:
|
||||
print "Switching to Edit Mode"
|
||||
gstt.EditStep = 1
|
||||
gstt.CurrentWindow = 0
|
||||
gstt.CurrentCorner = 0
|
||||
|
||||
# Back to normal if ENTER key is pressed ?
|
||||
if keystates[pygame.K_RETURN] and gstt.EditStep == 1:
|
||||
|
||||
print "Switching to Run Mode"
|
||||
gstt.EditStep =0
|
||||
|
||||
|
||||
|
||||
# EDIT MODE : cycle windows if press e key to adjust corner position
|
||||
# Escape edit mode with enter key
|
||||
if gstt.EditStep >0:
|
||||
|
||||
dots = []
|
||||
CurrentWindowPoints = gstt.Windows[gstt.CurrentWindow]
|
||||
|
||||
# Draw all windows points or "corners"
|
||||
for corner in xrange(len(CurrentWindowPoints)):
|
||||
dots.append(proj(int(CurrentWindowPoints[corner][0]),int(CurrentWindowPoints[corner][1]),0))
|
||||
fwork.PolyLineOneColor( dots, c=colorify.rgb2hex(gstt.color), PL = PL, closed = False )
|
||||
|
||||
# Left mouse is clicked, modify current Corner coordinate
|
||||
if gstt.mouse[1][0] == mouse_prev[1][0] and mouse_prev[1][0] == 1:
|
||||
deltax = gstt.mouse[0][0]-mouse_prev[0][0]
|
||||
deltay = gstt.mouse[0][1]-mouse_prev[0][1]
|
||||
CurrentWindowPoints[gstt.CurrentCorner][0] += (deltax *2)
|
||||
CurrentWindowPoints[gstt.CurrentCorner][1] -= (deltay * 2)
|
||||
|
||||
# Change corner if Z key is pressed.
|
||||
if keystates[pygame.K_z] and not keystates_prev[pygame.K_z]:
|
||||
if gstt.CurrentCorner < settings.Mapping(sections[gstt.CurrentSection]) - 1:
|
||||
gstt.CurrentCorner += 1
|
||||
print "Corner : ", gstt.CurrentCorner
|
||||
|
||||
# Press E inside Edit mode : Next window
|
||||
if keystates[pygame.K_e] and not keystates_prev[pygame.K_e]:
|
||||
|
||||
# Save current Window and switch to the next one.
|
||||
if gstt.CurrentWindow < settings.Mapping(sections[gstt.CurrentSection]) -1:
|
||||
print "saving "
|
||||
settings.MappingWrite(sections,str(gstt.CurrentWindow),CurrentWindowPoints)
|
||||
gstt.CurrentWindow += 1
|
||||
gstt.CurrentCorner = -1
|
||||
if gstt.CurrentWindow == settings.Mapping(sections[gstt.CurrentSection]) -1:
|
||||
gstt.EditStep == 0
|
||||
gstt.CurrentWindow = 0
|
||||
print "Now Editing window ", gstt.CurrentWindow
|
||||
|
||||
mouse_prev = gstt.mouse
|
||||
gstt.PL[PL] = fwork.LinesPL(PL)
|
||||
|
||||
# Press A : Next section ?
|
||||
if keystates[pygame.K_a] and not keystates_prev[pygame.K_a]:
|
||||
|
||||
print "current section : ", gstt.CurrentSection
|
||||
if gstt.CurrentSection < len(sections)-1:
|
||||
gstt.CurrentSection += 1
|
||||
print "Next section name is ", sections[gstt.CurrentSection]
|
||||
if "screen" in sections[gstt.CurrentSection]:
|
||||
print ""
|
||||
print "switching to section ", gstt.CurrentSection, " ", sections[gstt.CurrentSection]
|
||||
MappingConf(gstt.CurrentSection)
|
||||
else:
|
||||
gstt.CurrentSection = -1
|
||||
|
||||
|
||||
# RUN MODE
|
||||
if gstt.EditStep == 0:
|
||||
|
||||
# Add all windows to PL for display
|
||||
for Window in gstt.Windows:
|
||||
|
||||
dots = []
|
||||
for corner in xrange(len(Window)):
|
||||
#print "Editing : ", WindowPoints[corner]
|
||||
#print Window[corner][0]
|
||||
dots.append(proj(int(Window[corner][0]),int(Window[corner][1]),0))
|
||||
|
||||
fwork.PolyLineOneColor( dots, c=colorify.rgb2hex(gstt.color), PL = PL, closed = False )
|
||||
|
||||
gstt.PL[PL] = fwork.LinesPL(PL)
|
||||
|
||||
|
||||
|
||||
# Curve 1 : generic pose animations
|
||||
import json
|
||||
gstt.CurrentPose = 1
|
||||
'''
|
||||
# get absolute body position points
|
||||
def getCOCO(pose_json,pose_points):
|
||||
|
||||
dots = []
|
||||
for dot in pose_points:
|
||||
if len(pose_json['part_candidates'][0][str(dot)]) != 0:
|
||||
dots.append((pose_json['part_candidates'][0][str(dot)][0], pose_json['part_candidates'][0][str(dot)][1]))
|
||||
return dots
|
||||
|
||||
|
||||
# get relative (-1 0 1) body position points. a position -1, -1 means doesn't exist
|
||||
def getBODY(pose_json,pose_points):
|
||||
|
||||
dots = []
|
||||
for dot in pose_points:
|
||||
#print pose_points
|
||||
if len(pose_json['people'][0]['pose_keypoints_2d']) != 0:
|
||||
#print "people 0"
|
||||
if pose_json['people'][0]['pose_keypoints_2d'][dot * 3] != -1 and pose_json['people'][0]['pose_keypoints_2d'][(dot * 3)+1] != -1:
|
||||
dots.append((pose_json['people'][0]['pose_keypoints_2d'][dot * 3], pose_json['people'][0]['pose_keypoints_2d'][(dot * 3)+1]))
|
||||
|
||||
#if len(pose_json['people']) != 1:
|
||||
#print "people1"
|
||||
#print "people 1", pose_json['people'][1]['pose_keypoints_2d']
|
||||
#print len(pose_json['people'])
|
||||
|
||||
return dots
|
||||
|
||||
|
||||
# get absolute face position points
|
||||
def getFACE(pose_json,pose_points):
|
||||
|
||||
dots = []
|
||||
for dot in pose_points:
|
||||
|
||||
if len(pose_json['people'][0]['face_keypoints_2d']) != 0:
|
||||
print "people 0"
|
||||
if pose_json['people'][0]['face_keypoints_2d'][dot * 3] != -1 and pose_json['people'][0]['face_keypoints_2d'][(dot * 3)+1] != -1:
|
||||
dots.append((pose_json['people'][0]['face_keypoints_2d'][dot * 3], pose_json['people'][0]['face_keypoints_2d'][(dot * 3)+1]))
|
||||
|
||||
if len(pose_json['people']) != 1:
|
||||
print "people 1"
|
||||
#print "people 1", pose_json['people'][1]['face_keypoints_2d']
|
||||
return dots
|
||||
|
||||
|
||||
# Body parts
|
||||
def bodyCOCO(pose_json):
|
||||
pose_points = [10,9,8,1,11,12,13]
|
||||
return getBODY(pose_json,pose_points)
|
||||
|
||||
def armCOCO(pose_json):
|
||||
pose_points = [7,6,5,1,2,3,4]
|
||||
return getBODY(pose_json,pose_points)
|
||||
|
||||
def headCOCO(pose_json):
|
||||
pose_points = [1,0]
|
||||
return getBODY(pose_json,pose_points)
|
||||
|
||||
|
||||
# Face keypoints
|
||||
def face(pose_json):
|
||||
pose_points = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]
|
||||
return getFACE(pose_json,pose_points)
|
||||
|
||||
def browL(pose_json):
|
||||
pose_points = [26,25,24,23,22]
|
||||
return getFACE(pose_json,pose_points)
|
||||
|
||||
def browR(pose_json):
|
||||
pose_points = [21,20,19,18,17]
|
||||
return getFACE(pose_json,pose_points)
|
||||
|
||||
def eyeR(pose_json):
|
||||
pose_points = [36,37,38,39,40,41,36]
|
||||
return getFACE(pose_json,pose_points)
|
||||
|
||||
def eyeL(pose_json):
|
||||
pose_points = [42,43,44,45,46,47,42]
|
||||
return getFACE(pose_json,pose_points)
|
||||
|
||||
def nose(pose_json):
|
||||
pose_points = [27,28,29,30]
|
||||
return getFACE(pose_json,pose_points)
|
||||
|
||||
def mouth(pose_json):
|
||||
pose_points = [48,59,58,57,56,55,54,53,52,51,50,49,48,60,67,66,65,64,63,62,61,60]
|
||||
return getFACE(pose_json,pose_points)
|
||||
|
||||
|
||||
# best order face : face browL browr eyeR eyeL nose mouth
|
||||
'''
|
||||
|
||||
|
||||
# get absolute body position points
|
||||
def getCOCO(pose_json,pose_points, people):
|
||||
|
||||
dots = []
|
||||
for dot in pose_points:
|
||||
if len(pose_json['part_candidates'][people][str(dot)]) != 0:
|
||||
dots.append((pose_json['part_candidates'][people][str(dot)][0], pose_json['part_candidates'][people][str(dot)][1]))
|
||||
return dots
|
||||
|
||||
|
||||
# get relative (-1 0 1) body position points. a position -1, -1 means doesn't exist
|
||||
def getBODY(pose_json,pose_points, people):
|
||||
|
||||
dots = []
|
||||
for dot in pose_points:
|
||||
#print pose_points
|
||||
if len(pose_json['people'][people]['pose_keypoints_2d']) != 0:
|
||||
#print "people 0"
|
||||
if pose_json['people'][people]['pose_keypoints_2d'][dot * 3] != -1 and pose_json['people'][people]['pose_keypoints_2d'][(dot * 3)+1] != -1:
|
||||
dots.append((pose_json['people'][people]['pose_keypoints_2d'][dot * 3], pose_json['people'][people]['pose_keypoints_2d'][(dot * 3)+1]))
|
||||
|
||||
|
||||
return dots
|
||||
|
||||
|
||||
# get absolute face position points
|
||||
def getFACE(pose_json,pose_points, people):
|
||||
|
||||
dots = []
|
||||
for dot in pose_points:
|
||||
|
||||
if len(pose_json['people'][people]['face_keypoints_2d']) != 0:
|
||||
#print "people 0"
|
||||
if pose_json['people'][people]['face_keypoints_2d'][dot * 3] != -1 and pose_json['people'][people]['face_keypoints_2d'][(dot * 3)+1] != -1:
|
||||
dots.append((pose_json['people'][people]['face_keypoints_2d'][dot * 3], pose_json['people'][people]['face_keypoints_2d'][(dot * 3)+1]))
|
||||
'''
|
||||
if len(pose_json['people']) > 1:
|
||||
print len(pose_json['people'])
|
||||
print "people 1 face ", pose_json['people'][1]['face_keypoints_2d']
|
||||
'''
|
||||
|
||||
return dots
|
||||
|
||||
|
||||
# Body parts
|
||||
def bodyCOCO(pose_json, people):
|
||||
pose_points = [10,9,8,1,11,12,13]
|
||||
return getBODY(pose_json,pose_points, people)
|
||||
|
||||
def armCOCO(pose_json, people):
|
||||
pose_points = [7,6,5,1,2,3,4]
|
||||
return getBODY(pose_json,pose_points, people)
|
||||
|
||||
def headCOCO(pose_json, people):
|
||||
pose_points = [1,0]
|
||||
return getBODY(pose_json,pose_points, people)
|
||||
|
||||
|
||||
# Face keypoints
|
||||
def face(pose_json, people):
|
||||
pose_points = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]
|
||||
return getFACE(pose_json,pose_points, people)
|
||||
|
||||
def browL(pose_json, people):
|
||||
pose_points = [26,25,24,23,22]
|
||||
return getFACE(pose_json,pose_points, people)
|
||||
|
||||
def browR(pose_json, people):
|
||||
pose_points = [21,20,19,18,17]
|
||||
return getFACE(pose_json,pose_points, people)
|
||||
|
||||
def eyeR(pose_json, people):
|
||||
pose_points = [36,37,38,39,40,41,36]
|
||||
return getFACE(pose_json,pose_points, people)
|
||||
|
||||
def eyeL(pose_json, people):
|
||||
pose_points = [42,43,44,45,46,47,42]
|
||||
return getFACE(pose_json,pose_points, people)
|
||||
|
||||
def nose(pose_json, people):
|
||||
pose_points = [27,28,29,30]
|
||||
return getFACE(pose_json,pose_points, people)
|
||||
|
||||
def mouth(pose_json, people):
|
||||
pose_points = [48,59,58,57,56,55,54,53,52,51,50,49,48,60,67,66,65,64,63,62,61,60]
|
||||
return getFACE(pose_json,pose_points, people)
|
||||
|
||||
import os
|
||||
|
||||
|
||||
# Get frame number for pose path describe in gstt.PoseDir
|
||||
def lengthPOSE(pose_dir):
|
||||
|
||||
|
||||
if gstt.debug > 0:
|
||||
print "Check directory ",'poses/' + pose_dir + '/'
|
||||
numfiles = sum(1 for f in os.listdir('poses/' + pose_dir + '/') if os.path.isfile(os.path.join('poses/' + pose_dir + '/', f)) and f[0] != '.')
|
||||
if gstt.debug > 0:
|
||||
print "Pose : ", pose_dir, numfiles, "images"
|
||||
return numfiles
|
||||
|
||||
|
||||
def preparePOSE():
|
||||
|
||||
# anim format (name, xpos,ypos, resize, currentframe, totalframe, count, speed)
|
||||
# total frames is fetched from directory file count
|
||||
|
||||
anims1 = [['sky',50,100,300,0,0,0,1],['2dancer1', 400,100, 300,0,0,0,1],['1dancer', 400,100, 300,0,0,0,1],['window1',100,100,300,0,0,0,1]]
|
||||
anims2 = [['window1', 400,200, 300,0,0,0,1],['2dancer1',100,200,300,0,0,0,1]]
|
||||
|
||||
for anim in anims1:
|
||||
anim[5]= lengthPOSE(anim[0])
|
||||
gstt.anims0 = anims1
|
||||
|
||||
|
||||
# display n pose animations on Laser 0
|
||||
def Pose(fwork):
|
||||
|
||||
for anim in gstt.anims0:
|
||||
PL = 0
|
||||
dots = []
|
||||
print anim, anim[5]
|
||||
# repeat anim[7] time the same frame
|
||||
anim[6] +=1
|
||||
if anim[6] == anim[7]:
|
||||
|
||||
anim[6] = 0
|
||||
# increase current frame and compare to total frame
|
||||
anim[4] += 1
|
||||
if anim[4] == anim[5]:
|
||||
anim[4] = 0
|
||||
|
||||
|
||||
posename = 'poses/' + anim[0] + '/' + anim[0] +'-'+str("%05d"%anim[4])+'.json'
|
||||
posefile = open(posename , 'r')
|
||||
posedatas = posefile.read()
|
||||
pose_json = json.loads(posedatas)
|
||||
|
||||
for people in range(len(pose_json['people'])):
|
||||
|
||||
fwork.rPolyLineOneColor(bodyCOCO(pose_json, people), c=colorify.rgb2hex(gstt.color), PL = 0, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3])
|
||||
fwork.rPolyLineOneColor(armCOCO(pose_json, people), c=colorify.rgb2hex(gstt.color), PL = 0, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3])
|
||||
fwork.rPolyLineOneColor(headCOCO(pose_json, people), c=colorify.rgb2hex(gstt.color), PL = 0, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3])
|
||||
|
||||
# Face
|
||||
'''
|
||||
#fwork.rPolyLineOneColor(face(pose_json, people), c=colorify.rgb2hex(gstt.color), PL = 0, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3])
|
||||
fwork.rPolyLineOneColor(browL(pose_json, people), c=colorify.rgb2hex(gstt.color), PL = 0, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3])
|
||||
fwork.rPolyLineOneColor(browR(pose_json, people), c=colorify.rgb2hex(gstt.color), PL = 0, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3])
|
||||
fwork.rPolyLineOneColor(eyeR(pose_json, people), c=colorify.rgb2hex(gstt.color), PL = 0, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3])
|
||||
fwork.rPolyLineOneColor(eyeL(pose_json, people), c=colorify.rgb2hex(gstt.color), PL = 0, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3])
|
||||
fwork.rPolyLineOneColor(nose(pose_json, people), c=colorify.rgb2hex(gstt.color), PL = 0, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3])
|
||||
fwork.rPolyLineOneColor(mouth(pose_json, people), c=colorify.rgb2hex(gstt.color), PL = 0, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3])
|
||||
'''
|
||||
|
||||
gstt.PL[PL] = fwork.LinesPL(PL)
|
||||
time.sleep(0.02)
|
||||
|
||||
|
||||
# decrease current frame
|
||||
if gstt.keystates[pygame.K_w]: # and not gstt.keystates_prev[pygame.K_w]:
|
||||
gstt.CurrentPose -= 1
|
||||
if gstt.CurrentPose < 2:
|
||||
gstt.CurrentPose = gstt.numfiles -1
|
||||
#time.sleep(0.033)
|
||||
print "Frame : ",gstt.CurrentPose
|
||||
|
||||
# increaser current frame
|
||||
if gstt.keystates[pygame.K_x]: # and not gstt.keystates_prev[pygame.K_x]:
|
||||
gstt.CurrentPose += 1
|
||||
if gstt.CurrentPose > gstt.numfiles -1:
|
||||
gstt.CurrentPose = 1
|
||||
#time.sleep(0.033)
|
||||
print "Frame : ",gstt.CurrentPose
|
||||
|
||||
|
||||
|
||||
# Curve 2 Faces
|
||||
import json
|
||||
gstt.CurrentPose = 1
|
||||
|
||||
def prepareFACES():
|
||||
|
||||
|
||||
# anim format (name, xpos,ypos, resize, currentframe, totalframe, count, speed)
|
||||
# total frame is fetched from directory file count
|
||||
|
||||
gstt.anims[0] = [['detroit1', 300,300, 100,0,0,0,1]]
|
||||
gstt.anims[1] = [['detroit1', 400,200, 200,0,0,0,1]]
|
||||
gstt.anims[2] = [['detroit1', 500,200, 300,0,0,0,1]]
|
||||
|
||||
'''
|
||||
# read anims number of frames from disk.
|
||||
for anim in range(len(gstt.anims0)):
|
||||
gstt.anims0[anim][5]= lengthPOSE(gstt.anims0[anim][0])
|
||||
for anim in range(len(gstt.anims1)):
|
||||
gstt.anims1[anim][5]= lengthPOSE(gstt.anims1[anim][0])
|
||||
for anim in range(len(gstt.anims2)):
|
||||
gstt.anims2[anim][5]= lengthPOSE(gstt.anims2[anim][0])
|
||||
'''
|
||||
|
||||
for laseranims in range(3):
|
||||
print laseranims
|
||||
for anim in range(len(gstt.anims[laseranims])):
|
||||
gstt.anims[laseranims][anim][5]= lengthPOSE(gstt.anims[laseranims][anim][0])
|
||||
|
||||
# display the face animation describe in gstt.PoseDir
|
||||
def Faces(fwork):
|
||||
|
||||
for laseranims in range(3):
|
||||
for anim in gstt.anims[laseranims]:
|
||||
PL = laseranims
|
||||
#print PL, anim
|
||||
dots = []
|
||||
#print anim, anim[5]
|
||||
# repeat anim[7] time the same frame
|
||||
anim[6] +=1
|
||||
if anim[6] == anim[7]:
|
||||
|
||||
anim[6] = 0
|
||||
# increase current frame and compare to total frame
|
||||
anim[4] += 1
|
||||
if anim[4] == anim[5]:
|
||||
anim[4] = 0
|
||||
|
||||
|
||||
posename = 'poses/' + anim[0] + '/' + anim[0] +'-'+str("%05d"%anim[4])+'.json'
|
||||
posefile = open(posename , 'r')
|
||||
posedatas = posefile.read()
|
||||
pose_json = json.loads(posedatas)
|
||||
|
||||
# Face
|
||||
|
||||
for people in range(len(pose_json['people'])):
|
||||
|
||||
#fwork.rPolyLineOneColor(face(pose), c=colorify.rgb2hex(gstt.color), PL = 0, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3])
|
||||
fwork.rPolyLineOneColor(browL(pose_json, people), c=colorify.rgb2hex(gstt.color), PL = laseranims, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3])
|
||||
fwork.rPolyLineOneColor(browR(pose_json, people), c=colorify.rgb2hex(gstt.color), PL = laseranims, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3])
|
||||
fwork.rPolyLineOneColor(eyeR(pose_json, people), c=colorify.rgb2hex(gstt.color), PL = laseranims, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3])
|
||||
fwork.rPolyLineOneColor(eyeL(pose_json, people), c=colorify.rgb2hex(gstt.color), PL = laseranims, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3])
|
||||
fwork.rPolyLineOneColor(nose(pose_json, people), c=colorify.rgb2hex(gstt.color), PL = laseranims, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3])
|
||||
fwork.rPolyLineOneColor(mouth(pose_json, people), c=colorify.rgb2hex(gstt.color), PL = laseranims, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3])
|
||||
|
||||
gstt.PL[PL] = fwork.LinesPL(PL)
|
||||
time.sleep(0.02)
|
||||
|
||||
# Curve 3
|
||||
# Dancers
|
||||
import json
|
||||
gstt.CurrentPose = 1
|
||||
|
||||
def prepareDANCERS():
|
||||
|
||||
# anim format (name, xpos,ypos, resize, currentframe, totalframe, count, speed)
|
||||
# total frame is fetched from directory file count
|
||||
|
||||
gstt.anims[0] = [['1dancer',500,200,300,0,0,0,10]]
|
||||
gstt.anims[1] = [['2dancer1',500,200,300,0,0,0,10]]
|
||||
gstt.anims[2] = [['window1',500,200,300,0,0,0,10]]
|
||||
#gstt.anims[1] = [['2dancer1',100,200,300,0,0,0,10]]
|
||||
#gstt.anims[2] = [['window1',400,200, 300,0,0,0,10]]
|
||||
# read anims number of frames from disk.
|
||||
print gstt.anims
|
||||
|
||||
for laseranims in range(3):
|
||||
print laseranims
|
||||
for anim in range(len(gstt.anims[laseranims])):
|
||||
gstt.anims[laseranims][anim][5]= lengthPOSE(gstt.anims[laseranims][anim][0])
|
||||
|
||||
# display the pose animation describe in gstt.PoseDir
|
||||
def Dancers(fwork):
|
||||
|
||||
for laseranims in range(3):
|
||||
for anim in gstt.anims[laseranims]:
|
||||
PL = laseranims
|
||||
#print PL, anim
|
||||
dots = []
|
||||
#print anim, anim[5]
|
||||
# repeat anim[7] time the same frame
|
||||
anim[6] +=1
|
||||
if anim[6] == anim[7]:
|
||||
|
||||
anim[6] = 0
|
||||
# increase current frame and compare to total frame
|
||||
anim[4] += 1
|
||||
if anim[4] == anim[5]:
|
||||
anim[4] = 0
|
||||
|
||||
|
||||
#bhorosc.sendresol("/layer1/clip1/connect",1)
|
||||
#bhorosc.sendresol("/layer1/clip1/connect",0)
|
||||
|
||||
posename = 'poses/' + anim[0] + '/' + anim[0] +'-'+str("%05d"%anim[4])+'.json'
|
||||
posefile = open(posename , 'r')
|
||||
posedatas = posefile.read()
|
||||
pose_json = json.loads(posedatas)
|
||||
|
||||
|
||||
for people in range(len(pose_json['people'])):
|
||||
fwork.rPolyLineOneColor(bodyCOCO(pose_json, people), c=colorify.rgb2hex(gstt.color), PL = laseranims, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3])
|
||||
fwork.rPolyLineOneColor(armCOCO(pose_json, people), c=colorify.rgb2hex(gstt.color), PL = laseranims, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3])
|
||||
|
||||
fwork.rPolyLineOneColor(browL(pose_json, people), c=colorify.rgb2hex(gstt.color), PL = laseranims, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3])
|
||||
fwork.rPolyLineOneColor(browR(pose_json, people), c=colorify.rgb2hex(gstt.color), PL = laseranims, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3])
|
||||
fwork.rPolyLineOneColor(eyeR(pose_json, people), c=colorify.rgb2hex(gstt.color), PL = laseranims, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3])
|
||||
fwork.rPolyLineOneColor(eyeL(pose_json, people), c=colorify.rgb2hex(gstt.color), PL = laseranims, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3])
|
||||
fwork.rPolyLineOneColor(nose(pose_json, people), c=colorify.rgb2hex(gstt.color), PL = laseranims, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3])
|
||||
fwork.rPolyLineOneColor(mouth(pose_json, people), c=colorify.rgb2hex(gstt.color), PL = laseranims, closed = False,xpos = anim[1], ypos = anim[2], resize = anim[3])
|
||||
|
||||
|
||||
gstt.PL[PL] = fwork.LinesPL(PL)
|
||||
|
||||
'''
|
||||
fwork.rPolyLineOneColor(bodyCOCO(pose_json), c=colorify.rgb2hex(gstt.color), PL = 0, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3])
|
||||
fwork.rPolyLineOneColor(armCOCO(pose_json), c=colorify.rgb2hex(gstt.color), PL = 0, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3])
|
||||
fwork.rPolyLineOneColor(headCOCO(pose_json), c=colorify.rgb2hex(gstt.color), PL = 0, closed = False, xpos = anim[1], ypos = anim[2], resize = anim[3])
|
||||
|
||||
|
||||
gstt.PL[PL] = fwork.LinesPL(PL)
|
||||
'''
|
||||
Loading…
Add table
Add a link
Reference in a new issue