Ejemplo n.º 1
0
 /** Average normals for vertices with same position. */
 private void averageNormal() {
   this.tempVertices.clear();
   for (int i = 0; i < this.vertices.length; i++) {
     final IVertex v1 = this.vertices[i];
     this.tempVertices.add(v1);
     // Find all vertices with same position.
     for (int j = 0; j < this.vertices.length; j++) {
       final IVertex v2 = this.vertices[j];
       if (v1 != v2 && v2.getPosition().equals(v1.getPosition())) {
         this.tempVertices.add(v2);
       }
     }
     // Average vertices in list.
     float x = 0;
     float y = 0;
     float z = 0;
     for (IVertex vertex : this.tempVertices) {
       x += vertex.getNormal().getX();
       y += vertex.getNormal().getY();
       z += vertex.getNormal().getZ();
     }
     final int size = this.tempVertices.size();
     x = x / size;
     y = y / size;
     z = z / size;
     final Vector3f sharedNormal = new Vector3f(x, y, z);
     sharedNormal.normalizeLocal();
     for (IVertex vertex : this.tempVertices) {
       vertex.setNormalReference(sharedNormal);
     }
     // Clear out this group.
     this.tempVertices.clear();
   }
 }