deprecating and removing most AWT dependencies from heightmaps and TerrainGrid, still some more to do
git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@8930 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
This commit is contained in:
parent
598e8a73c5
commit
356c3b55cc
@ -4,22 +4,19 @@
|
|||||||
*/
|
*/
|
||||||
package com.jme3.terrain.geomipmap.grid;
|
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.AssetManager;
|
||||||
import com.jme3.asset.AssetNotFoundException;
|
import com.jme3.asset.AssetNotFoundException;
|
||||||
|
import com.jme3.asset.TextureKey;
|
||||||
import com.jme3.export.JmeExporter;
|
import com.jme3.export.JmeExporter;
|
||||||
import com.jme3.export.JmeImporter;
|
import com.jme3.export.JmeImporter;
|
||||||
import com.jme3.math.Vector3f;
|
import com.jme3.math.Vector3f;
|
||||||
import com.jme3.terrain.geomipmap.TerrainGridTileLoader;
|
import com.jme3.terrain.geomipmap.TerrainGridTileLoader;
|
||||||
import com.jme3.terrain.geomipmap.TerrainQuad;
|
import com.jme3.terrain.geomipmap.TerrainQuad;
|
||||||
import com.jme3.terrain.heightmap.*;
|
import com.jme3.terrain.heightmap.*;
|
||||||
import java.awt.image.BufferedImage;
|
import com.jme3.texture.Texture;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
import javax.imageio.ImageIO;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -31,8 +28,9 @@ public class ImageTileLoader implements TerrainGridTileLoader{
|
|||||||
private final Namer namer;
|
private final Namer namer;
|
||||||
private int patchSize;
|
private int patchSize;
|
||||||
private int quadSize;
|
private int quadSize;
|
||||||
private int imageType = BufferedImage.TYPE_USHORT_GRAY; // 16 bit grayscale
|
private float heightScale = 1;
|
||||||
private ImageHeightmap customImageHeightmap;
|
//private int imageType = BufferedImage.TYPE_USHORT_GRAY; // 16 bit grayscale
|
||||||
|
//private ImageHeightmap customImageHeightmap;
|
||||||
|
|
||||||
public ImageTileLoader(final String textureBase, final String textureExt, AssetManager assetManager) {
|
public ImageTileLoader(final String textureBase, final String textureExt, AssetManager assetManager) {
|
||||||
this(assetManager, new Namer() {
|
this(assetManager, new Namer() {
|
||||||
@ -47,27 +45,35 @@ public class ImageTileLoader implements TerrainGridTileLoader{
|
|||||||
this.assetManager = assetManager;
|
this.assetManager = assetManager;
|
||||||
this.namer = namer;
|
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
|
* Lets you specify the type of images that are being loaded. All images
|
||||||
* must be the same type.
|
* must be the same type.
|
||||||
* @param imageType eg. BufferedImage.TYPE_USHORT_GRAY
|
* @param imageType eg. BufferedImage.TYPE_USHORT_GRAY
|
||||||
*/
|
*/
|
||||||
public void setImageType(int imageType) {
|
/*public void setImageType(int imageType) {
|
||||||
this.imageType = imageType;
|
this.imageType = imageType;
|
||||||
}
|
}*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The ImageHeightmap that will parse the image type that you
|
* The ImageHeightmap that will parse the image type that you
|
||||||
* specify with setImageType().
|
* specify with setImageType().
|
||||||
* @param customImageHeightmap must extend AbstractHeightmap
|
* @param customImageHeightmap must extend AbstractHeightmap
|
||||||
*/
|
*/
|
||||||
public void setCustomImageHeightmap(ImageHeightmap customImageHeightmap) {
|
/*public void setCustomImageHeightmap(ImageHeightmap customImageHeightmap) {
|
||||||
if (!(customImageHeightmap instanceof AbstractHeightMap)) {
|
if (!(customImageHeightmap instanceof AbstractHeightMap)) {
|
||||||
throw new IllegalArgumentException("customImageHeightmap must be an AbstractHeightMap!");
|
throw new IllegalArgumentException("customImageHeightmap must be an AbstractHeightMap!");
|
||||||
}
|
}
|
||||||
this.customImageHeightmap = customImageHeightmap;
|
this.customImageHeightmap = customImageHeightmap;
|
||||||
}
|
}*/
|
||||||
|
|
||||||
private HeightMap getHeightMapAt(Vector3f location) {
|
private HeightMap getHeightMapAt(Vector3f location) {
|
||||||
// HEIGHTMAP image (for the terrain heightmap)
|
// HEIGHTMAP image (for the terrain heightmap)
|
||||||
@ -75,21 +81,23 @@ public class ImageTileLoader implements TerrainGridTileLoader{
|
|||||||
int z = (int) location.z;
|
int z = (int) location.z;
|
||||||
|
|
||||||
AbstractHeightMap heightmap = null;
|
AbstractHeightMap heightmap = null;
|
||||||
BufferedImage im = null;
|
//BufferedImage im = null;
|
||||||
|
|
||||||
|
String name = null;
|
||||||
try {
|
try {
|
||||||
String name = namer.getName(x, z);
|
name = namer.getName(x, z);
|
||||||
logger.log(Level.INFO, "Loading heightmap from file: {0}", name);
|
logger.log(Level.INFO, "Loading heightmap from file: {0}", name);
|
||||||
final AssetInfo assetInfo = assetManager.locateAsset(new AssetKey(name));
|
final Texture texture = assetManager.loadTexture(new TextureKey(name));
|
||||||
if (assetInfo != null){
|
heightmap = new ImageBasedHeightMap(texture.getImage());
|
||||||
|
/*if (assetInfo != null){
|
||||||
InputStream in = assetInfo.openStream();
|
InputStream in = assetInfo.openStream();
|
||||||
im = ImageIO.read(in);
|
im = ImageIO.read(in);
|
||||||
} else {
|
} else {
|
||||||
im = new BufferedImage(patchSize, patchSize, imageType);
|
im = new BufferedImage(patchSize, patchSize, imageType);
|
||||||
logger.log(Level.WARNING, "File: {0} not found, loading zero heightmap instead", name);
|
logger.log(Level.WARNING, "File: {0} not found, loading zero heightmap instead", name);
|
||||||
}
|
}*/
|
||||||
// CREATE HEIGHTMAP
|
// CREATE HEIGHTMAP
|
||||||
if (imageType == BufferedImage.TYPE_USHORT_GRAY) {
|
/*if (imageType == BufferedImage.TYPE_USHORT_GRAY) {
|
||||||
heightmap = new Grayscale16BitHeightMap(im);
|
heightmap = new Grayscale16BitHeightMap(im);
|
||||||
} else if (imageType == BufferedImage.TYPE_3BYTE_BGR) {
|
} else if (imageType == BufferedImage.TYPE_3BYTE_BGR) {
|
||||||
heightmap = new ImageBasedHeightMap(im);
|
heightmap = new ImageBasedHeightMap(im);
|
||||||
@ -106,11 +114,13 @@ public class ImageTileLoader implements TerrainGridTileLoader{
|
|||||||
if (!(customImageHeightmap instanceof AbstractHeightMap))
|
if (!(customImageHeightmap instanceof AbstractHeightMap))
|
||||||
logger.severe("customImageHeightmap must be an AbstractHeightMap!");
|
logger.severe("customImageHeightmap must be an AbstractHeightMap!");
|
||||||
return null;
|
return null;
|
||||||
}
|
}*/
|
||||||
heightmap.setHeightScale(256);
|
heightmap.setHeightScale(1);
|
||||||
heightmap.load();
|
heightmap.load();
|
||||||
} catch (IOException e) {
|
//} catch (IOException e) {
|
||||||
|
// e.printStackTrace();
|
||||||
} catch (AssetNotFoundException e) {
|
} catch (AssetNotFoundException e) {
|
||||||
|
logger.log(Level.WARNING, "Asset {0} not found, loading zero heightmap instead", name);
|
||||||
}
|
}
|
||||||
return heightmap;
|
return heightmap;
|
||||||
}
|
}
|
||||||
|
@ -41,6 +41,7 @@ import javax.imageio.ImageIO;
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Anthyon
|
* @author Anthyon
|
||||||
|
* @deprecated use assetManager instead
|
||||||
*/
|
*/
|
||||||
public class Grayscale16BitHeightMap extends AbstractHeightMap {
|
public class Grayscale16BitHeightMap extends AbstractHeightMap {
|
||||||
|
|
||||||
|
@ -32,12 +32,10 @@
|
|||||||
|
|
||||||
package com.jme3.terrain.heightmap;
|
package com.jme3.terrain.heightmap;
|
||||||
|
|
||||||
import java.awt.Graphics2D;
|
import java.nio.ByteBuffer;
|
||||||
import java.awt.Image;
|
import com.jme3.math.ColorRGBA;
|
||||||
import java.awt.image.BufferedImage;
|
import com.jme3.texture.Image;
|
||||||
import java.awt.image.ColorModel;
|
import java.nio.ShortBuffer;
|
||||||
import java.awt.image.PixelGrabber;
|
|
||||||
import java.awt.image.WritableRaster;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <code>ImageBasedHeightMap</code> is a height map created from the grayscale
|
* <code>ImageBasedHeightMap</code> is a height map created from the grayscale
|
||||||
@ -49,102 +47,15 @@ import java.awt.image.WritableRaster;
|
|||||||
* @version $id$
|
* @version $id$
|
||||||
*/
|
*/
|
||||||
public class ImageBasedHeightMap extends AbstractHeightMap implements ImageHeightmap {
|
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 Image colorImage;
|
||||||
protected float dampen = 1.0f;
|
|
||||||
|
|
||||||
|
|
||||||
public void setImage(Image image) {
|
public void setImage(Image image) {
|
||||||
this.colorImage = image;
|
this.colorImage = image;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getSupportedImageType() {
|
|
||||||
return BufferedImage.TYPE_3BYTE_BGR;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a HeightMap from an Image. The image will be converted to
|
* Creates a HeightMap from an Image. The image will be converted to
|
||||||
* grayscale, and the grayscale values will be used to generate the height
|
* 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.
|
* Image to map to the height map.
|
||||||
*/
|
*/
|
||||||
public ImageBasedHeightMap(Image colorImage) {
|
public ImageBasedHeightMap(Image colorImage) {
|
||||||
this(colorImage, 1.0f);
|
this.colorImage = colorImage;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ImageBasedHeightMap(Image colorImage, float dampen) {
|
public ImageBasedHeightMap(Image colorImage, float heightScale) {
|
||||||
super();
|
|
||||||
this.colorImage = colorImage;
|
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
|
* Get the grayscale value, or override in your own sub-classes
|
||||||
*/
|
*/
|
||||||
protected float calculateHeight(float red, float green, float blue) {
|
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) {
|
public boolean load(boolean flipX, boolean flipY) {
|
||||||
|
|
||||||
// FUTURE: Rescale image if not square?
|
int imageWidth = colorImage.getWidth();
|
||||||
BufferedImage colorBufferedImage = ImageConverter.toBufferedImage(
|
int imageHeight = colorImage.getHeight();
|
||||||
colorImage, BufferedImage.TYPE_3BYTE_BGR);
|
|
||||||
|
|
||||||
boolean hasAlpha = colorBufferedImage.getColorModel().hasAlpha();
|
|
||||||
|
|
||||||
int imageWidth = colorBufferedImage.getWidth();
|
|
||||||
int imageHeight = colorBufferedImage.getHeight();
|
|
||||||
|
|
||||||
if (imageWidth != imageHeight)
|
if (imageWidth != imageHeight)
|
||||||
throw new RuntimeException("imageWidth: " + imageWidth
|
throw new RuntimeException("imageWidth: " + imageWidth
|
||||||
@ -197,58 +101,24 @@ public class ImageBasedHeightMap extends AbstractHeightMap implements ImageHeigh
|
|||||||
|
|
||||||
size = imageWidth;
|
size = imageWidth;
|
||||||
|
|
||||||
byte data[] = (byte[]) colorBufferedImage.getRaster().getDataElements(
|
ByteBuffer buf = colorImage.getData(0);
|
||||||
0, 0, imageWidth, imageHeight, null);
|
|
||||||
|
|
||||||
int bytesPerPixel = 3;
|
|
||||||
int blueBase = 0;
|
|
||||||
if (hasAlpha) {
|
|
||||||
bytesPerPixel = 4;
|
|
||||||
blueBase = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
heightData = new float[(imageWidth * imageHeight)];
|
heightData = new float[(imageWidth * imageHeight)];
|
||||||
|
|
||||||
int startW = 0;
|
ColorRGBA colorStore = new ColorRGBA();
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
int index = 0;
|
int index = 0;
|
||||||
if (flipY) {
|
if (flipY) {
|
||||||
for (int h = 0; h < imageHeight; ++h) {
|
for (int h = 0; h < imageHeight; ++h) {
|
||||||
if (flipX) {
|
if (flipX) {
|
||||||
for (int w = imageWidth - 1; w >= 0; --w) {
|
for (int w = imageWidth - 1; w >= 0; --w) {
|
||||||
int baseIndex = (h * imageWidth * bytesPerPixel)
|
int baseIndex = (h * imageWidth)+ w;
|
||||||
+ (w * bytesPerPixel) + blueBase;
|
heightData[index++] = getHeightAtPostion(buf, colorImage, baseIndex, colorStore)*heightScale;
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (int w = 0; w < imageWidth; ++w) {
|
for (int w = 0; w < imageWidth; ++w) {
|
||||||
int baseIndex = (h * imageWidth * bytesPerPixel)
|
int baseIndex = (h * imageWidth)+ w;
|
||||||
+ (w * bytesPerPixel) + blueBase;
|
heightData[index++] = getHeightAtPostion(buf, colorImage, baseIndex, colorStore)*heightScale;
|
||||||
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);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -256,103 +126,52 @@ public class ImageBasedHeightMap extends AbstractHeightMap implements ImageHeigh
|
|||||||
for (int h = imageHeight - 1; h >= 0; --h) {
|
for (int h = imageHeight - 1; h >= 0; --h) {
|
||||||
if (flipX) {
|
if (flipX) {
|
||||||
for (int w = imageWidth - 1; w >= 0; --w) {
|
for (int w = imageWidth - 1; w >= 0; --w) {
|
||||||
int baseIndex = (h * imageWidth * bytesPerPixel)
|
int baseIndex = (h * imageWidth)+ w;
|
||||||
+ (w * bytesPerPixel) + blueBase;
|
heightData[index++] = getHeightAtPostion(buf, colorImage, baseIndex, colorStore)*heightScale;
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (int w = 0; w < imageWidth; ++w) {
|
for (int w = 0; w < imageWidth; ++w) {
|
||||||
int baseIndex = (h * imageWidth * bytesPerPixel)
|
int baseIndex = (h * imageWidth)+ w;
|
||||||
+ (w * bytesPerPixel) + blueBase;
|
heightData[index++] = getHeightAtPostion(buf, colorImage, baseIndex, colorStore)*heightScale;
|
||||||
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 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;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
@ -4,17 +4,14 @@
|
|||||||
*/
|
*/
|
||||||
package com.jme3.terrain.heightmap;
|
package com.jme3.terrain.heightmap;
|
||||||
|
|
||||||
import com.jme3.asset.AssetInfo;
|
|
||||||
import com.jme3.asset.AssetKey;
|
|
||||||
import com.jme3.asset.AssetManager;
|
import com.jme3.asset.AssetManager;
|
||||||
import com.jme3.asset.AssetNotFoundException;
|
import com.jme3.asset.AssetNotFoundException;
|
||||||
|
import com.jme3.asset.TextureKey;
|
||||||
import com.jme3.math.Vector3f;
|
import com.jme3.math.Vector3f;
|
||||||
|
import com.jme3.texture.Texture;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
import javax.imageio.ImageIO;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads Terrain grid tiles with image heightmaps.
|
* Loads Terrain grid tiles with image heightmaps.
|
||||||
@ -36,8 +33,7 @@ public class ImageBasedHeightMapGrid implements HeightMapGrid {
|
|||||||
private final AssetManager assetManager;
|
private final AssetManager assetManager;
|
||||||
private final Namer namer;
|
private final Namer namer;
|
||||||
private int size;
|
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) {
|
public ImageBasedHeightMapGrid(final String textureBase, final String textureExt, AssetManager assetManager) {
|
||||||
this(assetManager, new Namer() {
|
this(assetManager, new Namer() {
|
||||||
@ -52,27 +48,6 @@ public class ImageBasedHeightMapGrid implements HeightMapGrid {
|
|||||||
this.assetManager = assetManager;
|
this.assetManager = assetManager;
|
||||||
this.namer = namer;
|
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) {
|
public HeightMap getHeightMapAt(Vector3f location) {
|
||||||
// HEIGHTMAP image (for the terrain heightmap)
|
// HEIGHTMAP image (for the terrain heightmap)
|
||||||
@ -80,42 +55,21 @@ public class ImageBasedHeightMapGrid implements HeightMapGrid {
|
|||||||
int z = (int) location.z;
|
int z = (int) location.z;
|
||||||
|
|
||||||
AbstractHeightMap heightmap = null;
|
AbstractHeightMap heightmap = null;
|
||||||
BufferedImage im = null;
|
//BufferedImage im = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
String name = namer.getName(x, z);
|
String name = namer.getName(x, z);
|
||||||
logger.log(Level.INFO, "Loading heightmap from file: {0}", name);
|
logger.log(Level.INFO, "Loading heightmap from file: {0}", name);
|
||||||
final AssetInfo assetInfo = assetManager.locateAsset(new AssetKey(name));
|
final Texture texture = assetManager.loadTexture(new TextureKey(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);
|
|
||||||
}
|
|
||||||
// CREATE HEIGHTMAP
|
// CREATE HEIGHTMAP
|
||||||
if (imageType == BufferedImage.TYPE_USHORT_GRAY) {
|
heightmap = new ImageBasedHeightMap(texture.getImage());
|
||||||
heightmap = new Grayscale16BitHeightMap(im);
|
|
||||||
} else if (imageType == BufferedImage.TYPE_3BYTE_BGR) {
|
heightmap.setHeightScale(1);
|
||||||
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.load();
|
heightmap.load();
|
||||||
} catch (IOException e) {
|
|
||||||
} catch (AssetNotFoundException e) {
|
} catch (AssetNotFoundException e) {
|
||||||
|
logger.log(Level.SEVERE, "Asset Not found! ", e);
|
||||||
}
|
}
|
||||||
return heightmap;
|
return heightmap;
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.jme3.terrain.heightmap;
|
package com.jme3.terrain.heightmap;
|
||||||
|
|
||||||
import java.awt.Image;
|
import com.jme3.texture.Image;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A heightmap that is built off an image.
|
* A heightmap that is built off an image.
|
||||||
@ -13,17 +13,18 @@ import java.awt.Image;
|
|||||||
* and have that class extend Abstract heightmap.
|
* and have that class extend Abstract heightmap.
|
||||||
*
|
*
|
||||||
* @author bowens
|
* @author bowens
|
||||||
|
* @deprecated
|
||||||
*/
|
*/
|
||||||
public interface ImageHeightmap {
|
public interface ImageHeightmap {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the image to use for this heightmap
|
* Set the image to use for this heightmap
|
||||||
*/
|
*/
|
||||||
public void setImage(Image image);
|
//public void setImage(Image image);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The BufferedImage.TYPE_ that is supported
|
* The BufferedImage.TYPE_ that is supported
|
||||||
* by this ImageHeightmap
|
* by this ImageHeightmap
|
||||||
*/
|
*/
|
||||||
public int getSupportedImageType();
|
//public int getSupportedImageType();
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,6 @@ import com.jme3.texture.Texture.WrapMode;
|
|||||||
import com.jme3.util.SkyFactory;
|
import com.jme3.util.SkyFactory;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import jme3tools.converters.ImageToAwt;
|
|
||||||
|
|
||||||
public class TestHoveringTank extends SimpleApplication implements AnalogListener,
|
public class TestHoveringTank extends SimpleApplication implements AnalogListener,
|
||||||
ActionListener {
|
ActionListener {
|
||||||
@ -277,7 +276,7 @@ public class TestHoveringTank extends SimpleApplication implements AnalogListene
|
|||||||
|
|
||||||
AbstractHeightMap heightmap = null;
|
AbstractHeightMap heightmap = null;
|
||||||
try {
|
try {
|
||||||
heightmap = new ImageBasedHeightMap(ImageToAwt.convert(heightMapImage.getImage(), false, true, 0), 0.25f);
|
heightmap = new ImageBasedHeightMap(heightMapImage.getImage(), 0.25f);
|
||||||
heightmap.load();
|
heightmap.load();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -76,7 +76,6 @@ import com.jme3.texture.Texture.WrapMode;
|
|||||||
import com.jme3.util.SkyFactory;
|
import com.jme3.util.SkyFactory;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import jme3tools.converters.ImageToAwt;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A walking animated character followed by a 3rd person camera on a terrain with LOD.
|
* 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;
|
AbstractHeightMap heightmap = null;
|
||||||
try {
|
try {
|
||||||
heightmap = new ImageBasedHeightMap(ImageToAwt.convert(heightMapImage.getImage(), false, true, 0), 0.25f);
|
heightmap = new ImageBasedHeightMap(heightMapImage.getImage(), 0.25f);
|
||||||
heightmap.load();
|
heightmap.load();
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -41,7 +41,6 @@ import com.jme3.terrain.heightmap.AbstractHeightMap;
|
|||||||
import com.jme3.terrain.heightmap.ImageBasedHeightMap;
|
import com.jme3.terrain.heightmap.ImageBasedHeightMap;
|
||||||
import com.jme3.texture.Texture;
|
import com.jme3.texture.Texture;
|
||||||
import com.jme3.texture.Texture.WrapMode;
|
import com.jme3.texture.Texture.WrapMode;
|
||||||
import jme3tools.converters.ImageToAwt;
|
|
||||||
|
|
||||||
public class HelloTerrain extends SimpleApplication {
|
public class HelloTerrain extends SimpleApplication {
|
||||||
|
|
||||||
@ -90,8 +89,7 @@ public class HelloTerrain extends SimpleApplication {
|
|||||||
AbstractHeightMap heightmap = null;
|
AbstractHeightMap heightmap = null;
|
||||||
Texture heightMapImage = assetManager.loadTexture(
|
Texture heightMapImage = assetManager.loadTexture(
|
||||||
"Textures/Terrain/splat/mountains512.png");
|
"Textures/Terrain/splat/mountains512.png");
|
||||||
heightmap = new ImageBasedHeightMap(
|
heightmap = new ImageBasedHeightMap(heightMapImage.getImage());
|
||||||
ImageToAwt.convert(heightMapImage.getImage(), false, true, 0));
|
|
||||||
heightmap.load();
|
heightmap.load();
|
||||||
|
|
||||||
/** 3. We have prepared material and heightmap.
|
/** 3. We have prepared material and heightmap.
|
||||||
|
@ -54,7 +54,6 @@ import com.jme3.texture.Texture;
|
|||||||
import com.jme3.texture.Texture.WrapMode;
|
import com.jme3.texture.Texture.WrapMode;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import jme3tools.converters.ImageToAwt;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This demo shows a terrain with collision detection,
|
* This demo shows a terrain with collision detection,
|
||||||
@ -120,8 +119,7 @@ public class HelloTerrainCollision extends SimpleApplication
|
|||||||
AbstractHeightMap heightmap = null;
|
AbstractHeightMap heightmap = null;
|
||||||
Texture heightMapImage = assetManager.loadTexture(
|
Texture heightMapImage = assetManager.loadTexture(
|
||||||
"Textures/Terrain/splat/mountains512.png");
|
"Textures/Terrain/splat/mountains512.png");
|
||||||
heightmap = new ImageBasedHeightMap(
|
heightmap = new ImageBasedHeightMap(heightMapImage.getImage());
|
||||||
ImageToAwt.convert(heightMapImage.getImage(), false, true, 0));
|
|
||||||
heightmap.load();
|
heightmap.load();
|
||||||
|
|
||||||
/** 3. We have prepared material and heightmap.
|
/** 3. We have prepared material and heightmap.
|
||||||
|
@ -182,7 +182,7 @@ public class TestSpotLightTerrain extends SimpleApplication {
|
|||||||
try {
|
try {
|
||||||
//heightmap = new HillHeightMap(1025, 1000, 50, 100, (byte) 3);
|
//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();
|
heightmap.load();
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -23,7 +23,6 @@ import com.jme3.texture.Texture.WrapMode;
|
|||||||
import com.jme3.util.SkyFactory;
|
import com.jme3.util.SkyFactory;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import jme3tools.converters.ImageToAwt;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* test
|
* test
|
||||||
@ -166,7 +165,7 @@ public class TestDepthOfField extends SimpleApplication {
|
|||||||
|
|
||||||
AbstractHeightMap heightmap = null;
|
AbstractHeightMap heightmap = null;
|
||||||
try {
|
try {
|
||||||
heightmap = new ImageBasedHeightMap(ImageToAwt.convert(heightMapImage.getImage(), false, true, 0), 0.25f);
|
heightmap = new ImageBasedHeightMap(heightMapImage.getImage(), 0.25f);
|
||||||
heightmap.load();
|
heightmap.load();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -191,11 +191,11 @@ public class TerrainGridAlphaMapTest extends SimpleApplication {
|
|||||||
|
|
||||||
public void tileAttached(Vector3f cell, TerrainQuad quad) {
|
public void tileAttached(Vector3f cell, TerrainQuad quad) {
|
||||||
Texture alpha = null;
|
Texture alpha = null;
|
||||||
//try {
|
try {
|
||||||
// alpha = assetManager.loadTexture("TerrainAlphaTest/alpha_" + (int)cell.x+ "_" + (int)cell.z + ".png");
|
alpha = assetManager.loadTexture("TerrainAlphaTest/alpha_" + (int)cell.x+ "_" + (int)cell.z + ".png");
|
||||||
//} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
alpha = assetManager.loadTexture("TerrainAlphaTest/alpha_default.png");
|
alpha = assetManager.loadTexture("TerrainAlphaTest/alpha_default.png");
|
||||||
//}
|
}
|
||||||
quad.getMaterial().setTexture("AlphaMap", alpha);
|
quad.getMaterial().setTexture("AlphaMap", alpha);
|
||||||
if (usePhysics) {
|
if (usePhysics) {
|
||||||
quad.addControl(new RigidBodyControl(new HeightfieldCollisionShape(quad.getHeightMap(), terrain.getLocalScale()), 0));
|
quad.addControl(new RigidBodyControl(new HeightfieldCollisionShape(quad.getHeightMap(), terrain.getLocalScale()), 0));
|
||||||
|
@ -12,6 +12,7 @@ import com.jme3.bullet.control.RigidBodyControl;
|
|||||||
import com.jme3.input.KeyInput;
|
import com.jme3.input.KeyInput;
|
||||||
import com.jme3.input.controls.ActionListener;
|
import com.jme3.input.controls.ActionListener;
|
||||||
import com.jme3.input.controls.KeyTrigger;
|
import com.jme3.input.controls.KeyTrigger;
|
||||||
|
import com.jme3.light.DirectionalLight;
|
||||||
import com.jme3.material.Material;
|
import com.jme3.material.Material;
|
||||||
import com.jme3.math.ColorRGBA;
|
import com.jme3.math.ColorRGBA;
|
||||||
import com.jme3.math.Vector3f;
|
import com.jme3.math.Vector3f;
|
||||||
@ -33,7 +34,7 @@ public class TerrainGridTest extends SimpleApplication {
|
|||||||
private float grassScale = 64;
|
private float grassScale = 64;
|
||||||
private float dirtScale = 16;
|
private float dirtScale = 16;
|
||||||
private float rockScale = 128;
|
private float rockScale = 128;
|
||||||
private boolean usePhysics = true;
|
private boolean usePhysics = false;
|
||||||
private boolean physicsAdded = false;
|
private boolean physicsAdded = false;
|
||||||
|
|
||||||
public static void main(final String[] args) {
|
public static void main(final String[] args) {
|
||||||
@ -100,8 +101,8 @@ public class TerrainGridTest extends SimpleApplication {
|
|||||||
return "Scenes/TerrainMountains/terrain_" + x + "_" + y + ".png";
|
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.setLocalTranslation(0, 0, 0);
|
||||||
this.terrain.setLocalScale(1f, 1f, 1f);
|
this.terrain.setLocalScale(1f, 1f, 1f);
|
||||||
this.rootNode.attachChild(this.terrain);
|
this.rootNode.attachChild(this.terrain);
|
||||||
@ -113,10 +114,14 @@ public class TerrainGridTest extends SimpleApplication {
|
|||||||
final BulletAppState bulletAppState = new BulletAppState();
|
final BulletAppState bulletAppState = new BulletAppState();
|
||||||
stateManager.attach(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));
|
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) {
|
if (usePhysics) {
|
||||||
CapsuleCollisionShape capsuleShape = new CapsuleCollisionShape(0.5f, 1.8f, 1);
|
CapsuleCollisionShape capsuleShape = new CapsuleCollisionShape(0.5f, 1.8f, 1);
|
||||||
player3 = new CharacterControl(capsuleShape, 0.5f);
|
player3 = new CharacterControl(capsuleShape, 0.5f);
|
||||||
@ -141,12 +146,6 @@ public class TerrainGridTest extends SimpleApplication {
|
|||||||
while(quad.getControl(RigidBodyControl.class)!=null){
|
while(quad.getControl(RigidBodyControl.class)!=null){
|
||||||
quad.removeControl(RigidBodyControl.class);
|
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));
|
quad.addControl(new RigidBodyControl(new HeightfieldCollisionShape(quad.getHeightMap(), terrain.getLocalScale()), 0));
|
||||||
bulletAppState.getPhysicsSpace().add(quad);
|
bulletAppState.getPhysicsSpace().add(quad);
|
||||||
}
|
}
|
||||||
|
@ -49,7 +49,7 @@ import com.jme3.terrain.heightmap.AbstractHeightMap;
|
|||||||
import com.jme3.terrain.heightmap.ImageBasedHeightMap;
|
import com.jme3.terrain.heightmap.ImageBasedHeightMap;
|
||||||
import com.jme3.texture.Texture;
|
import com.jme3.texture.Texture;
|
||||||
import com.jme3.texture.Texture.WrapMode;
|
import com.jme3.texture.Texture.WrapMode;
|
||||||
import jme3tools.converters.ImageToAwt;
|
import com.jme3.asset.TextureKey;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Demonstrates how to use terrain.
|
* Demonstrates how to use terrain.
|
||||||
@ -140,7 +140,7 @@ public class TerrainTest extends SimpleApplication {
|
|||||||
try {
|
try {
|
||||||
//heightmap = new HillHeightMap(1025, 1000, 50, 100, (byte) 3);
|
//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();
|
heightmap.load();
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -52,7 +52,8 @@ import com.jme3.terrain.heightmap.ImageBasedHeightMap;
|
|||||||
import com.jme3.texture.Texture;
|
import com.jme3.texture.Texture;
|
||||||
import com.jme3.texture.Texture.WrapMode;
|
import com.jme3.texture.Texture.WrapMode;
|
||||||
import com.jme3.util.SkyFactory;
|
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.
|
* Uses the terrain's lighting texture with normal maps and lights.
|
||||||
@ -108,8 +109,8 @@ public class TerrainTestAdvanced extends SimpleApplication {
|
|||||||
// GRASS texture
|
// GRASS texture
|
||||||
Texture grass = assetManager.loadTexture("Textures/Terrain/splat/grass.jpg");
|
Texture grass = assetManager.loadTexture("Textures/Terrain/splat/grass.jpg");
|
||||||
grass.setWrap(WrapMode.Repeat);
|
grass.setWrap(WrapMode.Repeat);
|
||||||
matTerrain.setTexture("DiffuseMap_1", grass);
|
//matTerrain.setTexture("DiffuseMap_1", grass);
|
||||||
matTerrain.setFloat("DiffuseMap_1_scale", grassScale);
|
//matTerrain.setFloat("DiffuseMap_1_scale", grassScale);
|
||||||
|
|
||||||
// DIRT texture
|
// DIRT texture
|
||||||
Texture dirt = assetManager.loadTexture("Textures/Terrain/splat/dirt.jpg");
|
Texture dirt = assetManager.loadTexture("Textures/Terrain/splat/dirt.jpg");
|
||||||
@ -120,20 +121,20 @@ public class TerrainTestAdvanced extends SimpleApplication {
|
|||||||
// ROCK texture
|
// ROCK texture
|
||||||
Texture rock = assetManager.loadTexture("Textures/Terrain/splat/road.jpg");
|
Texture rock = assetManager.loadTexture("Textures/Terrain/splat/road.jpg");
|
||||||
rock.setWrap(WrapMode.Repeat);
|
rock.setWrap(WrapMode.Repeat);
|
||||||
matTerrain.setTexture("DiffuseMap_2", rock);
|
//matTerrain.setTexture("DiffuseMap_2", rock);
|
||||||
matTerrain.setFloat("DiffuseMap_2_scale", rockScale);
|
//matTerrain.setFloat("DiffuseMap_2_scale", rockScale);
|
||||||
|
|
||||||
// BRICK texture
|
// BRICK texture
|
||||||
Texture brick = assetManager.loadTexture("Textures/Terrain/BrickWall/BrickWall.jpg");
|
Texture brick = assetManager.loadTexture("Textures/Terrain/BrickWall/BrickWall.jpg");
|
||||||
brick.setWrap(WrapMode.Repeat);
|
brick.setWrap(WrapMode.Repeat);
|
||||||
matTerrain.setTexture("DiffuseMap_3", brick);
|
//matTerrain.setTexture("DiffuseMap_3", brick);
|
||||||
matTerrain.setFloat("DiffuseMap_3_scale", rockScale);
|
//matTerrain.setFloat("DiffuseMap_3_scale", rockScale);
|
||||||
|
|
||||||
// RIVER ROCK texture
|
// RIVER ROCK texture
|
||||||
Texture riverRock = assetManager.loadTexture("Textures/Terrain/Pond/Pond.jpg");
|
Texture riverRock = assetManager.loadTexture("Textures/Terrain/Pond/Pond.jpg");
|
||||||
riverRock.setWrap(WrapMode.Repeat);
|
riverRock.setWrap(WrapMode.Repeat);
|
||||||
matTerrain.setTexture("DiffuseMap_4", riverRock);
|
//matTerrain.setTexture("DiffuseMap_4", riverRock);
|
||||||
matTerrain.setFloat("DiffuseMap_4_scale", rockScale);
|
//matTerrain.setFloat("DiffuseMap_4_scale", rockScale);
|
||||||
|
|
||||||
|
|
||||||
Texture normalMap0 = assetManager.loadTexture("Textures/Terrain/splat/grass_normal.jpg");
|
Texture normalMap0 = assetManager.loadTexture("Textures/Terrain/splat/grass_normal.jpg");
|
||||||
@ -142,22 +143,22 @@ public class TerrainTestAdvanced extends SimpleApplication {
|
|||||||
normalMap1.setWrap(WrapMode.Repeat);
|
normalMap1.setWrap(WrapMode.Repeat);
|
||||||
Texture normalMap2 = assetManager.loadTexture("Textures/Terrain/splat/road_normal.png");
|
Texture normalMap2 = assetManager.loadTexture("Textures/Terrain/splat/road_normal.png");
|
||||||
normalMap2.setWrap(WrapMode.Repeat);
|
normalMap2.setWrap(WrapMode.Repeat);
|
||||||
matTerrain.setTexture("NormalMap", normalMap2);
|
matTerrain.setTexture("NormalMap", normalMap0);
|
||||||
matTerrain.setTexture("NormalMap_1", normalMap2);
|
//matTerrain.setTexture("NormalMap_1", normalMap2);
|
||||||
matTerrain.setTexture("NormalMap_2", normalMap2);
|
//matTerrain.setTexture("NormalMap_2", normalMap2);
|
||||||
matTerrain.setTexture("NormalMap_4", normalMap2);
|
//matTerrain.setTexture("NormalMap_4", normalMap2);
|
||||||
|
|
||||||
// WIREFRAME material
|
// WIREFRAME material
|
||||||
matWire = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
|
matWire = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
|
||||||
matWire.getAdditionalRenderState().setWireframe(true);
|
matWire.getAdditionalRenderState().setWireframe(true);
|
||||||
matWire.setColor("Color", ColorRGBA.Green);
|
matWire.setColor("Color", ColorRGBA.Green);
|
||||||
|
|
||||||
createSky();
|
//createSky();
|
||||||
|
|
||||||
// CREATE HEIGHTMAP
|
// CREATE HEIGHTMAP
|
||||||
AbstractHeightMap heightmap = null;
|
AbstractHeightMap heightmap = null;
|
||||||
try {
|
try {
|
||||||
heightmap = new ImageBasedHeightMap(ImageToAwt.convert(heightMapImage.getImage(), false, true, 0), 0.5f);
|
heightmap = new ImageBasedHeightMap(heightMapImage.getImage(), 0.5f);
|
||||||
heightmap.load();
|
heightmap.load();
|
||||||
heightmap.smooth(0.9f, 1);
|
heightmap.smooth(0.9f, 1);
|
||||||
|
|
||||||
@ -189,12 +190,14 @@ public class TerrainTestAdvanced extends SimpleApplication {
|
|||||||
//terrain.generateDebugTangents(debugMat);
|
//terrain.generateDebugTangents(debugMat);
|
||||||
|
|
||||||
DirectionalLight light = new DirectionalLight();
|
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);
|
rootNode.addLight(light);
|
||||||
|
|
||||||
cam.setLocation(new Vector3f(0, 10, -10));
|
cam.setLocation(new Vector3f(0, 10, -10));
|
||||||
cam.lookAtDirection(new Vector3f(0, -1.5f, -1).normalizeLocal(), Vector3f.UNIT_Y);
|
cam.lookAtDirection(new Vector3f(0, -1.5f, -1).normalizeLocal(), Vector3f.UNIT_Y);
|
||||||
flyCam.setMoveSpeed(400);
|
flyCam.setMoveSpeed(400);
|
||||||
|
|
||||||
|
rootNode.attachChild(createAxisMarker(20));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadHintText() {
|
public void loadHintText() {
|
||||||
@ -261,4 +264,35 @@ public class TerrainTestAdvanced extends SimpleApplication {
|
|||||||
Spatial sky = SkyFactory.createSky(assetManager, west, east, north, south, up, down);
|
Spatial sky = SkyFactory.createSky(assetManager, west, east, north, south, up, down);
|
||||||
rootNode.attachChild(sky);
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,7 @@
|
|||||||
*/
|
*/
|
||||||
package jme3test.terrain;
|
package jme3test.terrain;
|
||||||
|
|
||||||
|
import com.jme3.bullet.collision.shapes.SphereCollisionShape;
|
||||||
import com.jme3.app.SimpleApplication;
|
import com.jme3.app.SimpleApplication;
|
||||||
import com.jme3.bounding.BoundingBox;
|
import com.jme3.bounding.BoundingBox;
|
||||||
import com.jme3.bullet.BulletAppState;
|
import com.jme3.bullet.BulletAppState;
|
||||||
@ -127,7 +128,7 @@ public class TerrainTestCollision extends SimpleApplication {
|
|||||||
matWire.setColor("Color", ColorRGBA.Green);
|
matWire.setColor("Color", ColorRGBA.Green);
|
||||||
AbstractHeightMap heightmap = null;
|
AbstractHeightMap heightmap = null;
|
||||||
try {
|
try {
|
||||||
heightmap = new ImageBasedHeightMap(ImageToAwt.convert(heightMapImage.getImage(), false, true, 0), 0.25f);
|
heightmap = new ImageBasedHeightMap(heightMapImage.getImage(), 0.25f);
|
||||||
heightmap.load();
|
heightmap.load();
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -62,7 +62,6 @@ import com.jme3.texture.Texture;
|
|||||||
import com.jme3.texture.Texture.WrapMode;
|
import com.jme3.texture.Texture.WrapMode;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import jme3tools.converters.ImageToAwt;
|
|
||||||
import org.novyon.noise.ShaderUtils;
|
import org.novyon.noise.ShaderUtils;
|
||||||
import org.novyon.noise.basis.FilteredBasis;
|
import org.novyon.noise.basis.FilteredBasis;
|
||||||
import org.novyon.noise.filter.IterativeFilter;
|
import org.novyon.noise.filter.IterativeFilter;
|
||||||
@ -307,7 +306,7 @@ public class TerrainTestModifyHeight extends SimpleApplication {
|
|||||||
Texture heightMapImage = assetManager.loadTexture("Textures/Terrain/splat/mountains512.png");
|
Texture heightMapImage = assetManager.loadTexture("Textures/Terrain/splat/mountains512.png");
|
||||||
AbstractHeightMap heightmap = null;
|
AbstractHeightMap heightmap = null;
|
||||||
try {
|
try {
|
||||||
heightmap = new ImageBasedHeightMap(ImageToAwt.convert(heightMapImage.getImage(), false, true, 0), 0.5f);
|
heightmap = new ImageBasedHeightMap(heightMapImage.getImage(), 0.5f);
|
||||||
heightmap.load();
|
heightmap.load();
|
||||||
heightmap.smooth(0.9f, 1);
|
heightmap.smooth(0.9f, 1);
|
||||||
|
|
||||||
|
@ -55,7 +55,6 @@ import com.jme3.texture.Texture.WrapMode;
|
|||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
import jme3tools.converters.ImageToAwt;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Saves and loads terrain.
|
* Saves and loads terrain.
|
||||||
@ -142,7 +141,7 @@ public class TerrainTestReadWrite extends SimpleApplication {
|
|||||||
// CREATE HEIGHTMAP
|
// CREATE HEIGHTMAP
|
||||||
AbstractHeightMap heightmap = null;
|
AbstractHeightMap heightmap = null;
|
||||||
try {
|
try {
|
||||||
heightmap = new ImageBasedHeightMap(ImageToAwt.convert(heightMapImage.getImage(), false, true, 0), 1f);
|
heightmap = new ImageBasedHeightMap(heightMapImage.getImage(), 1f);
|
||||||
heightmap.load();
|
heightmap.load();
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -35,7 +35,6 @@ import com.jme3.util.SkyFactory;
|
|||||||
import com.jme3.water.WaterFilter;
|
import com.jme3.water.WaterFilter;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import jme3tools.converters.ImageToAwt;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* test
|
* test
|
||||||
@ -254,7 +253,7 @@ public class TestPostWater extends SimpleApplication {
|
|||||||
|
|
||||||
AbstractHeightMap heightmap = null;
|
AbstractHeightMap heightmap = null;
|
||||||
try {
|
try {
|
||||||
heightmap = new ImageBasedHeightMap(ImageToAwt.convert(heightMapImage.getImage(), false, true, 0), 0.25f);
|
heightmap = new ImageBasedHeightMap(heightMapImage.getImage(), 0.25f);
|
||||||
heightmap.load();
|
heightmap.load();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -86,7 +86,9 @@ public class AddTerrainAction extends AbstractNewSpatialWizardAction {
|
|||||||
int alphaTextureSize = (Integer) wizardDescriptor.getProperty("alphaTextureSize");
|
int alphaTextureSize = (Integer) wizardDescriptor.getProperty("alphaTextureSize");
|
||||||
|
|
||||||
float[] heightmapData = null;
|
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) {
|
if (heightmap != null) {
|
||||||
heightmap.load(); // can take a while
|
heightmap.load(); // can take a while
|
||||||
heightmapData = heightmap.getHeightMap();
|
heightmapData = heightmap.getHeightMap();
|
||||||
|
@ -31,6 +31,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.jme3.gde.terraineditor;
|
package com.jme3.gde.terraineditor;
|
||||||
|
|
||||||
|
import com.jme3.asset.AssetManager;
|
||||||
import com.jme3.asset.TextureKey;
|
import com.jme3.asset.TextureKey;
|
||||||
import com.jme3.gde.core.scene.SceneApplication;
|
import com.jme3.gde.core.scene.SceneApplication;
|
||||||
import com.jme3.terrain.heightmap.AbstractHeightMap;
|
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.terrain.heightmap.ImageBasedHeightMap;
|
||||||
import com.jme3.texture.Texture;
|
import com.jme3.texture.Texture;
|
||||||
import java.awt.Component;
|
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.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import javax.imageio.ImageIO;
|
|
||||||
import javax.swing.event.ChangeEvent;
|
import javax.swing.event.ChangeEvent;
|
||||||
import javax.swing.event.ChangeListener;
|
import javax.swing.event.ChangeListener;
|
||||||
import jme3tools.converters.ImageToAwt;
|
|
||||||
import org.openide.WizardDescriptor;
|
import org.openide.WizardDescriptor;
|
||||||
import org.openide.util.Exceptions;
|
import org.openide.util.Exceptions;
|
||||||
import org.openide.util.HelpCtx;
|
import org.openide.util.HelpCtx;
|
||||||
@ -143,21 +134,14 @@ public class CreateTerrainWizardPanel2 implements WizardDescriptor.Panel {
|
|||||||
public void storeSettings(Object settings) {
|
public void storeSettings(Object settings) {
|
||||||
|
|
||||||
CreateTerrainVisualPanel2 comp = (CreateTerrainVisualPanel2) getComponent();
|
CreateTerrainVisualPanel2 comp = (CreateTerrainVisualPanel2) getComponent();
|
||||||
|
|
||||||
if ("Flat".equals(comp.getHeightmapTypeComboBox().getSelectedItem()) ) {
|
if ("Flat".equals(comp.getHeightmapTypeComboBox().getSelectedItem()) ) {
|
||||||
heightmap = new FlatHeightmap(terrainTotalSize);
|
heightmap = new FlatHeightmap(terrainTotalSize);
|
||||||
}
|
}
|
||||||
else if ("Image Based".equals(comp.getHeightmapTypeComboBox().getSelectedItem()) ) {
|
else if ("Image Based".equals(comp.getHeightmapTypeComboBox().getSelectedItem()) ) {
|
||||||
|
AssetManager assetManager = SceneApplication.getApplication().getAssetManager();
|
||||||
BufferedImage bi = null;
|
Texture tex = assetManager.loadTexture(new TextureKey(comp.getImageBrowseTextField().getText()));
|
||||||
try {
|
heightmap = new ImageBasedHeightMap(tex.getImage());
|
||||||
bi = ImageIO.read(new File(comp.getImageBrowseTextField().getText()));
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
ImageBasedHeightMap ibhm = new ImageBasedHeightMap(bi, 1f);
|
|
||||||
|
|
||||||
heightmap = ibhm;
|
|
||||||
}
|
}
|
||||||
else if ("Hill".equals(comp.getHeightmapTypeComboBox().getSelectedItem()) ) {
|
else if ("Hill".equals(comp.getHeightmapTypeComboBox().getSelectedItem()) ) {
|
||||||
int iterations = new Integer(comp.getHillIterationsTextField().getText());
|
int iterations = new Integer(comp.getHillIterationsTextField().getText());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user