View Single Post
  #2  
Old 10-23-2008, 03:35 PM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,471
You can use viz.pick() to find what object the mouse is pointing at. Here's some code that uses viz.pick and checks to see if the mouse is pointing at the avatar's head mesh, body mesh, or some other object. Depending on what is picked the avatar will change animations.

Code:
import viz

viz.go()

viz.add('court.ive')
avatar = viz.add('vcc_male.cfg', pos = [0,0,5], euler = [180,0,0])
avatar.state(1)


def onMouseDown(button):
	
	#if you pass in a value 1 a VizIntersect object will be returned
	object = viz.pick(1)
	
	if object.valid and object.name == 'casual32_m_highpoly.CMFX':
		print "you picked the avatar's head"
		avatar.state(2)
	elif object.valid and object.name == 'casual32_m_highpoly01.CMFX':
		avatar.state(4)
		print "you picked the avatar's body"
	else:
		avatar.state(1)
		print "you picked " + object.name
	
		

viz.callback(viz.MOUSEDOWN_EVENT,onMouseDown)
Reply With Quote