[SOLVED] problem with recalculation normals on deployed systems

hi,

i’m trying to sent a complete mesh over network without normals(aren’t included in my obj files) and well the sending and everything works perfectly fine but the problem is that the normals only seem to be normal on my pc. every other pc who visualizes the data from my server seem to be having problems with recalculating the normals.

How it looks on my PC:



How it looks for everyone else:



maybe my function to recalculate the normals misses something.

the parameter index and positions are created from the VertexBuffer given when loading meshes.

[java]

private static float[] calculateNormals(short[] index, float[] positions) {

Vector3f vertex0, vertex1, vertex2, normal;

float[] normalArray = new float[positions.length];

for (int i = 0; i < normalArray.length; i++)

normalArray = 0;

int []indice = new int[3];

for (int i = 0; i < index.length; i+:3){

/converting the index values. conversion from shortBuffer to short[] converted ushort values to short values.

Only needed if more positions than Short.MAX_VALUE exists
/

indice[0] = (int) index;

indice[1] = (int) index[i+1];

indice[2] = (int) index[i+2];

if (indice[0] < 0)

indice[0] += 2*(Short.MAX_VALUE+1);

if (indice[1] < 0)

indice[1] += 2*(Short.MAX_VALUE+1);

if (indice[2] < 0)

indice[2] += 2*(Short.MAX_VALUE+1);

vertex0 = new Vector3f(positions[indice[0]*3],

positions[indice[0]*3+1],

positions[indice[0]*3+2]);

vertex1 = new Vector3f(positions[indice[1]*3],

positions[indice[1]*3+1],

positions[indice[1]*3+2]);

vertex2 = new Vector3f(positions[indice[2]*3],

positions[indice[2]*3+1],

positions[indice[2]*3+2]);

normal = (vertex1.subtractLocal(vertex0)).cross(vertex2.subtract(vertex0));

normalArray[indice[0]*3] += normal.getX();

normalArray[indice[0]*3+1] += normal.getY();

normalArray[indice[0]*3+2] += normal.getZ();

normalArray[indice[1]*3] += normal.getX();

normalArray[indice[1]*3+1] += normal.getY();

normalArray[indice[1]*3+2] += normal.getZ();

normalArray[indice[2]*3] += normal.getX();

normalArray[indice[2]*3+1] += normal.getY();

normalArray[indice[2]*3+2] += normal.getZ();

}

for (int i = 0; i < normalArray.length; i+:3){

float tmp = FastMath.sqr((normalArray*normalArray)

+(normalArray[i+1]*normalArray[i+1])

+(normalArray[i+2]*normalArray[i+2]));

normalArray /= tmp;

normalArray[i+1] /= tmp;

normalArray[i+2] /= tmp;

}

return normalArray;

}

[/java]



hope somebody has an idea what the problem might be.



EDIT:solution: for everyone with the prob. just set the shininess parameter on the material for the mesh.

Use this to learn if normals are the problem and post a picture.



[java]

public static Node createDebugNormals(Mesh mesh, Material mat, float scale)

{

Node debugNormals = new Node();



VertexBuffer vertex = mesh.getBuffer(Type.Position);

float[] vertexArray = BufferUtils.getFloatArray((FloatBuffer) vertex.getData());



VertexBuffer normals = mesh.getBuffer(Type.Normal);

if (normals == null) return debugNormals;

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(scale))));

}



GeometryBatchFactory.optimize(debugNormals);

return debugNormals;

}

[/java]

ty so far tralala. lucky for me u posted the complete code already on another thread ^^



btw: the reason why i think it has something to do with the normals is that if i set every normal to {0,0,1} for example every position is lit the same (depending on the position of the light and the camera) and it looks the same on every client.



an image from the inside of the mesh



an image from the outside of the mesh



sry that not all normals are used but my pc isn’t strong enough to visualize all normals because the mesh changes a lot ^^ i used a 90th of the complete length … think it should be sufficient. besides nobody would see anything despite a white screen with all normals shown.

@tralala

i find it still strange that the scale of the debugfunction is set to 0.001f and they are still that big. (0 btw lets all disappear like it should be)





any other idea what might be the case?

  1. i checked your code about generating normals on “sinbad” model, its wrong (sinbad got black spots because of normals).



    Edit : its not wrong, its is flat shading since all vertices have the same normal.

well i checked the whole stuff with another model which contains the normals.

the problem maybe doesn’t lie within the normals because the loaded normals have the same effect as the calculated ones.



well just to be safe. to recreate a mesh i only need the index, position, texCoords and normals right?

This particular issue has been fixed since alpha4. It only happens on NVIDIA cards

@Momoko

the problem also exists on Alpha-4. i’m using the nightly build so i think it should be fairly up2date.



the solution for this problem is simple:

[java]material.setParam(“Shininess”, VarType.Float, 3f);

mesh.setMaterial(material);

[/java]



The problem was that NVIDIA cards can’t visualize stuff correctly without a shininess parameter. After setting the shininess everything visualizes perfectly fine and i got the impression that the shadows on ati cards are a lot smoother too.



thx everyone.

The last nightly build is from Aug 29 … I am pretty sure this bug was fixed after that.