GeomVertexWriter

Is there any reason why the GeomVertexReader works, but the GeomVertexWriter does not (as does the GeomVertexRewriter doesn’t work either)? If you comment out the two lines dealing with the GeomVertexWriter, it works, and reads the data correctly. What am I doing wrong?\

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

#creating
prim = GeomTriangles(Geom.UHStatic)
vdata = GeomVertexData('',GeomVertexFormat.getV3(),Geom.UHDynamic)

geom = Geom(vdata)
geom.addPrimitive(prim)

vertex = GeomVertexWriter(vdata,'vertex')
for i in range(0,3):
	vertex.addData3f(0,0,0)

prim.addVertices(0,1,2)
prim.closePrimitive()

node = NodePath(GeomNode('gnode'))
node.node().addGeom(geom)

#modifying
mgeom = node.node().getGeom(0)
mvdata = mgeom.getVertexData()
mvertex = GeomVertexWriter(mvdata, 'vertex')	#comment this line to make work
mrvertex = GeomVertexReader(mvdata, 'vertex')
print mrvertex.getData3f()
mvertex.setData3f(0,1,0)    			#and this line

run()

You didn’t say in what way the GeomVertexWriter is failing, so I have to guess, but I do see a problem here:

mgeom = node.node().getGeom(0)
mvdata = mgeom.getVertexData() 

You need to use modifyGeom() and modifyVertexData() if you intend to use a GeomVertexWriter to modify the vertices. Otherwise you’re just getting a read-only copy, and the GeomVertexWriter will yell at you to that effect when you try to create it.

David

That fixed it, thanks. The error was that it was being called with the wrong kind of arguments…