![]()  | 
	
| 
		 
			 
			#1  
			
			
			
			
			
		 
		
	 | 
|||
		
		
  | 
|||
| 
		
	
		
		
			
			 
				
				Tractor beam module to inspect objects
			 
			
			
			Hacked a little code that moves selected objects close to the view, then puts them back.   
		
		
		
			To try, run the module, press and hold the spacebar, move the ball to an object, release the spacebar. Enjoy ![]() Code: 
	import viz
import vizmat
import viztask
import vizact
TRACTOR_TIME = 4
tractorNodes = []
def init(trackerNodeList):
	global startProjectSignal, tractorNodes
	tractorNodes = trackerNodeList
	startProjectSignal = viztask.Signal()
	viztask.schedule(think())
def startProject():
	global isProjectionDone
	startProjectSignal.send()
	
def stopProject():
	global isProjectionDone
	isProjectionDone = True
def think():
	global isProjectionDone
	cursor = viz.add('white_ball.wrl')
	cursor.color(viz.GREEN)
	cursor.alpha(.5)
	cursor.visible(viz.OFF)
	viz.startLayer(viz.LINES)
	viz.vertex([0,0,0])
	viz.vertex([0,0,0])
	lazer = viz.endLayer()
	lazer.color(viz.GREEN)
	lazer.visible(viz.OFF)
	while True:
#		print 'wait'
		yield startProjectSignal.wait()
		print 'start tractor'
		isProjectionDone = False
		cursor.visible(viz.ON)
		lazer.visible(viz.ON)
		hitObject = None
		while not isProjectionDone:
			line = viz.MainWindow.screenToWorld([.5, .5])
			line.length = 100
			lazerStart = line.begin
			lazerStart[1] -= .1 
			lazer.setVertex(0, lazerStart)
			lazer.setVertex(1, line.end)
			intersectObj = viz.phys.intersectLine(line.begin, line.end)
			if intersectObj.valid:
				cursor.setPosition(intersectObj.point)
				if intersectObj.object in tractorNodes:
					hitObject = intersectObj.object
				else:
					hitObject = None
			yield None
#		print 'done'
		cursor.visible(viz.OFF)
		lazer.visible(viz.OFF)
		if hitObject:
			#start Tractor
			isProjectionDone = False
			startTime = viz.tick()
			startPos = hitObject.getPosition(viz.ABS_GLOBAL)
			bb = hitObject.getBoundingBox(viz.ABS_GLOBAL)
			distanceFromView = max(bb.width, bb.height, bb.depth) * 2
			centerOffset = vizmat.Vector(startPos)- vizmat.Vector(bb.center)
			while not isProjectionDone:
				percentageToGo = (viz.tick()-startTime) / TRACTOR_TIME
				if percentageToGo > 1.0:
					isProjectionDone = True
					break
				line = viz.MainWindow.screenToWorld([.5, .5])
				line.length = distanceFromView
				targetPos = line.end + centerOffset
				pos = vizmat.Interpolate(hitObject.getPosition(viz.ABS_GLOBAL), targetPos, percentageToGo)
				hitObject.setPosition(pos, viz.ABS_GLOBAL)
				yield None
			hitObject.runAction( vizact.moveTo(startPos, time=TRACTOR_TIME*.2) )
		
		
if __name__ == "__main__":
	viz.go()
	viz.phys.enable()
	room = viz.add('gallery.osgb')
	room.collideMesh()
	list = []
	for i in range(5):
		b = viz.add('box.wrl', pos=[i*.5, 1.5, 2], scale=[.3]*3)
		b.collideMesh()
		list.append(b)
	h = viz.add('tut_hedra.wrl', pos=[-1, 1, 4])
	h.collideMesh()
	list.append( h )
	h = viz.add('vcc_female.cfg', pos=[-2, 1, 4])
	h.collideMesh()
	list.append( h )
	h = viz.add('ball.wrl', pos=[-2, 1, 4])
	h.collideMesh()
	list.append( h )
	
	init(list)
	
	vizact.onkeydown(' ', startProject)
	vizact.onkeyup(' ', stopProject)
				__________________ 
		
		
		
		
		
	
	Paul Elliott WorldViz LLC  | 
		
  | 
	
		
  | 
			 
			Similar Threads
		 | 
	||||
| Thread | Thread Starter | Forum | Replies | Last Post | 
| Exception in module vizjoy | fordprefect | Vizard | 2 | 12-03-2012 02:41 AM | 
| Trouble picking text3d objects | Salvar | Vizard | 4 | 12-01-2010 04:07 PM | 
| static or dynamic objects | shahramy | Vizard | 2 | 11-10-2010 01:32 AM | 
| Semi-circle array containing target and distractor objects | ptjt255 | Vizard | 3 | 08-04-2009 04:09 AM | 
| Could not find plugin to load objects... | halley | Vizard | 1 | 05-30-2006 12:01 PM |