WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 08-25-2009, 09:59 AM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
The following script will load an avatar and display the skeletal structure of its bones and the local coordinate system of each bone (r=x,g=y,b=z).
Code:
import viz
viz.go()

def CreateSkeleton(avatar):
	
	AXIS_SIZE = 0.03
	viz.startlayer(viz.LINES)
	viz.linewidth(2)
	viz.vertexcolor(viz.RED)
	viz.vertex(0,0,0)
	viz.vertex(AXIS_SIZE,0,0)
	viz.vertexcolor(viz.GREEN)
	viz.vertex(0,0,0)
	viz.vertex(0,AXIS_SIZE,0)
	viz.vertexcolor(viz.BLUE)
	viz.vertex(0,0,0)
	viz.vertex(0,0,AXIS_SIZE)
	axes = viz.endlayer()
	
	points = []
	lines = []

	def traverse(bone):
		points.append(bone)
		for b in bone.getChildren():
			lines.append((bone,b))
			traverse(b)
			
	#Collect list of bones for drawing points and lines
	for b in avatar.getRootBoneList():
		traverse(b)

	#Create OTF object
	viz.startlayer(viz.LINES)
	viz.linewidth(1)
	viz.pointsize(6)
	viz.vertexcolor(viz.WHITE)

	for l in lines:
		viz.vertex(0,0,0)
		viz.vertex(0,0,0)

	viz.startlayer(viz.POINTS)

	for p in points:
		viz.vertex(0,0,0)

	skeleton = viz.endlayer()
	skeleton.dynamic()

	#Link each vertex to corresponding bone
	count = 0
	for b1,b2 in lines:
		viz.link(b1,skeleton.Vertex(count))
		count += 1
		viz.link(b2,skeleton.Vertex(count))
		count += 1

	for b in points:
		viz.link(b,skeleton.Vertex(count))
		count += 1
		viz.link(b,axes.clone(),srcFlag=viz.ABS_GLOBAL)

	axes.remove()
	
	return skeleton
	
model = viz.add('vcc_male.cfg',alpha=0.7)

CreateSkeleton(model)

import vizcam
cam = vizcam.PivotNavigate(distance=3)
cam.centerNode(model)

#Toggle avatar mesh on space key
vizact.onkeydown(' ',model.visible,viz.TOGGLE)
I believe the actual problem is that you are not applying an offset rotation when transferring the sensor data to the avatar. If you are using viz.AVATAR_WORLD coordinates to apply the data, then keep in mind that the initial pose of the avatar is the zeroed rotation of the hand. If the zeroed rotation of your hand sensor is pointing in a different direction, then you will need to compute the rotation difference between the two and apply that offset when transferring the data.

If you are using link objects, then you will need to apply a preEuler operator to the link to get the data to match the avatar.
Reply With Quote
 


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 09:13 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
Copyright 2002-2023 WorldViz LLC