DirectSelection Not Working

Hey, I think there is a bug or something in the DirectSelection module.

When I import it I get this error:

Traceback (most recent call last):
  File "C:\Users\Sothh\Desktop\Python\Programs\Level Editor\Level", line 40, in <module>
    from direct.directtools import DirectSelection
  File "C:\Panda3D-1.7.1\direct\directtools\", line 421, in <module>
    class SelectionQueue(CollisionHandlerQueue):
  File "C:\Panda3D-1.7.1\direct\directtools\", line 422, in SelectionQueue
    def __init__(self, parentNP = render):
NameError: name 'render' is not defined

I am using the 2010.10.20-172 release.

All right, I’ll check in a fix for this particular issue. Some of the code in ‘direct’ mistakenly relies on ShowBase being instantiated (or DirectBase having been imported) before those modules are imported.

Okay, so I imported it after creating the window, and it works now, but I am having a problem with this code:

(self.x and self.y are the mouse’s x and y)

  self.selection = DirectSelection.SelectionRay()

        if self.selection.getNumEntries() > 0:
            self.entry = self.selection.getEntry(0)
            self.object = self.entry.getIntoNodePath()
            self.point3d = self.entry.getSurfacePoint(self.object)

            print self.entry, self.object, self.point3d

I have on 3d model in my scene which is created from this code:

class Model():

    def __init__(self,path,x=0,y=0,z=0,h=0,p=0,r=0):

        #Load a model:
        self.model = main.loader.loadModel(path)

        #Set the position:

        #Reparent the model to render:

When I print the number on entries I get 0.

Like any issues with the collision system failing to report a collision, you have to ask yourself the questions: Is the object actually in the right place for collision? How are the bitmasks set?

DirectSelection certainly works in general, but it might make some assumptions about the way you’ve set up your scene. Fortunately, all of the code is in Python, so you should be able to walk through it and figure out why it’s not working in your case.