[Solved]NodePathCollection.findAllMatches() problem

I’m currently having some hard time with NodePathCollections.

i have a NPC with the following nodepaths:

render/aircrafts/aeroplane1/camera ThirdPerson
render/aircrafts/aeroplane1/camera FirstPerson
<and so on>

what works:

for np in NPC:
    if np.getName() == "camera ThirdPerson":

what should and doesn’t work:

NPC.findAllMatches("**/camera ThirdPerson")

It always returns only an empty collection -> no matches
There are also no matches on “camera ThirdPerson”, “", "**/” or “/”. The only thing that returns something seems to be “**”, and it returns just all the contents of the NPC.

Where’s the problem? Is this a bug in panda or in my mind? (i kinda tend to the latter)

Hmm, by design, npc.findAllMatches(str) is the same thing as the union of npc[0].findAllMatches(str) … npc[n].findAllMatches(str). That is to say, it simply applies the search string to each of its contained NodePaths.

But NodePath(‘camera FirstPerson’).findAllMatches(‘camera FirstPerson’) will always return an empty set, because find() and findAllMatches() are designed to search the children of the NodePath, not the NodePath itself. Thus, all of your findAllMatches() end up in failure, because they are searching for a child node of one of your contained nodes with the indicated name, and none of your contained nodes have a child matching that name.

There isn’t a convenient method to search a NodePathCollection for a particular node with the indicated name. You could write one in Python, of course. :slight_smile:


ok, that explains a lot! thank you!

i think in the end i’ll use a single nodepath with the npc paths parented to it and only search in the nodepath for my cameras

could the NodePathCollection maybe be extended by something like this?:

def __contains__(self, arg):
    if not self.isEmpty():
        for np in self:
            if isinstance(arg, types.string):
                if np.getName() == expression:
                    return True
            elif isinstance(arg, NodePath):
                if arg == np:
                    return True
    return False

or maybe an extension for the hasPath() method that takes strings as well.
would make the work with NPCs way easier.