Refactoring: catching up wth latest jme3 core changes.

experimental
jmekaelthas 10 years ago
parent eb767e7580
commit a5c98a59be
  1. 2
      jme3-blender/src/main/java/com/jme3/scene/plugins/blender/landscape/LandscapeHelper.java
  2. 3
      jme3-blender/src/main/java/com/jme3/scene/plugins/blender/materials/MaterialHelper.java
  3. 8
      jme3-blender/src/main/java/com/jme3/scene/plugins/blender/textures/CombinedTexture.java
  4. 11
      jme3-blender/src/main/java/com/jme3/scene/plugins/blender/textures/ImageUtils.java
  5. 27
      jme3-blender/src/main/java/com/jme3/scene/plugins/blender/textures/TriangulatedTexture.java
  6. 4
      jme3-blender/src/main/java/com/jme3/scene/plugins/blender/textures/blending/TextureBlenderAWT.java
  7. 5
      jme3-blender/src/main/java/com/jme3/scene/plugins/blender/textures/blending/TextureBlenderDDS.java
  8. 4
      jme3-blender/src/main/java/com/jme3/scene/plugins/blender/textures/blending/TextureBlenderLuminance.java
  9. 18
      jme3-blender/src/main/java/com/jme3/scene/plugins/blender/textures/io/AWTPixelInputOutput.java
  10. 2
      jme3-blender/src/main/java/com/jme3/scene/plugins/blender/textures/io/PixelIOFactory.java

@ -208,6 +208,6 @@ public class LandscapeHelper extends AbstractBlenderHelper {
}
LOGGER.fine("Sky texture created. Creating sky.");
return SkyFactory.createSky(blenderContext.getAssetManager(), texture, false);
return SkyFactory.createSky(blenderContext.getAssetManager(), texture, SkyFactory.EnvMapType.CubeMap);
}
}

@ -51,6 +51,7 @@ import com.jme3.scene.plugins.blender.file.Structure;
import com.jme3.shader.VarType;
import com.jme3.texture.Image;
import com.jme3.texture.Image.Format;
import com.jme3.texture.image.ColorSpace;
import com.jme3.texture.Texture;
import com.jme3.util.BufferUtils;
@ -217,7 +218,7 @@ public class MaterialHelper extends AbstractBlenderHelper {
}
}
image = new Image(Format.RGBA8, w, h, bb);
image = new Image(Format.RGBA8, w, h, bb, ColorSpace.Linear);
texture.setImage(image);
result.setTextureParam("Texture", VarType.Texture2D, texture);

@ -444,13 +444,17 @@ public class CombinedTexture {
case RGB8:
return true;// these types have no alpha by definition
case ABGR8:
case DXT1A:
case DXT3:
case DXT5:
case Luminance16FAlpha16F:
case Luminance8Alpha8:
case RGBA16F:
case RGBA32F:
case RGBA8:// with these types it is better to make sure if the texture is or is not transparent
case RGBA8:
case ARGB8:
case BGRA8:
case RGB5A1:// with these types it is better to make sure if the texture is or is not transparent
PixelInputOutput pixelInputOutput = PixelIOFactory.getPixelIO(image.getFormat());
TexturePixel pixel = new TexturePixel();
int depth = image.getDepth() == 0 ? 1 : image.getDepth();
@ -465,6 +469,8 @@ public class CombinedTexture {
}
}
return true;
default:
throw new IllegalStateException("Unknown image format: " + image.getFormat());
}
}
}

