Hi! First time poster; I discovered Panda3d about a month ago, and I’ve been messing with it to expand my understanding of 3d rendering software (and Python programming in general). So far, I’ve loved it!
I wanted to ask a (potentially dumb!) question, though:
My current project is a hobby game with a clear division between the rendering code and the actual game engine code (so game objects are represented by nodes on the render tree, and the game ‘updates’ those nodes every so often, moving them in ways that reflect their new positions in the game engine half–things like collision detection, etc, are all handled by the separate game engine).
In working to better optimize communication between the game engine and the render component, I’ve realized it might be useful to store the game object inside the node object as an attribute (so I can cycle through visual node objects and acquire from them a list of the game objects that own them). But Panda3d restricts the attributes you can add to node objects.
Is there a way to create an ‘owner’ attribute to nodes? Or do I have to edit the Panda3d source code? I get the vibe there’s probably a function that will do this for me, but I just don’t know what it is (nor whether I can apply it directly to nodes, or if I can only do it to nodepaths, or if there’s a separate function to handle nodes and another to handle nodepath attributes).
Additionally, is there an easy low-cost method to discover if any part of a given node is currently ‘on-screen’?
I think the feature you are looking for is setTag/getTag.
It is described briefly in the manual: http://www.panda3d.org/manual/index.php/Clicking_on_3D_Objects
Of course there are many uses for it other than described on that page. You can store any information you want on a node, like an owner tag using this method.
But if I’m not much mistaken if might be worth watching out for cyclic references, and properly disconnecting them when you clean up so that the garbage collector doesn’t pass them by.
For example, let’s say that your logical-object class is “MyObj”. You may want each instance of MyObj to know its NodePath (so that it can move said NodePath, for example), and set the tag on that NodePath to reflect its MyObj owner. This means that when thy fall out of scope, they still each have a reference to the other, and so may never be garbage collected.
I appreciate the help! This definitely works for what I needed–although I still don’t see a (relatively easy, cheap) way to determine if a given object on the SceneGraph has been ‘rendered’ to the screen (ie, is it visible?)–I suspect the answer to that portion of my query involves understanding a bit more about how clicking on 3d objects work, however (or is there a function/attribute I can check for a given node/nodepath to quickly determine if any part of it is currently being rendered ‘on screen’?–or failing that, at least if it’s bounding box is ‘on screen’?)
(Also, thanks for the warning concerning cyclic references–I’m going to make sure my ‘destroy object’ function carefully removes every reference!)