adding imageRaster to ImageBasedHeightMap

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@10023 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
bre..om 12 years ago
parent feff63fda2
commit d81b46c2fb
  1. 38
      engine/src/terrain/com/jme3/terrain/heightmap/ImageBasedHeightMap.java

@ -33,6 +33,9 @@ package com.jme3.terrain.heightmap;
import com.jme3.math.ColorRGBA;
import com.jme3.texture.Image;
import com.jme3.texture.image.DefaultImageRaster;
import com.jme3.texture.image.ImageRaster;
import com.jme3.util.NativeObject;
import java.nio.ByteBuffer;
import java.nio.ShortBuffer;
@ -89,6 +92,14 @@ public class ImageBasedHeightMap extends AbstractHeightMap implements ImageHeigh
return (float) (0.299 * red + 0.587 * green + 0.114 * blue);
}
protected float calculateHeight(ColorRGBA color) {
return (float) (0.299 * color.r + 0.587 * color.g + 0.114 * color.b);
}
protected ImageRaster getImageRaster() {
return new DefaultImageRaster(colorImage, 0);
}
public boolean load(boolean flipX, boolean flipY) {
int imageWidth = colorImage.getWidth();
@ -99,8 +110,7 @@ public class ImageBasedHeightMap extends AbstractHeightMap implements ImageHeigh
+ " != imageHeight: " + imageHeight);
size = imageWidth;
ByteBuffer buf = colorImage.getData(0);
ImageRaster raster = getImageRaster();
heightData = new float[(imageWidth * imageHeight)];
@ -111,13 +121,15 @@ public class ImageBasedHeightMap extends AbstractHeightMap implements ImageHeigh
for (int h = 0; h < imageHeight; ++h) {
if (flipX) {
for (int w = imageWidth - 1; w >= 0; --w) {
int baseIndex = (h * imageWidth)+ w;
heightData[index++] = getHeightAtPostion(buf, colorImage, baseIndex, colorStore)*heightScale;
//int baseIndex = (h * imageWidth)+ w;
//heightData[index++] = getHeightAtPostion(raster, baseIndex, colorStore)*heightScale;
heightData[index++] = calculateHeight(raster.getPixel(w, h, colorStore))*heightScale;
}
} else {
for (int w = 0; w < imageWidth; ++w) {
int baseIndex = (h * imageWidth)+ w;
heightData[index++] = getHeightAtPostion(buf, colorImage, baseIndex, colorStore)*heightScale;
//int baseIndex = (h * imageWidth)+ w;
//heightData[index++] = getHeightAtPostion(raster, baseIndex, colorStore)*heightScale;
heightData[index++] = calculateHeight(raster.getPixel(w, h, colorStore))*heightScale;
}
}
}
@ -125,13 +137,15 @@ 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)+ w;
heightData[index++] = getHeightAtPostion(buf, colorImage, baseIndex, colorStore)*heightScale;
//int baseIndex = (h * imageWidth)+ w;
//heightData[index++] = getHeightAtPostion(raster, baseIndex, colorStore)*heightScale;
heightData[index++] = calculateHeight(raster.getPixel(w, h, colorStore))*heightScale;
}
} else {
for (int w = 0; w < imageWidth; ++w) {
int baseIndex = (h * imageWidth)+ w;
heightData[index++] = getHeightAtPostion(buf, colorImage, baseIndex, colorStore)*heightScale;
//int baseIndex = (h * imageWidth)+ w;
//heightData[index++] = getHeightAtPostion(raster, baseIndex, colorStore)*heightScale;
heightData[index++] = calculateHeight(raster.getPixel(w, h, colorStore))*heightScale;
}
}
}
@ -140,7 +154,7 @@ public class ImageBasedHeightMap extends AbstractHeightMap implements ImageHeigh
return true;
}
protected float getHeightAtPostion(ByteBuffer buf, Image image, int position, ColorRGBA store) {
/*protected float getHeightAtPostion(ImageRaster image, int position, ColorRGBA store) {
switch (image.getFormat()){
case RGBA8:
buf.position( position * 4 );
@ -172,5 +186,5 @@ public class ImageBasedHeightMap extends AbstractHeightMap implements ImageHeigh
private float byte2float(byte b){
return ((float)(b & 0xFF)) / 255f;
}
}*/
}
Loading…
Cancel
Save