public static void computePolygonNormal(FloatBuffer vertexBuffer,FloatBuffer normalBuffer,boolean zPos){
  int n=vertexBuffer.limit();
  double count=0;
  Vector3 meanNormal=new Vector3();
  Vector3 vec0=new Vector3();
  Vector3 vec1=new Vector3();
  Vector3 vec2=new Vector3();
  meanNormal.set(0,0,0);
  for (int i=0; i < n; i+=9) {
    vec0.set(vertexBuffer.get(i),vertexBuffer.get(i + 1),vertexBuffer.get(i + 2));
    vec1.set(vertexBuffer.get(i + 3),vertexBuffer.get(i + 4),vertexBuffer.get(i + 5));
    vec2.set(vertexBuffer.get(i + 6),vertexBuffer.get(i + 7),vertexBuffer.get(i + 8));
    vec0.subtractLocal(vec1);
    vec1.subtractLocal(vec2);
    vec0.crossLocal(vec1);
    if (zPos && (vec0.getZ() < 0)) {
      vec0.negateLocal();
    }
    meanNormal.addLocal(vec0);
    count++;
  }
  meanNormal.multiplyLocal(1.0 / count);
  meanNormal.normalizeLocal();
  for (int i=0; i < vertexBuffer.limit(); i+=3) {
    normalBuffer.put(meanNormal.getXf());
    normalBuffer.put(meanNormal.getYf());
    normalBuffer.put(meanNormal.getZf());
  }
  normalBuffer.flip();
}

public static void computePolygonNormal ( FloatBuffer vertexBuffer , FloatBuffer normalBuffer , boolean zPos ) { int n = vertexBuffer . limit ( ) ; double count = 0 ; Vector3 meanNormal = new Vector3 ( ) ; Vector3 vec0 = new Vector3 ( ) ; Vector3 vec1 = new Vector3 ( ) ; Vector3 vec2 = new Vector3 ( ) ; meanNormal . set ( 0 , 0 , 0 ) ; for ( int i = 0 ; i < n ; i += 9 ) { vec0 . set ( vertexBuffer . get ( i ) , vertexBuffer . get ( i + 1 ) , vertexBuffer . get ( i + 2 ) ) ; vec1 . set ( vertexBuffer . get ( i + 3 ) , vertexBuffer . get ( i + 4 ) , vertexBuffer . get ( i + 5 ) ) ; vec2 . set ( vertexBuffer . get ( i + 6 ) , vertexBuffer . get ( i + 7 ) , vertexBuffer . get ( i + 8 ) ) ; vec0 . subtractLocal ( vec1 ) ; vec1 . subtractLocal ( vec2 ) ; vec0 . crossLocal ( vec1 ) ; if ( zPos && ( vec0 . getZ ( ) < 0 ) ) { vec0 . negateLocal ( ) ; } meanNormal . addLocal ( vec0 ) ; count ++ ; } meanNormal . multiplyLocal ( 1.0 / count ) ; meanNormal . normalizeLocal ( ) ; for ( int i = 0 ; i < vertexBuffer . limit ( ) ; i += 3 ) { normalBuffer . put ( meanNormal . getXf ( ) ) ; normalBuffer . put ( meanNormal . getYf ( ) ) ; normalBuffer . put ( meanNormal . getZf ( ) ) ; } normalBuffer . flip ( ) ; }
compute the mean normal for a polygon .
