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]).normalized;
// Tangents?? I really do not understand these guys
tangents = mesh.tangents;
for (int i = 0; i < tangents.Length; ++i) {
Vector4 temp = transform.MultiplyVector(tangents[i]).normalized;
temp.w = tangents[i].w;
tangents[i] = temp;
}
Note: The input matrix converts from local to world space and is needed to combine multiple meshes together.
Mesh.CombineMeshes
seems to work fine with the same input matrix. But obviously it could be creating a normal matrix or something. Are you suggesting that I should be usingtransform.inverse.transpose.MultiplyVector
instead? – Lea Hayes Nov 26 '12 at 23:14normalMatrix = transform.inverse().transpose()
and see if that solves your problem. A tangent is just a vector that "grazes" the surface. – bobobobo Nov 27 '12 at 1:03w
component might be messed up)... cheers! – Lea Hayes Nov 27 '12 at 1:41