def collideOutFrowney(entry): global pickingEnabledOject np_into = entry.getIntoNodePath() np_into.getParent().setColor(1.0, 1.0, 1.0, 1) snipstuff.info_message("Left '%s'" % np_into.getParent().getName()) pickingEnabledOject = None
def collideOutSmiley(entry): global pickingEnabledOject np_into=entry.getIntoNodePath() np_into.getParent().setColor(1.0, 1.0, 1.0, 1) snipstuff.info_message("Left '%s'"%np_into.getParent().getName()) pickingEnabledOject=None
def collideEventOut(entry): global pickingEnabled # now we update the flag to inform mousePick routine that the picking is actually no more pickingEnabled=False snipstuff.info_message("you LEFT smiley alone") np_into=entry.getIntoNodePath() np_into.getParent().setColor(1.0, 1.0, 1.0, 1)
def mouseClick(status): global pickingEnabledOject if pickingEnabledOject: if status == 'down': pickingEnabledOject.setScale(.9) snipstuff.info_message("You clicked '%s'!"%pickingEnabledOject.getName()) if status == 'up': pickingEnabledOject.setScale(1.0)
def mouseClick(status): global pickingEnabledOject if pickingEnabledOject: if status == 'down': pickingEnabledOject.setScale(.9) snipstuff.info_message("You clicked '%s'!" % pickingEnabledOject.getName()) if status == 'up': pickingEnabledOject.setScale(1.0)
def collideAgainBalls(entry): global pickingEnabledOject # since this function is called constantly while the mousepointer is over the ball, with this condition check we'll change things just the first time we are over a different ball than before. if entry.getIntoNodePath().getParent() != pickingEnabledOject: np_from = entry.getFromNodePath() np_into = entry.getIntoNodePath() snipstuff.info_message("'%s' INTO '%s'!\nYou may now click the LMB" % (np_from.getName(), np_into.getName())) # we store the object actually picked because later, clicking the mouse button, we would change its shape a little fo showup - so, since the entry passed by the function is the collider object and not the model, to have its reference we need to call getParent() pickingEnabledOject = np_into.getParent()
def collideEventIn(entry): global pickingEnabled # here how we get the references of the two colliding objects to show their names ASA this happen np_from = entry.getFromNodePath() np_into = entry.getIntoNodePath() snipstuff.info_message("'%s' goes INTO '%s'!\nYou may now click the LMB" % (np_from.getName(), np_into.getName())) np_into.getParent().setColor(.6, 0.5, 1.0, 1) # we need also to raise a flag to inform the mousePick routine that the picking is now active pickingEnabled = True
def mouseClick(mousebutton): global pickingEnabledOject if pickingEnabledOject: if mousebutton == "up": cardid = pickingEnabledOject.getTag("id") status = pickingEnabledOject.getTag("status") if status == "hidden": pickingEnabledOject.setTag("status", "visible") tex = loader.loadTexture("textures/cards/%s.png" % cardid) else: pickingEnabledOject.setTag("status", "hidden") tex = loader.loadTexture("textures/cards/back.png") pickingEnabledOject.setTexture(tex) snipstuff.info_message("You clicked the '%s' card!" % cardid)
def mouseClick(mousebutton): global pickingEnabledOject if pickingEnabledOject: if mousebutton == 'up': cardid = pickingEnabledOject.getTag('id') status = pickingEnabledOject.getTag('status') if status == 'hidden': pickingEnabledOject.setTag('status', 'visible') tex = loader.loadTexture('textures/cards/%s.png' % cardid) else: pickingEnabledOject.setTag('status', 'hidden') tex = loader.loadTexture('textures/cards/back.png') pickingEnabledOject.setTexture(tex) snipstuff.info_message("You clicked the '%s' card!" % cardid)
def collideAgainBalls(entry): global pickingEnabledOject # since this function is called constantly while the mousepointer is over the ball, with this condition check we'll change things just the first time we are over a different ball than before. if entry.getIntoNodePath().getParent() <> pickingEnabledOject: np_from=entry.getFromNodePath() np_into=entry.getIntoNodePath() snipstuff.info_message( "'%s' INTO '%s'!\nYou may now click the LMB" % ( np_from.getName(), np_into.getName() ) ) # we store the object actually picked because later, clicking the mouse button, we would change its shape a little fo showup - so, since the entry passed by the function is the collider object and not the model, to have its reference we need to call getParent() pickingEnabledOject=np_into.getParent()
def collideEventIn(entry): global pickingEnabled # here how we get the references of the two colliding objects to show their names ASA this happen np_from=entry.getFromNodePath() np_into=entry.getIntoNodePath() snipstuff.info_message( "'%s' goes INTO '%s'!\nYou may now click the LMB" % ( np_from.getName(), np_into.getName() ) ) np_into.getParent().setColor(.6, 0.5, 1.0, 1) # we need also to raise a flag to inform the mousePick routine that the picking is now active pickingEnabled=True
def traverseTask(task=None): # as soon as a collison is detected, the collision queue handler will contain all the objects taking part in the collison, but we must sort that list first, so to have the first INTO object collided then the second and so on. Of course here it is pretty useless 'cos there is just one INTO object to collide with in the scene but this is the way to go when there are many other. collisionHandler.sortEntries() for i in range(collisionHandler.getNumEntries()): # we get here the n-th object collided (we know it is frowney for sure) - it is a CollisionEntry object (look into the manual to see its methods) entry = collisionHandler.getEntry(i) # we'll turn on the lights, to visually show this happy event snipstuff.dlight.setColor((.5, .5, .5, 1)) snipstuff.info_message("Smiley is now touching Frowney!") # and we skip out cos we ain't other things to do here. if task: return task.cont # If there are no collisions the collision queue will be empty so the program flow arrives here and we'll shut down the lights snipstuff.dlight.setColor((.0, .1, .0, 1)) snipstuff.info_message("") if task: return task.cont
def traverseTask(task=None): # as soon as a collison is detected, the collision queue handler will contain all the objects taking part in the collison - as we know we must put the list in order first. collisionHandler.sortEntries() for i in range(collisionHandler.getNumEntries()): # Differently from step1.py and to add more meat, we're going to use the useful getEntry() method of the CollisionHandlerQueue handler that allows us to get a reference of all the object colliders actually taking part the actual collisions entry = collisionHandler.getEntry(i) colliderNode = entry.getIntoNode() # now that we got the collider object reference, we may find out the name of who's involved in the current collision and therefore we'll going to change its appearance if colliderNode.getName() == 'smileycnode': smileyModel.setColor(1,1,1,1) heartModel.setScale(1.5) snipstuff.info_message("So much LOVE!") if task: return task.again elif colliderNode.getName() == 'frowneycnode': frowneyModel.setColor(1,1,1,1) brkheartModel.setScale(1.5) snipstuff.info_message("You broke my heart, sigh!") if task: return task.again # If there are no collisions the program flow arrives here and we'll reset the models appearance smileyModel.setColor(.4,.4,.4,1) frowneyModel.setColor(.4,.4,.4,1) heartModel.setScale(1.0) brkheartModel.setScale(1.0) snipstuff.info_message("") if task: return task.again
def traverseTask(task=None): # as soon as a collison is detected, the collision queue handler will contain all the objects taking part in the collison - as we know we must put the list in order first. collisionHandler.sortEntries() for i in range(collisionHandler.getNumEntries()): # Differently from step1.py and to add more meat, we're going to use the useful getEntry() method of the CollisionHandlerQueue handler that allows us to get a reference of all the object colliders actually taking part the actual collisions entry = collisionHandler.getEntry(i) colliderNode = entry.getIntoNode() # now that we got the collider object reference, we may find out the name of who's involved in the current collision and therefore we'll going to change its appearance if colliderNode.getName() == 'smileycnode': smileyModel.setColor(1, 1, 1, 1) heartModel.setScale(1.5) snipstuff.info_message("So much LOVE!") if task: return task.again elif colliderNode.getName() == 'frowneycnode': frowneyModel.setColor(1, 1, 1, 1) brkheartModel.setScale(1.5) snipstuff.info_message("You broke my heart, sigh!") if task: return task.again # If there are no collisions the program flow arrives here and we'll reset the models appearance smileyModel.setColor(.4, .4, .4, 1) frowneyModel.setColor(.4, .4, .4, 1) heartModel.setScale(1.0) brkheartModel.setScale(1.0) snipstuff.info_message("") if task: return task.again
#========================================================================= # Scenographic stuff #========================================================================= base.cam.setPos(40, -150, 35) splash = snipstuff.splashCard() snipstuff.info.append("Collision Octree") snipstuff.info.append( "A snippet to see performance improvement using octree splitting\nfor collision meshes." ) snipstuff.info.append( "Change collision mesh and compare the frame rate difference\n\n1=single collision mesh\n2=octreefied collision mesh" ) snipstuff.info_message("check out the frame rate meter above...") snipstuff.info_show() #========================================================================= # Main """ Here we settle up a simple scene with a wide terrain surface, where to compare 2 different floor colliders applied on it: the first is a whole single collision mesh with approx. 16.000 polygons and the other is the same former mesh but after being octreefied, using the octree script incorporated in the blender chicken exporter - have to know that the resulting model is not composed by a whole mesh anymore but rather by dozens of small mesh chunks that will relief the panda collision system for an extent you'll going to see by yourself with this snippet. The real deal with this tutorial is not much how to settle the collisions, explained in detail in former steps, but rather how to export your collision meshes with blender and how will change here the usual floor collision settings, because of the octreefication. I suggest you to check infos in oc3models.blend first and then return down here to continue. """ #========================================================================= #** Collision system ignition base.cTrav = CollisionTraverser() #** The floor collision handler - all stuff explained in step3 avatarFloorHandler = CollisionHandlerGravity()