Manual mesh vs normals
Blitz3D Forums/Blitz3D Programming/Manual mesh vs normals
| ||
Hi, I am trying to create a simple floor mesh, and calling updatenormals to calculate the normal vectors, but it seems I am doing something wrong. There is no "light effect" when using this mesh and a point light. Does UpdateNormals suppose to calculate the normals or did I misread something? :-\ Thanks. Function CreateFloor(DoubleSided = 1) Mesh = CreateMesh() Surface = CreateSurface(Mesh) AddVertex(Surface, -1, 0, -1, 0, 0) AddVertex(Surface, 1, 0, -1, 1, 0) AddVertex(Surface, -1, 0, 1, 0, 1) AddVertex(Surface, 1, 0, 1, 1, 1) AddTriangle(Surface, 0, 1, 2) AddTriangle(Surface, 1, 3, 2) If DoubleSided AddTriangle(Surface, 0, 2, 1) AddTriangle(Surface, 1, 2, 3) EndIf UpdateNormals Mesh Return Mesh End Function |
| ||
UpdateNormals considers all vertices at a single point in space to be the same vertex. There would be a proper normal for either side. But they point in exactly the opposite direction. So adding everything together gives a grand total of zero. Thus all normals will be zero. Your vertices all have y=0, so the floor is horizontal. Thus all normals are vertical and you can skip UpdateNormals. Just manually set every normal to (0,1,0). |
| ||
Thanks! Indeed, VertexNormal does the trick. :) Function CreateFloor(DoubleSided = 1) Mesh = CreateMesh() Surface = CreateSurface(Mesh) AddVertex(Surface, -1, 0, -1, 0, 0) AddVertex(Surface, 1, 0, -1, 1, 0) AddVertex(Surface, -1, 0, 1, 0, 1) AddVertex(Surface, 1, 0, 1, 1, 1) VertexNormal(Surface, 0, 0, 1, 0) VertexNormal(Surface, 1, 0, 1, 0) VertexNormal(Surface, 2, 0, 1, 0) VertexNormal(Surface, 3, 0, 1, 0) AddTriangle(Surface, 0, 1, 2) AddTriangle(Surface, 1, 3, 2) If DoubleSided AddTriangle(Surface, 0, 2, 1) AddTriangle(Surface, 1, 2, 3) EndIf Return Mesh End Function |