Panda XML model loader

Wath do you think of the project?

  • It’s worth making
  • It will be a waste of time

0 voters

I started learning Panda 3d today and for now it has everything I need.

After passing through a couple of the manual pages I got the idea to create a tool for panda that can load models to the scene graph from an xml file.
My idea is not to directly load the models to the the render node. But to load all the nodes in the xml file and return a single node that can than be reparented to a node in the scene graph.

Examlpe
I could create a xml file that discribes a house. This xml file can than have the house model and some furniture. It will also store light positions. I also want to give it the ability to create instances to for example to use instances of the columns in the house. It will also be able to load animated models.

I would like to let the xml file do as much as posible. I have even some ideas of how I can add some python programming in the files.

I am not sure what would be the best method to open the files. I thought first on a program that would open the file and convert it to a python file. But I think now that it would be better to convert the file on runtime, but I’m new to python and I am not sure how I could do this.

I’m still learning, maybe in a couple of weeks I could have a first version ready.

Here is how I think the XML file could look like.

<?xml version="1.0"?>
<root version="0.1">
	<nodes name="root_node">
		<model pos="10,12,-3" hpr="90,20,0" file="file1.egg" scale="0.25, 0.25 ,0.25" name="firstmodel">
			<model file="file2.egg" name="model3" pos="20,11,0">
				<instance name="instance1" of="model3" pos="3,6,0"></instance>
			</model>
		</model>
		<light pos="10,50,30" color="R, G, B"></light>
		<actor name="Actor_name" pos="0,0,0" hpr="30,0,1" file="file4.egg" scale="0.25, 0.25 ,0.25">
			<animation name="walk" file="actor_walk" ></animation>
			<animation name="run" file="actor_run"></animation>
		</actor>
	</nodes>
	<instances>
		<model name="model3" file="file3.egg" pos="0,0,0" hpr="0,0,0" scale="1,1,1"></model>
	</instances>
</root>

I would like to ask what you think of my project and if its worth making it.

Do you have any other ideas of wath else I could make the file support. Please post them.

Because I’m new to python I don’t yet know all the information that could me stored about the models, light, camera, …
It would help me alot if you could help me with this information.

Hmm, I think this already exists. The format is called COLLADA and is also based on XML. We’ll have native support for it in Panda 1.8.

Collada is a file to store 3d models.
My idea is to create a XML file that will load models to the engine, reparent them and set some propoties.
It would also create lights, place-holders, etc. I would load the actor and it’s animation files.

It could be seen as a XML level editor. Maybe after I’m done with the importer I could create a GUI to create these file.

[EDIT]
I was wrong. I looked a little bit more information about the COLLADA format and it looks like it supports all this. Looks like my prject isn’t that necessarily. But I will still do it. 1.7 is still in it’s beginnings and I think it’s a fun project to start with. I will understand the engine much better than if I would be creating a video game.

Or, you could help the devs with finishing the Collada support.

I have already done this.

Example:

(Note, you need to do all your Panda imports and such…

#Import xml:
import xml.etree.ElementTree as xml

class Loader():

    def __init__(self):

        #Set some var's:
        self.currentObject = 0

        #Parse XML directly from the file path
        self.tree = xml.parse("level.xml")
        self.root = self.tree.getroot()
        self.objectList = self.root.findall("object")

        #Load level:
        if self.objectList != None:
            for n in self.objectList:

                self.element = n

                self.type = self.element.get("type")
                self.name = self.element.get("name")

                if self.type == "model":

                    self.path = self.element.get("path")
                    self.x = float(self.element.get("x"))
                    self.y = float(self.element.get("y"))
                    self.z = float(self.element.get("z"))

                    model = Model("models/"+self.path,self.x,self.y,self.z)


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:
        self.model.setPos(x,y,z)

        #Reparent the model to render:
        self.model.reparentTo(render)

loader = Loader()

And the level it loads:

<world>
	<object name="Cube" type="model" path="Cube.egg" x="1" y="0" z="0" />
	<object name="Sphere" type="model" path="Sphere.egg" x="-1" y="0" z="0" />
</world>

If you expand on that, you can easily do what your asking for.

You could use collada as a scene storage format, but I wouldn’t. A simple xml scheme is much better. What Sothh posted above is a good starting point.