你好, welcome to the Panda3D community !
As @Thaumaturge pointed out, you should indeed call Geom.modify_vertex_data()
. But first you also need to call modify_geom(0)
on your GeomNode instead of getGeom(0)
. More about that on this manual page.
So your code sample would look something like this:
model = self.loader.load_model("somemodel.bam")
geomNodeCollection = model.findAllMatches('**/+GeomNode')
for nodePath in geomNodeCollection:
geomNode = nodePath.node()
geom = geomNode.modify_geom(0)
vdata = geom.modify_vertex_data()
vertex = GeomVertexRewriter(vdata, 'vertex')
while not vertex.isAtEnd():
vertex.setData3(0.0, 0.0, 0.0)
If you want to make your code as efficient as possible, it is recommended to use memoryviews instead of GeomVertexReader/Writer/Rewriter. Although this is not (yet) explained in the manual, I have made some code samples that you can study to get familiar with how that works.
Also, in case you wanted to offset (translate) the vertex positions instead of setting them to specific coordinates, it would be a lot better to call GeomVertexData.transform_vertices
, or even Geom.transform_vertices
.