From 801b87d6ce9525778eb0c9005f569273cb91fead Mon Sep 17 00:00:00 2001 From: "Kae..pl" Date: Tue, 26 Jun 2012 11:25:43 +0000 Subject: [PATCH] Fix to image to normal map convertion. The result image is no longer upside-down. git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9529 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../blender/textures/TextureHelper.java | 31 +++++++++++++------ 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/textures/TextureHelper.java b/engine/src/blender/com/jme3/scene/plugins/blender/textures/TextureHelper.java index 0e7a5a491..639308d4d 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/textures/TextureHelper.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/textures/TextureHelper.java @@ -31,6 +31,20 @@ */ package com.jme3.scene.plugins.blender.textures; +import java.awt.color.ColorSpace; +import java.awt.geom.AffineTransform; +import java.awt.image.AffineTransformOp; +import java.awt.image.BufferedImage; +import java.awt.image.ColorConvertOp; +import java.nio.ByteBuffer; +import java.util.ArrayList; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; + +import jme3tools.converters.ImageToAwt; +import jme3tools.converters.RGB565; + import com.jme3.asset.AssetManager; import com.jme3.asset.AssetNotFoundException; import com.jme3.asset.BlenderKey; @@ -55,16 +69,6 @@ import com.jme3.texture.Texture.MinFilter; import com.jme3.texture.Texture.WrapMode; import com.jme3.texture.Texture2D; import com.jme3.util.BufferUtils; -import java.awt.color.ColorSpace; -import java.awt.image.BufferedImage; -import java.awt.image.ColorConvertOp; -import java.nio.ByteBuffer; -import java.util.ArrayList; -import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; -import jme3tools.converters.ImageToAwt; -import jme3tools.converters.RGB565; /** * A class that is used in texture calculations. @@ -192,6 +196,13 @@ public class TextureHelper extends AbstractBlenderHelper { */ public Image convertToNormalMapTexture(Image source, float strengthFactor) { BufferedImage sourceImage = ImageToAwt.convert(source, false, false, 0); + + // flip the image because the result image is upside-down without this operation + AffineTransform tx = AffineTransform.getScaleInstance(1, -1); + tx.translate(0, -sourceImage.getHeight(null)); + AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_NEAREST_NEIGHBOR); + sourceImage = op.filter(sourceImage, null); + BufferedImage heightMap = new BufferedImage(sourceImage.getWidth(), sourceImage.getHeight(), BufferedImage.TYPE_INT_ARGB); BufferedImage bumpMap = new BufferedImage(sourceImage.getWidth(), sourceImage.getHeight(), BufferedImage.TYPE_INT_ARGB); ColorConvertOp gscale = new ColorConvertOp(ColorSpace.getInstance(ColorSpace.CS_GRAY), null);