   Splitting a Mesh... buffer help.
  Here''s the deal, I need to split a mesh by a plane.  I''ve read several hundred posts on varios forums and done a myriad of google searches and foud all kinds of info on how to do it... conceptually.  But when I get down to the nitty gritty I can''t figure out how to get the vertices I want to keep into a new mesh.The way I see it is that the mesh I am reading from has an index buffer that defines the order of vertex processing?  So it tells D3D what vertices need to be rendered in what order? I''m lost here folks."Index buffers ... are memory buffers that contain index data. Index data, or indices, are integer offsets into vertex buffers and are used to render primitives using the DrawIndexedPrimitive method."So I know how to tell what vertices are on either side of the plane, I just don''t know how to tell the new index buffer what order they should be in  I also can''t figure out how to get the vertices & indexes into a new mesh (or rather into buffers so I can stick them into a new mesh)   -Joe Bob Jr 
  It isnt'' so simple as deciding what point on are which side of the plane. You have to tell what triangles are on either side. And if a triangle manages to be on both sides you have to divide it manually. First I would start by building 2 meshes from the one that is filled with all the triangles that stay on either side. This done easily by saying all triangle point of on one side or the other. To make it easy use the index buffer in comparison to the vertex buffer rather than running through the vertex buffer. So index buffer would say 1,2,5,4,5,7,... so you know the first 2 triangles are at 1,2,5 and 4,5,7 in the vertex buffer. Check the 1,2,5 points in the vertex buffer (pVertices[1],[2],[5]) and see which side they are, if they all are on one side you know the triangle is on one side. If they are on both side, you have to clip the triangle to that plane and creat new points (which is a little more complex since a clipped triangle can become 2 triangles if clipped at an a single point, 2 points leave a triangle).  We say they are all on one side, you add them to the new meshes buffer as vertices 1,2,3 and the index buffer first 3 spots would be 1,2,3. This will build duplicate points but you can optimize later and it should weld them together.So your index buffer should look like 1,2,3,4,5,6,7,8,... until you optimize and weld together. It just makes it easy... There are of course ways to do it better but this seems reasonable. ;  I don''t have anything helpful to add, but I''m interested to know why you want to do this? The reason I ask is 1) because I''m always curious what cool effects other people are working on and 2) because it might effect whether you have to worry about the "split" triangles. I have two ideas of where it would be useful...1) I could see it would be neat to be able to slice a character up at an arbitrary angle in a fatal blow during a sword fight. In this case you obviously need to fill in the partial triangles and close off the object.But there may also be more practical applications such as clipping an explosion when it hits a wall. In this case you probably don''t need to worry about the partial triangles because it''s such a fast-happening event.In either case it''s an interesting problem. Sorry I''m adding nothing to this :0 ;  This is also something you might have to do for a leval editor, for when rooms (brushes) & stuff overlap, you have to find someway of clipping the rooms vertices back so they match and you don''t have one room halfway into another, also for doing doorways as well. ;  Nah, nothing so neat as cutting up people or stopping effects from going through walls.  As a precurser to "complete understanding of BSP trees" an instructor for a class I''m taking wants us to split an arbitrary mesh by an arbitrary plane.For the explosion, yah, the jaggies that would develope on the edge are of no real concern, but in this case I have to make the edge smooth, but I don''t have to fill in the gap (it is assumed the other chunk of the mesh would be covering the hole.So the index buffer just has a list of vertices in it listed v1, v2, v3 | v1, v2, v3 | v1, v2, v3 | ... ?  If so that makes it a lot easier than I thought.  That''d just be a list of unsigned ints to chomp through to pull out triangles.  I was trying hard to find info on what was in an index buffer but couldn''t seem to find it.   I already had an algorithm fleshed out to move the split triangles around and create vertices, this index buffer thing was causing issues.If that''s all an index buffer is then I''ll just create a huge array of BYTEs, say 128 or so for my small mesh I''m using (d3dxcreatesphere) and build my new index buffer into that and then toss that into a new mesh along with the new list of vertices... should work, heh.Thanks for the help   I should be able to get something going from this. 