View Single Post
  #11  
Old 10-19-2016, 04:12 PM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,471
Quote:
I try to use viz.mainview.pickrect as you suggested but the problem is that it gives me nodes that doesn't mean anything to me like viz.vizchild(18). My question is: if i will change my nodes names in the inspector to meaningful names such as sqaure for square object it will give me meaningful names?
You can check the nodes returned by the pickRect command against the node names defined in the script:

Code:
'''
Press the spacebar to call the pickRect command
'''

import viz
import vizinfo
import vizact
import vizshape

viz.go()

vizinfo.InfoPanel()

#Define pickRect coordinates
LEFT = 0.4
BOTTOM = 0.4
RIGHT = 0.6
TOP = 0.6

viz.move([0,0,-1])

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

pyramid = vizshape.addPyramid(base=(0.2,0.2),height=0.2,pos=[-0.5,1.7,1],alpha=0.7)
torus = vizshape.addTorus(radius=0.1,tubeRadius=0.015,axis=vizshape.AXIS_X, pos=[0,1.7,1])
box = vizshape.addCube(size=0.1, pos=[0.5,1.7,1],alpha=0.8)
pyramid.texture(viz.addTexture('images/tile_slate.jpg'))
torus.texture(viz.addTexture('images/tile_wood.jpg'))

# Visualize the area used by the pick operation
viz.startLayer(viz.LINE_LOOP)
viz.vertex([LEFT, BOTTOM, 0])
viz.vertex([LEFT, TOP, 0])
viz.vertex([RIGHT, TOP, 0])
viz.vertex([RIGHT, BOTTOM, 0])
rectangle = viz.endLayer(parent=viz.SCREEN)
rectangle.alpha(.8)

def pickNodes():

	# Get all nodes within the rectangle
	picked = viz.MainWindow.pickRect([LEFT,BOTTOM,RIGHT,TOP])
	for node in picked:
		if node == pyramid:
			print 'pyramid picked'
		elif node == torus:
			print 'torus picked'
		elif node == box:
			print 'box picked'
			
vizact.onkeydown(' ',pickNodes)
Reply With Quote