Package com.jme.scene.batch

Examples of com.jme.scene.batch.TriangleBatch


    setLocalTranslation(origin);

    buildVertices();
    buildTextureCoordinates();
    buildNormals();
    TriangleBatch batch = getBatch(0);

    VBOInfo vbo = new VBOInfo(true);
    batch.setVBOInfo(vbo);

    if (isUseClod()) {
      this.create(null);
      this.setTrisPerPixel(0.02f);
    }
View Full Code Here


   
  @Override
  public void buildTextureCoordinates() {
    float offsetX = getOffset().x + (getOffsetAmount() * getStepScale().x);
    float offsetY = getOffset().y + (getOffsetAmount() * getStepScale().z);
    TriangleBatch batch = getBatch(0);

    FloatBuffer texs = BufferUtils.createVector2Buffer(batch
        .getTextureBuffers().get(0), batch.getVertexCount());
    batch.getTextureBuffers().set(0, texs);
    texs.clear();

    batch.getVertexBuffer().rewind();
    float firstX = -1.0f;
    float firstY = -1.0f;
    for (int i = 0; i < batch.getVertexCount(); i++) {
      Vector2f mapCoord = new Vector2f();
      mapCoord.x = (batch.getVertexBuffer().get() + offsetX) / (getStepScale().x);
      batch.getVertexBuffer().get(); // ignore vert y coord.
      mapCoord.y = (batch.getVertexBuffer().get() + offsetY) / (getStepScale().z);
   
      if( firstX == -1.0f ) {
        firstX = mapCoord.x;
      }
      if( firstY == -1.0f ) {
View Full Code Here

      texs.put(fY);
    }
  }

  private void buildVertices() {
    TriangleBatch batch = getBatch(0);
    batch.setVertexCount(getHeightMap().length);
    batch.setVertexBuffer(BufferUtils.createVector3Buffer(batch
        .getVertexBuffer(), batch.getVertexCount()));
    Vector3f point = new Vector3f();
    for (int x = 0; x < getSize(); x++) {
      for (int y = 0; y < getSize(); y++) {
        point.set(x * getStepScale().x,
            getHeightMap()[x + (y * getSize())] * getStepScale().y,
            y * getStepScale().z);
        BufferUtils.setInBuffer(point, batch.getVertexBuffer(),
            (x + (y * getSize())));
      }
    }
   
    FloatBuffer fb = BufferUtils.createVector3Buffer( null, batch.getVertexCount());

    float offsetX = getOffset().x + (getOffsetAmount() * getStepScale().x);
    float offsetY = getOffset().y + (getOffsetAmount() * getStepScale().z);

    for (int x = 0; x < getSize(); x++) {
      for (int y = 0; y < getSize(); y++) {
       
        Vector3f newPoint = new Vector3f();
        Vector2f mapCoord = new Vector2f( x + offsetX, y + offsetY );
        int indexMain = (x + (y * getSize()));
        Vector2f texCoord = materialMap.textureForMap(mapCoord);
       
       
        BufferUtils.populateFromBuffer( newPoint, batch.getVertexBuffer(), indexMain);
        newPoint.y = averageHeight( batch, x, y );
        BufferUtils.setInBuffer( newPoint, fb, indexMain);
      }
    }
   
    batch.setVertexBuffer( fb );

    for (int x = 0; x < getSize(); x++) {
      for (int y = 0; y < getSize(); y++) {
    //    fixAllPoint( batch ,x,y);
      }
    }

   
    // set up the indices
    batch.setTriangleQuantity(((getSize() - 1) * (getSize() - 1)) * 2);
    batch.setIndexBuffer(BufferUtils.createIntBuffer(batch
        .getTriangleCount() * 3));

    // go through entire array up to the second to last column.
    for (int i = 0; i < (getSize() * (getSize() - 1)); i++) {
      // we want to skip the top row.
      if (i % ((getSize() * (i / getSize() + 1)) - 1) == 0 && i != 0) {
        continue;
      }

      int x = i % getSize();
      int y = i / getSize();
     
      // set the top left corner.
      batch.getIndexBuffer().put(i);

      // set the bottom right corner.
      batch.getIndexBuffer().put((1 + getSize()) + i);

      // set the top right corner.
      batch.getIndexBuffer().put(1 + i);

      // set the top left corner
      batch.getIndexBuffer().put(i);

      // set the bottom left corner
      batch.getIndexBuffer().put(getSize() + i);

      // set the bottom right corner
      batch.getIndexBuffer().put((1 + getSize()) + i);
    }
  }
View Full Code Here

 
  /**
   * <code>buildNormals</code> calculates the normals of each vertex that makes up the block of terrain.
   */
  private void buildNormals() {
    TriangleBatch batch = getBatch(0);
    batch.setNormalBuffer(BufferUtils.createVector3Buffer(batch
        .getNormalBuffer(), batch.getVertexCount()));
    Vector3f oppositePoint = new Vector3f();
    Vector3f adjacentPoint = new Vector3f();
    Vector3f rootPoint = new Vector3f();
    Vector3f tempNorm = new Vector3f();
    int adj = 0, opp = 0, normalIndex = 0;
    for (int row = 0; row < getSize(); row++) {
      for (int col = 0; col < getSize(); col++) {
        BufferUtils.populateFromBuffer(rootPoint, batch
            .getVertexBuffer(), normalIndex);
        if (row == getSize() - 1) {
          if (col == getSize() - 1) { // last row, last col
            // up cross left
            adj = normalIndex - getSize();
            opp = normalIndex - 1;
          } else { // last row, except for last col
            // right cross up
            adj = normalIndex + 1;
            opp = normalIndex - getSize();
          }
        } else {
          if (col == getSize() - 1) { // last column except for last row
            // left cross down
            adj = normalIndex - 1;
            opp = normalIndex + getSize();
          } else { // most cases
            // down cross right
            adj = normalIndex + getSize();
            opp = normalIndex + 1;
          }
        }
        BufferUtils.populateFromBuffer(adjacentPoint, batch
            .getVertexBuffer(), adj);
        BufferUtils.populateFromBuffer(oppositePoint, batch
            .getVertexBuffer(), opp);
        tempNorm.set(adjacentPoint).subtractLocal(rootPoint)
            .crossLocal(oppositePoint.subtractLocal(rootPoint))
            .normalizeLocal();
        BufferUtils.setInBuffer(tempNorm, batch.getNormalBuffer(),
            normalIndex);
        normalIndex++;
      }
    }
  }
View Full Code Here

      BufferUtils.setInBuffer( new Vector2f( overTextureCoord.x, overTextureCoord.y + TileTexture.TILE_HEIGHT ),  overTextureBuffer,  0 );
      BufferUtils.setInBuffer( overTextureCoord,  overTextureBuffer,  1 );
      BufferUtils.setInBuffer( new Vector2f( overTextureCoord.x + TileTexture.TILE_WIDTH, overTextureCoord.y ),  overTextureBuffer,  2 );
      BufferUtils.setInBuffer( new Vector2f( overTextureCoord.x + TileTexture.TILE_WIDTH, overTextureCoord.y + TileTexture.TILE_HEIGHT ),  overTextureBuffer,  3 );

      this.addBatch( new TriangleBatch() );
      this.getBatch( 1 ).setVertexCount( 4 );
      this.getBatch( 1 ).setTriangleQuantity( 2 );
      this.getBatch( 1 ).setVertexBuffer( vertexOver );
      this.getBatch( 1 ).setTextureBuffer( overTextureBuffer, 0 );
      this.getBatch( 1 ).setIndexBuffer( indexOver );
View Full Code Here

TOP

Related Classes of com.jme.scene.batch.TriangleBatch

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.