@ -41,13 +41,13 @@ public final class ImageUtils {
public static Image createEmptyImage(Format format, int width, int height, int depth) {
int bufferSize = width * height * (format.getBitsPerPixel() >> 3);
if (depth < 2) {
return new Image(format, width, height, BufferUtils.createByteBuffer(bufferSize));
return new Image(format, width, height, BufferUtils.createByteBuffer(bufferSize), com.jme3.texture.image.ColorSpace.Linear);
}
ArrayList<ByteBuffer> data = new ArrayList<ByteBuffer>(depth);
for (int i = 0; i < depth; ++i) {
data.add(BufferUtils.createByteBuffer(bufferSize));
}
return new Image(Format.RGB8, width, height, depth, data);
return new Image(Format.RGB8, width, height, depth, data, com.jme3.texture.image.ColorSpace.Linear);
}
/**
@ -337,7 +337,7 @@ public final class ImageUtils {
alphas[0] = data.get() * 255.0f;
alphas[1] = data.get() * 255.0f;
//the casts to long must be done here because otherwise 32-bit integers would be shifetd by 32 and 40 bits which would result in improper values
long alphaIndices = (long)data.get() | (long)data.get() << 8 | (long)data.get() << 16 | (long)data.get() << 24 | (long)data.get() << 32 | (long)data.get() << 40;
long alphaIndices = data.get() | (long)data.get() << 8 | (long)data.get() << 16 | (long)data.get() << 24 | (long)data.get() << 32 | (long)data.get() << 40;
if (alphas[0] > alphas[1]) {// 6 interpolated alpha values.
alphas[2] = (6 * alphas[0] + alphas[1]) / 7;
alphas[3] = (5 * alphas[0] + 2 * alphas[1]) / 7;
@ -404,7 +404,8 @@ public final class ImageUtils {
dataArray.add(BufferUtils.createByteBuffer(bytes));
}
Image result = depth > 1 ? new Image(Format.RGBA8, image.getWidth(), image.getHeight(), depth, dataArray) : new Image(Format.RGBA8, image.getWidth(), image.getHeight(), dataArray.get(0));
Image result = depth > 1 ? new Image(Format.RGBA8, image.getWidth(), image.getHeight(), depth, dataArray, com.jme3.texture.image.ColorSpace.Linear) :
new Image(Format.RGBA8, image.getWidth(), image.getHeight(), dataArray.get(0), com.jme3.texture.image.ColorSpace.Linear);
if (newMipmapSizes != null) {
result.setMipMapSizes(newMipmapSizes);
}
@ -467,6 +468,6 @@ public final class ImageUtils {
private static Image toJmeImage(BufferedImage bufferedImage, Format format) {
ByteBuffer byteBuffer = BufferUtils.createByteBuffer(bufferedImage.getWidth() * bufferedImage.getHeight() * 3);
ImageToAwt.convert(bufferedImage, format, byteBuffer);
return new Image(format, bufferedImage.getWidth(), bufferedImage.getHeight(), byteBuffer);
return new Image(format, bufferedImage.getWidth(), bufferedImage.getHeight(), byteBuffer, com.jme3.texture.image.ColorSpace.Linear);
}
}

@ -31,6 +31,7 @@ import com.jme3.texture.Image;
import com.jme3.texture.Image.Format;
import com.jme3.texture.Texture;
import com.jme3.texture.Texture2D;
import com.jme3.texture.image.ColorSpace;
import com.jme3.util.BufferUtils;
/**
@ -77,7 +78,7 @@ import com.jme3.util.BufferUtils;
for (int i = 0; i < facesCount; ++i) {
faceTextures.add(new TriangleTextureElement(i, texture2d.getImage(), uvs, true, blenderContext));
}
this.format = texture2d.getImage().getFormat();
format = texture2d.getImage().getFormat();
}
/**
@ -113,7 +114,7 @@ import com.jme3.util.BufferUtils;
*/
public void blend(TextureBlender textureBlender, TriangulatedTexture baseTexture, BlenderContext blenderContext) {
Format newFormat = null;
for (TriangleTextureElement triangleTextureElement : this.faceTextures) {
for (TriangleTextureElement triangleTextureElement : faceTextures) {
Image baseImage = baseTexture == null ? null : baseTexture.getFaceTextureElement(triangleTextureElement.faceIndex).image;
triangleTextureElement.image = textureBlender.blend(triangleTextureElement.image, baseImage, blenderContext);
if (newFormat == null) {
@ -122,7 +123,7 @@ import com.jme3.util.BufferUtils;
throw new IllegalArgumentException("Face texture element images MUST have the same image format!");
}
}
this.format = newFormat;
format = newFormat;
}
/**
@ -242,7 +243,7 @@ import com.jme3.util.BufferUtils;
resultUVS.set(entry.getKey().faceIndex * 3 + 2, uvs[2]);
}
Image resultImage = new Image(format, resultImageWidth, resultImageHeight, BufferUtils.createByteBuffer(resultImageWidth * resultImageHeight * (format.getBitsPerPixel() >> 3)));
Image resultImage = new Image(format, resultImageWidth, resultImageHeight, BufferUtils.createByteBuffer(resultImageWidth * resultImageHeight * (format.getBitsPerPixel() >> 3)), ColorSpace.Linear);
resultTexture = new Texture2D(resultImage);
for (Entry<TriangleTextureElement, Integer[]> entry : imageLayoutData.entrySet()) {
if (!duplicatedFaceIndexes.contains(entry.getKey().faceIndex)) {
@ -420,7 +421,7 @@ import com.jme3.util.BufferUtils;
data.put(pixel.getA8());
}
}
image = new Image(Format.RGBA8, width, height, data);
image = new Image(Format.RGBA8, width, height, data, ColorSpace.Linear);
// modify the UV values so that they fit the new image
float heightUV = maxUVY - minUVY;
@ -481,7 +482,7 @@ import com.jme3.util.BufferUtils;
imageHeight = 1;
}
ByteBuffer data = BufferUtils.createByteBuffer(imageWidth * imageHeight * (imageFormat.getBitsPerPixel() >> 3));
image = new Image(texture.getImage().getFormat(), imageWidth, imageHeight, data);
image = new Image(texture.getImage().getFormat(), imageWidth, imageHeight, data, ColorSpace.Linear);
// computing the pixels
PixelInputOutput pixelWriter = PixelIOFactory.getPixelIO(imageFormat);
@ -529,8 +530,8 @@ import com.jme3.util.BufferUtils;
public void computeFinalUVCoordinates(int totalImageWidth, int totalImageHeight, int xPos, int yPos, Vector2f[] result) {
for (int i = 0; i < 3; ++i) {
result[i] = new Vector2f();
result[i].x = xPos / (float) totalImageWidth + this.uv[i].x * (this.image.getWidth() / (float) totalImageWidth);
result[i].y = yPos / (float) totalImageHeight + this.uv[i].y * (this.image.getHeight() / (float) totalImageHeight);
result[i].x = xPos / (float) totalImageWidth + uv[i].x * (image.getWidth() / (float) totalImageWidth);
result[i].y = yPos / (float) totalImageHeight + uv[i].y * (image.getHeight() / (float) totalImageHeight);
}
}
@ -623,9 +624,9 @@ import com.jme3.util.BufferUtils;
* a position in 3D space
*/
public RectangleEnvelope(Vector3f pointPosition) {
this.min = pointPosition;
this.h = this.w = Vector3f.ZERO;
this.width = this.height = 1;
min = pointPosition;
h = w = Vector3f.ZERO;
width = height = 1;
}
/**
@ -642,8 +643,8 @@ import com.jme3.util.BufferUtils;
this.min = min;
this.h = h;
this.w = w;
this.width = w.length();
this.height = h.length();
width = w.length();
height = h.length();
}
@Override

@ -38,7 +38,9 @@ import com.jme3.scene.plugins.blender.textures.io.PixelIOFactory;
import com.jme3.scene.plugins.blender.textures.io.PixelInputOutput;
import com.jme3.texture.Image;
import com.jme3.texture.Image.Format;
import com.jme3.texture.image.ColorSpace;
import com.jme3.util.BufferUtils;
import java.nio.ByteBuffer;
import java.util.ArrayList;
@ -141,7 +143,7 @@ public class TextureBlenderAWT extends AbstractTextureBlender {
dataArray.add(newData);
}
Image result = depth > 1 ? new Image(Format.RGBA8, width, height, depth, dataArray) : new Image(Format.RGBA8, width, height, dataArray.get(0));
Image result = depth > 1 ? new Image(Format.RGBA8, width, height, depth, dataArray, ColorSpace.Linear) : new Image(Format.RGBA8, width, height, dataArray.get(0), ColorSpace.Linear);
if (image.getMipMapSizes() != null) {
result.setMipMapSizes(image.getMipMapSizes().clone());
}

@ -6,9 +6,12 @@ import com.jme3.scene.plugins.blender.textures.io.PixelIOFactory;
import com.jme3.scene.plugins.blender.textures.io.PixelInputOutput;
import com.jme3.texture.Image;
import com.jme3.texture.Image.Format;
import com.jme3.texture.image.ColorSpace;
import com.jme3.util.BufferUtils;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import jme3tools.converters.RGB565;
/**
@ -119,7 +122,7 @@ public class TextureBlenderDDS extends TextureBlenderAWT {
dataArray.add(newData);
}
Image result = dataArray.size() > 1 ? new Image(format, width, height, depth, dataArray) : new Image(format, width, height, dataArray.get(0));
Image result = dataArray.size() > 1 ? new Image(format, width, height, depth, dataArray, ColorSpace.Linear) : new Image(format, width, height, dataArray.get(0), ColorSpace.Linear);
if (image.getMipMapSizes() != null) {
result.setMipMapSizes(image.getMipMapSizes().clone());
}

@ -7,7 +7,9 @@ import com.jme3.scene.plugins.blender.textures.io.PixelIOFactory;
import com.jme3.scene.plugins.blender.textures.io.PixelInputOutput;
import com.jme3.texture.Image;
import com.jme3.texture.Image.Format;
import com.jme3.texture.image.ColorSpace;
import com.jme3.util.BufferUtils;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.logging.Level;
@ -93,7 +95,7 @@ public class TextureBlenderLuminance extends AbstractTextureBlender {
dataArray.add(newData);
}
Image result = depth > 1 ? new Image(Format.RGBA8, width, height, depth, dataArray) : new Image(Format.RGBA8, width, height, dataArray.get(0));
Image result = depth > 1 ? new Image(Format.RGBA8, width, height, depth, dataArray, ColorSpace.Linear) : new Image(Format.RGBA8, width, height, dataArray.get(0), ColorSpace.Linear);
if (image.getMipMapSizes() != null) {
result.setMipMapSizes(image.getMipMapSizes().clone());
}

@ -17,12 +17,18 @@ import jme3tools.converters.RGB565;
case RGBA8:
pixel.fromARGB8(data.get(index + 3), data.get(index), data.get(index + 1), data.get(index + 2));
break;
case ARGB8:
pixel.fromARGB8(data.get(index), data.get(index + 1), data.get(index + 2), data.get(index + 3));
break;
case ABGR8:
pixel.fromARGB8(data.get(index), data.get(index + 3), data.get(index + 2), data.get(index + 1));
break;
case BGR8:
pixel.fromARGB8((byte) 0xFF, data.get(index + 2), data.get(index + 1), data.get(index));
break;
case BGRA8:
pixel.fromARGB8(data.get(index + 3), data.get(index + 2), data.get(index + 1), data.get(index));
break;
case RGB8:
pixel.fromARGB8((byte) 0xFF, data.get(index), data.get(index + 1), data.get(index + 2));
break;
@ -72,6 +78,12 @@ import jme3tools.converters.RGB565;
data.put(index + 2, pixel.getB8());
data.put(index + 3, pixel.getA8());
break;
case ARGB8:
data.put(index, pixel.getA8());
data.put(index + 1, pixel.getR8());
data.put(index + 2, pixel.getG8());
data.put(index + 3, pixel.getB8());
break;
case ABGR8:
data.put(index, pixel.getA8());
data.put(index + 1, pixel.getB8());
@ -83,6 +95,12 @@ import jme3tools.converters.RGB565;
data.put(index + 1, pixel.getG8());
data.put(index + 2, pixel.getR8());
break;
case BGRA8:
data.put(index, pixel.getB8());
data.put(index + 1, pixel.getG8());
data.put(index + 2, pixel.getR8());
data.put(index + 3, pixel.getA8());
break;
case RGB8:
data.put(index, pixel.getR8());
data.put(index + 1, pixel.getG8());

@ -26,7 +26,9 @@ public class PixelIOFactory {
case ABGR8:
case RGBA8:
case BGR8:
case BGRA8:
case RGB8:
case ARGB8:
case RGB111110F:
case RGB16F:
case RGB16F_to_RGB111110F:

Loading…
Cancel
Save