Custom Object, Directional Light not working

Hey Guys,
i have an interpolation running to calculate “smooth” surfaces from data points. Works pretty well i guess, but in order to decide on the quality of the calculated surface i would need to have directional light (and shadow, probably). I already got it to work on different projects, but never with a custom created surface. But to give you some more details here we go:

The actual subdivided Bézier-surface of a subdivided octagon (18 data points) with “unshaded” material:

For the calculation of the actual geometry i use the following:

private Geometry calculateTextureGeometry(LinkedList<Point> in,
			ColorRGBA color) {
		Mesh m = new Mesh();
		m.setMode(Mesh.Mode.Triangles);

		Vector3f[] position = new Vector3f[in.size()];

		for (int i = 0; i < in.size(); i++) {
			position[i] = in.get(i).toVec3f();
		}

		m.setBuffer(Type.Position, 3, BufferUtils.createFloatBuffer(position));

		float[] normals = new float[in.size() * 3];
		for (int i = 0; i < normals.length / 3; i++) {
			normals[3 * i] = (float) in.get(i).getNormal().getEntry(0, 0);
			normals[3 * i + 1] = (float) in.get(i).getNormal().getEntry(1, 0);
			normals[3 * i + 2] = (float) in.get(i).getNormal().getEntry(2, 0);
		}

		m.setBuffer(Type.Normal, 3, BufferUtils.createFloatBuffer(normals));

		Vector2f[] texCoord = new Vector2f[3];
		texCoord[0] = new Vector2f(0, 0);
		texCoord[1] = new Vector2f(1, 0);
		texCoord[2] = new Vector2f(0, 1);

		m.setBuffer(Type.TexCoord, 2, BufferUtils.createFloatBuffer(texCoord));

		int[] indexes = new int[position.length];

		for (int i = 0; i < indexes.length; i++) {
			indexes[i] = i;
		}

		m.setBuffer(Type.Index, 3, indexes);
		m.updateBound();
		m.updateCounts();
		m.setStatic();

		Geometry geo = new Geometry("texture");
		geo.setMesh(m);
		Material mat = new Material(assetManager,
				"Common/MatDefs/Light/Lighting.j3md");
		// mat.setColor("Color", color);
		assetManager.registerLocator("assets/texture", FileLocator.class);
		Texture tex = assetManager.loadTexture("test.jpg");
		mat.setTexture("DiffuseMap", tex);
		mat.getAdditionalRenderState().setFaceCullMode(FaceCullMode.Off);
		geo.setMaterial(mat);
		return geo;
	}

Don’t take that code to seriously as it is copied out of my testing and fooling around, so there might be some fragments which are… well, you know.

For the lighting i kept it simple:

DirectionalLight dl = new DirectionalLight();
		dl.setDirection(Vector3f.UNIT_X);
		dl.setColor(ColorRGBA.White);
		rootNode.addLight(dl);

So when i render it using the above settings i just get my wireframe, but no textures… any ideas? (i think it might be the texCoords but…)

EDIT: it just came to my mind, are the normals to be normalized for the renderer buffer??

Thanks in advance,
Ben

hm, it seems to work now, but only if i set
mat.setBoolean("VertexLighting", true);
which has the bad effect to not work properly with rotating light etc…

Ok, finally i find some time to share what was wrong for anybody who might be in need for a solution… always make sure to have the direction of your triangles consistent (always clockwise or counter-clockwise, do NOT mix them up). You can write fancy code to check for the correct norm all you want (facing in the correct direction), it wont work if the triangle direction isnt consistent. Once you get that worked out the available code(s) for lighting and shadows will work just fine.