View Single Post
  #8  
Old 04-19-2013, 05:08 PM
Gladsomebeast Gladsomebeast is offline
Member
 
Join Date: Mar 2005
Location: Isla Vizta, CA
Posts: 397
Have some rough code here that moves the limbs and root/pelvis of the original Complete Character samples in Vizard with the kinect.


Code:
import viz
import vizact
import vizshape
import math

viz.go(viz.FULLSCREEN)

#viz.clearcolor(viz.SKYBLUE)
ground = viz.add('gallery.osgb')

#Kinect Tracker object ID's
#myHead = vrpn.addTracker( 'Tracker0@localhost', HEAD).
HEAD = 0
NECK = 1
TORSO = 2
WAIST = 3
LEFTCOLLAR = 4
LEFTSHOULDER = 5
LEFTELBOW = 6
LEFTWRIST = 7
LEFTHAND = 8
LEFTFINGERTIP = 9
RIGHTCOLLAR = 10
RIGHTSHOULDER = 11
RIGHTELBOW = 12
RIGHTWRIST = 13
RIGHTHAND = 14
RIGHTFINGERTIP = 15
LEFTHIP = 16
LEFTKNEE = 17
LEFTANKLE = 18
LEFTFOOT = 19
RIGHTHIP = 20
RIGHTKNEE = 21
RIGHTANKLE = 22
RIGHTFOOT = 23

#store trackers, links, and vizshape objects
trackers = []
links = []
shapes = []

#start vrpn
vrpn = viz.addExtension('vrpn7.dle')

#set the camera facing the avatar
viz.MainView.setPosition(0,0,0)

rootRaw = viz.addGroup(euler=[0, 0, 0])
lastX = 0
lastZ = 3
#now add all trackers and link a shape to it
for i in range(0,24):
	t = vrpn.addTracker( 'Tracker0@localhost',i )
	
	s = viz.add('wheelbarrow.ive', scale=[.3]*3, parent=rootRaw)
	if i == TORSO:
		s.color(viz.RED)
		#display an arrow pointing away from the avatar		
	elif i in [LEFTSHOULDER,RIGHTSHOULDER,LEFTHIP,RIGHTHIP]:
		s.color(viz.BLUE)

	l = viz.link(t,s)
	trackers.append(t)
	links.append(l)
	shapes.append(s)

#Debug 3d models with orientaton affordances
rootWheelbarrow = viz.add('wheelbarrow.ive', scale=[.3]*3)
rootWheelbarrow.color(viz.YELLOW)
target = viz.add('wheelbarrow.ive', scale=[.3]*3, pos=[.5, 0, 0])
target.color(viz.GREEN)

#girl = viz.add('vcc_female.cfg', pos=[0, -1, 0], euler=[180, 0, 0])
girl = viz.add('vcc_male.cfg', pos=[0, 0, 0], euler=[0, 0, 0])

RF = vrpn.addTracker('Tracker0@localhost', RIGHTFOOT)
LF = vrpn.addTracker('Tracker0@localhost', LEFTFOOT)
RK = vrpn.addTracker('Tracker0@localhost', RIGHTKNEE)
LK = vrpn.addTracker('Tracker0@localhost', LEFTKNEE)
Torso = vrpn.addTracker('Tracker0@localhost', TORSO)
head = vrpn.addTracker('Tracker0@localhost', HEAD)
neck = vrpn.addTracker('Tracker0@localhost', NECK)
rightShoulder = vrpn.addTracker('Tracker0@localhost', RIGHTSHOULDER)
rightElbow = vrpn.addTracker('Tracker0@localhost', RIGHTELBOW)
leftShoulder = vrpn.addTracker('Tracker0@localhost', LEFTSHOULDER)
leftElbow = vrpn.addTracker('Tracker0@localhost',LEFTELBOW)
rightHip = vrpn.addTracker('Tracker0@localhost',RIGHTHIP)
rightKnee = vrpn.addTracker('Tracker0@localhost',RIGHTKNEE)
leftHip = vrpn.addTracker('Tracker0@localhost',LEFTHIP)
leftKnee = vrpn.addTracker('Tracker0@localhost',LEFTKNEE)

waist = vrpn.addTracker('Tracker0@localhost', WAIST)
rootWaist = girl.getBone('Bip01')
rootWaist.lock()

headBone = girl.getBone('Bip01 Head')
headBone.lock()

kinectToCharacter = {	'Bip01 L UpperArm':(rightShoulder, [0, 90, 0]), \
						'Bip01 L Forearm':(rightElbow, [0, 90, 0]), \
						'Bip01 R UpperArm':(leftShoulder, [0, -90, 180]), \
						'Bip01 R Forearm':(leftElbow, [0, -90, 180]), \
						'Bip01 L Thigh':(rightHip, [90, 0, -90]), \
						'Bip01 L Calf':(rightKnee, [90, 0, -90]), \
						'Bip01 R Thigh':(leftHip, [90, 0, -90]), \
						'Bip01 R Calf':(leftKnee, [90, 0, -90]), \
						'Bip01':(waist, [0, 90, -90]) \
					}
bones = {}
for boneName in kinectToCharacter:
	b = girl.getBone(boneName)
	b.lock()
	bones[b] = kinectToCharacter[boneName]

boneToTest = girl.getBone('Bip01 L Thigh')
boneToTest.lock()
boneToTest.setEuler([180, 0, 0])
import vizmat
def animate():
	#debug code
	m = vizmat.Transform()
	euler = rightHip.getEuler()
	m.setEuler(euler)
	m.preEuler([90, 0, -90])
	
	target.setEuler(m.getEuler())
	rootWheelbarrow.setEuler( boneToTest.getEuler(viz.ABS_GLOBAL) )
#	rootWaist.setEuler(m.getEuler(), viz.ABS_GLOBAL)
	
	#position of root
	pos = waist.getPosition()
	rootWaist.setPosition(pos, viz.ABS_GLOBAL)
#	rootWaist.setPosition([2.64658, 0.53107, 3.37627], viz.ABS_GLOBAL) #if you want to fix the avatar to point in room.
	
	for bone in bones:
		kinectTracker = bones[bone][0]
		euler = kinectTracker.getEuler()
		m = vizmat.Transform()
		m.setEuler(euler)
		m.preEuler(bones[bone][1])
		bone.setEuler(m.getEuler(), viz.ABS_GLOBAL)
	
vizact.ontimer(0, animate)

viz.MainView.setPosition([0, 0, 5])
viz.MainView.setEuler([180, 0, 0])

import vizcam
viz.cam.setHandler(vizcam.PivotNavigate(distance=5))

def viewInHead():
	m = vizmat.Transform()
	m.setEuler(headBone.getEuler(viz.ABS_GLOBAL))
	m.preEuler([-90, -90, 0])
	viz.MainView.setEuler( m.getEuler() )
	viz.MainView.setPosition( headBone.getPosition(viz.ABS_GLOBAL) )

#vizact.ontimer(0, viewInHead)
__________________
Paul Elliott
WorldViz LLC
Reply With Quote