I have some code that is returning a plane equation in this form:
A(x - x0) + B(y - y0) + C(z - z0) = 0
where the normal vector is (A, B, C) and a point on the plane is (x0, y0, z0). Currently I have code that can create a plane of some width and height here:
public static GameObject createPlane(float width, float height)
{
GameObject go = new GameObject("Plane");
MeshFilter mf = go.AddComponent(typeof(MeshFilter)) as MeshFilter;
MeshRenderer mr = go.AddComponent(typeof(MeshRenderer)) as MeshRenderer;
Mesh m = new Mesh();
m.vertices = new Vector3[]
{
new Vector3(0, 0, 0),
new Vector3(width, 0, 0),
new Vector3(width, height, 0),
new Vector3(0, height, 0)
};
m.uv = new Vector2[]
{
new Vector2(0,0),
new Vector2(0,1),
new Vector2(1,1),
new Vector2(1,0)
};
mf.mesh = m;
m.RecalculateBounds();
m.RecalculateNormals();
return go;
}
The problem that I’m having with this code is that I’m unsure of how to change the plane’s normal. I attempted to use the mesh.normals array to change the normal, but whenever I made changes to that I never saw those changes reflected in unity. All I found out is that it seems the mesh.normals has to be the same size as mesh.vertices. I would understand if it needed to have 2 vectors in this case as it seems that the plane is being created by 2 triangles, but I don’t understand why each vertex would need a vector.