1/* 2 * To change this template, choose Tools | Templates 3 * and open the template in the editor. 4 */ 5package com.jme3.terrain.heightmap; 6 7import com.jme3.asset.AssetManager; 8import com.jme3.asset.AssetNotFoundException; 9import com.jme3.asset.TextureKey; 10import com.jme3.math.Vector3f; 11import com.jme3.texture.Texture; 12import java.util.logging.Level; 13import java.util.logging.Logger; 14 15/** 16 * Loads Terrain grid tiles with image heightmaps. 17 * By default it expects a 16-bit grayscale image as the heightmap, but 18 * you can also call setImageType(BufferedImage.TYPE_) to set it to be a different 19 * image type. If you do this, you must also set a custom ImageHeightmap that will 20 * understand and be able to parse the image. By default if you pass in an image of type 21 * BufferedImage.TYPE_3BYTE_BGR, it will use the ImageBasedHeightMap for you. 22 * 23 * @author Anthyon, Brent Owens 24 */ 25@Deprecated 26/** 27 * @Deprecated in favor of ImageTileLoader 28 */ 29public class ImageBasedHeightMapGrid implements HeightMapGrid { 30 31 private static final Logger logger = Logger.getLogger(ImageBasedHeightMapGrid.class.getName()); 32 private final AssetManager assetManager; 33 private final Namer namer; 34 private int size; 35 36 37 public ImageBasedHeightMapGrid(final String textureBase, final String textureExt, AssetManager assetManager) { 38 this(assetManager, new Namer() { 39 40 public String getName(int x, int y) { 41 return textureBase + "_" + x + "_" + y + "." + textureExt; 42 } 43 }); 44 } 45 46 public ImageBasedHeightMapGrid(AssetManager assetManager, Namer namer) { 47 this.assetManager = assetManager; 48 this.namer = namer; 49 } 50 51 public HeightMap getHeightMapAt(Vector3f location) { 52 // HEIGHTMAP image (for the terrain heightmap) 53 int x = (int) location.x; 54 int z = (int) location.z; 55 56 AbstractHeightMap heightmap = null; 57 //BufferedImage im = null; 58 59 try { 60 String name = namer.getName(x, z); 61 logger.log(Level.INFO, "Loading heightmap from file: {0}", name); 62 final Texture texture = assetManager.loadTexture(new TextureKey(name)); 63 64 // CREATE HEIGHTMAP 65 heightmap = new ImageBasedHeightMap(texture.getImage()); 66 67 heightmap.setHeightScale(1); 68 heightmap.load(); 69 70 } catch (AssetNotFoundException e) { 71 logger.log(Level.SEVERE, "Asset Not found! ", e); 72 } 73 return heightmap; 74 } 75 76 public void setSize(int size) { 77 this.size = size - 1; 78 } 79} 80