- Home /
calculate normals
How do I calculate normals? normals must indeed at a 90 ° angle to the surface are ... how do I calculate that at a mesh?
I cant use RecalculateNormals becase this smooths my mesh
Answer by Xyotic · Aug 27, 2014 at 12:56 PM
you need to set the normal for each vertex. Just use an array for your normals. Like so:
normals [yourVertices] = Vector3.up;
Vector3.up should mean a 90° angle. (correct me if I'm wrong) After you've set your normals in the array just use:
mesh.normals = normals;
(sry my english isn't the best but I hope it helps. ^^' )
there an problem ... dat onyl works for an plan.. but my mesh isnt only an plane so how to calculate for a skew vertecie/face
Answer by _dns_ · Aug 27, 2014 at 06:39 PM
Hi, meshes have the same amount of normals than vertices so if you want to have different normals for 2 faces that share 1 or more vertices: you have to duplicate vertices (and then normals).
When it's done, I guess that Unity's RecalculateNormals will compute a normal for the face and not an average of all the faces that share the same vertex.
If not: you can use the cross product of 2 vectors from each triangle to compute the normal. If the triangle is ABC, a cross product between AB and AC will give you a vector to normalize to create a normal (maybe you'll need to negate the normal to point "outside" or "inside" the mesh, as you need)
Your answer
Follow this Question
Related Questions
How would you go about shaping terrain with scripting? (C#) 1 Answer
Few problems with arrays 1 Answer
Procedural array of meshes problem / solved 1 Answer
C# Array of OtherArray's Meshes 1 Answer
Modify mesh problems 1 Answer