Sign in to follow this  
Nazdreg

Scaling a mesh without scaling its normals

Recommended Posts

Hi,

in a snowboarding game im making, i have a skinned mesh and a few animations, but now i need to be able to have the character's body face in the opposite direction but still have his head, arms etc all posed in the same direction, so i cannot simply rotate it. rather than make another mesh which is inverted along the x axis, i tried scaling it with a x scaling of -1.0. this works, however the normals are now inverted, so it looks funny.
I tried SetRenderState(D3DRS_NORMALIZENORMALS, TRUE), but it seems that that is only for setting the normals to the correct length rather than the correct direction.
does anyone know how to scale a model, but not affect the surface normals?

thanks

Share this post


Link to post
Share on other sites
I don't really understand _why_ you apply the x *= -1 scale, and maybe there's a better way.
But if you're really sure you need it, here is my comment on your problem:

I think the normals need to be transformed, what (most likely) screws up your rendering is the fact that you have to reverse the vertex winding after the mirroring.
If you cannot access the mesh and do this on the index buffer, you can reverse the cull mode to make the triangles visible again.

If that's not the problem a screenshot would help.

Share this post


Link to post
Share on other sites
Ah i never thought about reverse culling.

here is a screen shot of the snowboarder with no scaling:



and here is a screen shot of when i scale it by {-1.0,1.0,1.0}




And thanks, changing the cullmode worked:




So thank you very much :)

Share this post


Link to post
Share on other sites
You'll need to build a reflection matrix to transform the normals across the yz plane. You can do the reflection transformation in the shader when needed or build a new input stream with the transformed normals. The light direction between the original and the fixed version makes me suspect that the shading isn't matching the light location unless you also moved the light too.

Share this post


Link to post
Share on other sites

It may be useful to create this mirrored copy in your modelling package and export it as a seperate mesh with the correct normals that you can use whenever it's needed. Unless you have a particular reason for doing this mirroring in code, it's probably better to have an additional model than an additional rendering codepath.

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