How to transform mesh components?

Posted by Lea Hayes on Game Development See other posts from Game Development or by Lea Hayes
Published on 2012-11-26T22:50:48Z Indexed on 2012/11/26 23:25 UTC
Read the original article Hit count: 292

Filed under:
|
|
|

I am attempting to transform the components of a mesh directly using a 4x4 matrix. This is working for the vertex positions, but it is not working for the normals (and probably not the tangents either).

Here is what I have:

// Transform vertex positions - Works like a charm!
vertices = mesh.vertices;
for (int i = 0; i < vertices.Length; ++i)
    vertices[i] = transform.MultiplyPoint(vertices[i]);

// Does not work, lighting is messed up on mesh
normals = mesh.normals;
for (int i = 0; i < normals.Length; ++i)
    normals[i] = transform.MultiplyVector(normals[i]);

Note: The input matrix converts from local to world space and is needed to combine multiple meshes together.

© Game Development or respective owner

Related posts about math

Related posts about unity