Deforming an SMesh

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Helderash
Posts: 49
Joined: Sun Mar 25, 2007 8:41 pm

Deforming an SMesh

Post by Helderash »

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!
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

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
Helderash
Posts: 49
Joined: Sun Mar 25, 2007 8:41 pm

Post by Helderash »

Hi vitek, thanks for the help!

So there's no way of editing an SMesh's vertex buffer and having Irrlicht visualise the change without reconstructing a new mesh?
Helderash
Posts: 49
Joined: Sun Mar 25, 2007 8:41 pm

Post by Helderash »

Actually, I think I'm doing what you're suggesting (besides wiping the mesh cache). My mesh is originally declared as follows:

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));
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:

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;
}
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?
Post Reply