Hi, I ve defined some models, Ive loaded them with loadmodel copy, well, then I define everything for getting collision on click above an object , just like the example in the documentation (by the way the example had some syntax fails) :
base.cTrav = CollisionTraverser()
myTraverser = base.cTrav
myHandler = CollisionHandlerQueue()
pickerNode = CollisionNode(‘mouseRay’)
pickerNP=camera.attachNewNode(pickerNode)
pickerNode.setFromCollideMask(GeomNode.getDefaultCollideMask())
pickerRay=CollisionRay()
pickerNode.addSolid(pickerRay)
myTraverser.addCollider(pickerNP, myHandler)
Load the models and tag them
model1 = loader.loadModel(‘whatevermodel’)
model1.reparentTo(render)
model1.setPos(5, 25,0)
model1.setTag(‘myObjectTag’, ‘1’)
print model1.getTag(‘myObjectTag’)# prints 1 runs ok
Now the class…
class event(DirectObject.DirectObject):
def init(self):
self.accept(‘mouse1’,self.mifuncion)
def mifuncion(self):
mpos=base.mouseWatcherNode.getMouse()# da coordenadas de mouse
#This makes the ray’s origin the camera and makes the ray point
#to the screen coordinates of the mouse
pickerRay.setFromLens(base.camNode, mpos.getX(), mpos.getY())
myTraverser.traverse(render)
#assume for simplicity’s sake that myHandler is a CollisionHandlerQueue
if myHandler.getNumEntries() > 0:
myHandler.sortEntries() #this is so we get the closest object
#pickedObj=myHandler.getEntry(0).getIntoNodePath()
pickedObj=myHandler.getEntry(0).getIntoNode()
print pickedObj.getTag(‘myObjectTag’)# prints “” blank string
Well at this point I ve tried getIntoNodePath and getIntoNode, also findNetTag and getTag, but tis always the same blank str… so im stucked here
Ive looked at the chessboard example and it seems there the tag is :
self.squares[i].find("**/polygon").node().setTag(‘square’, str(i))
But if I try this way I get an error :
AssertionError: !is_empty()
Maybe it is because I ve loaded my own model and this is not like the chessboard example
Someone knows something that could help me ?