Is there any way a can access geometric information like vertex positions etc. in Panda when you have loaded a egg-model?.
I have tried to use getCoordsArray on a Geom-object, but the points returned are all “None”… So the real question is: Is there another way to access the vertex positions af a loaded object?
There is a minor bug in the current version of Panda that prevents the retrieval of individual values from the array returned by getCoordsArray(). Future versions of Panda, however, beginning with version 1.1, will have a completely different, much more robust mechanism for reading and writing the vertex values from a loaded model.
In the meantime, there are other ways to get the actual vertex data from an egg file. One way is to load it as an EggData hierarchy, rather than converting it into renderable geometry; this will give you direct access to everything that literally appears in the egg file. To do this:
The vertex data is going to be used for building bounding boxes and triangle collision meshes in ODE, so the mentioned approach is definetly usable but it requires the application to parse the egg-file once more.
Furthermore I pressume it makes it impossible to use bam-files (at least in an easy way), so the answer to your question is both yes and no: If there is no other way retrieve the vertex data it has to be done like suggested, but a more direct approach would be preferable…
Ah, well, if you just want the bounding box you can use NodePath.getTightBounds(). This returns a pair of Point3’s that represent the minimum and maximum extents of the vertices defined within the NodePath.
You may also be interested in NodePath.getBounds(), which returns the bounding volume (usually a sphere) that has already been pre-computed by Panda; it is usually a looser bounding volume than the box returned by getTightBounds(), because of the way it is built up hierarchically. However, this call is much faster for a node with lots of children, since it doesn’t have to go iterate through all of the vertices on the spot.
As you wrote earlier it is posible to get the list of vertices from EggVertexPool. Can you be more specific of how to do this? How do i check that i’ve iterated to a eggVertexPool from that while-loop? and how do i get the vertices from the vertexPool?
While iterating through the nodes, you can just use the Python isinstance() function to ask if the node you have encountered is an EggVertexPool (and I just realized you need to check to see if it is an EggGroupNode before you try to walk through its list of children), e.g.:
def iterateEgg(egg):
if isinstance(egg, EggVertexPool):
handleVertexPool(egg)
if isinstance(egg, EggGroupNode):
child = egg.getFirstChild()
while child != None:
iterateEgg(child)
child = egg.getNextChild()
Once you get to a vertex pool, you can iterate through the vertices like this:
def handleVertexPool(vpool):
for i in range(vpool.getHighestIndex() + 1):
vertex = vpool.getVertex(i)
if vertex:
print vertex
Note that you do have to check the result of vpool.getVertex(), since a vertex pool might not define every vertex in its range (getVertex() will return None for the missing vertices).
The available methods are listed within the .h file (look for methods within the section marked PUBLISHED:, not public, private, or protected), and the detailed description of what each method does and how to use it is given with the method body itself, in the .I file (for a method declared INLINE) or the .cxx file (for a method not declared INLINE).
Note that we rename methods from C++ to Python, by removing underscores and capitalizing the next letter, so that (for instance) EggVertexPool::get_highest_vertex() in C++ becomes EggVertexPool.getHighestVertex() in Python.
Thanks that helped a lot. I just still do not know what to import to get access to these egg-methods. I’ve tried almost everything and looked in source-files, on the net, libraries etc. I just can’t find out how to import those egg modules (and is it Eggbase i need to import?)
Hmm, they should come in with the rest of the panda symbols when you do “from pandac.PandaModules import *”. Are they not there? If not, that’s probably a bug in the distribution script.
No, I have tried to include all in that package (from pandac.PandaModules import *) but I can still not get access to EggData() and all other egg mothods that’s “PUBLISHED” :…(