Retrieving geometric information

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:

egg = EggData()
Filename fname('myEggFile.egg')
egg.resolveEggFileanme(fname)
egg.read(fname)

Then you can iterate through the individual groups in the egg file with something like this:

def iterateEgg(egg):
  print egg.getName()
  child = egg.getFirstChild()
  while child != None:
    iterateEgg(child)
    child = egg.getNextChild()

When you come to an EggVertexPool, you can iterate through its list of vertices and get the data you want.

Does this give you what you want? I don’t know exactly what your application for querying vertices is, so it’s hard to suggest the best approach.

David

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.

David

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?

Kinds regards

by the way, are there any documentation for those egg methods (none on this site) and which modules do I have to import to use them?

kind regards

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).

To learn about these interfaces, the best place to look is in the source code, via ViewCVS. The root of the tree is here: http://cvs.sourceforge.net/viewcvs.py/panda3d/ and you can get to eggVertexPool.h here: http://cvs.sourceforge.net/viewcvs.py/panda3d/panda/src/egg/eggVertexPool.h?only_with_tag=HEAD&view=markup.

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.

David

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?)

Regards

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.

David

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” :…(

Yes, it looks like the egg library was inadvertently omitted from the initial generate list by the publish script.

But you can get it back. Just run the command:


genPyCode libpandaegg

You only need to run this once. This will take a minute or two to execute, but when it is done you will have the Egg interfaces available.

David

Thanks david! :slight_smile: Now everything works as expected.

Best Regards