Package edu.ups.gamedev.terrain

Source Code of edu.ups.gamedev.terrain.Map

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package edu.ups.gamedev.terrain;

import com.jme.image.Texture;
import com.jme.math.Vector3f;
import com.jme.scene.Skybox;
import com.jme.scene.state.TextureState;
import com.jme.util.TextureManager;
import com.jmex.terrain.TerrainBlock;
import com.jmex.terrain.TerrainPage;
import com.jmex.terrain.util.AbstractHeightMap;
import com.jmex.terrain.util.ImageBasedHeightMap;
import com.jmex.terrain.util.ProceduralTextureGenerator;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;

/**
*
* @author scanfield
*/
public class Map {

  private String RootTerrainPage = "RootTerrainPage";
  private boolean continuousLevelOfDetail = false;

  private AbstractHeightMap _heightMap;
  private MaterialMap _materialMap;
  private MaterialTerrainPage _terrain;
  private Skybox _skybox;
  private Vector3f _bounds;
  private Texture _groundTexture;
  private Texture _groundDetailTexture;
  private Texture _skyboxTexture[];

  public Map(File heightMapFile, File materialMapFile, Vector3f scaleFactor,
      File groundTexture, File groundDetailTexture, File skyboxDir)
      throws FileNotFoundException, IOException {
    _heightMap = new  ImageBasedHeightMap(ImageIO.read(heightMapFile));

    _materialMap = new MaterialMap(ImageIO.read(materialMapFile), 32);

    _terrain = new MaterialTerrainPage(RootTerrainPage, _heightMap
        .getSize() / 8, _heightMap.getSize(), scaleFactor, _heightMap
        .getHeightMap(), continuousLevelOfDetail, _materialMap);

    _groundTexture = TextureManager.loadTexture(
        ImageIO.read(groundTexture), Texture.MM_LINEAR_LINEAR,
        Texture.MM_LINEAR, false);

    _groundDetailTexture = TextureManager.loadTexture(ImageIO
        .read(groundDetailTexture), Texture.MM_LINEAR_LINEAR,
        Texture.MM_LINEAR, true);

    TextureState ts = HeightMap.getTextureState();
    /* Now we have to set up our ground texture */
    _groundTexture.setApply(Texture.AM_COMBINE);
    _groundTexture.setCombineFuncRGB(Texture.ACF_MODULATE);
    _groundTexture.setCombineSrc0RGB(Texture.ACS_TEXTURE);
    _groundTexture.setCombineOp0RGB(Texture.ACO_SRC_COLOR);
    _groundTexture.setCombineSrc1RGB(Texture.ACS_PRIMARY_COLOR);
    _groundTexture.setCombineOp1RGB(Texture.ACO_SRC_COLOR);
    _groundTexture.setCombineScaleRGB(1.0f);

    ts.setTexture(_groundTexture, 0);

    _groundDetailTexture.setApply(Texture.AM_COMBINE);
    _groundDetailTexture.setWrap(Texture.WM_WRAP_S_WRAP_T);
    _groundDetailTexture.setCombineFuncRGB(Texture.ACF_ADD_SIGNED);
    _groundDetailTexture.setCombineSrc0RGB(Texture.ACS_TEXTURE);
    _groundDetailTexture.setCombineOp0RGB(Texture.ACO_SRC_COLOR);
    _groundDetailTexture.setCombineSrc1RGB(Texture.ACS_PREVIOUS);
    _groundDetailTexture.setCombineOp1RGB(Texture.ACO_SRC_COLOR);
    _groundDetailTexture.setCombineScaleRGB(1.0f);

    ts.setTexture(_groundDetailTexture, 1);

    _terrain.setRenderState(ts);
    _terrain.setDetailTexture(1, 32);

    /* Load Skybox Texture */
  }

  public AbstractHeightMap getHeightMap() {
    return _heightMap;
  }

  public void setHeightMap(AbstractHeightMap heightMap) {
    this._heightMap = heightMap;
  }

  public TerrainPage getTerrain() {
    return _terrain;
  }

  public void setTerrain(MaterialTerrainPage terrain) {
    this._terrain = terrain;
  }

  public Skybox getSkybox() {
    return _skybox;
  }

  public void setSkybox(Skybox skybox) {
    this._skybox = skybox;
  }

  public Vector3f getBounds() {
    return _bounds;
  }

  public void setBounds(Vector3f bounds) {
    this._bounds = bounds;
  }

  public Texture getGroundTexture() {
    return _groundTexture;
  }

  public void setGroundTexture(Texture groundTexture) {
    this._groundTexture = groundTexture;
  }

  public Texture getGroundDetailTexture() {
    return _groundDetailTexture;
  }

  public void setGroundDetailTexture(Texture groundDetailTexture) {
    this._groundDetailTexture = groundDetailTexture;
  }

  public Texture getSkyboxTextureAtIndex(int index) {
    if (index <= 5) {
      return _skyboxTexture[index];
    }
    return null;
  }

  public void setSkyboxTexture(Texture texture, int index) {
    if (index <= 5) {
      _skyboxTexture[index] = texture;
    }
  }
}
TOP

Related Classes of edu.ups.gamedev.terrain.Map

TOP
Copyright © 2018 www.massapi.com. 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.