Sign in to follow this  

directx 9 skinned mesh morphing

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all

 

I'm trying to morph 2 skinned meshes (through software for now) to alter a facial expression.

The 2 meshes load in with no problems as a hierarchy and render without issue too. Both have identical index buffers (they're the exact same mesh but with some vertices slightly altered) to simulate the expressions.

 

The issue I'm having is that there is no alteration to the facial expression at all. Even when loading them both as static meshes and trying that way

The following is the code I'm using to morph the meshes (Vertex is the custom vertex struct)

Vertex *srce = NULL, *dest = NULL;

src->GetMesh()->LockVertexBuffer(0, (void**)&srce);
bln->GetMesh()->LockVertexBuffer(D3DLOCK_READONLY, (void**)&dest);

for(int i = 0; i < src->GetMesh()->GetNumVertices(); ++i)
{
	srce->nor = srce->nor * weight + dest->nor * (1.0f - weight);
	srce->pos = srce->nor * weight + dest->pos * (1.0f - weight);
}

bln->GetMesh()->UnlockVertexBuffer();
src->GetMesh()->UnlockVertexBuffer();

If it helps; I can provide the meshes to see if it's an issue with them (but they're a little larger than than the single file size limit)

 

Any help would be greatly appreciated.

Share this post


Link to post
Share on other sites

Looks to me that your destination has "read only" flags. Shouldn't it be for the source?

 

Otherwise I suggest strongly not to read from a vertex buffer. It could result as poor performance.

 

Cheers!

Share this post


Link to post
Share on other sites

Sorry, poor naming convention on my part. The part I'm writing to is srce.

 

Thanks for the tip about reading from the vertex buffer; I'm hoping to switch to hardware morphing but need to get this working as a proof of concept

Share this post


Link to post
Share on other sites

Well before using hardware morphing you could still store your vertex data in two different (CPU side) constant arrays and then store the blended result in the vertex buffer.

 

If I understand correctly, your code uses the already blended data to blend some more, so I'm not sure if this is what you are after. Eventually the src buffer content will be the same as the dst buffer content. 

 

Cheers!

Share this post


Link to post
Share on other sites

First, your loop modifies only a single vertex. There's no change in pointers. [ EDIT: and other problems ]

for(int i = 0; i < src->GetMesh()->GetNumVertices(); ++i)
{
    srce->nor = srce->nor * weight + dest->nor * (1.0f - weight);
    srce->pos = srce->nor * weight + dest->pos * (1.0f - weight); // scre->pos based on srce->nor ???
    // srce += size_of_vertex ???
    // dest += size_of_vertex ???
    // is weight same for every calc? if so, that's fine. EDIT: I assume that's the time-dependent morphing
    // EDIT: Also assume you have changed "srce->nor =" to "dest->nor =" etc. as mentioned.
}

EDIT: ignore the following. I now see what you're doing with the weight morphing.

Is there a specific need for copying over the entire buffer? Can you just change the mesh buffer pointer depending on which expression you want to use?

Edited by Buckeye

Share this post


Link to post
Share on other sites
Sign in to follow this