- Home /
mesh generation + normal maps
I'm trying to create a 3d maze out of a 2d grid of ones and zeros where 0 is a wall and 1 is a passage. as you can see in the picture below, the left wall looks correct, but the right wall looks like the normal maps are inverted. also the back and front facing walls look flat.
each wall is generated using
Matrix4x4.TRS(new Vector3((j + .5f) * width, halfH, i * width),Quaternion.LookRotation(Vector3.left),new Vector3(width, height, 1)
with the corresponsing rotation, and then the matrix is used to generate this way:
Vector3 vert1 = new Vector3(-.5f, -.5f, 0);
Vector3 vert2 = new Vector3(-.5f, .5f, 0);
Vector3 vert3 = new Vector3(.5f, .5f, 0);
Vector3 vert4 = new Vector3(.5f, -.5f, 0);
var verts = new Vector3[4];
verts[0] = matrix.MultiplyPoint3x4(vert1);
verts[1] = matrix.MultiplyPoint3x4(vert2);
verts[2] = matrix.MultiplyPoint3x4(vert3);
verts[3] = matrix.MultiplyPoint3x4(vert4);
newVertices.Add(verts[0]);
newVertices.Add(verts[1]);
newVertices.Add(verts[2]);
newVertices.Add(verts[3]);
newUVs.Add(new Vector2(1, 0));
newUVs.Add(new Vector2(1, 1));
newUVs.Add(new Vector2(0, 1));
newUVs.Add(new Vector2(0, 0));
newTriangles.Add(index + 2);
newTriangles.Add(index + 1);
newTriangles.Add(index);
newTriangles.Add(index + 3);
newTriangles.Add(index + 2);
newTriangles.Add(index);
Answer by Bunny83 · Jul 14, 2019 at 05:04 PM
Uhm, do you actually generate any normal vectors? If not, do you at least call RecalculateNormals() instead? We only see the code snipped you posted here. After you assigned all your data to your mesh you should call RecalculateBounds and if you did not generate any normals yourself you should call RecalculateNormals.
Your answer
Follow this Question
Related Questions
How can i create a Plane using this Mesh generator script ? 0 Answers
Alternatives to 3D boolean operations 1 Answer
how do i fix how i make triangels in my mesh 0 Answers
c# - List with multiple types - Trading Engine - Stock Simulator 2 Answers
variable not being changed outside of a method. [C#] 3 Answers