Simple Panda3D tutorial - terrain from height map

Yay for height maps!

All right, so the reason why you can’t go passed 250x250 is a bit of a doozy (I may be way off on this too, but it seems right):

So if you use pdb.pm() at the crash, you’ll see it dying around vertex index 65535, which is in line with the assertion error (in this case, its asking if the newest index is indexArray[65536],
and since uint16(65536)=0x0000, its triggering the assertion error)

Okay, so the heart of this lies in the GeometryPrimitive’s cycleDataWriter. Its based off of CycleData, which is a generic object used by many panda classes to store data. Each class usually implements their own version, and the GeomPrimitive unfortunately uses uint16s to store the vertex indices (check
panda/src/gobj/geomPrimitive.i line 367. CDWriter and Reader are built off of CDATA).

I’m curious if this is a hardware limitation?
(by the way, geomPrimitive.cxx line 247 is the add_vertex function)

Anywho, there’s a funny solution that may be nigh impossible (other than
splitting into multiple geomPrimitives to avoid the 65k vertex limit):

So the GeomPrimitive only builds an index off of the vertex list if it perceives the need to. If your vertex indices in the primitive are strictly ordered (1,2,3,4,5, etc). then it keeps the primitive unindexed. As a result, it avoids using the cycle data at all, preventing the assertion. You can test this with the following:

myGeom=GeomTriangles(Geom.UHStatic)


for i in range(100000):
   myGeom.addVertex(3*i)
   myGeom.addVertex(3*i+1)
   myGeom.addVertex(3*i+2)
   myGeom.closePrimitive()

will make 1000000 polygons. You can kill the whole thing by following up with:


myGeom.addVertex(1)  #BEWAAAAAAARE

This will force indexing, and subsequently cause roughly 3000000 assertion errors to trigger. whee. So yeah, if you find a way to order the triangles to the same order as the verticess, you can do larger than 250x250 height maps.