Modify existing vertex position


I’ve got a triangle and I would like to modifiy it’s vertex positions.

I got a little helper class that stores a

LVector3& mPosition

whenever I move that position I want the corrisponding vertex in the triangle to move as well.

hence I was thinking the mPosition should simply reference one of the vertices in the triangle.

IS that a good approach ?

I have not been able to figure out how to get the reference off each of my vertices in the triangle.

I thought I could parse the vertices like this and simply store the reference to it. But it’s all in “const” domain so it wouldnt really work.

void cAWNavMeshObject::InitVertexInterface()
	PT(Geom) geom = mDebugGeometry->mMeshGeom;

	CPT(GeomVertexData) vData = geom->get_vertex_data();

	GeomVertexReader vertex = GeomVertexReader(vData, "vertex");

	for (int i = 0; i < geom->get_num_primitives(); ++i) 
		CPT(GeomPrimitive) prim = geom->get_primitive(i); 
		for (int p = 0; p < prim->get_num_primitives(); ++p) 
			int start = prim->get_primitive_start(p); 
			int end = prim->get_primitive_end(p); 
			for (int i = start; i < end; ++i) 
				int vertID = prim->get_vertex(i); 

				const LVecBase3f& v = vertex.get_data3f(); 
                               // I would store the reference here into my helper class...

As you can see here the resulting vertex “v” is const and throughout the parsing of the Geom get_vertex_data() returns a CPT as well.

any ideas how I could do this ?

the goal is to have a little box at each vertex position ( hence the helper class ) and whenever I move the box I want it to reflect in the rendered geometry vertex.

This isn’t a great approach, actually. You can’t have a LVector3f reference directly into the vertex data. There are a couple of reasons for this, but the bottom line is that the easiest way to modify an existing vertex position is with a call to modify_vertex_data() and then using the GeomVertexWriter or GeomVertexRewriter class.

Fortunately, since you are wrapping all of this inside a helper class anyway, you can have the helper class do whatever needs doing to find the appropriate vertices and modify them.