PDA

View Full Version : Hand Grab and Object Action


rmcconnell11
04-29-2014, 08:15 AM
Hi guys,

I am trying to add an action to an object once it is grabbed by a hand. Unfortunately I am having a bit of trouble in getting the objects to move at all!
This is what I have so far....

import viz
import vizact

#function for changing numbers to three decimal places
def decimal(Pos):
for i, number in enumerate(Pos):
Pos[i] = round(number,3)

ground = viz.addChild('ground.osgb')

Tool = viz.add('Tool_V12.osgb', pos=[0,0,4], euler=[180,0,0])
Tool.collideMesh()

#Get the clamp parts
ClampA_Transform = Tool.getChild('G05515000_SAJG01A-5068.2')
ClampA = ClampA_Transform.getChild('All Nodes')
ClampA.setCenter(56,30,24)
ClampA.color(viz.YELLOW)
ClampA_Pos = ClampA.getPosition(mode=viz.REL_GLOBAL)
decimal(ClampA_Pos)
ClampA.collideBox()

#Clamp B
ClampB_Transform = Tool.getChild('G05515000_SAJG01A-5068.1')
ClampB = ClampB_Transform.getChild('All Nodes')
ClampB.setCenter(56,30,24)
ClampB.color(viz.YELLOW)
ClampB_Pos = ClampB.getPosition(mode=viz.REL_GLOBAL)
decimal(ClampB_Pos)
ClampB.collideMesh()

import viztracker
viztracker.DEFAULT_HANDS = True
viztracker.go()
rightHand = viztracker.get('lefthand')

#enable physics
viz.phys.enable()
ground.collidePlane()
rightHand.collideMesh()
#ball.collideSphere()

closest = None #Used to identify closest object to hand
MoveableParts = [ClampA, ClampB]

def updateClosest():
global closest
list = viz.phys.intersectNode(rightHand)

if list != []:
closestDistance = 999999
closest = None
handPos = rightHand.getPosition()

for object in list:
if (object in MoveableParts):
distance = vizmat.Distance(handPos, object.getPosition(viz.ABS_GLOBAL))
if distance < closestDistance:
closest = object
closestDistance = distance
else:
closest = None
vizact.onupdate(viz.PRIORITY_DEFAULT, updateClosest)

link = None
def onGesture(e):
global link
if closest is not None:
node = closest
link = viz.grab(rightHand, node)
if node is ClampA:
#link= viz.grab(hand, closest)
global ClampA_Pos
Pos = ClampA.getPosition(mode=viz.REL_GLOBAL)
decimal(Pos)
if Pos == ClampA_Pos:
node.addAction(vizact.spinTo(euler=[-90,0,0], speed=90))
elif Pos != ClampA_Pos:
node.addAction(vizact.spinTo(euler=[90,0,0], speed=90))
if node is ClampB:
global ClampB_Pos
Pos = ClampB.getPosition(mode=viz.REL_GLOBAL)
decimal(Pos)
if Pos == ClampB_Pos:
node.addAction(vizact.spinTo(euler=[90,0,0], speed=90))
else:# CurrentPos != ClampB_Pos:
node.addAction(vizact.spinTo(euler=[-90,0,0], speed=90))

import hand
viz.callback( hand.HAND_GESTURE_EVENT, onGesture )

Jeff
04-29-2014, 09:25 PM
This is difficult to troubleshoot without being able to run the script directly. Also, it's always best to post the most basic example that reproduces the issue. Since you're using viztracker you might find the simple technique shown in the Grabbing with viztracker (http://kb.worldviz.com/articles/1500) article to help.

If you're planning to upgrade to Vizard 5, I would suggest to start using vizconnect to set up a grabber tool linked to a hand model or avatar hand.

rmcconnell11
04-30-2014, 06:51 AM
Sorry, never thought! I've looked at the viztracker file you suggested already, it's where I started from, I can set everything up to work ok on it but when it comes to linking with a sub-object it stops working. Same thing happens when it is picking or grabbing commands being used.
I have a grabhand script for grabbing objects just can't figured out how to add the actions for each individual node being selected or grabbed.