Scaling a mesh without scaling its normals

Started by
3 comments, last by remigius 13 years, 7 months ago
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
"REAL programmers use a magnetised needle and a steady hand"xkcd.com/378
Advertisement
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.
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 :)
"REAL programmers use a magnetised needle and a steady hand"xkcd.com/378
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.

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.
Rim van Wersch [ MDXInfo ] [ XNAInfo ] [ YouTube ] - Do yourself a favor and bookmark this excellent free online D3D/shader book!

This topic is closed to new replies.

Advertisement