Just started using Panda3D and I love it! Cant wait to really get into it all!
I’ve started working on my first project and am trying to learn the best practice type ways of doing things.
My question is about loading objects with the aim of making them user interactive. I have two files at the moment, one is an object.py (where I have defined my object class) and the other is main.py (the file for my game). I would like to be able to load a model to represent ‘Object’ when I create an instance of it (with the goal of displaying data about the instance when the model is clicked). I figured this would probably be done with the use of NodePaths?
So my plan was to create an instance of the ‘Object’ class, load a model and parent it to the instance of ‘Object’, then parent ‘Object’ to the render node.
That way, when the object is clicked, I can call a function to find its parent (the ‘Object’ instance). Also, when I actually load the model, should I create a method in the Object.py for loading, or should I load the object in the main.py?
Am I on the right track with this?
Thanks a lot for any advice!
I won’t claim to know the best way to do things, but my own approach to this is to use aggregation: the “Object” class is simply a Python class, and it has as one of its members a NodePath that holds the model in question.
For one thing, I think that there are some complications with simply subclassing either PandaNode or NodePath (but I’ll confess that I don’t think that I’ve read the linked page in any real depth, and so stand to be corrected)–not insurmountable (indeed, a solution is described on that page, I believe), but not wonderful.
But the main thing for me, I think, is that it simply feels a little cleaner: I like that the responsibilities are a little more separated. My “Object” classes hold game-logic, as well as references to relevant nodes (such as the model), while scene-graph nodes hold scene-graph information (for the most part).
Thank you very much for the reply, it was really useful!
So, I believe what you are saying is how to load and reparent objects, and how to add user-input to those objects to make them move? I am getting to that point in my Panda3D tutorial series, the next tutorial will explain about user input with Keymaps. You can take a look here: Request Topic Deletion I hope this series helps you out, it is meant for beginners and advanced alike, and it seems you are beginner since you are new to Panda3D. For now, I recommend you test around with just 1 file and learn how to do things before you get into complicated things such as multiple files with object inheritance. Starting easy and working your way up is the best way to do it. I hope this helps!
Those tutorials are amazing! Thank you very much, I’m working through them now