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[0].add(worldtranslation), pointsXaxis[1].add(worldtranslation), new Vector3f(pointsXaxis[0].x, height, 0).add(worldtranslation),
remainingEdges[0].add(worldtranslation), remainingEdges[1].add(worldtranslation), new Vector3f(remainingEdges[0].x, height, 0).add(worldtranslation),
quadPoints1[0],quadPoints1[1],quadPoints1[2],quadPoints1[3],
quadPoints2[0],quadPoints2[1],quadPoints2[2],quadPoints2[3]};
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[6];
triangleVec[0] = new Triangle(roofVertexes[0], roofVertexes[1], roofVertexes[2]);
triangleVec[1] = new Triangle(roofVertexes[3], roofVertexes[4], roofVertexes[5]);
triangleVec[2] = new Triangle(roofVertexes[6], roofVertexes[7], roofVertexes[8]);
triangleVec[3] = new Triangle(roofVertexes[7], roofVertexes[8], roofVertexes[9]);
triangleVec[4] = new Triangle(roofVertexes[10], roofVertexes[11], roofVertexes[12]);
triangleVec[5] = new Triangle(roofVertexes[11], roofVertexes[12], roofVertexes[13]);
for (Triangle triangle : triangleVec) {
triangle.calculateCenter();
triangle.calculateNormal();
}
Vector3f[] normals = {triangleVec[0].getNormal(), triangleVec[0].getNormal(), triangleVec[0].getNormal(),
triangleVec[1].getNormal(), triangleVec[1].getNormal(), triangleVec[1].getNormal(),
triangleVec[2].getNormal(), triangleVec[2].getNormal(), triangleVec[2].getNormal(),
triangleVec[3].getNormal(), triangleVec[3].getNormal(), triangleVec[3].getNormal(),
triangleVec[4].getNormal(), triangleVec[4].getNormal(), triangleVec[4].getNormal(),
triangleVec[5].getNormal(), triangleVec[5].getNormal(), triangleVec[5].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();