Getting mesh data. How?

Hello folks,

well, I wonder how can I read some mesh data in Panda in order to create a navmesh (for pathfinding), for that I´m gonna need the vertex and the polygons information, from that I can build the ‘nodes’ and implement the, in case, the A*.

I was thinking about two possible approaches:

  1. read the egg file and get the info i need, using some python script I will have to write.
  2. try to use the Geom &Cia classes from Panda3D that I don’t know how they work.

So… do you have any tips for me? :slight_smile: There is any implementation of Navmesh for Panda3D, I didn’t found… or even some tips about how to deal with the egg files…

thanks.

There are many examples in the forum and I suggest you can look into “Code Snipplets” for some examples. You can deal with the egg file directly or deal with the model you loaded into memory.

Yesterday I just copy some code from a sample program which deal with a geomnode to get the data after it is loaded:

def getVertexInfo(np, relative=None):
    vertexinfo = []
    geomnode = np.node()
    nrgeoms = geomnode.getNumGeoms()
    for n in range(nrgeoms):
        geom = geomnode.getGeom(n)
        data = geom.getVertexData()
        numVtx = data.getNumRows()
        vtxReader=GeomVertexReader(data)
        # begin reading at vertex 0
        vtxReader.setRow(0)
        # get the vertex position column
        column=-1
        columnName=''
        while ( columnName!='vertex' ):
            column+=1
            vtxReader.setColumn(column)
            columnName=str(vtxReader.getColumn().getName())
        #=========================================================
        # create vertex normal reader
        normalReader=GeomVertexReader(data)
        # begin reading at vertex 0
        normalReader.setRow(0)
        # get the vertex normal column
        hasNormals=True
        column=-1
        columnName=''
        while ( columnName!='normal' ):
           column+=1
           normalReader.setColumn(column)
           if normalReader.getColumn()==None:
               hasNormals=False
               break
           else:
               columnName=str(normalReader.getColumn().getName())

        for i in range(numVtx):
            vtx = vtxReader.getData3f()
            if relative != None:
                vtx=relative.getRelativePoint(np,vtx)

            normal=normalReader.getData3f()
            if relative != None:
                normal=relative.getRelativeVector(np,normal)
            vertexinfo.append((vtx,normal))
    return vertexinfo

It seems working well for my case. You can take it as a start point.

hi all,

well here i am again, trying to get the mesh data…

I took a good look at the manual : www1.panda3d.org/manual/index.php/ … metry_data

But my attempts are not getting any better, here is the code I am using:

main.py:

from pandac.PandaModules import loadPrcFileData
loadPrcFileData('','show-frame-rate-meter 1')

import direct.directbase.DirectStart
from pandac.PandaModules import *

from direct.task.Task import Task
from direct.showbase.DirectObject import DirectObject
#egg stuff
from pandac.PandaModules import EggAttributes
from pandac.PandaModules import GeomNode

from VectorMesh import VectorMesh

import sys

a = loader.loadModel('res/planoSimples')
a.setScale(1)
a.setPos(0,5,-1)
a.reparentTo(render)

obj = VectorMesh(a)

run()

now the VectorMesh class:

from pandac.PandaModules import GeomNode

class VectorMesh(object):
	def __init__(self, np):
		print ('              np: '), np
		print ('         np type: '), type(np)
		print ('      np pointer: '), np.node()
		print ('         np list: '), np.ls()
		print ('    np find geom: '), np.find('Plane')
		plane = np.find('Plane')
		print ('           Plane: '), plane
		print ('      Plane type: '), type(plane)
		print ('     np getChild: '), np.getChildren()
		print ('np getChild type: '), type(np.getChildren())
		print ('   find GeomNode: '), np.findAllMatches('**/+GeomNode')
		plane2 = np.findAllMatches('**/+GeomNode')
		for nodeFound in plane2:
			print ('    nodeFound: '), nodeFound
			print ('    type: '), type(nodeFound)
			print ('    numGeoms: '), nodeFound.getGeom(1)

and finally the outputs…

DirectStart: Starting the game.
Known pipe types:
  glxGraphicsPipe
(all display modules loaded.)
              np:  render/planoSimples.egg
         np type:  <type 'libpanda.NodePath'>
      np pointer:  ModelRoot planoSimples.egg T:(pos 0 5 -1)

         np list: ModelRoot planoSimples.egg T:(pos 0 5 -1)
  GeomNode Plane (1 geoms)
 None
    np find geom:  render/planoSimples.egg/Plane
           Plane:  render/planoSimples.egg/Plane
      Plane type:  <type 'libpanda.NodePath'>
     np getChild:  render/planoSimples.egg/Plane

np getChild type:  <type 'libpanda.NodePathCollection'>
   find GeomNode:  render/planoSimples.egg/Plane

    nodeFound:  render/planoSimples.egg/Plane
    type:  <type 'libpanda.NodePath'>
    numGeoms: 
Traceback (most recent call last):
  File "tentativa01.py", line 22, in <module>
    obj = VectorMesh(a)
  File "/home/web/Documentos/Pesquisas/geomNode/VectorMesh.py", line 20, in __init__
    print ('    numGeoms: '), nodeFound.getGeom(1)
AttributeError: 'libpanda.NodePath' object has no attribute 'getGeom'

I’m gonna cry… sniff sniff
Why it is not working? i mean… the GeomNode, how can i get it?
I always get stuck in the NodePaths.

Ah… Using the Panda 1.6.0

Once you have a NodePath, call np.node() to get to its underlying Node.

David