Hey folks!
I'm currently working on a deformation project, and need to be able to alter the co-ordinates of an SMesh's vertices during run time. I've managed to alter the SMesh's buffer, but don't seem to be able to find a way of replacing the old SMesh buffer with the new one.
I did think about calculating a new buffer, deleting the old SMesh, and creating a new, deformed SMesh. However, deleting the SMesh doesn't seem to remove it visually from my screen.
Any ideas on how to solve this problem would be very appreciated. Thanks for the help!
Deforming an SMesh
I hope you're not calling delete on a mesh buffer pointer. The mesh buffer is reference counted, so you should be calling drop() in most cases.
If you want to replace an entire mesh, you would have to rebuild the replacement mesh, and then go back and update the mesh pointer held by any scene nodes that are using the mesh and maybe the mesh cache. If you don't do that, they will continue using the original mesh.
Travis
If you want to replace an entire mesh, you would have to rebuild the replacement mesh, and then go back and update the mesh pointer held by any scene nodes that are using the mesh and maybe the mesh cache. If you don't do that, they will continue using the original mesh.
Travis
Actually, I think I'm doing what you're suggesting (besides wiping the mesh cache). My mesh is originally declared as follows:
My deformation mathematics returns a displacement array, of length 3xnumVertices, containing the x, y and z displacements of each vertex. I deform the vertex buffer as follows:
I've checked the buffer and the values are definately being changed, but the visualised mesh is not. How would I go about wiping the mesh cache to see if that fixes things?
Code: Select all
buffer = new SMeshBuffer();
cubeForm(buffer); //Fills the buffer
cubeMesh = new SMesh();
cubeMesh->addMeshBuffer(buffer);
cubeSceneNode = smgr->addOctTreeSceneNode(cubeMesh);
cubeSceneNode->setPosition(vector3df(3, -2, (f32)-0.3));
cubeSceneNode->setRotation(vector3df(0, 60, 0));
Code: Select all
int n = 0;
for(int i = 0; i < nNodes; i++)
{
buffer->Vertices[i].Pos.X += disp[n];
buffer->Vertices[i].Pos.Y += disp[n+1];
buffer->Vertices[i].Pos.Z += disp[n+2];
n = n+3;
}