Hi there,
i have created and custom Mesh and have used the “unshaded” mode for the texture, now i want to use the “Lighting.j3md”.
I have used the “Lighting.j3md” for other meshes withouf problems, but if i do it on my Mesh the Texture only appears if im near to it.
Can you help me?
thank you
your mesh has wrong index order or wrong normals.
[java]
result.indexArray = new short[mesh.indexArray.length];
for (int i = 0; i < mesh.indexArray.length; i += 3)
{
result.indexArray = mesh.indexArray;
result.indexArray = mesh.indexArray;
result.indexArray = mesh.indexArray;
}
[/java]
i have allready tried to change the order of the indexes, but this has no effect. What do you mean with “wrong normals”?
thanks
use this to visualize your normals.
[java]public static Node createDebugNormals(Mesh mesh, Material mat)
{
Node debugNormals = new Node();
VertexBuffer vertex = mesh.getBuffer(Type.Position);
float[] vertexArray = BufferUtils.getFloatArray((FloatBuffer) vertex.getData());
VertexBuffer normals = mesh.getBuffer(Type.Normal);
float[] normalArray = BufferUtils.getFloatArray((FloatBuffer) normals.getData());
for (int i = 0; i < vertexArray.length; i += 3)
{
Vector3f p1 = new Vector3f(vertexArray, vertexArray, vertexArray);
Vector3f n1 = new Vector3f(normalArray, normalArray, normalArray);
debugNormals.attachChild(createLine("DebugShowNormalsLine", mat, p1, p1.add(n1.mult(0.1f))));
}
GeometryBatchFactory.optimize(debugNormals);
return debugNormals;
}
public static Geometry createLine(Material mat, Vector3f startPosition, Vector3f endPosition)
{
return createLine("Line", mat, startPosition, endPosition);
}
public static Geometry createLine(String name, Material mat, Vector3f startPosition, Vector3f endPosition)
{
Line line = new Line(startPosition, endPosition);
Geometry lineGeom = new Geometry(name, line);
lineGeom.setMaterial(mat);
return lineGeom;
}
[/java]
thanks a lot, it seems to be caused by the wrong normals.