diff --git a/engine/src/terrain/com/jme3/terrain/geomipmap/grid/ImageTileLoader.java b/engine/src/terrain/com/jme3/terrain/geomipmap/grid/ImageTileLoader.java index 4f0ad209c..cef6a727c 100644 --- a/engine/src/terrain/com/jme3/terrain/geomipmap/grid/ImageTileLoader.java +++ b/engine/src/terrain/com/jme3/terrain/geomipmap/grid/ImageTileLoader.java @@ -4,22 +4,19 @@ */ package com.jme3.terrain.geomipmap.grid; -import com.jme3.asset.AssetInfo; -import com.jme3.asset.AssetKey; import com.jme3.asset.AssetManager; import com.jme3.asset.AssetNotFoundException; +import com.jme3.asset.TextureKey; import com.jme3.export.JmeExporter; import com.jme3.export.JmeImporter; import com.jme3.math.Vector3f; import com.jme3.terrain.geomipmap.TerrainGridTileLoader; import com.jme3.terrain.geomipmap.TerrainQuad; import com.jme3.terrain.heightmap.*; -import java.awt.image.BufferedImage; +import com.jme3.texture.Texture; import java.io.IOException; -import java.io.InputStream; import java.util.logging.Level; import java.util.logging.Logger; -import javax.imageio.ImageIO; /** * @@ -31,8 +28,9 @@ public class ImageTileLoader implements TerrainGridTileLoader{ private final Namer namer; private int patchSize; private int quadSize; - private int imageType = BufferedImage.TYPE_USHORT_GRAY; // 16 bit grayscale - private ImageHeightmap customImageHeightmap; + private float heightScale = 1; + //private int imageType = BufferedImage.TYPE_USHORT_GRAY; // 16 bit grayscale + //private ImageHeightmap customImageHeightmap; public ImageTileLoader(final String textureBase, final String textureExt, AssetManager assetManager) { this(assetManager, new Namer() { @@ -47,27 +45,35 @@ public class ImageTileLoader implements TerrainGridTileLoader{ this.assetManager = assetManager; this.namer = namer; } + + /** + * Effects vertical scale of the height of the terrain when loaded. + */ + public void setHeightScale(float heightScale) { + this.heightScale = heightScale; + } + /** * Lets you specify the type of images that are being loaded. All images * must be the same type. * @param imageType eg. BufferedImage.TYPE_USHORT_GRAY */ - public void setImageType(int imageType) { + /*public void setImageType(int imageType) { this.imageType = imageType; - } + }*/ /** * The ImageHeightmap that will parse the image type that you * specify with setImageType(). * @param customImageHeightmap must extend AbstractHeightmap */ - public void setCustomImageHeightmap(ImageHeightmap customImageHeightmap) { + /*public void setCustomImageHeightmap(ImageHeightmap customImageHeightmap) { if (!(customImageHeightmap instanceof AbstractHeightMap)) { throw new IllegalArgumentException("customImageHeightmap must be an AbstractHeightMap!"); } this.customImageHeightmap = customImageHeightmap; - } + }*/ private HeightMap getHeightMapAt(Vector3f location) { // HEIGHTMAP image (for the terrain heightmap) @@ -75,21 +81,23 @@ public class ImageTileLoader implements TerrainGridTileLoader{ int z = (int) location.z; AbstractHeightMap heightmap = null; - BufferedImage im = null; + //BufferedImage im = null; + String name = null; try { - String name = namer.getName(x, z); + name = namer.getName(x, z); logger.log(Level.INFO, "Loading heightmap from file: {0}", name); - final AssetInfo assetInfo = assetManager.locateAsset(new AssetKey(name)); - if (assetInfo != null){ + final Texture texture = assetManager.loadTexture(new TextureKey(name)); + heightmap = new ImageBasedHeightMap(texture.getImage()); + /*if (assetInfo != null){ InputStream in = assetInfo.openStream(); im = ImageIO.read(in); } else { im = new BufferedImage(patchSize, patchSize, imageType); logger.log(Level.WARNING, "File: {0} not found, loading zero heightmap instead", name); - } + }*/ // CREATE HEIGHTMAP - if (imageType == BufferedImage.TYPE_USHORT_GRAY) { + /*if (imageType == BufferedImage.TYPE_USHORT_GRAY) { heightmap = new Grayscale16BitHeightMap(im); } else if (imageType == BufferedImage.TYPE_3BYTE_BGR) { heightmap = new ImageBasedHeightMap(im); @@ -106,11 +114,13 @@ public class ImageTileLoader implements TerrainGridTileLoader{ if (!(customImageHeightmap instanceof AbstractHeightMap)) logger.severe("customImageHeightmap must be an AbstractHeightMap!"); return null; - } - heightmap.setHeightScale(256); + }*/ + heightmap.setHeightScale(1); heightmap.load(); - } catch (IOException e) { + //} catch (IOException e) { + // e.printStackTrace(); } catch (AssetNotFoundException e) { + logger.log(Level.WARNING, "Asset {0} not found, loading zero heightmap instead", name); } return heightmap; } diff --git a/engine/src/terrain/com/jme3/terrain/heightmap/Grayscale16BitHeightMap.java b/engine/src/terrain/com/jme3/terrain/heightmap/Grayscale16BitHeightMap.java index 29e307d4e..7c117fbce 100644 --- a/engine/src/terrain/com/jme3/terrain/heightmap/Grayscale16BitHeightMap.java +++ b/engine/src/terrain/com/jme3/terrain/heightmap/Grayscale16BitHeightMap.java @@ -41,6 +41,7 @@ import javax.imageio.ImageIO; /** * * @author Anthyon + * @deprecated use assetManager instead */ public class Grayscale16BitHeightMap extends AbstractHeightMap { diff --git a/engine/src/terrain/com/jme3/terrain/heightmap/ImageBasedHeightMap.java b/engine/src/terrain/com/jme3/terrain/heightmap/ImageBasedHeightMap.java index 89d3b2857..84eb8571a 100644 --- a/engine/src/terrain/com/jme3/terrain/heightmap/ImageBasedHeightMap.java +++ b/engine/src/terrain/com/jme3/terrain/heightmap/ImageBasedHeightMap.java @@ -32,12 +32,10 @@ package com.jme3.terrain.heightmap; -import java.awt.Graphics2D; -import java.awt.Image; -import java.awt.image.BufferedImage; -import java.awt.image.ColorModel; -import java.awt.image.PixelGrabber; -import java.awt.image.WritableRaster; +import java.nio.ByteBuffer; +import com.jme3.math.ColorRGBA; +import com.jme3.texture.Image; +import java.nio.ShortBuffer; /** * ImageBasedHeightMap is a height map created from the grayscale @@ -49,102 +47,15 @@ import java.awt.image.WritableRaster; * @version $id$ */ public class ImageBasedHeightMap extends AbstractHeightMap implements ImageHeightmap { - - static protected class ImageConverter { - - // Posted by DrLaszloJamf to Java Technology Forums - // - // Copyright 1994-2004 Sun Microsystems, Inc. All Rights Reserved. - // Redistribution and use in source and binary forms, with or without - // modification, are permitted provided that the following conditions - // are met: - // - // Redistribution of source code must retain the above copyright notice, - // this list of conditions and the following disclaimer. - // - // Redistribution in binary form must reproduce the above copyright - // notice, this list of conditions and the following disclaimer in the - // documentation and/or other materials provided with the distribution. - // - // Neither the name of Sun Microsystems, Inc. or the names of - // contributors may be used to endorse or promote products derived from - // this software without specific prior written permission. - // - // This software is provided "AS IS," without a warranty of any kind. - // ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, - // INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A - // PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN - // MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR - // ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR - // DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN - // OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR - // FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE - // DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, - // ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF - // SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - // - // - // You acknowledge that this software is not designed, licensed or - // intended for use in the design, construction, operation or - // maintenance of any nuclear facility. - - // preserves image's colormodel. Assumes image is loaded - public static BufferedImage toBufferedImage(Image image) { - if (image instanceof BufferedImage) return (BufferedImage) image; - ColorModel cm = getColorModel(image); - int width = image.getWidth(null); - int height = image.getHeight(null); - return copy(createBufferedImage(cm, width, height), image); - } - - public static BufferedImage toBufferedImage(Image image, int type) { - if (image instanceof BufferedImage - && ((BufferedImage) image).getType() == type) - return (BufferedImage) image; - int width = image.getWidth(null); - int height = image.getHeight(null); - return copy(new BufferedImage(width, height, type), image); - } - - // Returns target. Assumes source is loaded - public static BufferedImage copy(BufferedImage target, Image source) { - Graphics2D g = target.createGraphics(); - g.drawImage(source, 0, 0, null); - g.dispose(); - return target; - } - - public static ColorModel getColorModel(Image image) { - try { - PixelGrabber pg = new PixelGrabber(image, 0, 0, 1, 1, false); - pg.grabPixels(); - return pg.getColorModel(); - } catch (InterruptedException e) { - throw new RuntimeException("Unexpected interruption", e); - } - } - - public static BufferedImage createBufferedImage(ColorModel cm, int w, - int h) { - WritableRaster raster = cm.createCompatibleWritableRaster(w, h); - boolean isRasterPremultiplied = cm.isAlphaPremultiplied(); - return new BufferedImage(cm, raster, isRasterPremultiplied, null); - } - } protected Image colorImage; - protected float dampen = 1.0f; public void setImage(Image image) { this.colorImage = image; } - public int getSupportedImageType() { - return BufferedImage.TYPE_3BYTE_BGR; - } - /** * Creates a HeightMap from an Image. The image will be converted to * grayscale, and the grayscale values will be used to generate the height @@ -157,13 +68,12 @@ public class ImageBasedHeightMap extends AbstractHeightMap implements ImageHeigh * Image to map to the height map. */ public ImageBasedHeightMap(Image colorImage) { - this(colorImage, 1.0f); + this.colorImage = colorImage; } - public ImageBasedHeightMap(Image colorImage, float dampen) { - super(); + public ImageBasedHeightMap(Image colorImage, float heightScale) { this.colorImage = colorImage; - this.dampen = dampen; + this.heightScale = heightScale; } /** @@ -177,19 +87,13 @@ public class ImageBasedHeightMap extends AbstractHeightMap implements ImageHeigh * Get the grayscale value, or override in your own sub-classes */ protected float calculateHeight(float red, float green, float blue) { - return (float) ((0.299 * red + 0.587 * green + 0.114 * blue) * dampen); + return (float) (0.299 * red + 0.587 * green + 0.114 * blue); } public boolean load(boolean flipX, boolean flipY) { - // FUTURE: Rescale image if not square? - BufferedImage colorBufferedImage = ImageConverter.toBufferedImage( - colorImage, BufferedImage.TYPE_3BYTE_BGR); - - boolean hasAlpha = colorBufferedImage.getColorModel().hasAlpha(); - - int imageWidth = colorBufferedImage.getWidth(); - int imageHeight = colorBufferedImage.getHeight(); + int imageWidth = colorImage.getWidth(); + int imageHeight = colorImage.getHeight(); if (imageWidth != imageHeight) throw new RuntimeException("imageWidth: " + imageWidth @@ -197,58 +101,24 @@ public class ImageBasedHeightMap extends AbstractHeightMap implements ImageHeigh size = imageWidth; - byte data[] = (byte[]) colorBufferedImage.getRaster().getDataElements( - 0, 0, imageWidth, imageHeight, null); - - int bytesPerPixel = 3; - int blueBase = 0; - if (hasAlpha) { - bytesPerPixel = 4; - blueBase = 1; - } + ByteBuffer buf = colorImage.getData(0); heightData = new float[(imageWidth * imageHeight)]; - int startW = 0; - int endW = imageWidth-1; - if (flipX) { - startW = imageWidth-1; - endW = 0; - } - int startH = imageHeight-1; - int endH = 0; - if (flipY) { - startH = 0; - endH = imageHeight-1; - } - + ColorRGBA colorStore = new ColorRGBA(); + int index = 0; if (flipY) { for (int h = 0; h < imageHeight; ++h) { if (flipX) { for (int w = imageWidth - 1; w >= 0; --w) { - int baseIndex = (h * imageWidth * bytesPerPixel) - + (w * bytesPerPixel) + blueBase; - float blue = data[baseIndex] >= 0 ? data[baseIndex] - : (256 + (data[baseIndex])); - float green = data[baseIndex + 1] >= 0 ? data[baseIndex + 1] - : (256 + (data[baseIndex + 1])); - float red = data[baseIndex + 2] >= 0 ? data[baseIndex + 2] - : (256 + (data[baseIndex + 2])); - heightData[index++] = calculateHeight(red,green,blue); + int baseIndex = (h * imageWidth)+ w; + heightData[index++] = getHeightAtPostion(buf, colorImage, baseIndex, colorStore)*heightScale; } } else { for (int w = 0; w < imageWidth; ++w) { - int baseIndex = (h * imageWidth * bytesPerPixel) - + (w * bytesPerPixel) + blueBase; - float blue = data[baseIndex] >= 0 ? data[baseIndex] - : (256 + (data[baseIndex])); - float green = data[baseIndex + 1] >= 0 ? data[baseIndex + 1] - : (256 + (data[baseIndex + 1])); - float red = data[baseIndex + 2] >= 0 ? data[baseIndex + 2] - : (256 + (data[baseIndex + 2])); - heightData[index++] = calculateHeight(red,green,blue); - + int baseIndex = (h * imageWidth)+ w; + heightData[index++] = getHeightAtPostion(buf, colorImage, baseIndex, colorStore)*heightScale; } } } @@ -256,103 +126,52 @@ public class ImageBasedHeightMap extends AbstractHeightMap implements ImageHeigh for (int h = imageHeight - 1; h >= 0; --h) { if (flipX) { for (int w = imageWidth - 1; w >= 0; --w) { - int baseIndex = (h * imageWidth * bytesPerPixel) - + (w * bytesPerPixel) + blueBase; - float blue = data[baseIndex] >= 0 ? data[baseIndex] - : (256 + (data[baseIndex])); - float green = data[baseIndex + 1] >= 0 ? data[baseIndex + 1] - : (256 + (data[baseIndex + 1])); - float red = data[baseIndex + 2] >= 0 ? data[baseIndex + 2] - : (256 + (data[baseIndex + 2])); - heightData[index++] = calculateHeight(red,green,blue); + int baseIndex = (h * imageWidth)+ w; + heightData[index++] = getHeightAtPostion(buf, colorImage, baseIndex, colorStore)*heightScale; } } else { for (int w = 0; w < imageWidth; ++w) { - int baseIndex = (h * imageWidth * bytesPerPixel) - + (w * bytesPerPixel) + blueBase; - float blue = data[baseIndex] >= 0 ? data[baseIndex] - : (256 + (data[baseIndex])); - float green = data[baseIndex + 1] >= 0 ? data[baseIndex + 1] - : (256 + (data[baseIndex + 1])); - float red = data[baseIndex + 2] >= 0 ? data[baseIndex + 2] - : (256 + (data[baseIndex + 2])); - heightData[index++] = calculateHeight(red,green,blue); + int baseIndex = (h * imageWidth)+ w; + heightData[index++] = getHeightAtPostion(buf, colorImage, baseIndex, colorStore)*heightScale; } } } } - /*int index = 0; - if (flipY) { - for (int h = 0; h < imageHeight; ++h) { - if (flipX) { - for (int w = imageWidth-1; w >= 0; --w) { - int baseIndex = (h * imageWidth * bytesPerPixel) - + (w * bytesPerPixel) + blueBase; - float blue = data[baseIndex] >= 0 ? data[baseIndex] - : (256 + (data[baseIndex])); - float green = data[baseIndex + 1] >= 0 ? data[baseIndex + 1] - : (256 + (data[baseIndex + 1])); - float red = data[baseIndex + 2] >= 0 ? data[baseIndex + 2] - : (256 + (data[baseIndex + 2])); - - float grayscale = (float) ((0.299 * red + 0.587 * green + 0.114 * blue) * dampen); - - heightData[index++] = grayscale; - } - } else { - for (int w = 0; w < imageWidth; ++w) { - int baseIndex = (h * imageWidth * bytesPerPixel) - + (w * bytesPerPixel) + blueBase; - float blue = data[baseIndex] >= 0 ? data[baseIndex] - : (256 + (data[baseIndex])); - float green = data[baseIndex + 1] >= 0 ? data[baseIndex + 1] - : (256 + (data[baseIndex + 1])); - float red = data[baseIndex + 2] >= 0 ? data[baseIndex + 2] - : (256 + (data[baseIndex + 2])); - - float grayscale = (float) ((0.299 * red + 0.587 * green + 0.114 * blue) * dampen); - - heightData[index++] = grayscale; - } - } - } - } else { - for (int h = imageHeight-1; h >= 0; --h) { - if (flipX) { - for (int w = imageWidth-1; w >= 0; --w) { - int baseIndex = (h * imageWidth * bytesPerPixel) - + (w * bytesPerPixel) + blueBase; - float blue = data[baseIndex] >= 0 ? data[baseIndex] - : (256 + (data[baseIndex])); - float green = data[baseIndex + 1] >= 0 ? data[baseIndex + 1] - : (256 + (data[baseIndex + 1])); - float red = data[baseIndex + 2] >= 0 ? data[baseIndex + 2] - : (256 + (data[baseIndex + 2])); - - float grayscale = (float) ((0.299 * red + 0.587 * green + 0.114 * blue) * dampen); - - heightData[index++] = grayscale; - } - } else { - for (int w = 0; w < imageWidth; ++w) { - int baseIndex = (h * imageWidth * bytesPerPixel) - + (w * bytesPerPixel) + blueBase; - float blue = data[baseIndex] >= 0 ? data[baseIndex] - : (256 + (data[baseIndex])); - float green = data[baseIndex + 1] >= 0 ? data[baseIndex + 1] - : (256 + (data[baseIndex + 1])); - float red = data[baseIndex + 2] >= 0 ? data[baseIndex + 2] - : (256 + (data[baseIndex + 2])); - - float grayscale = (float) ((0.299 * red + 0.587 * green + 0.114 * blue) * dampen); - - heightData[index++] = grayscale; - } - } - } - }*/ - return true; } + + protected float getHeightAtPostion(ByteBuffer buf, Image image, int position, ColorRGBA store) { + switch (image.getFormat()){ + case RGBA8: + buf.position( position * 4 ); + store.set(byte2float(buf.get()), byte2float(buf.get()), byte2float(buf.get()), byte2float(buf.get())); + return calculateHeight(store.r, store.g, store.b); + case ABGR8: + buf.position( position * 4 ); + float a = byte2float(buf.get()); + float b = byte2float(buf.get()); + float g = byte2float(buf.get()); + float r = byte2float(buf.get()); + store.set(r,g,b,a); + return calculateHeight(store.r, store.g, store.b); + case RGB8: + buf.position( position * 3 ); + store.set(byte2float(buf.get()), byte2float(buf.get()), byte2float(buf.get()), 1); + return calculateHeight(store.r, store.g, store.b); + case Luminance8: + buf.position( position ); + return byte2float(buf.get())*255*heightScale; + case Luminance16: + ShortBuffer sbuf = buf.asShortBuffer(); + sbuf.position( position ); + return (sbuf.get() & 0xFFFF) / 65535f * 255f * heightScale; + default: + throw new UnsupportedOperationException("Image format: "+image.getFormat()); + } + } + + private float byte2float(byte b){ + return ((float)(b & 0xFF)) / 255f; + } } \ No newline at end of file diff --git a/engine/src/terrain/com/jme3/terrain/heightmap/ImageBasedHeightMapGrid.java b/engine/src/terrain/com/jme3/terrain/heightmap/ImageBasedHeightMapGrid.java index ff12fc3f2..6c12f3e4b 100644 --- a/engine/src/terrain/com/jme3/terrain/heightmap/ImageBasedHeightMapGrid.java +++ b/engine/src/terrain/com/jme3/terrain/heightmap/ImageBasedHeightMapGrid.java @@ -4,17 +4,14 @@ */ package com.jme3.terrain.heightmap; -import com.jme3.asset.AssetInfo; -import com.jme3.asset.AssetKey; import com.jme3.asset.AssetManager; import com.jme3.asset.AssetNotFoundException; +import com.jme3.asset.TextureKey; import com.jme3.math.Vector3f; +import com.jme3.texture.Texture; import java.awt.image.BufferedImage; -import java.io.IOException; -import java.io.InputStream; import java.util.logging.Level; import java.util.logging.Logger; -import javax.imageio.ImageIO; /** * Loads Terrain grid tiles with image heightmaps. @@ -36,8 +33,7 @@ public class ImageBasedHeightMapGrid implements HeightMapGrid { private final AssetManager assetManager; private final Namer namer; private int size; - private int imageType = BufferedImage.TYPE_USHORT_GRAY; // 16 bit grayscale - private ImageHeightmap customImageHeightmap; + public ImageBasedHeightMapGrid(final String textureBase, final String textureExt, AssetManager assetManager) { this(assetManager, new Namer() { @@ -52,27 +48,6 @@ public class ImageBasedHeightMapGrid implements HeightMapGrid { this.assetManager = assetManager; this.namer = namer; } - - /** - * Lets you specify the type of images that are being loaded. All images - * must be the same type. - * @param imageType eg. BufferedImage.TYPE_USHORT_GRAY - */ - public void setImageType(int imageType) { - this.imageType = imageType; - } - - /** - * The ImageHeightmap that will parse the image type that you - * specify with setImageType(). - * @param customImageHeightmap must extend AbstractHeightmap - */ - public void setCustomImageHeightmap(ImageHeightmap customImageHeightmap) { - if (!(customImageHeightmap instanceof AbstractHeightMap)) { - throw new IllegalArgumentException("customImageHeightmap must be an AbstractHeightMap!"); - } - this.customImageHeightmap = customImageHeightmap; - } public HeightMap getHeightMapAt(Vector3f location) { // HEIGHTMAP image (for the terrain heightmap) @@ -80,42 +55,21 @@ public class ImageBasedHeightMapGrid implements HeightMapGrid { int z = (int) location.z; AbstractHeightMap heightmap = null; - BufferedImage im = null; + //BufferedImage im = null; try { String name = namer.getName(x, z); logger.log(Level.INFO, "Loading heightmap from file: {0}", name); - final AssetInfo assetInfo = assetManager.locateAsset(new AssetKey(name)); - if (assetInfo != null){ - InputStream in = assetInfo.openStream(); - im = ImageIO.read(in); - } else { - im = new BufferedImage(size, size, imageType); - logger.log(Level.WARNING, "File: {0} not found, loading zero heightmap instead", name); - } + final Texture texture = assetManager.loadTexture(new TextureKey(name)); + // CREATE HEIGHTMAP - if (imageType == BufferedImage.TYPE_USHORT_GRAY) { - heightmap = new Grayscale16BitHeightMap(im); - } else if (imageType == BufferedImage.TYPE_3BYTE_BGR) { - heightmap = new ImageBasedHeightMap(im); - } else if (customImageHeightmap != null && customImageHeightmap instanceof AbstractHeightMap) { - // If it gets here, it means you have specified a different image type, and you must - // then also supply a custom image heightmap class that can parse that image into - // a heightmap. - customImageHeightmap.setImage(im); - heightmap = (AbstractHeightMap) customImageHeightmap; - } else { - // error, no supported image format and no custom image heightmap specified - if (customImageHeightmap == null) - logger.log(Level.SEVERE, "Custom image type specified [{0}] but no customImageHeightmap declared! Use setCustomImageHeightmap()",imageType); - if (!(customImageHeightmap instanceof AbstractHeightMap)) - logger.severe("customImageHeightmap must be an AbstractHeightMap!"); - return null; - } - heightmap.setHeightScale(256); + heightmap = new ImageBasedHeightMap(texture.getImage()); + + heightmap.setHeightScale(1); heightmap.load(); - } catch (IOException e) { + } catch (AssetNotFoundException e) { + logger.log(Level.SEVERE, "Asset Not found! ", e); } return heightmap; } diff --git a/engine/src/terrain/com/jme3/terrain/heightmap/ImageHeightmap.java b/engine/src/terrain/com/jme3/terrain/heightmap/ImageHeightmap.java index fe1baae7e..76a222bf5 100644 --- a/engine/src/terrain/com/jme3/terrain/heightmap/ImageHeightmap.java +++ b/engine/src/terrain/com/jme3/terrain/heightmap/ImageHeightmap.java @@ -4,7 +4,7 @@ */ package com.jme3.terrain.heightmap; -import java.awt.Image; +import com.jme3.texture.Image; /** * A heightmap that is built off an image. @@ -13,17 +13,18 @@ import java.awt.Image; * and have that class extend Abstract heightmap. * * @author bowens + * @deprecated */ public interface ImageHeightmap { /** * Set the image to use for this heightmap */ - public void setImage(Image image); + //public void setImage(Image image); /** * The BufferedImage.TYPE_ that is supported * by this ImageHeightmap */ - public int getSupportedImageType(); + //public int getSupportedImageType(); } diff --git a/engine/src/test/jme3test/bullet/TestHoveringTank.java b/engine/src/test/jme3test/bullet/TestHoveringTank.java index 4059c0b53..7e5fd4a7f 100644 --- a/engine/src/test/jme3test/bullet/TestHoveringTank.java +++ b/engine/src/test/jme3test/bullet/TestHoveringTank.java @@ -66,7 +66,6 @@ import com.jme3.texture.Texture.WrapMode; import com.jme3.util.SkyFactory; import java.util.ArrayList; import java.util.List; -import jme3tools.converters.ImageToAwt; public class TestHoveringTank extends SimpleApplication implements AnalogListener, ActionListener { @@ -277,7 +276,7 @@ public class TestHoveringTank extends SimpleApplication implements AnalogListene AbstractHeightMap heightmap = null; try { - heightmap = new ImageBasedHeightMap(ImageToAwt.convert(heightMapImage.getImage(), false, true, 0), 0.25f); + heightmap = new ImageBasedHeightMap(heightMapImage.getImage(), 0.25f); heightmap.load(); } catch (Exception e) { e.printStackTrace(); diff --git a/engine/src/test/jme3test/bullet/TestWalkingChar.java b/engine/src/test/jme3test/bullet/TestWalkingChar.java index 8a5038085..e9746fb58 100644 --- a/engine/src/test/jme3test/bullet/TestWalkingChar.java +++ b/engine/src/test/jme3test/bullet/TestWalkingChar.java @@ -76,7 +76,6 @@ import com.jme3.texture.Texture.WrapMode; import com.jme3.util.SkyFactory; import java.util.ArrayList; import java.util.List; -import jme3tools.converters.ImageToAwt; /** * A walking animated character followed by a 3rd person camera on a terrain with LOD. @@ -271,7 +270,7 @@ public class TestWalkingChar extends SimpleApplication implements ActionListener AbstractHeightMap heightmap = null; try { - heightmap = new ImageBasedHeightMap(ImageToAwt.convert(heightMapImage.getImage(), false, true, 0), 0.25f); + heightmap = new ImageBasedHeightMap(heightMapImage.getImage(), 0.25f); heightmap.load(); } catch (Exception e) { diff --git a/engine/src/test/jme3test/helloworld/HelloTerrain.java b/engine/src/test/jme3test/helloworld/HelloTerrain.java index 2b45b1d2b..6986b6cca 100644 --- a/engine/src/test/jme3test/helloworld/HelloTerrain.java +++ b/engine/src/test/jme3test/helloworld/HelloTerrain.java @@ -41,7 +41,6 @@ import com.jme3.terrain.heightmap.AbstractHeightMap; import com.jme3.terrain.heightmap.ImageBasedHeightMap; import com.jme3.texture.Texture; import com.jme3.texture.Texture.WrapMode; -import jme3tools.converters.ImageToAwt; public class HelloTerrain extends SimpleApplication { @@ -90,8 +89,7 @@ public class HelloTerrain extends SimpleApplication { AbstractHeightMap heightmap = null; Texture heightMapImage = assetManager.loadTexture( "Textures/Terrain/splat/mountains512.png"); - heightmap = new ImageBasedHeightMap( - ImageToAwt.convert(heightMapImage.getImage(), false, true, 0)); + heightmap = new ImageBasedHeightMap(heightMapImage.getImage()); heightmap.load(); /** 3. We have prepared material and heightmap. diff --git a/engine/src/test/jme3test/helloworld/HelloTerrainCollision.java b/engine/src/test/jme3test/helloworld/HelloTerrainCollision.java index a42a85194..c1a96a880 100644 --- a/engine/src/test/jme3test/helloworld/HelloTerrainCollision.java +++ b/engine/src/test/jme3test/helloworld/HelloTerrainCollision.java @@ -54,7 +54,6 @@ import com.jme3.texture.Texture; import com.jme3.texture.Texture.WrapMode; import java.util.ArrayList; import java.util.List; -import jme3tools.converters.ImageToAwt; /** * This demo shows a terrain with collision detection, @@ -120,8 +119,7 @@ public class HelloTerrainCollision extends SimpleApplication AbstractHeightMap heightmap = null; Texture heightMapImage = assetManager.loadTexture( "Textures/Terrain/splat/mountains512.png"); - heightmap = new ImageBasedHeightMap( - ImageToAwt.convert(heightMapImage.getImage(), false, true, 0)); + heightmap = new ImageBasedHeightMap(heightMapImage.getImage()); heightmap.load(); /** 3. We have prepared material and heightmap. diff --git a/engine/src/test/jme3test/light/TestSpotLightTerrain.java b/engine/src/test/jme3test/light/TestSpotLightTerrain.java index 86a7936cc..7e6139f7b 100644 --- a/engine/src/test/jme3test/light/TestSpotLightTerrain.java +++ b/engine/src/test/jme3test/light/TestSpotLightTerrain.java @@ -182,7 +182,7 @@ public class TestSpotLightTerrain extends SimpleApplication { try { //heightmap = new HillHeightMap(1025, 1000, 50, 100, (byte) 3); - heightmap = new ImageBasedHeightMap(ImageToAwt.convert(heightMapImage.getImage(), false, true, 0), 1f); + heightmap = new ImageBasedHeightMap(heightMapImage.getImage(), 1f); heightmap.load(); } catch (Exception e) { diff --git a/engine/src/test/jme3test/post/TestDepthOfField.java b/engine/src/test/jme3test/post/TestDepthOfField.java index cbfc384dd..5426a335d 100644 --- a/engine/src/test/jme3test/post/TestDepthOfField.java +++ b/engine/src/test/jme3test/post/TestDepthOfField.java @@ -23,7 +23,6 @@ import com.jme3.texture.Texture.WrapMode; import com.jme3.util.SkyFactory; import java.util.ArrayList; import java.util.List; -import jme3tools.converters.ImageToAwt; /** * test @@ -166,7 +165,7 @@ public class TestDepthOfField extends SimpleApplication { AbstractHeightMap heightmap = null; try { - heightmap = new ImageBasedHeightMap(ImageToAwt.convert(heightMapImage.getImage(), false, true, 0), 0.25f); + heightmap = new ImageBasedHeightMap(heightMapImage.getImage(), 0.25f); heightmap.load(); } catch (Exception e) { e.printStackTrace(); diff --git a/engine/src/test/jme3test/terrain/TerrainGridAlphaMapTest.java b/engine/src/test/jme3test/terrain/TerrainGridAlphaMapTest.java index 9f42391ba..2cae145b9 100644 --- a/engine/src/test/jme3test/terrain/TerrainGridAlphaMapTest.java +++ b/engine/src/test/jme3test/terrain/TerrainGridAlphaMapTest.java @@ -191,11 +191,11 @@ public class TerrainGridAlphaMapTest extends SimpleApplication { public void tileAttached(Vector3f cell, TerrainQuad quad) { Texture alpha = null; - //try { - // alpha = assetManager.loadTexture("TerrainAlphaTest/alpha_" + (int)cell.x+ "_" + (int)cell.z + ".png"); - //} catch (Exception e) { + try { + alpha = assetManager.loadTexture("TerrainAlphaTest/alpha_" + (int)cell.x+ "_" + (int)cell.z + ".png"); + } catch (Exception e) { alpha = assetManager.loadTexture("TerrainAlphaTest/alpha_default.png"); - //} + } quad.getMaterial().setTexture("AlphaMap", alpha); if (usePhysics) { quad.addControl(new RigidBodyControl(new HeightfieldCollisionShape(quad.getHeightMap(), terrain.getLocalScale()), 0)); diff --git a/engine/src/test/jme3test/terrain/TerrainGridTest.java b/engine/src/test/jme3test/terrain/TerrainGridTest.java index deca43f63..85f8ee424 100644 --- a/engine/src/test/jme3test/terrain/TerrainGridTest.java +++ b/engine/src/test/jme3test/terrain/TerrainGridTest.java @@ -12,6 +12,7 @@ import com.jme3.bullet.control.RigidBodyControl; import com.jme3.input.KeyInput; import com.jme3.input.controls.ActionListener; import com.jme3.input.controls.KeyTrigger; +import com.jme3.light.DirectionalLight; import com.jme3.material.Material; import com.jme3.math.ColorRGBA; import com.jme3.math.Vector3f; @@ -33,7 +34,7 @@ public class TerrainGridTest extends SimpleApplication { private float grassScale = 64; private float dirtScale = 16; private float rockScale = 128; - private boolean usePhysics = true; + private boolean usePhysics = false; private boolean physicsAdded = false; public static void main(final String[] args) { @@ -100,8 +101,8 @@ public class TerrainGridTest extends SimpleApplication { return "Scenes/TerrainMountains/terrain_" + x + "_" + y + ".png"; } })); - - this.terrain.setMaterial(this.mat_terrain); + + this.terrain.setMaterial(mat_terrain); this.terrain.setLocalTranslation(0, 0, 0); this.terrain.setLocalScale(1f, 1f, 1f); this.rootNode.attachChild(this.terrain); @@ -113,10 +114,14 @@ public class TerrainGridTest extends SimpleApplication { final BulletAppState bulletAppState = new BulletAppState(); stateManager.attach(bulletAppState); - this.getCamera().setLocation(new Vector3f(0, 256, 0)); + this.getCamera().setLocation(new Vector3f(0, 200, 0)); this.viewPort.setBackgroundColor(new ColorRGBA(0.7f, 0.8f, 1f, 1f)); + DirectionalLight light = new DirectionalLight(); + light.setDirection((new Vector3f(-0.5f, -1f, -0.5f)).normalize()); + rootNode.addLight(light); + if (usePhysics) { CapsuleCollisionShape capsuleShape = new CapsuleCollisionShape(0.5f, 1.8f, 1); player3 = new CharacterControl(capsuleShape, 0.5f); @@ -141,12 +146,6 @@ public class TerrainGridTest extends SimpleApplication { while(quad.getControl(RigidBodyControl.class)!=null){ quad.removeControl(RigidBodyControl.class); } -// try { -// BinaryExporter.getInstance().save(quad, new File("/Users/normenhansen/Documents/Code/jme3/engine/src/test-data/TerrainGrid/" -// + "testgrid_" + Math.round(cell.x) + "_" + Math.round(cell.y) + "_" + Math.round(cell.z) + ".j3o")); -// } catch (IOException ex) { -// Logger.getLogger(TerrainFractalGridTest.class.getName()).log(Level.SEVERE, null, ex); -// } quad.addControl(new RigidBodyControl(new HeightfieldCollisionShape(quad.getHeightMap(), terrain.getLocalScale()), 0)); bulletAppState.getPhysicsSpace().add(quad); } diff --git a/engine/src/test/jme3test/terrain/TerrainTest.java b/engine/src/test/jme3test/terrain/TerrainTest.java index 30a5ec9d9..4180c4797 100644 --- a/engine/src/test/jme3test/terrain/TerrainTest.java +++ b/engine/src/test/jme3test/terrain/TerrainTest.java @@ -49,7 +49,7 @@ import com.jme3.terrain.heightmap.AbstractHeightMap; import com.jme3.terrain.heightmap.ImageBasedHeightMap; import com.jme3.texture.Texture; import com.jme3.texture.Texture.WrapMode; -import jme3tools.converters.ImageToAwt; +import com.jme3.asset.TextureKey; /** * Demonstrates how to use terrain. @@ -140,7 +140,7 @@ public class TerrainTest extends SimpleApplication { try { //heightmap = new HillHeightMap(1025, 1000, 50, 100, (byte) 3); - heightmap = new ImageBasedHeightMap(ImageToAwt.convert(heightMapImage.getImage(), false, true, 0), 1f); + heightmap = new ImageBasedHeightMap(heightMapImage.getImage(), 1f); heightmap.load(); } catch (Exception e) { diff --git a/engine/src/test/jme3test/terrain/TerrainTestAdvanced.java b/engine/src/test/jme3test/terrain/TerrainTestAdvanced.java index 9336df2f1..92a88d33c 100644 --- a/engine/src/test/jme3test/terrain/TerrainTestAdvanced.java +++ b/engine/src/test/jme3test/terrain/TerrainTestAdvanced.java @@ -52,7 +52,8 @@ import com.jme3.terrain.heightmap.ImageBasedHeightMap; import com.jme3.texture.Texture; import com.jme3.texture.Texture.WrapMode; import com.jme3.util.SkyFactory; -import jme3tools.converters.ImageToAwt; +import com.jme3.scene.Node; +import com.jme3.scene.debug.Arrow; /** * Uses the terrain's lighting texture with normal maps and lights. @@ -108,8 +109,8 @@ public class TerrainTestAdvanced extends SimpleApplication { // GRASS texture Texture grass = assetManager.loadTexture("Textures/Terrain/splat/grass.jpg"); grass.setWrap(WrapMode.Repeat); - matTerrain.setTexture("DiffuseMap_1", grass); - matTerrain.setFloat("DiffuseMap_1_scale", grassScale); + //matTerrain.setTexture("DiffuseMap_1", grass); + //matTerrain.setFloat("DiffuseMap_1_scale", grassScale); // DIRT texture Texture dirt = assetManager.loadTexture("Textures/Terrain/splat/dirt.jpg"); @@ -120,20 +121,20 @@ public class TerrainTestAdvanced extends SimpleApplication { // ROCK texture Texture rock = assetManager.loadTexture("Textures/Terrain/splat/road.jpg"); rock.setWrap(WrapMode.Repeat); - matTerrain.setTexture("DiffuseMap_2", rock); - matTerrain.setFloat("DiffuseMap_2_scale", rockScale); + //matTerrain.setTexture("DiffuseMap_2", rock); + //matTerrain.setFloat("DiffuseMap_2_scale", rockScale); // BRICK texture Texture brick = assetManager.loadTexture("Textures/Terrain/BrickWall/BrickWall.jpg"); brick.setWrap(WrapMode.Repeat); - matTerrain.setTexture("DiffuseMap_3", brick); - matTerrain.setFloat("DiffuseMap_3_scale", rockScale); + //matTerrain.setTexture("DiffuseMap_3", brick); + //matTerrain.setFloat("DiffuseMap_3_scale", rockScale); // RIVER ROCK texture Texture riverRock = assetManager.loadTexture("Textures/Terrain/Pond/Pond.jpg"); riverRock.setWrap(WrapMode.Repeat); - matTerrain.setTexture("DiffuseMap_4", riverRock); - matTerrain.setFloat("DiffuseMap_4_scale", rockScale); + //matTerrain.setTexture("DiffuseMap_4", riverRock); + //matTerrain.setFloat("DiffuseMap_4_scale", rockScale); Texture normalMap0 = assetManager.loadTexture("Textures/Terrain/splat/grass_normal.jpg"); @@ -142,22 +143,22 @@ public class TerrainTestAdvanced extends SimpleApplication { normalMap1.setWrap(WrapMode.Repeat); Texture normalMap2 = assetManager.loadTexture("Textures/Terrain/splat/road_normal.png"); normalMap2.setWrap(WrapMode.Repeat); - matTerrain.setTexture("NormalMap", normalMap2); - matTerrain.setTexture("NormalMap_1", normalMap2); - matTerrain.setTexture("NormalMap_2", normalMap2); - matTerrain.setTexture("NormalMap_4", normalMap2); + matTerrain.setTexture("NormalMap", normalMap0); + //matTerrain.setTexture("NormalMap_1", normalMap2); + //matTerrain.setTexture("NormalMap_2", normalMap2); + //matTerrain.setTexture("NormalMap_4", normalMap2); // WIREFRAME material matWire = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); matWire.getAdditionalRenderState().setWireframe(true); matWire.setColor("Color", ColorRGBA.Green); - createSky(); + //createSky(); // CREATE HEIGHTMAP AbstractHeightMap heightmap = null; try { - heightmap = new ImageBasedHeightMap(ImageToAwt.convert(heightMapImage.getImage(), false, true, 0), 0.5f); + heightmap = new ImageBasedHeightMap(heightMapImage.getImage(), 0.5f); heightmap.load(); heightmap.smooth(0.9f, 1); @@ -189,12 +190,14 @@ public class TerrainTestAdvanced extends SimpleApplication { //terrain.generateDebugTangents(debugMat); DirectionalLight light = new DirectionalLight(); - light.setDirection((new Vector3f(-0.25f, -1f, -0.25f)).normalize()); + light.setDirection((new Vector3f(-0.5f, -0.5f, -0.5f)).normalize()); rootNode.addLight(light); cam.setLocation(new Vector3f(0, 10, -10)); cam.lookAtDirection(new Vector3f(0, -1.5f, -1).normalizeLocal(), Vector3f.UNIT_Y); flyCam.setMoveSpeed(400); + + rootNode.attachChild(createAxisMarker(20)); } public void loadHintText() { @@ -261,4 +264,35 @@ public class TerrainTestAdvanced extends SimpleApplication { Spatial sky = SkyFactory.createSky(assetManager, west, east, north, south, up, down); rootNode.attachChild(sky); } + + protected Node createAxisMarker(float arrowSize) { + + Material redMat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); + redMat.getAdditionalRenderState().setWireframe(true); + redMat.setColor("Color", ColorRGBA.Red); + + Material greenMat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); + greenMat.getAdditionalRenderState().setWireframe(true); + greenMat.setColor("Color", ColorRGBA.Green); + + Material blueMat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); + blueMat.getAdditionalRenderState().setWireframe(true); + blueMat.setColor("Color", ColorRGBA.Blue); + + Node axis = new Node(); + + // create arrows + Geometry arrowX = new Geometry("arrowX", new Arrow(new Vector3f(arrowSize, 0, 0))); + arrowX.setMaterial(redMat); + Geometry arrowY = new Geometry("arrowY", new Arrow(new Vector3f(0, arrowSize, 0))); + arrowY.setMaterial(greenMat); + Geometry arrowZ = new Geometry("arrowZ", new Arrow(new Vector3f(0, 0, arrowSize))); + arrowZ.setMaterial(blueMat); + axis.attachChild(arrowX); + axis.attachChild(arrowY); + axis.attachChild(arrowZ); + + //axis.setModelBound(new BoundingBox()); + return axis; + } } diff --git a/engine/src/test/jme3test/terrain/TerrainTestCollision.java b/engine/src/test/jme3test/terrain/TerrainTestCollision.java index 6b375547d..9bcd48a61 100644 --- a/engine/src/test/jme3test/terrain/TerrainTestCollision.java +++ b/engine/src/test/jme3test/terrain/TerrainTestCollision.java @@ -31,6 +31,7 @@ */ package jme3test.terrain; +import com.jme3.bullet.collision.shapes.SphereCollisionShape; import com.jme3.app.SimpleApplication; import com.jme3.bounding.BoundingBox; import com.jme3.bullet.BulletAppState; @@ -127,7 +128,7 @@ public class TerrainTestCollision extends SimpleApplication { matWire.setColor("Color", ColorRGBA.Green); AbstractHeightMap heightmap = null; try { - heightmap = new ImageBasedHeightMap(ImageToAwt.convert(heightMapImage.getImage(), false, true, 0), 0.25f); + heightmap = new ImageBasedHeightMap(heightMapImage.getImage(), 0.25f); heightmap.load(); } catch (Exception e) { diff --git a/engine/src/test/jme3test/terrain/TerrainTestModifyHeight.java b/engine/src/test/jme3test/terrain/TerrainTestModifyHeight.java index 14fdbdb76..7996f8e93 100644 --- a/engine/src/test/jme3test/terrain/TerrainTestModifyHeight.java +++ b/engine/src/test/jme3test/terrain/TerrainTestModifyHeight.java @@ -62,7 +62,6 @@ import com.jme3.texture.Texture; import com.jme3.texture.Texture.WrapMode; import java.util.ArrayList; import java.util.List; -import jme3tools.converters.ImageToAwt; import org.novyon.noise.ShaderUtils; import org.novyon.noise.basis.FilteredBasis; import org.novyon.noise.filter.IterativeFilter; @@ -307,7 +306,7 @@ public class TerrainTestModifyHeight extends SimpleApplication { Texture heightMapImage = assetManager.loadTexture("Textures/Terrain/splat/mountains512.png"); AbstractHeightMap heightmap = null; try { - heightmap = new ImageBasedHeightMap(ImageToAwt.convert(heightMapImage.getImage(), false, true, 0), 0.5f); + heightmap = new ImageBasedHeightMap(heightMapImage.getImage(), 0.5f); heightmap.load(); heightmap.smooth(0.9f, 1); diff --git a/engine/src/test/jme3test/terrain/TerrainTestReadWrite.java b/engine/src/test/jme3test/terrain/TerrainTestReadWrite.java index 765fd7dce..8ba94043b 100644 --- a/engine/src/test/jme3test/terrain/TerrainTestReadWrite.java +++ b/engine/src/test/jme3test/terrain/TerrainTestReadWrite.java @@ -55,7 +55,6 @@ import com.jme3.texture.Texture.WrapMode; import java.io.*; import java.util.logging.Level; import java.util.logging.Logger; -import jme3tools.converters.ImageToAwt; /** * Saves and loads terrain. @@ -142,7 +141,7 @@ public class TerrainTestReadWrite extends SimpleApplication { // CREATE HEIGHTMAP AbstractHeightMap heightmap = null; try { - heightmap = new ImageBasedHeightMap(ImageToAwt.convert(heightMapImage.getImage(), false, true, 0), 1f); + heightmap = new ImageBasedHeightMap(heightMapImage.getImage(), 1f); heightmap.load(); } catch (Exception e) { diff --git a/engine/src/test/jme3test/water/TestPostWater.java b/engine/src/test/jme3test/water/TestPostWater.java index 85ca62ab0..9a89f984b 100644 --- a/engine/src/test/jme3test/water/TestPostWater.java +++ b/engine/src/test/jme3test/water/TestPostWater.java @@ -35,7 +35,6 @@ import com.jme3.util.SkyFactory; import com.jme3.water.WaterFilter; import java.util.ArrayList; import java.util.List; -import jme3tools.converters.ImageToAwt; /** * test @@ -254,7 +253,7 @@ public class TestPostWater extends SimpleApplication { AbstractHeightMap heightmap = null; try { - heightmap = new ImageBasedHeightMap(ImageToAwt.convert(heightMapImage.getImage(), false, true, 0), 0.25f); + heightmap = new ImageBasedHeightMap(heightMapImage.getImage(), 0.25f); heightmap.load(); } catch (Exception e) { e.printStackTrace(); diff --git a/sdk/jme3-terrain-editor/src/com/jme3/gde/terraineditor/AddTerrainAction.java b/sdk/jme3-terrain-editor/src/com/jme3/gde/terraineditor/AddTerrainAction.java index 7d680f9ec..5d3504ff6 100644 --- a/sdk/jme3-terrain-editor/src/com/jme3/gde/terraineditor/AddTerrainAction.java +++ b/sdk/jme3-terrain-editor/src/com/jme3/gde/terraineditor/AddTerrainAction.java @@ -86,7 +86,9 @@ public class AddTerrainAction extends AbstractNewSpatialWizardAction { int alphaTextureSize = (Integer) wizardDescriptor.getProperty("alphaTextureSize"); float[] heightmapData = null; - AbstractHeightMap heightmap = (AbstractHeightMap) wizardDescriptor.getProperty("abstractHeightMap"); + AbstractHeightMap heightmap = null; + if (wizardDescriptor.getProperty("abstractHeightMap") != null) + heightmap = (AbstractHeightMap) wizardDescriptor.getProperty("abstractHeightMap"); if (heightmap != null) { heightmap.load(); // can take a while heightmapData = heightmap.getHeightMap(); diff --git a/sdk/jme3-terrain-editor/src/com/jme3/gde/terraineditor/CreateTerrainWizardPanel2.java b/sdk/jme3-terrain-editor/src/com/jme3/gde/terraineditor/CreateTerrainWizardPanel2.java index 28376999a..ce0fed86c 100644 --- a/sdk/jme3-terrain-editor/src/com/jme3/gde/terraineditor/CreateTerrainWizardPanel2.java +++ b/sdk/jme3-terrain-editor/src/com/jme3/gde/terraineditor/CreateTerrainWizardPanel2.java @@ -31,6 +31,7 @@ */ package com.jme3.gde.terraineditor; +import com.jme3.asset.AssetManager; import com.jme3.asset.TextureKey; import com.jme3.gde.core.scene.SceneApplication; import com.jme3.terrain.heightmap.AbstractHeightMap; @@ -38,21 +39,11 @@ import com.jme3.terrain.heightmap.HillHeightMap; import com.jme3.terrain.heightmap.ImageBasedHeightMap; import com.jme3.texture.Texture; import java.awt.Component; -import java.awt.Toolkit; -import java.awt.image.BufferedImage; -import java.awt.image.ImageObserver; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileReader; -import java.io.IOException; -import java.net.URL; import java.util.HashSet; import java.util.Iterator; import java.util.Set; -import javax.imageio.ImageIO; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; -import jme3tools.converters.ImageToAwt; import org.openide.WizardDescriptor; import org.openide.util.Exceptions; import org.openide.util.HelpCtx; @@ -143,21 +134,14 @@ public class CreateTerrainWizardPanel2 implements WizardDescriptor.Panel { public void storeSettings(Object settings) { CreateTerrainVisualPanel2 comp = (CreateTerrainVisualPanel2) getComponent(); - + if ("Flat".equals(comp.getHeightmapTypeComboBox().getSelectedItem()) ) { heightmap = new FlatHeightmap(terrainTotalSize); } else if ("Image Based".equals(comp.getHeightmapTypeComboBox().getSelectedItem()) ) { - - BufferedImage bi = null; - try { - bi = ImageIO.read(new File(comp.getImageBrowseTextField().getText())); - } catch (IOException e) { - e.printStackTrace(); - } - ImageBasedHeightMap ibhm = new ImageBasedHeightMap(bi, 1f); - - heightmap = ibhm; + AssetManager assetManager = SceneApplication.getApplication().getAssetManager(); + Texture tex = assetManager.loadTexture(new TextureKey(comp.getImageBrowseTextField().getText())); + heightmap = new ImageBasedHeightMap(tex.getImage()); } else if ("Hill".equals(comp.getHeightmapTypeComboBox().getSelectedItem()) ) { int iterations = new Integer(comp.getHillIterationsTextField().getText());