eggdata geomvertexwriter difference

Hi,

i have experienced a curious difference between procedurally generated objects using eggdata and geomvertexwriter.

when doing collision detection against a model i have generated using the geomvertexwriter it is way faster (like 2times) in comparison to a model generated with eggdata. Both models are not optimized for collisions, but i actually dont understand what can cause this difference.

i have put together a small sample showing the problem. To test the both situations change the follwing line (line number 4 of bam-egg-test.py) to eigther True or False:
misc.wallgenerator.wallGenerator2_v0007.USE_GEOMVERTEXWRITER = False

http://public.nouser.org/~rspoerri/tmp/problemsample.zip

The difference is revealed by render.analyze(). With your eggdata approach:

>>> render.analyze()
14 total nodes (including 0 instances); 0 LODNodes.
1 transforms; 7% of nodes have some render attribute.
4 Geoms, with 4 GeomVertexDatas and 2 GeomVertexFormats, appear on 3 GeomNodes.
2578 vertices, 2578 normals, 2566 colors, 2578 texture coordinates.
GeomVertexData arrays occupy 154K memory.
GeomPrimitive arrays occupy 9K memory.
2 GeomVertexArrayDatas are redundant, wasting 1K.
1 GeomPrimitive arrays are redundant, wasting 3K.
1382 triangles:
  1382 of these are on 691 tristrips (2 average tris per strip).
  0 of these are independent triangles.
0 textures, estimated minimum 0K texture memory required.

And with your geomvertexwriter approach:

>>> render.analyze()
11 total nodes (including 0 instances); 0 LODNodes.
1 transforms; 36% of nodes have some render attribute.
3 Geoms, with 3 GeomVertexDatas and 1 GeomVertexFormats, appear on 3 GeomNodes.
2764 vertices, 2764 normals, 2764 colors, 2764 texture coordinates.
GeomVertexData arrays occupy 98K memory.
GeomPrimitive arrays occupy 9K memory.
1 GeomPrimitive arrays are redundant, wasting 3K.
1382 triangles:
  0 of these are on 0 tristrips.
  1382 of these are independent triangles.
0 textures, estimated minimum 0K texture memory required.

So, the egg library is creating triangle strips for you automatically. Triangle strips are a little bit faster to render than individual triangles, but it means just one more step for the collision system to have to decompose the triangle strips before it can test for collisions.

David

i have been playing around with the eggdata generator i use (misc/wallgenerator/wallGenerator2_V0007.py):

INVERT_ALPHA = False
from pandac.PandaModules import EggData, EggGroup, EggVertexPool, EggPolygon, \
EggVertex, VBase4, Point3D, Point2D, Vec3D, Filename, loadEggData, GlobPattern
class eggGeneratorClass:
  # this one takes longer to generate
  # but it automatically generates a ?optimized? version
  # includes tangent and binormals as well
  def __init__( self ):
    self.egg = EggData()
    self.vtxPool = EggVertexPool('eggvertexpool')
    self.egg.addChild(self.vtxPool)
    self.group = EggGroup('egggroup')
    self.egg.addChild(self.group)
    self.c = 0
  
  def addSquare( self, in_position, in_color
                , normal=[(0,0,1),(0,0,1),(0,0,1),(0,0,1)]
                , texCoord = [[1,0],[1,1],[0,1],[0,0]] ):
    epoly = EggPolygon()
    self.group.addChild(epoly)
    for i in xrange(4):
      eprim = epoly
      ev = EggVertex()
      ev.setPos(Point3D(*in_position[i]))
      ev.setUv(Point2D(*texCoord[i]))
      ev.setNormal(Vec3D(*normal[i]))
      if INVERT_ALPHA:
        in_color[i][3] = 1.0-in_color[i][3]
      ev.setColor(VBase4(*in_color[i]))
      self.vtxPool.addVertex(ev)
      eprim.addVertex(ev)
  
  def generate( self ):
    self.egg.recomputeTangentBinormal(GlobPattern(""))
    self.egg.removeUnusedVertices(GlobPattern(""))
    #self.save( 'tmp.egg' )
    return loadEggData( self.egg )
  
  def save( self, filename ):
    self.egg.writeEgg( Filename( filename ) )
  
  def reset( self ):
    self.egg = EggData()

i’d like to know if there is a way to prevent this optimization which is done in the egg-file.

The problem really is, that if i take the bam file created from the geomvertexwriter, convert it to egg and convert it back to to bam the performance goes down quite a lot. Even if i use all possible tools like the octree-optimization tools found in the forums i cant get the speed, i get from using the geomvertexwriter version.

Since you’re building an egg file anyway, why not just put:

<Collide> { Polyset keep descend }

in the egg file to duplicate all of the geometry into CollisionPolygons? Then stop colliding with visible geometry. This will be far, far faster than your current approach anyway.

If you insist on colliding with visible geometry, you can put:

egg-mesh 0

in your Config.prc file to turn off this triangle-strip optimization.

David

Ok :slight_smile: i was confused by the slow speed the egg file caused, especially that converting the files caused such a difference in the collision detection speed.

By adding the flags in the generator i now have a gain in speed of about 30%

      cFlags = EggGroup.CFKeep+EggGroup.CFDescend
      self.group.setCsType(EggGroup.CSTPolyset)
      self.group.setCollideFlags(cFlags)

thanks a lot drwr