• 15
• 15
• 11
• 9
• 10

# MDX - BaseMesh's LockVertexBuffer() Problem

This topic is 4145 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I'm trying to Morph one mesh(a teapot) and another(the skull that came with the occlusion factor lighting tutorial). So I wrote this method that would take the teapot and access its Vertex Data then loop through all vertices and use its normal as the rayDir for use as a parameter in the skull's Intersect method. The problem is, the teapot.LockVertexBuffer(...) returns an array of size 1, then I tried using GraphicsStream way, but its unsafe code so I used the modifyer in the method header and that didn't work and I tried using it as a block and that didn't work. I have another mesh that clones the teapot but uses a Vertex structure I've made that has 2 Positions and a Normal(I have its format like Position | Position | Normal, not sure if thats right since the LockBertexBuffer isn't returning what I want) I have a VertexDeclaration though that has a Position0 and Position1 and a Normal0. So the shader just takes in a variable from the main program that goes between 0 and 1 and I lerp() the 2 positions(the original and where the vertex morphs to) based on that, so when it runs the teapot has 1 vertex out of place(I guess the one vertex I replace by calling morph.SetVertexBufferData()) and all its points go to zero. And in all this I just want to know how to access a Mesh's VertexData, all of it!
private void ComputeTransPosition()
{
CustomVertex.PositionNormal[] verts = (CustomVertex.PositionNormal[])teapot.LockVertexBuffer(typeof(CustomVertex.PositionNormal),LockFlags.None,new int[]{1});

Vector3 rayPos = new Vector3(0.0f,0.0f,0.0f);
Vector3 rayDir = new Vector3(0.0f,0.0f,0.0f);

int length = verts.Length;
IntersectInformation inter = new IntersectInformation();

Vector3[] info = new Vector3[length];

for(int i = 0; i &lt; length; i++)
{
rayDir = new Vector3(verts.Nx,verts.Ny,verts.Nz);
bool b = skull.Intersect(rayPos,rayDir,out inter);
if(b)
{
rayDir = (inter.Dist * rayDir) + rayPos;
info = new Vector3(rayDir.X,rayDir.Y,rayDir.Z);
}
else
{
info = new Vector3(verts.X,verts.Y,verts.Z);
}
}

morpher = teapot.Clone(MeshFlags.SystemMemory,fmt,device);
Vertex[] nVerts = new Vertex[length];

for(int i = 0; i &lt; length; i++)
{
nVerts = new Vertex(verts.X,verts.Y,verts.Z,
info.X,info.Y,info.Z,
verts.Nx,verts.Ny,verts.Nz);
}
morpher.SetVertexBufferData(nVerts,LockFlags.None);

teapot.UnlockVertexBuffer();
}