public void generateNormals ( final RandomElementReader vertexReader , final ElementReader faceReader ) throws IOException { if ( vertexReader == null ) { throw new NullPointerException ( "vertexReader must not be null." ) ; } if ( faceReader == null ) { throw new NullPointerException ( "faceReader must not be null." ) ; } if ( ! vertexReader . getElementType ( ) . getName ( ) . equals ( "vertex" ) ) { throw new IllegalArgumentException ( "vertexReader does not read vertices." ) ; } boolean foundX = false ; boolean foundY = false ; boolean foundZ = false ; for ( Property p : vertexReader . getElementType ( ) . getProperties ( ) ) { foundX |= p . getName ( ) . equals ( "x" ) && ! ( p instanceof ListProperty ) ; foundY |= p . getName ( ) . equals ( "y" ) && ! ( p instanceof ListProperty ) ; foundZ |= p . getName ( ) . equals ( "z" ) && ! ( p instanceof ListProperty ) ; } if ( ! foundX || ! foundY || ! foundZ ) { throw new IllegalArgumentException ( "Vertex type does not include" + " the three non-list properties x y and z." ) ; } if ( ! faceReader . getElementType ( ) . getName ( ) . equals ( "face" ) ) { throw new IllegalArgumentException ( "faceReader does not read faces." ) ; } boolean foundVertexIndex = false ; for ( Property p : faceReader . getElementType ( ) . getProperties ( ) ) { foundVertexIndex |= p . getName ( ) . equals ( "vertex_index" ) && ( p instanceof ListProperty ) ; } if ( ! foundVertexIndex ) { throw new IllegalArgumentException ( "Face type does not include a list property named " + "vertex_index." ) ; } // Phase 1: accumulate weighted normals for ( Element face = faceReader . readElement ( ) ; face != null ; face = faceReader . readElement ( ) ) { accumulateNormals ( vertexReader , face ) ; } // Phase 2: normalize the normal vectors for ( Element vertex = vertexReader . readElement ( ) ; vertex != null ; vertex = vertexReader . readElement ( ) ) { normalize ( vertex ) ; } }
Performs the normal generation .