Search code examples
pythonmeshpanda3d

Causes of Panda3D GeomVertex Writer/Rewriter type error when using the same syntax and object types as in the documentation?


I am completely new to Panda3D on Python and trying to edit a 3D mesh in-place to move its vertices following the user's inputs. I am using the GeomVertexRewriter or GeomVertexReader + GeomVertexWriter APIs (I tried both), as suggested in the Panda3D documentation here. However I could not create any GeomVertexWriter (or GeomVertexRewriter which herits from both GeomVertexReader and GeomVertexWriter) object without encountering the following error:

TypeError: Arguments must match:
GeomVertexWriter()
GeomVertexWriter(GeomVertexArrayData array_data)
GeomVertexWriter(GeomVertexData vertex_data)
GeomVertexWriter(Thread current_thread)
GeomVertexWriter(GeomVertexData vertex_data, const InternalName name, Thread current_thread)
GeomVertexWriter(GeomVertexArrayData array_data, int column, Thread current_thread)
GeomVertexWriter(GeomVertexArrayData array_data, Thread current_thread)
GeomVertexWriter(GeomVertexData vertex_data, Thread current_thread)

The error does not happen when I create a GeomVertexReader, and it seems to work perfectly. Also, my vdata is of the correct type (<class 'panda3d.core.GeomVertexData'>) and prints correctly too (shortened version below):

CatMesh2
  949 rows.
  Array 0 (0000018310B6A3E0, [ vertex(3f) normal(3f) ]):
    row 0:
      vertex 1.57086 8.22246 0.487809
      normal 0.672279 0.738758 0.0477129
    row 1:
      vertex 1.69762 8.07273 1.88392
      normal 0.748853 0.662674 0.00910493

[...]

    row 948:
      texcoord 0.249509 0.530177 0

It seems that everywhere I searched, the only way this constructor is ever called is with the very same syntax GeomVertexWriter(vdata, 'vertex') (or 'texcoord'), so I don't really see why this type error occurs.

I tried the following code (that doesn't work):

vertex = GeomVertexRewriter(vdata, 'vertex')
while not vertex.isAtEnd():
    v = vertex.getData3()
    vertex.setData3(v[0], v[1], 0.0)

>>>   File "...\src\geometry_processing.py", line 6, in editVertexData
    vertex = GeomVertexRewriter(vdata, 'vertex')
TypeError: Arguments must match:
[...]

Same goes for this one:

vertexW = GeomVertexWriter(vdata, 'vertex')
vertexR = GeomVertexReader(vdata, 'vertex')
v = vertexR.getData3()
vertexW.setData3(v[0], v[1], newVal)

It also happens when I replace 'vertex' with 'texcoord'.

The reader version however works fine:

vertexR = GeomVertexReader(vdata, 'vertex')
v = vertexR.getData3()
print(v)

>>> LVecBase3f(1.57086, 8.22246, 0.487809)

Has anyone ever encountered this error? I have no idea why it occurs even though I am doing the same thing as in the examples in the documentation and in other places. If it was not my mistake, could it be that the vdata from the model I am using is the issue?


Solution

  • How did you obtain the GeomVertexData object? It's possible that you have a "const" version of this object, such as obtained from geom.getVertexData(), but you need a non-const version, such as obtained from geom.modifyVertexData().