# Modifying existing geometry data¶

If you want to load a model and operate on its vertices, you can walk through the vertices as shown in the previous section, but you should substitute modifyGeom(), modifyVertexData(), and modifyPrimitive() for getGeom(), getVertexData(), and getPrimitive(), respectively. These calls ensure that, in case the data happens to be shared between multiple different GeomNodes, you will get your own unique copy to modify, without inadvertently affecting other nodes.

If you want to modify the vertex data, you have two choices. The simplest option is to create a new GeomVertexData and fill it up with your new vertex data (as described in Creating and filling a GeomVertexData), and then assigning this data to the geom with the call geom.setVertexData(). You must ensure that you add enough vertices to the new GeomVertexData to satisfy the GeomPrimitives that reference it.

Your second choice is to modify the vertex data in-place, by operating on the existing vertices. You can do this with a GeomVertexWriter. For instance, if you want to copy the (X, Y) position of each vertex to its (U, V) texture coordinate, you could do something like this:

texcoord = GeomVertexWriter(vdata, 'texcoord')

Writing to a column with a GeomVertexWriter does require that the GeomVertexData’s format already has the appropriate columns to handle the data you are writing (in the above example, for instance, the format must already have a ‘texcoord’ column, or the above code will fail). Furthermore, the columns must have the appropriate format. For instance, if you wanted to upgrade a model’s texture coordinates from 2-D texture coordinates to 3-D texture coordinates, simply calling texcoord.setData3(u, v, w) wouldn’t change the fact that the existing texcoord column is a 2-component format; you would just be trying to stuff a 3-component value into a 2-component column.