Deformation

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
jstroh
Posts: 37
Joined: Fri May 02, 2008 9:33 am

Deformation

Post by jstroh »

You mention this in the documentation but how would one go about deforming a statictrianglegroup?
User avatar
Zukarakox
Not a Site Admin
Posts: 426
Joined: Mon Jul 10, 2006 4:28 am

Re: Deformation

Post by Zukarakox »

Editting the triangles then calling reinitialize() on the statictrianglegroup would do it -- I don't particualrily know the best way to edit the triangles. I'm assuming they are shallow copies, so if you store whatever you originally made it from, then edit it, (then reinitalize) it would do the trick.
i has multiple toes
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Deformation

Post by Norbo »

Well there's a couple of ways to go about doing this. There are some parts that aren't as clear as they should be in regards to the references being kept, so some methods may generate extra garbage when it isn't really necessary.

If you use the initializeData(vertices, indices) method to create the group, those lists are used internally with no copying. You can then scoot the vertices around within the vertices list and then call reinitialize(). This is basically what Zukarakox mentioned.

The other way, assuming you used an initializeData convenience method and you don't have direct references, would be to grab a copy of the interior vertex list by using getVerticesCopy, mess with it, then use switchOutVertices. switchOutVertices reinitializes the data as well. Note that when you use switchOutVertices, the vertex list you pass in becomes the new interior vertex list, which means you once again have a direct reference outside of the engine. This allows you to just scoot vertices and then call reinitialize(), like above.

Really, there's an extra step in there that only seems to cause confusion. I initially put it in there to protect people from messing with data without reinitializing it, but that really didn't happen since you can still hold direct references outside of the group. In v0.6.0, you'll probably see the getVerticesCopy method replaced with just a reference to the vertexBuffer field with a few extra instructions on how to modify it safely. This would require the user to reinitializing after adjusting positions of vertices and to maintain the connectivity of the mesh (avoiding the addition of new vertices or changing indices).
Post Reply