# Illuminating a trimesh?

Hi,

I have created a TriMesh which has the shape of a typical roof (it's created dynamically during the course of the program). My problem is that each triangle in it are illuminated independently from each other, which creates sharp edges between the triangles instead of an smooth transition. What I want is that the triangles which are in the same plane should be illuminated by the lightning as a unit, just as if they were a Quad for an example.

You can see the picture below what I mean. The box next to it shows more the way I would like it to look.

I tried calculating the normals for it, but I don't know if that helps or if I did it wrong. In the code below I left out how I calculate the vertexes, since these are correct and shouldn't affect anything (correct me if I'm wrong).

Anyone know how I can fix this?

``` Vector3f[] roofVertexes = {pointsXaxis.add(worldtranslation), pointsXaxis.add(worldtranslation), new Vector3f(pointsXaxis.x, height, 0).add(worldtranslation),                          remainingEdges.add(worldtranslation), remainingEdges.add(worldtranslation), new Vector3f(remainingEdges.x, height, 0).add(worldtranslation),                          quadPoints1,quadPoints1,quadPoints1,quadPoints1,                          quadPoints2,quadPoints2,quadPoints2,quadPoints2}; int[] roofIndexes = {0,1,2,                      3,4,5,                      6,7,8,                      7,8,9,                      10,11,12,                      11,12,13}; // calculate normals Triangle[] triangleVec = new Triangle; triangleVec = new Triangle(roofVertexes, roofVertexes, roofVertexes); triangleVec = new Triangle(roofVertexes, roofVertexes, roofVertexes); triangleVec = new Triangle(roofVertexes, roofVertexes, roofVertexes); triangleVec = new Triangle(roofVertexes, roofVertexes, roofVertexes); triangleVec = new Triangle(roofVertexes, roofVertexes, roofVertexes); triangleVec = new Triangle(roofVertexes, roofVertexes, roofVertexes); for (Triangle triangle : triangleVec) {     triangle.calculateCenter();     triangle.calculateNormal(); } Vector3f[] normals = {triangleVec.getNormal(), triangleVec.getNormal(), triangleVec.getNormal(),                     triangleVec.getNormal(), triangleVec.getNormal(), triangleVec.getNormal(),                     triangleVec.getNormal(), triangleVec.getNormal(), triangleVec.getNormal(),                     triangleVec.getNormal(), triangleVec.getNormal(), triangleVec.getNormal(),                     triangleVec.getNormal(), triangleVec.getNormal(), triangleVec.getNormal(),                     triangleVec.getNormal(), triangleVec.getNormal(), triangleVec.getNormal()}; TriMesh roof = new TriMesh("roof" +newObject(), BufferUtils.createFloatBuffer(roofVertexes), BufferUtils.createFloatBuffer(normals), null, null, BufferUtils.createIntBuffer(roofIndexes)); pickNode.attachChild(roof); roof.setModelBound(new BoundingBox()); roof.updateModelBound(); roof.setRenderState(blue); roof.updateRenderState(); ```

Your indexes. -Reverse the order you name the three vertexes for the dark triangle. If they are added clockwise switch to counter-clockwise and vice versa. That will make the normal of this triangle point in the right direction.

i.e. go from

a,b,c

to

c, b, a

where a,b,c are the vertexes of the offending triangle.

tnx! that works fine!

I understand now that this occurs beacuse the triangles aren't aware of the trimesh as a whole and set their normals independently, that's why some of them isn't displayed "correctly".