Ejemplo n.º 1
0
  /** Process and setup the <code>TextureState</code> and texture UV buffer. */
  private void processTexture() {
    FloatBuffer textureBuffer = BufferUtils.createVector2Buffer(this.vertices.length);
    float maxU = 1;
    float maxV = 1;
    float minU = 0;
    float minV = 0;
    int index = 0;
    for (IVertex vertex : this.vertices) {
      BufferUtils.setInBuffer(vertex.getTextureCoords(), textureBuffer, index);
      if (vertex.getTextureCoords().x > maxU) maxU = vertex.getTextureCoords().x;
      else if (vertex.getTextureCoords().x < minU) minU = vertex.getTextureCoords().x;
      if (vertex.getTextureCoords().y > maxV) maxV = vertex.getTextureCoords().y;
      else if (vertex.getTextureCoords().y < minV) minV = vertex.getTextureCoords().y;
      index++;
    }
    this.setTextureCoords(new TexCoords(textureBuffer));

    // Get texture state.
    TextureState state = (TextureState) this.getRenderState(StateType.Texture);
    if (state == null) {
      state = DisplaySystem.getDisplaySystem().getRenderer().createTextureState();
      this.setRenderState(state);
    }
    // Set color map.
    if (this.color != null) state.setTexture(this.loadTexture(this.color, maxU, maxV), 0);
    // Set normal map.
    if (this.normal != null) state.setTexture(this.loadTexture(this.normal, maxU, maxV), 1);
    // Set specular map.
    if (this.specular != null) state.setTexture(this.loadTexture(this.specular, maxU, maxV), 2);
  }
Ejemplo n.º 2
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();
   }
 }