Sign in to follow this  
Kranar

Managed DirectX Scaling a Mesh

Recommended Posts

Kranar    122
I've decided to give Managed DirectX in C# a try but can not think of a way to resize a mesh. In C++ you could lock the mesh's VertexBuffer and then directly multiply each vertex by your a scaling factor, but in C# there seems to be no way to do this. Anyone have any suggestions or advice?

Share this post


Link to post
Share on other sites
Kranar    122
Actually, I think I found a similar way to directly access the vertices of a mesh doing something like this in C#


private void ScaleObject(float scale) {
Mesh scaledMesh = mesh.Clone((MeshFlags)(0),
VertexFormats.Position,
device);

Array ar = scaledMesh.LockVertexBuffer(...);

foreach(Vector3 i in ar) {
i.Scale(scale);
}
scaledMesh.UnlockVertexBuffer();
mesh = scaledMesh;
}



The problem is that I don't know what I'm supposed to pass into scaledMesh.LockVertexBuffer() in order for it to properly return an array of vertices.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this