Panda3D Manual: Searching the Scene GraphIt is often useful to get a handle to a particular node deep within the scene graph, especially to get a sub-part of a model that was loaded from a single file. There are a number of methods dedicated to finding entrenched nodes and returning the NodePaths. First, and most useful, is the ls() command: myNodePath.ls(); This simply lists all of the children of the indicated NodePath, along with all of their children, and so on until the entire subgraph is printed out. It also lists the transforms and Render Attributes that are on each node. This is an especially useful command for when you're running interactively with Python; it's a good way to check that the scene graph is what you think it should be. The two methods
Standard filename globbing characters, such as *, ?, and [a-z] are also usable. Also the @@ special character before a node name indicates that this particular node is a stashed node. Normally, stashed nodes are not returned. @@*, by extension, means any stashed node. The argument may also be followed with control flags. To use a control flag, add a semicolon after the argument, followed by at least one of the special flags with no extra spaces or punctuation.
The default flags are +h-s-i. The myNodePath.find("<Path>"); Some examples: myNodePath.find("house/door"); This will look for a node named "door", which is a child of a node named "house", which is a child of the starting path. myNodePath.find("**/red*"); This will look for any node anywhere in the tree (below the starting path) with a name that begins with "red". More documentation about matching patterns can be found at the NodePath API reference page. shipNP.findAllMatches("**/=type=weaponMount"); This will search myNodePath recursively using tag/value. Tag name is "type" and tag value is "weaponMount". All matches found will be returned. In addition there are also the methods NodePathCollection children = myNodePath.get_children(); For more information and a complete list of NodePath functions please see the API reference. © Carnegie Mellon University 2010 |