WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 02-14-2012, 01:53 PM
EnvisMJ EnvisMJ is offline
Member
 
Join Date: May 2009
Location: Purdue University, West Lafayette, Indiana
Posts: 44
Identify a class via its mesh

So I've been having a problem for a while, I need to identify a class object via the 3D mesh that represents it in the environment.

Example code:

Code:
import viz
import vizact

#Sample Environment
ground = viz.add('tut_ground.wrl')
ground.tag = "You missed clicking on a box."

class exampleObject(object):	#Example class containing a mesh
	def __init__(self,classTag,geometryTag,x,y,z,color):
		self.tag = classTag
		self.model = viz.add('box.wrl')
		self.model.tag = geometryTag
		self.model.setPosition(x,y,z)
		self.model.color(color)
		self.model.setScale(.333,.333,.333)

#Creating some objects
A = exampleObject("classA","geometryA",-.5,1.6,2,viz.RED)
B = exampleObject("classB","geometryB",0,1.6,2,viz.BLUE)
C = exampleObject("classC","geometryC",.5,1.6,2,viz.GREEN)

def clickPick():	#Pick an object
	mesh = viz.pick()
	classObject = mesh  ###This line should be modified###
	print classObject.tag

vizact.onmousedown(viz.MOUSEBUTTON_LEFT, clickPick)	#Pick an object on Left-click

viz.go()


#The problem, how do I go from the mesh to the class object...

#As in what (function) do I need to apply to the [mesh] to return the [class object]
#Example:

def classPick():	#Pick an object, print it's class' tag
	mesh = viz.pick()
	classObject = mesh.(function)()
	print classObject.tag
	
#Should print "classA" rather than "geometryA"
#Should print "classB" rather than "geometryB"
#Should print "classC" rather than "geometryC"
How do I get it to return the class object rather than the geometry?
Reply With Quote
  #2  
Old 02-15-2012, 08:43 AM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
If you have your exampleObject class inherit from the Vizard node class, then your class instance will be returned from the pick command. I modified your example to show this:
Code:
import viz
import vizact

#Sample Environment
ground = viz.add('tut_ground.wrl')
ground.tag = "You missed clicking on a box."

class exampleObject(viz.VizNode):	#Example class containing a mesh
	def __init__(self,classTag,geometryTag,x,y,z,color):

		model = viz.add('box.wrl')
		viz.VizNode.__init__(self,model.id)

		self.class_tag = classTag
		self.geometry_tag = geometryTag
		self.setPosition(x,y,z)
		self.color(color)
		self.setScale(.333,.333,.333)

	def printTag(self):
		print self.class_tag,self.geometry_tag

#Creating some objects
A = exampleObject("classA","geometryA",-.5,1.6,2,viz.RED)
B = exampleObject("classB","geometryB",0,1.6,2,viz.BLUE)
C = exampleObject("classC","geometryC",.5,1.6,2,viz.GREEN)

def clickPick():	#Pick an object
	mesh = viz.pick()
	if isinstance(mesh,exampleObject):
		mesh.printTag()

vizact.onmousedown(viz.MOUSEBUTTON_LEFT, clickPick)	#Pick an object on Left-click

viz.go()
Reply With Quote
Reply

Tags
class, mesh, object, pick

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Jumping to a class object from one of it's components EnvisMJ Vizard 0 04-25-2011 11:22 AM
Collide mesh on child objects Enlil Vizard 1 08-31-2010 05:52 PM
Multiple Mesh Avatar Texturing v-jbinney Vizard 6 11-13-2007 11:00 AM
changing the texture of an avatars shirt/body bailenson Vizard 19 05-04-2006 10:00 AM
method of a class instance not accepted as Callback Gilliard Vizard 1 08-10-2005 05:49 PM


All times are GMT -7. The time now is 12:53 AM.


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