Trouble with Vertex Writer

I’ve been working on in game model generation. I’ve been able to build the models fine. I’ve moved on to trying to add texcoordinates to the vertices but I’ve run into a problem.

My implmentation is just to create a for loop going through vertices in a circle then adding the processed data points to the vertexData object.

For the texcoording code in the ‘U’ direction I have:

#Texcoord calculations
			if oldvert is not None: 
				rowPos = vdata.getNumRows()
				print "rowPos =  ",rowPos
				texWriter.setRow(rowPos-1)			  #Back up one vertex to grab the data. 	
				cdist = self.spinnerets[i].getDistance(oldvert)
				print "distance = ", cdist
				if texWriter.hasColumn():
					print "column here"
					q = texWriter.getData2f()
					CoordU = q + cdist
				else: print "no column"
				CoordU = q + cdist
			else: CoordU = 0.001

Basically I’m trying to calculate the real world distance between the currect vertex and the previous one to use that information to scale the texture in the U direction. The first pass of the loop bypasses the function and just sets the U coordinate to zero.

My GeomVertexRewriter gives me an error. It looks like its saying there isn’t any data in the column, but as you can see from the print out of the vertexData, the column is there and has data in it. Here’s the error message, I’ve told it to print out some of the relevant variables in the terminal as well:

  1 rows.
  Array 0 (0ABAA094, [ vertex(3f) normal(3f) texcoord(2f) ]):
    row 0:
      vertex -0.701939 -1.63289 -6.22406
      normal 0.212537 0.367605 0.90537
      texcoord 0.001 0.001

  i= 1 rowPos =   1
distance =  7.01223564148
Assertion failed: GeomVertexWriter::get_column() == GeomVertexReader::get_column() at line 268 of c:\buildslave\release_sdk_win32\
Traceback (most recent call last):
  File "C:\Panda3D-1.7.2\direct\showbase\", line 61, in eventLoopTask
  File "C:\Panda3D-1.7.2\direct\showbase\", line 55, in doEvents
  File "C:\Panda3D-1.7.2\direct\showbase\", line 124, in processEvent
  File "C:\Panda3D-1.7.2\direct\showbase\", line 388, in send
    self.__dispatch(acceptorDict, event, sentArgs, foundWatch)
  File "C:\Panda3D-1.7.2\direct\showbase\", line 473, in __dispatch
    method (*(extraArgs + sentArgs))
  File "", line 204, in toggleRecord
  File "", line 219, in initiateMap
    self.getVertices(self.vdata, self.imageCoordinates, self.PatientMarker, self.verticesPerCircle, [self.panelresX, self.panelres
Y], self.panelscale)
  File "", line 316, in getVertices
    if texWriter.hasColumn():
AssertionError: GeomVertexWriter::get_column() == GeomVertexReader::get_column() at line 268 of c:\buildslave\release_sdk_win32\bu
:task(error): Exception occurred in PythonTask eventManager

Hmm, the error message isn’t actually reporting that there’s no data in the column, but rather that the internal data structures within the GeomVertexRewriter have gotten confuzzled–where the “writer” and “reader” columns should be the same, they are instead unexpectedly different.

I’m not sure how that happened, and it bears investigation. Would you mind putting together a complete sample application that demonstrates the crash?

But as to your bigger issue, I don’t think you’re going about it the best way anyway. The GeomVertexRewriter ought to work the way you are trying to use it, but it isn’t designed to work that way, and it will be fairly slow to move back and forth in the data that way. It would be better to keep track of the previous vertex’s value separately, rather than re-reading it from the GeomVertexRewriter. If you’re just walking through the vertices from beginning to end, this should be easy.


Thanks for your reply. Enlightening as ever.

You’re exactly right. After thinking about this some more, I got it to work precisely the way you describe. The only reason I did it like this was because I saw that the fractal_tree sample uses this call and I figured that was the best way to do what I was doing as well.

I’ll work on the sample program.

This code reproduces the error. It doesn’t actually do anything with the vertices it makes.

from pandac.PandaModules import * 
from direct.directbase.DirectStart import *
vdata=GeomVertexData("body vertices", format, Geom.UHStatic)
vertWriter=GeomVertexWriter(vdata, "vertex")
normalWriter=GeomVertexWriter(vdata, "normal")
TexReWriter=GeomVertexRewriter(vdata, "texcoord")
vPC = 8
startRow = vdata.getNumRows()

z = 0

for next in range(2):
	z += 10
	for i in range(8):
		point = Point3(i,i,z)
		rowPos = vdata.getNumRows() 
		if rowPos > 0:
			TexReWriter.setRow(rowPos-1)           #Back up one vertex to grab the data.     
			q = TexReWriter.getData2f() 
		vertWriter.addData3f(point)   #Vertex writer saves the 3D position
		TexReWriter.addData2f(0.5, 0.5) 

OK, I finally tracked down the problem; there was a bug when using a GeomVertexRewriter with an initially empty vdata. My apologies for the bug, and thanks for your help! I committed a fix which will eventually become part of 1.8.