Implementation changes in texture blending methods.

Prepared for more texture types support (and should be more readable for developers now :) ).

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7571 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
Kae..pl 14 years ago
parent 83da85efd3
commit e6532fc7ed
  1. 387
      engine/src/blender/com/jme3/scene/plugins/blender/helpers/v249/TextureHelper.java
  2. BIN
      engine/src/test-data/Blender/2.4x/BaseScene.blend
  3. BIN
      engine/src/test-data/Blender/2.4x/test.conf

@ -144,7 +144,7 @@ public class TextureHelper extends AbstractBlenderHelper {
* versions. * versions.
* *
* @param blenderVersion * @param blenderVersion
* the version read from the blend file * the version read from the blend file
*/ */
public TextureHelper(String blenderVersion) { public TextureHelper(String blenderVersion) {
super(blenderVersion); super(blenderVersion);
@ -155,12 +155,12 @@ public class TextureHelper extends AbstractBlenderHelper {
* its blender type. * its blender type.
* *
* @param tex * @param tex
* texture structure filled with data * texture structure filled with data
* @param dataRepository * @param dataRepository
* the data repository * the data repository
* @return the texture that can be used by JME engine * @return the texture that can be used by JME engine
* @throws BlenderFileException * @throws BlenderFileException
* this exception is thrown when the blend file structure is somehow invalid or corrupted * this exception is thrown when the blend file structure is somehow invalid or corrupted
*/ */
public Texture getTexture(Structure tex, DataRepository dataRepository) throws BlenderFileException { public Texture getTexture(Structure tex, DataRepository dataRepository) throws BlenderFileException {
Texture result = (Texture) dataRepository.getLoadedFeature(tex.getOldMemoryAddress(), LoadedFeatureDataType.LOADED_FEATURE); Texture result = (Texture) dataRepository.getLoadedFeature(tex.getOldMemoryAddress(), LoadedFeatureDataType.LOADED_FEATURE);
@ -227,13 +227,13 @@ public class TextureHelper extends AbstractBlenderHelper {
* This method generates the clouds texture. The result is one pixel. * This method generates the clouds texture. The result is one pixel.
* *
* @param tex * @param tex
* the texture structure * the texture structure
* @param width * @param width
* the width of texture (in pixels) * the width of texture (in pixels)
* @param height * @param height
* the height of texture (in pixels) * the height of texture (in pixels)
* @param dataRepository * @param dataRepository
* the data repository * the data repository
* @return generated texture * @return generated texture
*/ */
protected Texture clouds(Structure tex, int width, int height, DataRepository dataRepository) { protected Texture clouds(Structure tex, int width, int height, DataRepository dataRepository) {
@ -256,8 +256,7 @@ public class TextureHelper extends AbstractBlenderHelper {
width <<= 1; width <<= 1;
height <<= 1; height <<= 1;
ColorBand colorBand = this.readColorband(tex, dataRepository); ColorBand colorBand = this.readColorband(tex, dataRepository);
Format format = sType == com.jme3.scene.plugins.blender.helpers.v249.NoiseHelper.TEX_COLOR || colorBand != null ? Format.RGB8 Format format = sType == com.jme3.scene.plugins.blender.helpers.v249.NoiseHelper.TEX_COLOR || colorBand != null ? Format.RGB8 : Format.Luminance8;
: Format.Luminance8;
int bytesPerPixel = sType == com.jme3.scene.plugins.blender.helpers.v249.NoiseHelper.TEX_COLOR || colorBand != null ? 3 : 1; int bytesPerPixel = sType == com.jme3.scene.plugins.blender.helpers.v249.NoiseHelper.TEX_COLOR || colorBand != null ? 3 : 1;
ByteBuffer data = BufferUtils.createByteBuffer(width * height * bytesPerPixel); ByteBuffer data = BufferUtils.createByteBuffer(width * height * bytesPerPixel);
@ -272,12 +271,9 @@ public class TextureHelper extends AbstractBlenderHelper {
if (texres.nor != null) { if (texres.nor != null) {
float nabla = ((Number) tex.getFieldValue("nabla")).floatValue(); float nabla = ((Number) tex.getFieldValue("nabla")).floatValue();
// calculate bumpnormal // calculate bumpnormal
texres.nor[0] = noiseHelper.bliGTurbulence(noisesize, texvec[0] + nabla, texvec[1], texvec[2], noiseDepth, isHard, texres.nor[0] = noiseHelper.bliGTurbulence(noisesize, texvec[0] + nabla, texvec[1], texvec[2], noiseDepth, isHard, noiseBasis);
noiseBasis); texres.nor[1] = noiseHelper.bliGTurbulence(noisesize, texvec[0], texvec[1] + nabla, texvec[2], noiseDepth, isHard, noiseBasis);
texres.nor[1] = noiseHelper.bliGTurbulence(noisesize, texvec[0], texvec[1] + nabla, texvec[2], noiseDepth, isHard, texres.nor[2] = noiseHelper.bliGTurbulence(noisesize, texvec[0], texvec[1], texvec[2] + nabla, noiseDepth, isHard, noiseBasis);
noiseBasis);
texres.nor[2] = noiseHelper.bliGTurbulence(noisesize, texvec[0], texvec[1], texvec[2] + nabla, noiseDepth, isHard,
noiseBasis);
noiseHelper.texNormalDerivate(colorBand, texres, dataRepository); noiseHelper.texNormalDerivate(colorBand, texres, dataRepository);
} }
noiseHelper.brightnesAndContrastRGB(tex, texres); noiseHelper.brightnesAndContrastRGB(tex, texres);
@ -307,13 +303,13 @@ public class TextureHelper extends AbstractBlenderHelper {
* This method generates the wood texture. * This method generates the wood texture.
* *
* @param tex * @param tex
* the texture structure * the texture structure
* @param width * @param width
* the width of the texture * the width of the texture
* @param height * @param height
* the height of the texture * the height of the texture
* @param dataRepository * @param dataRepository
* the data repository * the data repository
* @return the generated texture * @return the generated texture
*/ */
protected Texture wood(Structure tex, int width, int height, DataRepository dataRepository) { protected Texture wood(Structure tex, int width, int height, DataRepository dataRepository) {
@ -364,13 +360,13 @@ public class TextureHelper extends AbstractBlenderHelper {
* This method generates the marble texture. * This method generates the marble texture.
* *
* @param tex * @param tex
* the texture structure * the texture structure
* @param width * @param width
* the width of the texture * the width of the texture
* @param height * @param height
* the height of the texture * the height of the texture
* @param dataRepository * @param dataRepository
* the data repository * the data repository
* @return the generated texture * @return the generated texture
*/ */
protected Texture marble(Structure tex, int width, int height, DataRepository dataRepository) { protected Texture marble(Structure tex, int width, int height, DataRepository dataRepository) {
@ -421,13 +417,13 @@ public class TextureHelper extends AbstractBlenderHelper {
* This method generates the magic texture. * This method generates the magic texture.
* *
* @param tex * @param tex
* the texture structure * the texture structure
* @param width * @param width
* the width of the texture * the width of the texture
* @param height * @param height
* the height of the texture * the height of the texture
* @param dataRepository * @param dataRepository
* the data repository * the data repository
* @return the generated texture * @return the generated texture
*/ */
protected Texture magic(Structure tex, int width, int height, DataRepository dataRepository) { protected Texture magic(Structure tex, int width, int height, DataRepository dataRepository) {
@ -452,7 +448,7 @@ public class TextureHelper extends AbstractBlenderHelper {
x = (float) Math.sin((texvec[0] + texvec[1]) * 5.0f);// in blender: Math.sin((texvec[0] + texvec[1] + texvec[2]) * 5.0f); x = (float) Math.sin((texvec[0] + texvec[1]) * 5.0f);// in blender: Math.sin((texvec[0] + texvec[1] + texvec[2]) * 5.0f);
y = (float) Math.cos((-texvec[0] + texvec[1]) * 5.0f);// in blender: Math.cos((-texvec[0] + texvec[1] - texvec[2]) * 5.0f); y = (float) Math.cos((-texvec[0] + texvec[1]) * 5.0f);// in blender: Math.cos((-texvec[0] + texvec[1] - texvec[2]) * 5.0f);
z = -(float) Math.cos((-texvec[0] - texvec[1]) * 5.0f);// in blender: Math.cos((-texvec[0] - texvec[1] + texvec[2]) * 5.0f); z = -(float) Math.cos((-texvec[0] - texvec[1]) * 5.0f);// in blender: Math.cos((-texvec[0] - texvec[1] + texvec[2]) * 5.0f);
if (colorBand != null) { if (colorBand != null) {
texres.tin = 0.3333f * (x + y + z); texres.tin = 0.3333f * (x + y + z);
noiseHelper.doColorband(colorBand, texres, dataRepository); noiseHelper.doColorband(colorBand, texres, dataRepository);
@ -515,13 +511,13 @@ public class TextureHelper extends AbstractBlenderHelper {
* This method generates the blend texture. * This method generates the blend texture.
* *
* @param tex * @param tex
* the texture structure * the texture structure
* @param width * @param width
* the width of the texture * the width of the texture
* @param height * @param height
* the height of the texture * the height of the texture
* @param dataRepository * @param dataRepository
* the data repository * the data repository
* @return the generated texture * @return the generated texture
*/ */
protected Texture blend(Structure tex, int width, int height, DataRepository dataRepository) { protected Texture blend(Structure tex, int width, int height, DataRepository dataRepository) {
@ -604,13 +600,13 @@ public class TextureHelper extends AbstractBlenderHelper {
* This method generates the stucci texture. * This method generates the stucci texture.
* *
* @param tex * @param tex
* the texture structure * the texture structure
* @param width * @param width
* the width of the texture * the width of the texture
* @param height * @param height
* the height of the texture * the height of the texture
* @param dataRepository * @param dataRepository
* the data repository * the data repository
* @return the generated texture * @return the generated texture
*/ */
protected Texture stucci(Structure tex, int width, int height, DataRepository dataRepository) { protected Texture stucci(Structure tex, int width, int height, DataRepository dataRepository) {
@ -684,13 +680,13 @@ public class TextureHelper extends AbstractBlenderHelper {
* This method generates the noise texture. * This method generates the noise texture.
* *
* @param tex * @param tex
* the texture structure * the texture structure
* @param width * @param width
* the width of the texture * the width of the texture
* @param height * @param height
* the height of the texture * the height of the texture
* @param dataRepository * @param dataRepository
* the data repository * the data repository
* @return the generated texture * @return the generated texture
*/ */
// TODO: correct this one, so it looks more like the texture generated by blender // TODO: correct this one, so it looks more like the texture generated by blender
@ -741,13 +737,13 @@ public class TextureHelper extends AbstractBlenderHelper {
* This method generates the musgrave texture. * This method generates the musgrave texture.
* *
* @param tex * @param tex
* the texture structure * the texture structure
* @param width * @param width
* the width of the texture * the width of the texture
* @param height * @param height
* the height of the texture * the height of the texture
* @param dataRepository * @param dataRepository
* the data repository * the data repository
* @return the generated texture * @return the generated texture
*/ */
protected Texture musgrave(Structure tex, int width, int height, DataRepository dataRepository) { protected Texture musgrave(Structure tex, int width, int height, DataRepository dataRepository) {
@ -801,13 +797,13 @@ public class TextureHelper extends AbstractBlenderHelper {
* This method generates the voronoi texture. * This method generates the voronoi texture.
* *
* @param tex * @param tex
* the texture structure * the texture structure
* @param width * @param width
* the width of the texture * the width of the texture
* @param height * @param height
* the height of the texture * the height of the texture
* @param dataRepository * @param dataRepository
* the data repository * the data repository
* @return the generated texture * @return the generated texture
*/ */
protected Texture voronoi(Structure tex, int width, int height, DataRepository dataRepository) { protected Texture voronoi(Structure tex, int width, int height, DataRepository dataRepository) {
@ -923,13 +919,13 @@ public class TextureHelper extends AbstractBlenderHelper {
* This method generates the distorted noise texture. * This method generates the distorted noise texture.
* *
* @param tex * @param tex
* the texture structure * the texture structure
* @param width * @param width
* the width of the texture * the width of the texture
* @param height * @param height
* the height of the texture * the height of the texture
* @param dataRepository * @param dataRepository
* the data repository * the data repository
* @return the generated texture * @return the generated texture
*/ */
protected Texture distnoise(Structure tex, int width, int height, DataRepository dataRepository) { protected Texture distnoise(Structure tex, int width, int height, DataRepository dataRepository) {
@ -987,9 +983,9 @@ public class TextureHelper extends AbstractBlenderHelper {
* This method reads the colorband data from the given texture structure. * This method reads the colorband data from the given texture structure.
* *
* @param tex * @param tex
* the texture structure * the texture structure
* @param dataRepository * @param dataRepository
* the data repository * the data repository
* @return read colorband or null if not present * @return read colorband or null if not present
*/ */
protected ColorBand readColorband(Structure tex, DataRepository dataRepository) { protected ColorBand readColorband(Structure tex, DataRepository dataRepository) {
@ -1011,25 +1007,24 @@ public class TextureHelper extends AbstractBlenderHelper {
/** /**
* This method blends the given texture with material color and the defined color in 'map to' panel. As a result of this method a new * This method blends the given texture with material color and the defined color in 'map to' panel. As a result of this method a new
* texture is created. The input texture is NOT modified. * texture is created. The input texture is NOT.
* *
* @param materialColor * @param materialColor
* the material diffuse color * the material diffuse color
* @param texture * @param texture
* the texture we use in blending * the texture we use in blending
* @param color * @param color
* the color defined for the texture * the color defined for the texture
* @param affectFactor * @param affectFactor
* the factor that the color affects the texture (value form 0.0 to 1.0) * the factor that the color affects the texture (value form 0.0 to 1.0)
* @param blendType * @param blendType
* the blending type * the blending type
* @param dataRepository * @param dataRepository
* the data repository * the data repository
* @return new texture that was created after the blending * @return new texture that was created after the blending
*/ */
public Texture blendTexture(float[] materialColor, Texture texture, float[] color, float affectFactor, public Texture blendTexture(float[] materialColor, Texture texture, float[] color, float affectFactor, int blendType, boolean neg, DataRepository dataRepository) {
int blendType, boolean neg, float[] materialColorClone = materialColor.clone();//this array may change, so we copy it
DataRepository dataRepository) {
Format format = texture.getImage().getFormat(); Format format = texture.getImage().getFormat();
ByteBuffer data = texture.getImage().getData(0); ByteBuffer data = texture.getImage().getData(0);
data.rewind(); data.rewind();
@ -1038,118 +1033,146 @@ public class TextureHelper extends AbstractBlenderHelper {
ByteBuffer newData = BufferUtils.createByteBuffer(width * height * 3); ByteBuffer newData = BufferUtils.createByteBuffer(width * height * 3);
float[] resultPixel = new float[3]; float[] resultPixel = new float[3];
float[] texPixel = new float[3];
int dataIndex = 0; int dataIndex = 0;
while (data.hasRemaining()) { while (data.hasRemaining()) {
byte pixelValue = data.get(); float tin = this.setupMaterialColor(data, format, neg, materialColorClone);
texPixel[0] = pixelValue >= 0 ? 1.0f - pixelValue / 255.0f : (~pixelValue + 1) / 255.0f; this.blendPixel(resultPixel, materialColorClone, color, tin, affectFactor, blendType, dataRepository);
if(neg) { newData.put(dataIndex++, (byte) (resultPixel[0] * 255.0f));
texPixel[0] = 1.0f - texPixel[0]; newData.put(dataIndex++, (byte) (resultPixel[1] * 255.0f));
} newData.put(dataIndex++, (byte) (resultPixel[2] * 255.0f));
if (format == Format.ABGR8) { }
//intensity not used at the moment return new Texture2D(new Image(Format.RGB8, width, height, newData));
}
/**
* This method alters the material color in a way dependent on the type of the image.
* For example the color remains untouched if the texture is of Luminance type.
* The luminance defines the interaction between the material color and color defined
* for texture blending.
* If the type has 3 or more color channels then the material color is replaces with the texture's
* color and later blended with the defined blend color.
* All alpha values (if present) are ignored and not used during blending.
* @param data
* the image data
* @param imageFormat
* the format of the image
* @param neg
* defines it the result color should be nagated
* @param materialColor
* the material's color (value may be changed)
* @return texture intensity for the current pixel
*/
protected float setupMaterialColor(ByteBuffer data, Format imageFormat, boolean neg, float[] materialColor) {
// at least one byte is always taken :)
float tin = 0.0f;
byte pixelValue = data.get();
float firstPixelValue = pixelValue >= 0 ? 1.0f - pixelValue / 255.0f : (~pixelValue + 1) / 255.0f;
switch (imageFormat) {
case ABGR8:
pixelValue = data.get(); pixelValue = data.get();
texPixel[2] = pixelValue >= 0 ? 1.0f - pixelValue / 255.0f : (~pixelValue + 1) / 255.0f; materialColor[2] = pixelValue >= 0 ? 1.0f - pixelValue / 255.0f : (~pixelValue + 1) / 255.0f;
if(neg) {
texPixel[2] = 1.0f - texPixel[2];
}
pixelValue = data.get(); pixelValue = data.get();
texPixel[1] = pixelValue >= 0 ? 1.0f - pixelValue / 255.0f : (~pixelValue + 1) / 255.0f; materialColor[1] = pixelValue >= 0 ? 1.0f - pixelValue / 255.0f : (~pixelValue + 1) / 255.0f;
if(neg) {
texPixel[1] = 1.0f - texPixel[1];
}
pixelValue = data.get(); pixelValue = data.get();
texPixel[0] = pixelValue >= 0 ? 1.0f - pixelValue / 255.0f : (~pixelValue + 1) / 255.0f; materialColor[0] = pixelValue >= 0 ? 1.0f - pixelValue / 255.0f : (~pixelValue + 1) / 255.0f;
if(neg) { break;
texPixel[0] = 1.0f - texPixel[0]; case BGR8:
} materialColor[2] = firstPixelValue;
this.blendPixel(resultPixel, materialColor, texPixel, 1.0f, affectFactor, blendType, dataRepository);
newData.put(dataIndex++, (byte) (resultPixel[0] * 255.0f));
newData.put(dataIndex++, (byte) (resultPixel[1] * 255.0f));
newData.put(dataIndex++, (byte) (resultPixel[2] * 255.0f));
} else if (format == Format.RGB8) {
pixelValue = data.get(); pixelValue = data.get();
texPixel[1] = pixelValue >= 0 ? 1.0f - pixelValue / 255.0f : (~pixelValue + 1) / 255.0f; materialColor[1] = pixelValue >= 0 ? 1.0f - pixelValue / 255.0f : (~pixelValue + 1) / 255.0f;
if(neg) {
texPixel[1] = 1.0f - texPixel[1];
}
pixelValue = data.get(); pixelValue = data.get();
texPixel[2] = pixelValue >= 0 ? 1.0f - pixelValue / 255.0f : (~pixelValue + 1) / 255.0f; materialColor[0] = pixelValue >= 0 ? 1.0f - pixelValue / 255.0f : (~pixelValue + 1) / 255.0f;
if(neg) { break;
texPixel[2] = 1.0f - texPixel[2]; case RGB8:
} materialColor[0] = firstPixelValue;
float tin = texPixel[0];//(texPixel[0] + texPixel[1] + texPixel[2]) / 3.0f; pixelValue = data.get();
this.blendPixel(resultPixel, texPixel, color, tin, affectFactor, blendType, dataRepository); materialColor[1] = pixelValue >= 0 ? 1.0f - pixelValue / 255.0f : (~pixelValue + 1) / 255.0f;
newData.put(dataIndex++, (byte) (resultPixel[0] * 255.0f)); pixelValue = data.get();
newData.put(dataIndex++, (byte) (resultPixel[1] * 255.0f)); materialColor[2] = pixelValue >= 0 ? 1.0f - pixelValue / 255.0f : (~pixelValue + 1) / 255.0f;
newData.put(dataIndex++, (byte) (resultPixel[2] * 255.0f)); break;
} else if (format == Format.RGBA8) { case RGBA8:
pixelValue = data.get(); materialColor[0] = firstPixelValue;
texPixel[1] = pixelValue >= 0 ? 1.0f - pixelValue / 255.0f : (~pixelValue + 1) / 255.0f; pixelValue = data.get();
if(neg) { materialColor[1] = pixelValue >= 0 ? 1.0f - pixelValue / 255.0f : (~pixelValue + 1) / 255.0f;
texPixel[1] = 1.0f - texPixel[1]; pixelValue = data.get();
} materialColor[2] = pixelValue >= 0 ? 1.0f - pixelValue / 255.0f : (~pixelValue + 1) / 255.0f;
pixelValue = data.get(); data.get(); // ignore alpha
texPixel[2] = pixelValue >= 0 ? 1.0f - pixelValue / 255.0f : (~pixelValue + 1) / 255.0f; break;
if(neg) { case Luminance8:
texPixel[2] = 1.0f - texPixel[2]; tin = neg ? 1.0f - firstPixelValue : firstPixelValue;
} neg = false;//do not negate the materialColor, it must be unchanged
data.get(); // ignore alpha break;
this.blendPixel(resultPixel, materialColor, texPixel, 1.0f, affectFactor, blendType, dataRepository); case Luminance8Alpha8:
newData.put(dataIndex++, (byte) (resultPixel[0] * 255.0f)); tin = neg ? 1.0f - firstPixelValue : firstPixelValue;
newData.put(dataIndex++, (byte) (resultPixel[1] * 255.0f)); neg = false;//do not negate the materialColor, it must be unchanged
newData.put(dataIndex++, (byte) (resultPixel[2] * 255.0f)); data.get(); // ignore alpha
} else if (format == Format.BGR8) { break;
texPixel[2] = texPixel[0]; case Luminance16:
pixelValue = data.get(); case Luminance16Alpha16:
texPixel[1] = pixelValue >= 0 ? 1.0f - pixelValue / 255.0f : (~pixelValue + 1) / 255.0f; case Alpha16:
if(neg) { case Alpha8:
texPixel[1] = 1.0f - texPixel[1]; case ARGB4444:
} case Depth:
pixelValue = data.get(); case Depth16:
texPixel[0] = pixelValue >= 0 ? 1.0f - pixelValue / 255.0f : (~pixelValue + 1) / 255.0f; case Depth24:
if(neg) { case Depth32:
texPixel[0] = 1.0f - texPixel[0]; case Depth32F:
} case DXT1:
this.blendPixel(resultPixel, materialColor, texPixel, 1.0f, affectFactor, blendType, dataRepository); case DXT1A:
newData.put(dataIndex++, (byte) (resultPixel[0] * 255.0f)); case DXT3:
newData.put(dataIndex++, (byte) (resultPixel[1] * 255.0f)); case DXT5:
newData.put(dataIndex++, (byte) (resultPixel[2] * 255.0f)); case Intensity16:
} else if (format == Format.Luminance8) { case Intensity8:
this.blendPixel(resultPixel, materialColor, color, texPixel[0], affectFactor, blendType, dataRepository); case LATC:
newData.put((byte) (resultPixel[0] * 255.0f)); case LTC:
newData.put((byte) (resultPixel[1] * 255.0f)); case Luminance16F:
newData.put((byte) (resultPixel[2] * 255.0f)); case Luminance16FAlpha16F:
} else { case Luminance32F:
throw new IllegalStateException("Invalid texture format for blending operation: " + format); case RGB10:
} case RGB111110F:
case RGB16:
case RGB16F:
case RGB16F_to_RGB111110F:
case RGB16F_to_RGB9E5:
case RGB32F:
case RGB565:
case RGB5A1:
case RGB9E5:
case RGBA16:
case RGBA16F:
case RGBA32F:
LOGGER.warning("Image type not yet supported for blending: " + imageFormat);
break;
default:
throw new IllegalStateException("Unknown image format type: " + imageFormat);
} }
return new Texture2D(new Image(Format.RGB8, width, height, newData)); if (neg) {
materialColor[0] = 1.0f - materialColor[0];
materialColor[1] = 1.0f - materialColor[1];
materialColor[2] = 1.0f - materialColor[2];
}
return tin;
} }
/** /**
* This method blends the texture with an appropriate color. * This method blends the texture with an appropriate color.
* *
* @param result * @param result
* the result color (variable 'in' in blender source code) * the result color (variable 'in' in blender source code)
* @param materialColor * @param materialColor
* the texture color (variable 'out' in blender source coude) * the texture color (variable 'out' in blender source coude)
* @param color * @param color
* the previous color (variable 'tex' in blender source code) * the previous color (variable 'tex' in blender source code)
* @param textureIntensity * @param textureIntensity
* texture intensity (variable 'fact' in blender source code) * texture intensity (variable 'fact' in blender source code)
* @param textureFactor * @param textureFactor
* texture affection factor (variable 'facg' in blender source code) * texture affection factor (variable 'facg' in blender source code)
* @param blendtype * @param blendtype
* the blend type * the blend type
* @param dataRepository * @param dataRepository
* the data repository * the data repository
*/ */
public void blendPixel(float[] result, float[] materialColor, float[] color, float textureIntensity, float textureFactor, public void blendPixel(float[] result, float[] materialColor, float[] color, float textureIntensity, float textureFactor, int blendtype, DataRepository dataRepository) {
int blendtype, DataRepository dataRepository) {
float facm, col; float facm, col;
switch (blendtype) { switch (blendtype) {
@ -1275,15 +1298,15 @@ public class TextureHelper extends AbstractBlenderHelper {
* The method that performs the ramp blending (whatever it is :P - copied from blender sources). * The method that performs the ramp blending (whatever it is :P - copied from blender sources).
* *
* @param type * @param type
* the ramp type * the ramp type
* @param rgb * @param rgb
* the rgb value where the result is stored * the rgb value where the result is stored
* @param fac * @param fac
* color affection factor * color affection factor
* @param col * @param col
* the texture color * the texture color
* @param dataRepository * @param dataRepository
* the data repository * the data repository
*/ */
public void rampBlend(int type, float[] rgb, float fac, float[] col, DataRepository dataRepository) { public void rampBlend(int type, float[] rgb, float fac, float[] col, DataRepository dataRepository) {
float tmp, facm = 1.0f - fac; float tmp, facm = 1.0f - fac;
@ -1526,12 +1549,12 @@ public class TextureHelper extends AbstractBlenderHelper {
* This class returns a texture read from the file or from packed blender data. * This class returns a texture read from the file or from packed blender data.
* *
* @param image * @param image
* image structure filled with data * image structure filled with data
* @param dataRepository * @param dataRepository
* the data repository * the data repository
* @return the texture that can be used by JME engine * @return the texture that can be used by JME engine
* @throws BlenderFileException * @throws BlenderFileException
* this exception is thrown when the blend file structure is somehow invalid or corrupted * this exception is thrown when the blend file structure is somehow invalid or corrupted
*/ */
public Texture getTextureFromImage(Structure image, DataRepository dataRepository) throws BlenderFileException { public Texture getTextureFromImage(Structure image, DataRepository dataRepository) throws BlenderFileException {
Texture result = (Texture) dataRepository.getLoadedFeature(image.getOldMemoryAddress(), LoadedFeatureDataType.LOADED_FEATURE); Texture result = (Texture) dataRepository.getLoadedFeature(image.getOldMemoryAddress(), LoadedFeatureDataType.LOADED_FEATURE);
@ -1568,9 +1591,9 @@ public class TextureHelper extends AbstractBlenderHelper {
* This method loads the textre from outside the blend file. * This method loads the textre from outside the blend file.
* *
* @param name * @param name
* the path to the image * the path to the image
* @param dataRepository * @param dataRepository
* the data repository * the data repository
* @return the loaded image or null if the image cannot be found * @return the loaded image or null if the image cannot be found
*/ */
protected Texture loadTextureFromFile(String name, DataRepository dataRepository) { protected Texture loadTextureFromFile(String name, DataRepository dataRepository) {
@ -1651,7 +1674,7 @@ public class TextureHelper extends AbstractBlenderHelper {
* This method closes the given stream. * This method closes the given stream.
* *
* @param is * @param is
* the input stream that is to be closed * the input stream that is to be closed
*/ */
protected void closeStream(InputStream is) { protected void closeStream(InputStream is) {
if (is != null) { if (is != null) {
@ -1678,11 +1701,11 @@ public class TextureHelper extends AbstractBlenderHelper {
* This method loads the image from the blender file itself. It tries each loader to load the image. * This method loads the image from the blender file itself. It tries each loader to load the image.
* *
* @param inputStream * @param inputStream
* blender input stream * blender input stream
* @param startPosition * @param startPosition
* position in the stream where the image data starts * position in the stream where the image data starts
* @param flipY * @param flipY
* if the image should be flipped (does not work with DirectX image) * if the image should be flipped (does not work with DirectX image)
* @return loaded image or null if it could not be loaded * @return loaded image or null if it could not be loaded
*/ */
public Image loadImage(BlenderInputStream inputStream, int startPosition, boolean flipY) { public Image loadImage(BlenderInputStream inputStream, int startPosition, boolean flipY) {
@ -1711,11 +1734,11 @@ public class TextureHelper extends AbstractBlenderHelper {
* This method loads an image of a specified type from the given input stream. * This method loads an image of a specified type from the given input stream.
* *
* @param inputStream * @param inputStream
* the input stream we read the image from * the input stream we read the image from
* @param imageType * @param imageType
* the type of the image {@link ImageType} * the type of the image {@link ImageType}
* @param flipY * @param flipY
* if the image should be flipped (does not work with DirectX image) * if the image should be flipped (does not work with DirectX image)
* @return loaded image or null if it could not be loaded * @return loaded image or null if it could not be loaded
*/ */
public Image loadImage(InputStream inputStream, ImageType imageType, boolean flipY) { public Image loadImage(InputStream inputStream, ImageType imageType, boolean flipY) {
@ -1787,7 +1810,7 @@ public class TextureHelper extends AbstractBlenderHelper {
* Constructor. Loads the data from the given structure. * Constructor. Loads the data from the given structure.
* *
* @param cbdataStructure * @param cbdataStructure
* the colorband structure * the colorband structure
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public ColorBand(Structure colorbandStructure) { public ColorBand(Structure colorbandStructure) {
@ -1815,7 +1838,7 @@ public class TextureHelper extends AbstractBlenderHelper {
* Constructor. Loads the data from the given structure. * Constructor. Loads the data from the given structure.
* *
* @param cbdataStructure * @param cbdataStructure
* the structure containing the CBData object * the structure containing the CBData object
*/ */
public CBData(Structure cbdataStructure) { public CBData(Structure cbdataStructure) {
this.r = ((Number) cbdataStructure.getFieldValue("r")).floatValue(); this.r = ((Number) cbdataStructure.getFieldValue("r")).floatValue();
@ -1831,14 +1854,14 @@ public class TextureHelper extends AbstractBlenderHelper {
return super.clone(); return super.clone();
} }
} }
public static class GeneratedTextureData { public static class GeneratedTextureData {
public ByteBuffer luminanceData; public ByteBuffer luminanceData;
public ByteBuffer rgbData; public ByteBuffer rgbData;
public Format rgbFormat; public Format rgbFormat;
public int width; public int width;
public int height; public int height;
public GeneratedTextureData(ByteBuffer luminanceData, ByteBuffer rgbData, Format rgbFormat, int width, int height) { public GeneratedTextureData(ByteBuffer luminanceData, ByteBuffer rgbData, Format rgbFormat, int width, int height) {
this.luminanceData = luminanceData; this.luminanceData = luminanceData;
this.rgbData = rgbData; this.rgbData = rgbData;

Loading…
Cancel
Save