Generated textures refactoring.
* Algorithms changed (not depending on blender sources any more). * Improved loading speed (at least in some cases). * Unnecessary functions removed (there were a few :) ). * Several bugs fixed (some blending functions did not work well with textures; colorbands now calculated properly). git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@8222 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
This commit is contained in:
parent
08f7363d1f
commit
b86c1f4e64
@ -201,6 +201,10 @@ public class MaterialHelper extends AbstractBlenderHelper {
|
|||||||
MaterialContext materialContext = new MaterialContext(structure, dataRepository);
|
MaterialContext materialContext = new MaterialContext(structure, dataRepository);
|
||||||
LOGGER.log(Level.INFO, "Material's name: {0}", materialContext.name);
|
LOGGER.log(Level.INFO, "Material's name: {0}", materialContext.name);
|
||||||
|
|
||||||
|
DiffuseShader diffuseShader = this.getDiffuseShader(structure);
|
||||||
|
ColorRGBA diffuseColor = this.getDiffuseColor(structure, diffuseShader);
|
||||||
|
float[] diffuseColorArray = new float[] {diffuseColor.r, diffuseColor.g, diffuseColor.b};
|
||||||
|
|
||||||
// texture
|
// texture
|
||||||
Map<String, Texture> texturesMap = new HashMap<String, Texture>();
|
Map<String, Texture> texturesMap = new HashMap<String, Texture>();
|
||||||
Type firstTextureType = null;
|
Type firstTextureType = null;
|
||||||
@ -236,7 +240,7 @@ public class MaterialHelper extends AbstractBlenderHelper {
|
|||||||
int blendType = ((Number) mtex.getFieldValue("blendtype")).intValue();
|
int blendType = ((Number) mtex.getFieldValue("blendtype")).intValue();
|
||||||
float[] color = new float[] { ((Number) mtex.getFieldValue("r")).floatValue(), ((Number) mtex.getFieldValue("g")).floatValue(), ((Number) mtex.getFieldValue("b")).floatValue() };
|
float[] color = new float[] { ((Number) mtex.getFieldValue("r")).floatValue(), ((Number) mtex.getFieldValue("g")).floatValue(), ((Number) mtex.getFieldValue("b")).floatValue() };
|
||||||
float colfac = ((Number) mtex.getFieldValue("colfac")).floatValue();
|
float colfac = ((Number) mtex.getFieldValue("colfac")).floatValue();
|
||||||
texture = textureHelper.blendTexture(new float[] {1, 1, 1}, texture, color, colfac, blendType, negateTexture, dataRepository);
|
texture = textureHelper.blendTexture(diffuseColorArray, texture, color, colfac, blendType, negateTexture, dataRepository);
|
||||||
texture.setWrap(WrapMode.Repeat);
|
texture.setWrap(WrapMode.Repeat);
|
||||||
//TODO: textures merging
|
//TODO: textures merging
|
||||||
if (materialContext.shadeless) {
|
if (materialContext.shadeless) {
|
||||||
@ -289,7 +293,7 @@ public class MaterialHelper extends AbstractBlenderHelper {
|
|||||||
if (materialContext.vertexColor) {
|
if (materialContext.vertexColor) {
|
||||||
result.setBoolean(materialContext.shadeless ? "VertexColor" : "UseVertexColor", true);
|
result.setBoolean(materialContext.shadeless ? "VertexColor" : "UseVertexColor", true);
|
||||||
}
|
}
|
||||||
ColorRGBA diffuseColor = null;
|
|
||||||
if (materialContext.shadeless) {
|
if (materialContext.shadeless) {
|
||||||
// color of shadeless? doesn't seem to work in blender ..
|
// color of shadeless? doesn't seem to work in blender ..
|
||||||
diffuseColor = ColorRGBA.White.clone();
|
diffuseColor = ColorRGBA.White.clone();
|
||||||
@ -297,9 +301,7 @@ public class MaterialHelper extends AbstractBlenderHelper {
|
|||||||
result.setBoolean("UseMaterialColors", Boolean.TRUE);
|
result.setBoolean("UseMaterialColors", Boolean.TRUE);
|
||||||
|
|
||||||
// setting the colors
|
// setting the colors
|
||||||
DiffuseShader diffuseShader = this.getDiffuseShader(structure);
|
|
||||||
result.setBoolean("Minnaert", diffuseShader == DiffuseShader.MINNAERT);
|
result.setBoolean("Minnaert", diffuseShader == DiffuseShader.MINNAERT);
|
||||||
diffuseColor = this.getDiffuseColor(structure, diffuseShader);
|
|
||||||
if (!materialContext.transparent) {
|
if (!materialContext.transparent) {
|
||||||
diffuseColor.a = 1;
|
diffuseColor.a = 1;
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,40 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2009-2010 jMonkeyEngine
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are
|
||||||
|
* met:
|
||||||
|
*
|
||||||
|
* * Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* * Redistributions 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 'jMonkeyEngine' nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||||
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||||
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||||
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||||
|
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||||
|
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||||
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
package com.jme3.scene.plugins.blender.textures;
|
package com.jme3.scene.plugins.blender.textures;
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import com.jme3.scene.plugins.blender.file.BlenderInputStream;
|
import com.jme3.scene.plugins.blender.file.BlenderInputStream;
|
||||||
import com.jme3.scene.plugins.blender.textures.TextureHelper.ImageType;
|
|
||||||
import com.jme3.texture.Image;
|
import com.jme3.texture.Image;
|
||||||
import com.jme3.texture.plugins.AWTLoader;
|
import com.jme3.texture.plugins.AWTLoader;
|
||||||
import com.jme3.texture.plugins.DDSLoader;
|
import com.jme3.texture.plugins.DDSLoader;
|
||||||
@ -94,4 +124,13 @@ import com.jme3.texture.plugins.TGALoader;
|
|||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Image types that can be loaded. AWT: png, jpg, jped or bmp TGA: tga DDS: DirectX image files
|
||||||
|
*
|
||||||
|
* @author Marcin Roguski (Kaelthas)
|
||||||
|
*/
|
||||||
|
private static enum ImageType {
|
||||||
|
AWT, TGA, DDS;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -1,12 +1,47 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2009-2010 jMonkeyEngine
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are
|
||||||
|
* met:
|
||||||
|
*
|
||||||
|
* * Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* * Redistributions 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 'jMonkeyEngine' nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||||
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||||
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||||
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||||
|
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||||
|
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||||
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
package com.jme3.scene.plugins.blender.textures;
|
package com.jme3.scene.plugins.blender.textures;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.TreeMap;
|
||||||
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import com.jme3.math.FastMath;
|
||||||
import com.jme3.scene.plugins.blender.DataRepository;
|
import com.jme3.scene.plugins.blender.DataRepository;
|
||||||
import com.jme3.scene.plugins.blender.exceptions.BlenderFileException;
|
import com.jme3.scene.plugins.blender.exceptions.BlenderFileException;
|
||||||
|
import com.jme3.scene.plugins.blender.file.DynamicArray;
|
||||||
import com.jme3.scene.plugins.blender.file.Pointer;
|
import com.jme3.scene.plugins.blender.file.Pointer;
|
||||||
import com.jme3.scene.plugins.blender.file.Structure;
|
import com.jme3.scene.plugins.blender.file.Structure;
|
||||||
import com.jme3.scene.plugins.blender.textures.TextureHelper.ColorBand;
|
|
||||||
import com.jme3.texture.Texture;
|
import com.jme3.texture.Texture;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -47,7 +82,7 @@ import com.jme3.texture.Texture;
|
|||||||
* 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) {
|
private ColorBand readColorband(Structure tex, DataRepository dataRepository) {
|
||||||
ColorBand result = null;
|
ColorBand result = null;
|
||||||
int flag = ((Number) tex.getFieldValue("flag")).intValue();
|
int flag = ((Number) tex.getFieldValue("flag")).intValue();
|
||||||
if ((flag & NoiseGenerator.TEX_COLORBAND) != 0) {
|
if ((flag & NoiseGenerator.TEX_COLORBAND) != 0) {
|
||||||
@ -57,10 +92,340 @@ import com.jme3.texture.Texture;
|
|||||||
colorbandStructure = pColorband.fetchData(dataRepository.getInputStream()).get(0);
|
colorbandStructure = pColorband.fetchData(dataRepository.getInputStream()).get(0);
|
||||||
result = new ColorBand(colorbandStructure);
|
result = new ColorBand(colorbandStructure);
|
||||||
} catch (BlenderFileException e) {
|
} catch (BlenderFileException e) {
|
||||||
LOGGER.warning("Cannot fetch the colorband structure. The reason: " + e.getLocalizedMessage());
|
LOGGER.log(Level.WARNING, "Cannot fetch the colorband structure. The reason: {0}", e.getLocalizedMessage());
|
||||||
// TODO: throw an exception here ???
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected float[][] computeColorband(Structure tex, DataRepository dataRepository) {
|
||||||
|
ColorBand colorBand = this.readColorband(tex, dataRepository);
|
||||||
|
float[][] result = null;
|
||||||
|
if(colorBand!=null) {
|
||||||
|
result = new float[1001][4];//1001 - amount of possible cursor positions; 4 = [r, g, b, a]
|
||||||
|
ColorBandData[] dataArray = colorBand.data;
|
||||||
|
|
||||||
|
if(dataArray.length==1) {//special case; use only one color for all types of colorband interpolation
|
||||||
|
for(int i=0;i<result.length;++i) {
|
||||||
|
result[i][0] = dataArray[0].r;
|
||||||
|
result[i][1] = dataArray[0].g;
|
||||||
|
result[i][2] = dataArray[0].b;
|
||||||
|
result[i][3] = dataArray[0].a;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
int currentCursor = 0;
|
||||||
|
ColorBandData currentData = dataArray[0];
|
||||||
|
ColorBandData nextData = dataArray[0];
|
||||||
|
switch(colorBand.ipoType) {
|
||||||
|
case ColorBand.IPO_LINEAR:
|
||||||
|
float rDiff = 0, gDiff = 0, bDiff = 0, aDiff = 0, posDiff;
|
||||||
|
for(int i=0;i<result.length;++i) {
|
||||||
|
posDiff = i - currentData.pos;
|
||||||
|
result[i][0] = currentData.r + rDiff * posDiff;
|
||||||
|
result[i][1] = currentData.g + gDiff * posDiff;
|
||||||
|
result[i][2] = currentData.b + bDiff * posDiff;
|
||||||
|
result[i][3] = currentData.a + aDiff * posDiff;
|
||||||
|
if(nextData.pos==i) {
|
||||||
|
currentData = dataArray[currentCursor++];
|
||||||
|
if(currentCursor < dataArray.length) {
|
||||||
|
nextData = dataArray[currentCursor];
|
||||||
|
//calculate differences
|
||||||
|
int d = nextData.pos - currentData.pos;
|
||||||
|
rDiff = (nextData.r - currentData.r)/d;
|
||||||
|
gDiff = (nextData.g - currentData.g)/d;
|
||||||
|
bDiff = (nextData.b - currentData.b)/d;
|
||||||
|
aDiff = (nextData.a - currentData.a)/d;
|
||||||
|
} else {
|
||||||
|
rDiff = gDiff = bDiff = aDiff = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case ColorBand.IPO_BSPLINE:
|
||||||
|
case ColorBand.IPO_CARDINAL:
|
||||||
|
Map<Integer, ColorBandData> cbDataMap = new TreeMap<Integer, ColorBandData>();
|
||||||
|
for(int i=0;i<colorBand.data.length;++i) {
|
||||||
|
cbDataMap.put(Integer.valueOf(i), colorBand.data[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(colorBand.data[0].pos==0) {
|
||||||
|
cbDataMap.put(Integer.valueOf(-1), colorBand.data[0]);
|
||||||
|
} else {
|
||||||
|
ColorBandData cbData = colorBand.data[0].clone();
|
||||||
|
cbData.pos = 0;
|
||||||
|
cbDataMap.put(Integer.valueOf(-1), cbData);
|
||||||
|
cbDataMap.put(Integer.valueOf(-2), cbData);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(colorBand.data[colorBand.data.length - 1].pos==1000) {
|
||||||
|
cbDataMap.put(Integer.valueOf(colorBand.data.length), colorBand.data[colorBand.data.length - 1]);
|
||||||
|
} else {
|
||||||
|
ColorBandData cbData = colorBand.data[colorBand.data.length - 1].clone();
|
||||||
|
cbData.pos = 1000;
|
||||||
|
cbDataMap.put(Integer.valueOf(colorBand.data.length), cbData);
|
||||||
|
cbDataMap.put(Integer.valueOf(colorBand.data.length + 1), cbData);
|
||||||
|
}
|
||||||
|
|
||||||
|
float[] ipoFactors = new float[4];
|
||||||
|
float f;
|
||||||
|
|
||||||
|
ColorBandData data0 = cbDataMap.get(currentCursor - 2);
|
||||||
|
ColorBandData data1 = cbDataMap.get(currentCursor - 1);
|
||||||
|
ColorBandData data2 = cbDataMap.get(currentCursor);
|
||||||
|
ColorBandData data3 = cbDataMap.get(currentCursor + 1);
|
||||||
|
|
||||||
|
for(int i=0;i<result.length;++i) {
|
||||||
|
if (data2.pos != data1.pos) {
|
||||||
|
f = (i - data2.pos) / (float)(data1.pos - data2.pos);
|
||||||
|
} else {
|
||||||
|
f = 0.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
f = FastMath.clamp(f, 0.0f, 1.0f);
|
||||||
|
|
||||||
|
this.getIpoData(colorBand, f, ipoFactors);
|
||||||
|
result[i][0] = ipoFactors[3] * data0.r + ipoFactors[2] * data1.r + ipoFactors[1] * data2.r + ipoFactors[0] * data3.r;
|
||||||
|
result[i][1] = ipoFactors[3] * data0.g + ipoFactors[2] * data1.g + ipoFactors[1] * data2.g + ipoFactors[0] * data3.g;
|
||||||
|
result[i][2] = ipoFactors[3] * data0.b + ipoFactors[2] * data1.b + ipoFactors[1] * data2.b + ipoFactors[0] * data3.b;
|
||||||
|
result[i][3] = ipoFactors[3] * data0.a + ipoFactors[2] * data1.a + ipoFactors[1] * data2.a + ipoFactors[0] * data3.a;
|
||||||
|
result[i][0] = FastMath.clamp(result[i][0], 0.0f, 1.0f);
|
||||||
|
result[i][1] = FastMath.clamp(result[i][1], 0.0f, 1.0f);
|
||||||
|
result[i][2] = FastMath.clamp(result[i][2], 0.0f, 1.0f);
|
||||||
|
result[i][3] = FastMath.clamp(result[i][3], 0.0f, 1.0f);
|
||||||
|
|
||||||
|
if(nextData.pos==i) {
|
||||||
|
++currentCursor;
|
||||||
|
data0 = cbDataMap.get(currentCursor - 2);
|
||||||
|
data1 = cbDataMap.get(currentCursor - 1);
|
||||||
|
data2 = cbDataMap.get(currentCursor);
|
||||||
|
data3 = cbDataMap.get(currentCursor + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case ColorBand.IPO_EASE:
|
||||||
|
float d, a, b, d2;
|
||||||
|
for(int i=0;i<result.length;++i) {
|
||||||
|
if(nextData.pos != currentData.pos) {
|
||||||
|
d = (i - currentData.pos) / (float)(nextData.pos - currentData.pos);
|
||||||
|
d2 = d * d;
|
||||||
|
a = 3.0f * d2 - 2.0f * d * d2;
|
||||||
|
b = 1.0f - a;
|
||||||
|
} else {
|
||||||
|
d = a = 0.0f;
|
||||||
|
b = 1.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
result[i][0] = b * currentData.r + a * nextData.r;
|
||||||
|
result[i][1] = b * currentData.g + a * nextData.g;
|
||||||
|
result[i][2] = b * currentData.b + a * nextData.b;
|
||||||
|
result[i][3] = b * currentData.a + a * nextData.a;
|
||||||
|
if(nextData.pos==i) {
|
||||||
|
currentData = dataArray[currentCursor++];
|
||||||
|
if(currentCursor < dataArray.length) {
|
||||||
|
nextData = dataArray[currentCursor];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case ColorBand.IPO_CONSTANT:
|
||||||
|
for(int i=0;i<result.length;++i) {
|
||||||
|
result[i][0] = currentData.r;
|
||||||
|
result[i][1] = currentData.g;
|
||||||
|
result[i][2] = currentData.b;
|
||||||
|
result[i][3] = currentData.a;
|
||||||
|
if(nextData.pos==i) {
|
||||||
|
currentData = dataArray[currentCursor++];
|
||||||
|
if(currentCursor < dataArray.length) {
|
||||||
|
nextData = dataArray[currentCursor];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new IllegalStateException("Unknown interpolation type: " + colorBand.ipoType);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method returns the data for either B-spline of Cardinal interpolation.
|
||||||
|
* @param colorBand the color band
|
||||||
|
* @param d distance factor for the current intensity
|
||||||
|
* @param ipoFactors table to store the results (size of the table must be at least 4)
|
||||||
|
*/
|
||||||
|
private void getIpoData(ColorBand colorBand, float d, float[] ipoFactors) {
|
||||||
|
float d2 = d * d;
|
||||||
|
float d3 = d2 * d;
|
||||||
|
if(colorBand.ipoType==ColorBand.IPO_BSPLINE) {
|
||||||
|
ipoFactors[0] = -0.71f * d3 + 1.42f * d2 - 0.71f * d;
|
||||||
|
ipoFactors[1] = 1.29f * d3 - 2.29f * d2 + 1.0f;
|
||||||
|
ipoFactors[2] = -1.29f * d3 + 1.58f * d2 + 0.71f * d;
|
||||||
|
ipoFactors[3] = 0.71f * d3 - 0.71f * d2;
|
||||||
|
} else if(colorBand.ipoType==ColorBand.IPO_CARDINAL) {
|
||||||
|
ipoFactors[0] = -0.16666666f * d3 + 0.5f * d2 - 0.5f * d + 0.16666666f;
|
||||||
|
ipoFactors[1] = 0.5f * d3 - d2 + 0.6666666f;
|
||||||
|
ipoFactors[2] = -0.5f * d3 + 0.5f * d2 + 0.5f * d + 0.16666666f;
|
||||||
|
ipoFactors[3] = 0.16666666f * d3;
|
||||||
|
} else {
|
||||||
|
throw new IllegalStateException("Cannot get interpolation data for other colorband types than B-spline and Cardinal!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method applies brightness and contrast for RGB textures.
|
||||||
|
* @param tex texture structure
|
||||||
|
* @param texres
|
||||||
|
*/
|
||||||
|
protected void applyBrightnessAndContrast(BrightnessAndContrastData bacd, TextureResult texres) {
|
||||||
|
texres.red = (texres.red - 0.5f) * bacd.contrast + bacd.brightness;
|
||||||
|
if (texres.red < 0.0f) {
|
||||||
|
texres.red = 0.0f;
|
||||||
|
}
|
||||||
|
texres.green =(texres.green - 0.5f) * bacd.contrast + bacd.brightness;
|
||||||
|
if (texres.green < 0.0f) {
|
||||||
|
texres.green = 0.0f;
|
||||||
|
}
|
||||||
|
texres.blue = (texres.blue - 0.5f) * bacd.contrast + bacd.brightness;
|
||||||
|
if (texres.blue < 0.0f) {
|
||||||
|
texres.blue = 0.0f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method applies brightness and contrast for Luminance textures.
|
||||||
|
* @param texres
|
||||||
|
* @param contrast
|
||||||
|
* @param brightness
|
||||||
|
*/
|
||||||
|
protected void applyBrightnessAndContrast(TextureResult texres, float contrast, float brightness) {
|
||||||
|
texres.intensity = (texres.intensity - 0.5f) * contrast + brightness;
|
||||||
|
if (texres.intensity < 0.0f) {
|
||||||
|
texres.intensity = 0.0f;
|
||||||
|
} else if (texres.intensity > 1.0f) {
|
||||||
|
texres.intensity = 1.0f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The result pixel of generated texture computations;
|
||||||
|
*
|
||||||
|
* @author Marcin Roguski (Kaelthas)
|
||||||
|
*/
|
||||||
|
protected static class TextureResult implements Cloneable {
|
||||||
|
public float intensity, red, green, blue, alpha;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object clone() throws CloneNotSupportedException {
|
||||||
|
return super.clone();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A class constaining the colorband data.
|
||||||
|
*
|
||||||
|
* @author Marcin Roguski (Kaelthas)
|
||||||
|
*/
|
||||||
|
protected static class ColorBand {
|
||||||
|
//interpolation types
|
||||||
|
public static final int IPO_LINEAR = 0;
|
||||||
|
public static final int IPO_EASE = 1;
|
||||||
|
public static final int IPO_BSPLINE = 2;
|
||||||
|
public static final int IPO_CARDINAL = 3;
|
||||||
|
public static final int IPO_CONSTANT = 4;
|
||||||
|
|
||||||
|
public int cursorsAmount, ipoType;
|
||||||
|
public ColorBandData[] data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor. Loads the data from the given structure.
|
||||||
|
*
|
||||||
|
* @param cbdataStructure
|
||||||
|
* the colorband structure
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public ColorBand(Structure colorbandStructure) {
|
||||||
|
this.cursorsAmount = ((Number) colorbandStructure.getFieldValue("tot")).intValue();
|
||||||
|
this.ipoType = ((Number) colorbandStructure.getFieldValue("ipotype")).intValue();
|
||||||
|
this.data = new ColorBandData[this.cursorsAmount];
|
||||||
|
DynamicArray<Structure> data = (DynamicArray<Structure>) colorbandStructure.getFieldValue("data");
|
||||||
|
for (int i = 0; i < this.cursorsAmount; ++i) {
|
||||||
|
this.data[i] = new ColorBandData(data.get(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class to store the single colorband cursor data.
|
||||||
|
*
|
||||||
|
* @author Marcin Roguski (Kaelthas)
|
||||||
|
*/
|
||||||
|
protected static class ColorBandData implements Cloneable {
|
||||||
|
public final float r, g, b, a;
|
||||||
|
public int pos;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copy constructor.
|
||||||
|
*/
|
||||||
|
private ColorBandData(ColorBandData data) {
|
||||||
|
this.r = data.r;
|
||||||
|
this.g = data.g;
|
||||||
|
this.b = data.b;
|
||||||
|
this.a = data.a;
|
||||||
|
this.pos = data.pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor. Loads the data from the given structure.
|
||||||
|
*
|
||||||
|
* @param cbdataStructure
|
||||||
|
* the structure containing the CBData object
|
||||||
|
*/
|
||||||
|
public ColorBandData(Structure cbdataStructure) {
|
||||||
|
this.r = ((Number) cbdataStructure.getFieldValue("r")).floatValue();
|
||||||
|
this.g = ((Number) cbdataStructure.getFieldValue("g")).floatValue();
|
||||||
|
this.b = ((Number) cbdataStructure.getFieldValue("b")).floatValue();
|
||||||
|
this.a = ((Number) cbdataStructure.getFieldValue("a")).floatValue();
|
||||||
|
this.pos = (int) (((Number) cbdataStructure.getFieldValue("pos")).floatValue() * 1000.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ColorBandData clone() {
|
||||||
|
try {
|
||||||
|
return (ColorBandData) super.clone();
|
||||||
|
} catch (CloneNotSupportedException e) {
|
||||||
|
return new ColorBandData(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "P: " + this.pos + " [" + this.r+", "+this.g+", "+this.b+", "+this.a+"]";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class contains brightness and contrast data.
|
||||||
|
* @author Marcin Roguski (Kaelthas)
|
||||||
|
*/
|
||||||
|
protected static class BrightnessAndContrastData {
|
||||||
|
public final float contrast;
|
||||||
|
public final float brightness;
|
||||||
|
public final float rFactor;
|
||||||
|
public final float gFactor;
|
||||||
|
public final float bFactor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor reads the required data from the given structure.
|
||||||
|
* @param tex texture structure
|
||||||
|
*/
|
||||||
|
public BrightnessAndContrastData(Structure tex) {
|
||||||
|
contrast = ((Number) tex.getFieldValue("contrast")).floatValue();
|
||||||
|
brightness = ((Number) tex.getFieldValue("bright")).floatValue() - 0.5f;
|
||||||
|
rFactor = ((Number) tex.getFieldValue("rfac")).floatValue();
|
||||||
|
gFactor = ((Number) tex.getFieldValue("gfac")).floatValue();
|
||||||
|
bFactor = ((Number) tex.getFieldValue("bfac")).floatValue();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,32 +1,33 @@
|
|||||||
/*
|
/*
|
||||||
*
|
* Copyright (c) 2009-2010 jMonkeyEngine
|
||||||
* $Id: noise.c 14611 2008-04-29 08:24:33Z campbellbarton $
|
|
||||||
*
|
|
||||||
* ***** BEGIN GPL LICENSE BLOCK *****
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or
|
|
||||||
* modify it under the terms of the GNU General Public License
|
|
||||||
* as published by the Free Software Foundation; either version 2
|
|
||||||
* of the License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program; if not, write to the Free Software Foundation,
|
|
||||||
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
||||||
*
|
|
||||||
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* The Original Code is: all of this file.
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are
|
||||||
|
* met:
|
||||||
*
|
*
|
||||||
* Contributor(s): none yet.
|
* * Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
*
|
*
|
||||||
* ***** END GPL LICENSE BLOCK *****
|
* * Redistributions 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 'jMonkeyEngine' nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||||
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||||
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||||
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||||
|
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||||
|
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||||
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
package com.jme3.scene.plugins.blender.textures;
|
package com.jme3.scene.plugins.blender.textures;
|
||||||
|
|
||||||
@ -36,8 +37,6 @@ import java.util.ArrayList;
|
|||||||
import com.jme3.math.FastMath;
|
import com.jme3.math.FastMath;
|
||||||
import com.jme3.scene.plugins.blender.DataRepository;
|
import com.jme3.scene.plugins.blender.DataRepository;
|
||||||
import com.jme3.scene.plugins.blender.file.Structure;
|
import com.jme3.scene.plugins.blender.file.Structure;
|
||||||
import com.jme3.scene.plugins.blender.textures.TextureHelper.ColorBand;
|
|
||||||
import com.jme3.scene.plugins.blender.textures.TextureHelper.TexResult;
|
|
||||||
import com.jme3.texture.Image;
|
import com.jme3.texture.Image;
|
||||||
import com.jme3.texture.Image.Format;
|
import com.jme3.texture.Image.Format;
|
||||||
import com.jme3.texture.Texture;
|
import com.jme3.texture.Texture;
|
||||||
@ -50,6 +49,62 @@ import com.jme3.util.BufferUtils;
|
|||||||
*/
|
*/
|
||||||
public final class TextureGeneratorBlend extends TextureGenerator {
|
public final class TextureGeneratorBlend extends TextureGenerator {
|
||||||
|
|
||||||
|
private static final IntensityFunction INTENSITY_FUNCTION[] = new IntensityFunction[7];
|
||||||
|
static {
|
||||||
|
INTENSITY_FUNCTION[0] = new IntensityFunction() {//Linear: stype = 0 (TEX_LIN)
|
||||||
|
@Override
|
||||||
|
public float getIntensity(float x, float y, float z) {
|
||||||
|
return (1.0f + x) * 0.5f;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
INTENSITY_FUNCTION[1] = new IntensityFunction() {//Quad: stype = 1 (TEX_QUAD)
|
||||||
|
@Override
|
||||||
|
public float getIntensity(float x, float y, float z) {
|
||||||
|
float result = (1.0f + x) * 0.5f;
|
||||||
|
return result * result;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
INTENSITY_FUNCTION[2] = new IntensityFunction() {//Ease: stype = 2 (TEX_EASE)
|
||||||
|
@Override
|
||||||
|
public float getIntensity(float x, float y, float z) {
|
||||||
|
float result = (1.0f + x) * 0.5f;
|
||||||
|
if (result <= 0.0f) {
|
||||||
|
return 0.0f;
|
||||||
|
} else if (result >= 1.0f) {
|
||||||
|
return 1.0f;
|
||||||
|
} else {
|
||||||
|
return result * result *(3.0f - 2.0f * result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
INTENSITY_FUNCTION[3] = new IntensityFunction() {//Diagonal: stype = 3 (TEX_DIAG)
|
||||||
|
@Override
|
||||||
|
public float getIntensity(float x, float y, float z) {
|
||||||
|
return (2.0f + x + y) * 0.25f;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
INTENSITY_FUNCTION[4] = new IntensityFunction() {//Sphere: stype = 4 (TEX_SPHERE)
|
||||||
|
@Override
|
||||||
|
public float getIntensity(float x, float y, float z) {
|
||||||
|
float result = 1.0f - (float) Math.sqrt(x * x + y * y + z * z);
|
||||||
|
return result < 0.0f ? 0.0f : result;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
INTENSITY_FUNCTION[5] = new IntensityFunction() {//Halo: stype = 5 (TEX_HALO)
|
||||||
|
@Override
|
||||||
|
public float getIntensity(float x, float y, float z) {
|
||||||
|
float result = 1.0f - (float) Math.sqrt(x * x + y * y + z * z);
|
||||||
|
return result <= 0.0f ? 0.0f : result * result;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
INTENSITY_FUNCTION[6] = new IntensityFunction() {//Radial: stype = 6 (TEX_RAD)
|
||||||
|
@Override
|
||||||
|
public float getIntensity(float x, float y, float z) {
|
||||||
|
return (float) Math.atan2(y, x) * FastMath.INV_TWO_PI + 0.5f;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor stores the given noise generator.
|
* Constructor stores the given noise generator.
|
||||||
* @param noiseGenerator
|
* @param noiseGenerator
|
||||||
@ -63,81 +118,51 @@ public final class TextureGeneratorBlend extends TextureGenerator {
|
|||||||
protected Texture generate(Structure tex, int width, int height, int depth, DataRepository dataRepository) {
|
protected Texture generate(Structure tex, int width, int height, int depth, DataRepository dataRepository) {
|
||||||
int flag = ((Number) tex.getFieldValue("flag")).intValue();
|
int flag = ((Number) tex.getFieldValue("flag")).intValue();
|
||||||
int stype = ((Number) tex.getFieldValue("stype")).intValue();
|
int stype = ((Number) tex.getFieldValue("stype")).intValue();
|
||||||
float contrast = ((Number) tex.getFieldValue("contrast")).floatValue();
|
TextureResult texres = new TextureResult();
|
||||||
float brightness = ((Number) tex.getFieldValue("bright")).floatValue();
|
int halfW = width >> 1, halfH = height >> 1, halfD = depth >> 1, index = 0;
|
||||||
float wDelta = 1.0f / width, hDelta = 1.0f / height, dDelta = 1.0f / depth, x, y, t;
|
float wDelta = 1.0f / halfW, hDelta = 1.0f / halfH, dDelta = 1.0f / halfD, x, y;
|
||||||
float[] texvec = new float[] { 0, 0, 0 };
|
float[][] colorBand = this.computeColorband(tex, dataRepository);
|
||||||
TexResult texres = new TexResult();
|
BrightnessAndContrastData bacd = new BrightnessAndContrastData(tex);
|
||||||
int halfW = width, halfH = height, halfD = depth;
|
|
||||||
width <<= 1;
|
|
||||||
height <<= 1;
|
|
||||||
depth <<= 1;
|
|
||||||
ColorBand colorBand = this.readColorband(tex, dataRepository);
|
|
||||||
Format format = colorBand != null ? Format.RGB8 : Format.Luminance8;
|
Format format = colorBand != null ? Format.RGB8 : Format.Luminance8;
|
||||||
int bytesPerPixel = colorBand != null ? 3 : 1;
|
int bytesPerPixel = colorBand != null ? 3 : 1;
|
||||||
|
boolean flipped = (flag & NoiseGenerator.TEX_FLIPBLEND) != 0;
|
||||||
|
|
||||||
ByteBuffer data = BufferUtils.createByteBuffer(width * height * depth * bytesPerPixel);
|
byte[] data = new byte[width * height * depth * bytesPerPixel];
|
||||||
for (int i = -halfW; i < halfW; ++i) {
|
for (int i = -halfW; i < halfW; ++i) {
|
||||||
texvec[0] = wDelta * i;
|
x = wDelta * i;
|
||||||
for (int j = -halfH; j < halfH; ++j) {
|
for (int j = -halfH; j < halfH; ++j) {
|
||||||
texvec[1] = hDelta * j;
|
if (flipped) {
|
||||||
|
y = x;
|
||||||
|
x = hDelta * j;
|
||||||
|
} else {
|
||||||
|
y = hDelta * j;
|
||||||
|
}
|
||||||
for (int k = -halfD; k < halfD; ++k) {
|
for (int k = -halfD; k < halfD; ++k) {
|
||||||
texvec[2] = dDelta * k;
|
texres.intensity = INTENSITY_FUNCTION[stype].getIntensity(x, y, dDelta * k);
|
||||||
if ((flag & NoiseGenerator.TEX_FLIPBLEND) != 0) {
|
|
||||||
x = texvec[1];
|
|
||||||
y = texvec[0];
|
|
||||||
} else {
|
|
||||||
x = texvec[0];
|
|
||||||
y = texvec[1];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (stype == NoiseGenerator.TEX_LIN) { /* lin */
|
|
||||||
texres.tin = (1.0f + x) / 2.0f;
|
|
||||||
} else if (stype == NoiseGenerator.TEX_QUAD) { /* quad */
|
|
||||||
texres.tin = (1.0f + x) / 2.0f;
|
|
||||||
if (texres.tin < 0.0f) {
|
|
||||||
texres.tin = 0.0f;
|
|
||||||
} else {
|
|
||||||
texres.tin *= texres.tin;
|
|
||||||
}
|
|
||||||
} else if (stype == NoiseGenerator.TEX_EASE) { /* ease */
|
|
||||||
texres.tin = (1.0f + x) / 2.0f;
|
|
||||||
if (texres.tin <= 0.0f) {
|
|
||||||
texres.tin = 0.0f;
|
|
||||||
} else if (texres.tin >= 1.0f) {
|
|
||||||
texres.tin = 1.0f;
|
|
||||||
} else {
|
|
||||||
t = texres.tin * texres.tin;
|
|
||||||
texres.tin = 3.0f * t - 2.0f * t * texres.tin;
|
|
||||||
}
|
|
||||||
} else if (stype == NoiseGenerator.TEX_DIAG) { /* diag */
|
|
||||||
texres.tin = (2.0f + x + y) / 4.0f;
|
|
||||||
} else if (stype == NoiseGenerator.TEX_RAD) { /* radial */
|
|
||||||
texres.tin = (float) Math.atan2(y, x) / FastMath.TWO_PI + 0.5f;
|
|
||||||
} else { /* sphere TEX_SPHERE */
|
|
||||||
texres.tin = 1.0f - (float) Math.sqrt(x * x + y * y + texvec[2] * texvec[2]);
|
|
||||||
if (texres.tin < 0.0f) {
|
|
||||||
texres.tin = 0.0f;
|
|
||||||
}
|
|
||||||
if (stype == NoiseGenerator.TEX_HALO) {
|
|
||||||
texres.tin *= texres.tin;
|
|
||||||
} /* halo */
|
|
||||||
}
|
|
||||||
if (colorBand != null) {
|
if (colorBand != null) {
|
||||||
noiseGenerator.doColorband(colorBand, texres, dataRepository);
|
int colorbandIndex = (int) (texres.intensity * 1000.0f);
|
||||||
noiseGenerator.brightnesAndContrastRGB(tex, texres);
|
texres.red = colorBand[colorbandIndex][0];
|
||||||
data.put((byte) (texres.tr * 255.0f));
|
texres.green = colorBand[colorbandIndex][1];
|
||||||
data.put((byte) (texres.tg * 255.0f));
|
texres.blue = colorBand[colorbandIndex][2];
|
||||||
data.put((byte) (texres.tb * 255.0f));
|
|
||||||
|
this.applyBrightnessAndContrast(bacd, texres);
|
||||||
|
data[index++] = (byte) (texres.red * 255.0f);
|
||||||
|
data[index++] = (byte) (texres.green * 255.0f);
|
||||||
|
data[index++] = (byte) (texres.blue * 255.0f);
|
||||||
} else {
|
} else {
|
||||||
noiseGenerator.brightnesAndContrast(texres, contrast, brightness);
|
this.applyBrightnessAndContrast(texres, bacd.contrast, bacd.brightness);
|
||||||
data.put((byte) (texres.tin * 255.0f));
|
data[index++] = (byte) (texres.intensity * 255.0f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ArrayList<ByteBuffer> dataArray = new ArrayList<ByteBuffer>(1);
|
ArrayList<ByteBuffer> dataArray = new ArrayList<ByteBuffer>(1);
|
||||||
dataArray.add(data);
|
dataArray.add(BufferUtils.createByteBuffer(data));
|
||||||
return new Texture3D(new Image(format, width, height, depth, dataArray));
|
return new Texture3D(new Image(format, width, height, depth, dataArray));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static interface IntensityFunction {
|
||||||
|
float getIntensity(float x, float y, float z);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,42 +1,42 @@
|
|||||||
/*
|
/*
|
||||||
*
|
* Copyright (c) 2009-2010 jMonkeyEngine
|
||||||
* $Id: noise.c 14611 2008-04-29 08:24:33Z campbellbarton $
|
|
||||||
*
|
|
||||||
* ***** BEGIN GPL LICENSE BLOCK *****
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or
|
|
||||||
* modify it under the terms of the GNU General Public License
|
|
||||||
* as published by the Free Software Foundation; either version 2
|
|
||||||
* of the License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program; if not, write to the Free Software Foundation,
|
|
||||||
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
||||||
*
|
|
||||||
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* The Original Code is: all of this file.
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are
|
||||||
|
* met:
|
||||||
*
|
*
|
||||||
* Contributor(s): none yet.
|
* * Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
*
|
*
|
||||||
* ***** END GPL LICENSE BLOCK *****
|
* * Redistributions 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 'jMonkeyEngine' nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||||
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||||
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||||
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||||
|
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||||
|
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||||
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
package com.jme3.scene.plugins.blender.textures;
|
package com.jme3.scene.plugins.blender.textures;
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import com.jme3.math.FastMath;
|
||||||
import com.jme3.scene.plugins.blender.DataRepository;
|
import com.jme3.scene.plugins.blender.DataRepository;
|
||||||
import com.jme3.scene.plugins.blender.file.Structure;
|
import com.jme3.scene.plugins.blender.file.Structure;
|
||||||
import com.jme3.scene.plugins.blender.textures.TextureHelper.ColorBand;
|
|
||||||
import com.jme3.scene.plugins.blender.textures.TextureHelper.TexResult;
|
|
||||||
import com.jme3.texture.Image;
|
import com.jme3.texture.Image;
|
||||||
import com.jme3.texture.Image.Format;
|
import com.jme3.texture.Image.Format;
|
||||||
import com.jme3.texture.Texture;
|
import com.jme3.texture.Texture;
|
||||||
@ -48,6 +48,13 @@ import com.jme3.util.BufferUtils;
|
|||||||
* @author Marcin Roguski (Kaelthas)
|
* @author Marcin Roguski (Kaelthas)
|
||||||
*/
|
*/
|
||||||
public class TextureGeneratorClouds extends TextureGenerator {
|
public class TextureGeneratorClouds extends TextureGenerator {
|
||||||
|
// tex->noisetype
|
||||||
|
protected static final int TEX_NOISESOFT = 0;
|
||||||
|
protected static final int TEX_NOISEPERL = 1;
|
||||||
|
|
||||||
|
// tex->stype
|
||||||
|
protected static final int TEX_DEFAULT = 0;
|
||||||
|
protected static final int TEX_COLOR = 1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor stores the given noise generator.
|
* Constructor stores the given noise generator.
|
||||||
@ -60,69 +67,64 @@ public class TextureGeneratorClouds extends TextureGenerator {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Texture generate(Structure tex, int width, int height, int depth, DataRepository dataRepository) {
|
protected Texture generate(Structure tex, int width, int height, int depth, DataRepository dataRepository) {
|
||||||
// preparing the proper data
|
|
||||||
float wDelta = 1.0f / width, hDelta = 1.0f / height, dDelta = 1.0f / depth;
|
|
||||||
float[] texvec = new float[] { 0, 0, 0 };
|
float[] texvec = new float[] { 0, 0, 0 };
|
||||||
TexResult texres = new TexResult();
|
TextureResult texres = new TextureResult();
|
||||||
|
|
||||||
// reading the data from the texture structure
|
// reading the data from the texture structure
|
||||||
float noisesize = ((Number) tex.getFieldValue("noisesize")).floatValue();
|
float noisesize = ((Number) tex.getFieldValue("noisesize")).floatValue();
|
||||||
int noiseDepth = ((Number) tex.getFieldValue("noisedepth")).intValue();
|
int noiseDepth = ((Number) tex.getFieldValue("noisedepth")).intValue();
|
||||||
int noiseBasis = ((Number) tex.getFieldValue("noisebasis")).intValue();
|
int noiseBasis = ((Number) tex.getFieldValue("noisebasis")).intValue();
|
||||||
int noiseType = ((Number) tex.getFieldValue("noisetype")).intValue();
|
int noiseType = ((Number) tex.getFieldValue("noisetype")).intValue();
|
||||||
float contrast = ((Number) tex.getFieldValue("contrast")).floatValue();
|
boolean isHard = noiseType != TEX_NOISESOFT;
|
||||||
float bright = ((Number) tex.getFieldValue("bright")).floatValue();
|
|
||||||
boolean isHard = noiseType != NoiseGenerator.TEX_NOISESOFT;
|
|
||||||
int sType = ((Number) tex.getFieldValue("stype")).intValue();
|
int sType = ((Number) tex.getFieldValue("stype")).intValue();
|
||||||
int halfW = width, halfH = height, halfD = depth;
|
int halfW = width >> 1, halfH = height >> 1, halfD = depth >> 1, index = 0;
|
||||||
width <<= 1;
|
float wDelta = 1.0f / halfW, hDelta = 1.0f / halfH, dDelta = 1.0f / halfD;
|
||||||
height <<= 1;
|
float[][] colorBand = this.computeColorband(tex, dataRepository);
|
||||||
depth <<= 1;
|
Format format = sType == TEX_COLOR || colorBand != null ? Format.RGB8 : Format.Luminance8;
|
||||||
ColorBand colorBand = this.readColorband(tex, dataRepository);
|
int bytesPerPixel = sType == TEX_COLOR || colorBand != null ? 3 : 1;
|
||||||
Format format = sType == NoiseGenerator.TEX_COLOR || colorBand != null ? Format.RGB8 : Format.Luminance8;
|
BrightnessAndContrastData bacd = new BrightnessAndContrastData(tex);
|
||||||
int bytesPerPixel = sType == NoiseGenerator.TEX_COLOR || colorBand != null ? 3 : 1;
|
|
||||||
|
|
||||||
ByteBuffer data = BufferUtils.createByteBuffer(width * height * depth * bytesPerPixel);
|
byte[] data = new byte[width * height * depth * bytesPerPixel];
|
||||||
for (int i = -halfW; i < halfW; ++i) {
|
for (int i = -halfW; i < halfW; ++i) {
|
||||||
texvec[0] = wDelta * i;
|
texvec[0] = wDelta * i;
|
||||||
for (int j = -halfH; j < halfH; ++j) {
|
for (int j = -halfH; j < halfH; ++j) {
|
||||||
texvec[1] = hDelta * j;
|
texvec[1] = hDelta * j;
|
||||||
for (int k = -halfD; k < halfD; ++k) {
|
for (int k = -halfD; k < halfD; ++k) {
|
||||||
texvec[2] = dDelta * k;
|
texvec[2] = dDelta * k;
|
||||||
texres.tin = noiseGenerator.bliGTurbulence(noisesize, texvec[0], texvec[1], texvec[2], noiseDepth, isHard, noiseBasis);
|
texres.intensity = NoiseGenerator.NoiseFunctions.turbulence(texvec[0], texvec[1], texvec[2], noisesize, noiseDepth, noiseBasis, isHard);
|
||||||
|
texres.intensity = FastMath.clamp(texres.intensity, 0.0f, 1.0f);
|
||||||
if (colorBand != null) {
|
if (colorBand != null) {
|
||||||
noiseGenerator.doColorband(colorBand, texres, dataRepository);
|
int colorbandIndex = (int) (texres.intensity * 1000.0f);
|
||||||
if (texres.nor != null) {
|
texres.red = colorBand[colorbandIndex][0];
|
||||||
float nabla = ((Number) tex.getFieldValue("nabla")).floatValue();
|
texres.green = colorBand[colorbandIndex][1];
|
||||||
// calculate bumpnormal
|
texres.blue = colorBand[colorbandIndex][2];
|
||||||
texres.nor[0] = noiseGenerator.bliGTurbulence(noisesize, texvec[0] + nabla, texvec[1], texvec[2], noiseDepth, isHard, noiseBasis);
|
|
||||||
texres.nor[1] = noiseGenerator.bliGTurbulence(noisesize, texvec[0], texvec[1] + nabla, texvec[2], noiseDepth, isHard, noiseBasis);
|
this.applyBrightnessAndContrast(bacd, texres);
|
||||||
texres.nor[2] = noiseGenerator.bliGTurbulence(noisesize, texvec[0], texvec[1], texvec[2] + nabla, noiseDepth, isHard, noiseBasis);
|
data[index++] = (byte) (texres.red * 255.0f);
|
||||||
noiseGenerator.texNormalDerivate(colorBand, texres, dataRepository);
|
data[index++] = (byte) (texres.green * 255.0f);
|
||||||
}
|
data[index++] = (byte) (texres.blue * 255.0f);
|
||||||
noiseGenerator.brightnesAndContrastRGB(tex, texres);
|
} else if (sType == TEX_COLOR) {
|
||||||
data.put((byte) (texres.tr * 255.0f));
|
texres.red = texres.intensity;
|
||||||
data.put((byte) (texres.tg * 255.0f));
|
texres.green = NoiseGenerator.NoiseFunctions.turbulence(texvec[1], texvec[0], texvec[2], noisesize, noiseDepth, noiseBasis, isHard);
|
||||||
data.put((byte) (texres.tb * 255.0f));
|
texres.blue = NoiseGenerator.NoiseFunctions.turbulence(texvec[1], texvec[2], texvec[0], noisesize, noiseDepth, noiseBasis, isHard);
|
||||||
} else if (sType == NoiseGenerator.TEX_COLOR) {
|
|
||||||
// in this case, int. value should really be computed from color,
|
texres.green = FastMath.clamp(texres.green, 0.0f, 1.0f);
|
||||||
// and bumpnormal from that, would be too slow, looks ok as is
|
texres.blue = FastMath.clamp(texres.blue, 0.0f, 1.0f);
|
||||||
texres.tr = texres.tin;
|
|
||||||
texres.tg = noiseGenerator.bliGTurbulence(noisesize, texvec[1], texvec[0], texvec[2], noiseDepth, isHard, noiseBasis);
|
this.applyBrightnessAndContrast(bacd, texres);
|
||||||
texres.tb = noiseGenerator.bliGTurbulence(noisesize, texvec[1], texvec[2], texvec[0], noiseDepth, isHard, noiseBasis);
|
data[index++] = (byte) (texres.red * 255.0f);
|
||||||
noiseGenerator.brightnesAndContrastRGB(tex, texres);
|
data[index++] = (byte) (texres.green * 255.0f);
|
||||||
data.put((byte) (texres.tr * 255.0f));
|
data[index++] = (byte) (texres.blue * 255.0f);
|
||||||
data.put((byte) (texres.tg * 255.0f));
|
|
||||||
data.put((byte) (texres.tb * 255.0f));
|
|
||||||
} else {
|
} else {
|
||||||
noiseGenerator.brightnesAndContrast(texres, contrast, bright);
|
this.applyBrightnessAndContrast(texres, bacd.contrast, bacd.brightness);
|
||||||
data.put((byte) (texres.tin * 255));
|
data[index++] = (byte) (texres.intensity * 255.0f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ArrayList<ByteBuffer> dataArray = new ArrayList<ByteBuffer>(1);
|
ArrayList<ByteBuffer> dataArray = new ArrayList<ByteBuffer>(1);
|
||||||
dataArray.add(data);
|
dataArray.add(BufferUtils.createByteBuffer(data));
|
||||||
return new Texture3D(new Image(format, width, height, depth, dataArray));
|
return new Texture3D(new Image(format, width, height, depth, dataArray));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,32 +1,33 @@
|
|||||||
/*
|
/*
|
||||||
*
|
* Copyright (c) 2009-2010 jMonkeyEngine
|
||||||
* $Id: noise.c 14611 2008-04-29 08:24:33Z campbellbarton $
|
|
||||||
*
|
|
||||||
* ***** BEGIN GPL LICENSE BLOCK *****
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or
|
|
||||||
* modify it under the terms of the GNU General Public License
|
|
||||||
* as published by the Free Software Foundation; either version 2
|
|
||||||
* of the License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program; if not, write to the Free Software Foundation,
|
|
||||||
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
||||||
*
|
|
||||||
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* The Original Code is: all of this file.
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are
|
||||||
|
* met:
|
||||||
*
|
*
|
||||||
* Contributor(s): none yet.
|
* * Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
*
|
*
|
||||||
* ***** END GPL LICENSE BLOCK *****
|
* * Redistributions 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 'jMonkeyEngine' nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||||
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||||
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||||
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||||
|
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||||
|
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||||
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
package com.jme3.scene.plugins.blender.textures;
|
package com.jme3.scene.plugins.blender.textures;
|
||||||
|
|
||||||
@ -35,8 +36,7 @@ import java.util.ArrayList;
|
|||||||
|
|
||||||
import com.jme3.scene.plugins.blender.DataRepository;
|
import com.jme3.scene.plugins.blender.DataRepository;
|
||||||
import com.jme3.scene.plugins.blender.file.Structure;
|
import com.jme3.scene.plugins.blender.file.Structure;
|
||||||
import com.jme3.scene.plugins.blender.textures.TextureHelper.ColorBand;
|
import com.jme3.scene.plugins.blender.textures.NoiseGenerator.NoiseFunction;
|
||||||
import com.jme3.scene.plugins.blender.textures.TextureHelper.TexResult;
|
|
||||||
import com.jme3.texture.Image;
|
import com.jme3.texture.Image;
|
||||||
import com.jme3.texture.Image.Format;
|
import com.jme3.texture.Image.Format;
|
||||||
import com.jme3.texture.Texture;
|
import com.jme3.texture.Texture;
|
||||||
@ -61,56 +61,73 @@ public class TextureGeneratorDistnoise extends TextureGenerator {
|
|||||||
@Override
|
@Override
|
||||||
protected Texture generate(Structure tex, int width, int height, int depth, DataRepository dataRepository) {
|
protected Texture generate(Structure tex, int width, int height, int depth, DataRepository dataRepository) {
|
||||||
float noisesize = ((Number) tex.getFieldValue("noisesize")).floatValue();
|
float noisesize = ((Number) tex.getFieldValue("noisesize")).floatValue();
|
||||||
float nabla = ((Number) tex.getFieldValue("nabla")).floatValue();
|
|
||||||
float distAmount = ((Number) tex.getFieldValue("dist_amount")).floatValue();
|
float distAmount = ((Number) tex.getFieldValue("dist_amount")).floatValue();
|
||||||
int noisebasis = ((Number) tex.getFieldValue("noisebasis")).intValue();
|
int noisebasis = ((Number) tex.getFieldValue("noisebasis")).intValue();
|
||||||
int noisebasis2 = ((Number) tex.getFieldValue("noisebasis2")).intValue();
|
int noisebasis2 = ((Number) tex.getFieldValue("noisebasis2")).intValue();
|
||||||
float contrast = ((Number) tex.getFieldValue("contrast")).floatValue();
|
|
||||||
float brightness = ((Number) tex.getFieldValue("bright")).floatValue();
|
|
||||||
|
|
||||||
TexResult texres = new TexResult();
|
TextureResult texres = new TextureResult();
|
||||||
float[] texvec = new float[] { 0, 0, 0 };
|
float[] texvec = new float[] { 0, 0, 0 };
|
||||||
float wDelta = 1.0f / width, hDelta = 1.0f / height, dDelta = 1.0f / depth;
|
int halfW = width >> 1, halfH = height >> 1, halfD = depth >> 1, index = 0;
|
||||||
int halfW = width, halfH = height, halfD = depth;
|
float wDelta = 1.0f / halfW, hDelta = 1.0f / halfH, dDelta = 1.0f / halfD;
|
||||||
width <<= 1;
|
float[][] colorBand = this.computeColorband(tex, dataRepository);
|
||||||
height <<= 1;
|
|
||||||
depth <<= 1;
|
|
||||||
ColorBand colorBand = this.readColorband(tex, dataRepository);
|
|
||||||
Format format = colorBand != null ? Format.RGB8 : Format.Luminance8;
|
Format format = colorBand != null ? Format.RGB8 : Format.Luminance8;
|
||||||
int bytesPerPixel = colorBand != null ? 3 : 1;
|
int bytesPerPixel = colorBand != null ? 3 : 1;
|
||||||
|
BrightnessAndContrastData bacd = new BrightnessAndContrastData(tex);
|
||||||
|
|
||||||
ByteBuffer data = BufferUtils.createByteBuffer(width * height * depth * bytesPerPixel);
|
byte[] data = new byte[width * height * depth * bytesPerPixel];
|
||||||
for (int i = -halfW; i < halfW; ++i) {
|
for (int i = -halfW; i < halfW; ++i) {
|
||||||
texvec[0] = wDelta * i / noisesize;
|
texvec[0] = wDelta * i / noisesize;
|
||||||
for (int j = -halfH; j < halfH; ++j) {
|
for (int j = -halfH; j < halfH; ++j) {
|
||||||
texvec[1] = hDelta * j / noisesize;
|
texvec[1] = hDelta * j / noisesize;
|
||||||
for (int k = -halfD; k < halfD; ++k) {
|
for (int k = -halfD; k < halfD; ++k) {
|
||||||
texvec[2] = dDelta * k;// z
|
texvec[2] = dDelta * k;
|
||||||
texres.tin = noiseGenerator.mgVLNoise(texvec[0], texvec[1], texvec[2], distAmount, noisebasis, noisebasis2);
|
texres.intensity = this.musgraveVariableLunacrityNoise(texvec[0], texvec[1], texvec[2], distAmount, noisebasis, noisebasis2);
|
||||||
if (colorBand != null) {
|
if (colorBand != null) {
|
||||||
noiseGenerator.doColorband(colorBand, texres, dataRepository);
|
int colorbandIndex = (int) (texres.intensity * 1000.0f);
|
||||||
if (texres.nor != null) {
|
texres.red = colorBand[colorbandIndex][0];
|
||||||
float offs = nabla / noisesize; // also scaling of texvec
|
texres.green = colorBand[colorbandIndex][1];
|
||||||
/* calculate bumpnormal */
|
texres.blue = colorBand[colorbandIndex][2];
|
||||||
texres.nor[0] = noiseGenerator.mgVLNoise(texvec[0] + offs, texvec[1], texvec[2], distAmount, noisebasis, noisebasis2);
|
|
||||||
texres.nor[1] = noiseGenerator.mgVLNoise(texvec[0], texvec[1] + offs, texvec[2], distAmount, noisebasis, noisebasis2);
|
|
||||||
texres.nor[2] = noiseGenerator.mgVLNoise(texvec[0], texvec[1], texvec[2] + offs, distAmount, noisebasis, noisebasis2);
|
|
||||||
noiseGenerator.texNormalDerivate(colorBand, texres, dataRepository);
|
|
||||||
}
|
|
||||||
|
|
||||||
noiseGenerator.brightnesAndContrastRGB(tex, texres);
|
this.applyBrightnessAndContrast(bacd, texres);
|
||||||
data.put((byte) (texres.tr * 255.0f));
|
data[index++] = (byte) (texres.red * 255.0f);
|
||||||
data.put((byte) (texres.tg * 255.0f));
|
data[index++] = (byte) (texres.green * 255.0f);
|
||||||
data.put((byte) (texres.tb * 255.0f));
|
data[index++] = (byte) (texres.blue * 255.0f);
|
||||||
} else {
|
} else {
|
||||||
noiseGenerator.brightnesAndContrast(texres, contrast, brightness);
|
this.applyBrightnessAndContrast(texres, bacd.contrast, bacd.brightness);
|
||||||
data.put((byte) (texres.tin * 255.0f));
|
data[index++] = (byte) (texres.intensity * 255.0f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ArrayList<ByteBuffer> dataArray = new ArrayList<ByteBuffer>(1);
|
ArrayList<ByteBuffer> dataArray = new ArrayList<ByteBuffer>(1);
|
||||||
dataArray.add(data);
|
dataArray.add(BufferUtils.createByteBuffer(data));
|
||||||
return new Texture3D(new Image(format, width, height, depth, dataArray));
|
return new Texture3D(new Image(format, width, height, depth, dataArray));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* "Variable Lacunarity Noise" A distorted variety of Perlin noise. This method is used to calculate distorted noise
|
||||||
|
* texture.
|
||||||
|
* @param x
|
||||||
|
* @param y
|
||||||
|
* @param z
|
||||||
|
* @param distortion
|
||||||
|
* @param nbas1
|
||||||
|
* @param nbas2
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private float musgraveVariableLunacrityNoise(float x, float y, float z, float distortion, int nbas1, int nbas2) {
|
||||||
|
NoiseFunction abstractNoiseFunc1 = NoiseGenerator.noiseFunctions.get(Integer.valueOf(nbas1));
|
||||||
|
if (abstractNoiseFunc1 == null) {
|
||||||
|
abstractNoiseFunc1 = NoiseGenerator.noiseFunctions.get(Integer.valueOf(0));
|
||||||
|
}
|
||||||
|
NoiseFunction abstractNoiseFunc2 = NoiseGenerator.noiseFunctions.get(Integer.valueOf(nbas2));
|
||||||
|
if (abstractNoiseFunc2 == null) {
|
||||||
|
abstractNoiseFunc2 = NoiseGenerator.noiseFunctions.get(Integer.valueOf(0));
|
||||||
|
}
|
||||||
|
// get a random vector and scale the randomization
|
||||||
|
float rx = abstractNoiseFunc1.execute(x + 13.5f, y + 13.5f, z + 13.5f) * distortion;
|
||||||
|
float ry = abstractNoiseFunc1.execute(x, y, z) * distortion;
|
||||||
|
float rz = abstractNoiseFunc1.execute(x - 13.5f, y - 13.5f, z - 13.5f) * distortion;
|
||||||
|
return abstractNoiseFunc2.executeSigned(x + rx, y + ry, z + rz); //distorted-domain noise
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,32 +1,33 @@
|
|||||||
/*
|
/*
|
||||||
*
|
* Copyright (c) 2009-2010 jMonkeyEngine
|
||||||
* $Id: noise.c 14611 2008-04-29 08:24:33Z campbellbarton $
|
|
||||||
*
|
|
||||||
* ***** BEGIN GPL LICENSE BLOCK *****
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or
|
|
||||||
* modify it under the terms of the GNU General Public License
|
|
||||||
* as published by the Free Software Foundation; either version 2
|
|
||||||
* of the License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program; if not, write to the Free Software Foundation,
|
|
||||||
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
||||||
*
|
|
||||||
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* The Original Code is: all of this file.
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are
|
||||||
|
* met:
|
||||||
*
|
*
|
||||||
* Contributor(s): none yet.
|
* * Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
*
|
*
|
||||||
* ***** END GPL LICENSE BLOCK *****
|
* * Redistributions 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 'jMonkeyEngine' nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||||
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||||
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||||
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||||
|
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||||
|
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||||
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
package com.jme3.scene.plugins.blender.textures;
|
package com.jme3.scene.plugins.blender.textures;
|
||||||
|
|
||||||
@ -35,8 +36,6 @@ import java.util.ArrayList;
|
|||||||
|
|
||||||
import com.jme3.scene.plugins.blender.DataRepository;
|
import com.jme3.scene.plugins.blender.DataRepository;
|
||||||
import com.jme3.scene.plugins.blender.file.Structure;
|
import com.jme3.scene.plugins.blender.file.Structure;
|
||||||
import com.jme3.scene.plugins.blender.textures.TextureHelper.ColorBand;
|
|
||||||
import com.jme3.scene.plugins.blender.textures.TextureHelper.TexResult;
|
|
||||||
import com.jme3.texture.Image;
|
import com.jme3.texture.Image;
|
||||||
import com.jme3.texture.Image.Format;
|
import com.jme3.texture.Image.Format;
|
||||||
import com.jme3.texture.Texture;
|
import com.jme3.texture.Texture;
|
||||||
@ -48,6 +47,69 @@ import com.jme3.util.BufferUtils;
|
|||||||
* @author Marcin Roguski (Kaelthas)
|
* @author Marcin Roguski (Kaelthas)
|
||||||
*/
|
*/
|
||||||
public class TextureGeneratorMagic extends TextureGenerator {
|
public class TextureGeneratorMagic extends TextureGenerator {
|
||||||
|
private static NoiseDepthFunction[] noiseDepthFunctions = new NoiseDepthFunction[10];
|
||||||
|
static {
|
||||||
|
noiseDepthFunctions[0] = new NoiseDepthFunction() {
|
||||||
|
@Override
|
||||||
|
public void compute(float[] xyz, float turbulence) {
|
||||||
|
xyz[1] = -(float) Math.cos(xyz[0] - xyz[1] + xyz[2]) * turbulence;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
noiseDepthFunctions[1] = new NoiseDepthFunction() {
|
||||||
|
@Override
|
||||||
|
public void compute(float[] xyz, float turbulence) {
|
||||||
|
xyz[0] = (float) Math.cos(xyz[0] - xyz[1] - xyz[2]) * turbulence;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
noiseDepthFunctions[2] = new NoiseDepthFunction() {
|
||||||
|
@Override
|
||||||
|
public void compute(float[] xyz, float turbulence) {
|
||||||
|
xyz[2] = (float) Math.sin(-xyz[0] - xyz[1] - xyz[2]) * turbulence;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
noiseDepthFunctions[3] = new NoiseDepthFunction() {
|
||||||
|
@Override
|
||||||
|
public void compute(float[] xyz, float turbulence) {
|
||||||
|
xyz[0] = -(float) Math.cos(-xyz[0] + xyz[1] - xyz[2]) * turbulence;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
noiseDepthFunctions[4] = new NoiseDepthFunction() {
|
||||||
|
@Override
|
||||||
|
public void compute(float[] xyz, float turbulence) {
|
||||||
|
xyz[1] = -(float) Math.sin(-xyz[0] + xyz[1] + xyz[2]) * turbulence;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
noiseDepthFunctions[5] = new NoiseDepthFunction() {
|
||||||
|
@Override
|
||||||
|
public void compute(float[] xyz, float turbulence) {
|
||||||
|
xyz[1] = -(float) Math.cos(-xyz[0] + xyz[1] + xyz[2]) * turbulence;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
noiseDepthFunctions[6] = new NoiseDepthFunction() {
|
||||||
|
@Override
|
||||||
|
public void compute(float[] xyz, float turbulence) {
|
||||||
|
xyz[0] = (float) Math.cos(xyz[0] + xyz[1] + xyz[2]) * turbulence;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
noiseDepthFunctions[7] = new NoiseDepthFunction() {
|
||||||
|
@Override
|
||||||
|
public void compute(float[] xyz, float turbulence) {
|
||||||
|
xyz[2] = (float) Math.sin(xyz[0] + xyz[1] - xyz[2]) * turbulence;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
noiseDepthFunctions[8] = new NoiseDepthFunction() {
|
||||||
|
@Override
|
||||||
|
public void compute(float[] xyz, float turbulence) {
|
||||||
|
xyz[0] = -(float) Math.cos(-xyz[0] - xyz[1] + xyz[2]) * turbulence;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
noiseDepthFunctions[9] = new NoiseDepthFunction() {
|
||||||
|
@Override
|
||||||
|
public void compute(float[] xyz, float turbulence) {
|
||||||
|
xyz[1] = -(float) Math.sin(xyz[0] - xyz[1] + xyz[2]) * turbulence;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor stores the given noise generator.
|
* Constructor stores the given noise generator.
|
||||||
@ -60,88 +122,67 @@ public class TextureGeneratorMagic extends TextureGenerator {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Texture generate(Structure tex, int width, int height, int depth, DataRepository dataRepository) {
|
protected Texture generate(Structure tex, int width, int height, int depth, DataRepository dataRepository) {
|
||||||
float x, y, z, turb;
|
float xyz[] = new float[3], turb;
|
||||||
int noisedepth = ((Number) tex.getFieldValue("noisedepth")).intValue();
|
int noisedepth = ((Number) tex.getFieldValue("noisedepth")).intValue();
|
||||||
float turbul = ((Number) tex.getFieldValue("turbul")).floatValue() / 5.0f;
|
float turbul = ((Number) tex.getFieldValue("turbul")).floatValue() / 5.0f;
|
||||||
float[] texvec = new float[] { 0, 0, 0 };
|
float[] texvec = new float[] { 0, 0, 0 };
|
||||||
TexResult texres = new TexResult();
|
TextureResult texres = new TextureResult();
|
||||||
float wDelta = 1.0f / width, hDelta = 1.0f / height, dDelta = 1.0f / depth;
|
int halfW = width >> 1, halfH = height >> 1, halfD = depth >> 1, index = 0;
|
||||||
int halfW = width, halfH = height, halfD = depth;
|
float wDelta = 1.0f / halfW, hDelta = 1.0f / halfH, dDelta = 1.0f / halfD;
|
||||||
width <<= 1;
|
float[][] colorBand = this.computeColorband(tex, dataRepository);
|
||||||
height <<= 1;
|
BrightnessAndContrastData bacd = new BrightnessAndContrastData(tex);
|
||||||
depth <<= 1;
|
|
||||||
ColorBand colorBand = this.readColorband(tex, dataRepository);
|
|
||||||
|
|
||||||
ByteBuffer data = BufferUtils.createByteBuffer(width * height * depth * 4);
|
byte[] data = new byte[width * height * depth * 3];
|
||||||
for (int i = -halfW; i < halfW; ++i) {
|
for (int i = -halfW; i < halfW; ++i) {
|
||||||
texvec[0] = wDelta * i;
|
texvec[0] = wDelta * i;
|
||||||
for (int j = -halfH; j < halfH; ++j) {
|
for (int j = -halfH; j < halfH; ++j) {
|
||||||
texvec[1] = hDelta * j;
|
texvec[1] = hDelta * j;
|
||||||
for (int k = -halfD; k < halfD; ++k) {
|
for (int k = -halfD; k < halfD; ++k) {
|
||||||
turb = turbul;
|
turb = turbul;
|
||||||
texvec[2] = dDelta * k;// z
|
texvec[2] = dDelta * k;
|
||||||
x = (float) Math.sin((texvec[0] + texvec[1] + texvec[2]) * 5.0f);
|
xyz[0] = (float) Math.sin((texvec[0] + texvec[1] + texvec[2]) * 5.0f);
|
||||||
y = (float) Math.cos((-texvec[0] + texvec[1] - texvec[2]) * 5.0f);
|
xyz[1] = (float) Math.cos((-texvec[0] + texvec[1] - texvec[2]) * 5.0f);
|
||||||
z = -(float) Math.cos((-texvec[0] - texvec[1] + texvec[2]) * 5.0f);
|
xyz[2] = -(float) Math.cos((-texvec[0] - texvec[1] + texvec[2]) * 5.0f);
|
||||||
|
|
||||||
if (colorBand != null) {
|
if (colorBand != null) {
|
||||||
texres.tin = 0.3333f * (x + y + z);
|
texres.intensity = 0.3333f * (xyz[0] + xyz[1] + xyz[2]);
|
||||||
noiseGenerator.doColorband(colorBand, texres, dataRepository);
|
int colorbandIndex = (int) (texres.intensity * 1000.0f);
|
||||||
|
texres.red = colorBand[colorbandIndex][0];
|
||||||
|
texres.green = colorBand[colorbandIndex][1];
|
||||||
|
texres.blue = colorBand[colorbandIndex][2];
|
||||||
} else {
|
} else {
|
||||||
if (noisedepth > 0) {
|
if (noisedepth > 0) {
|
||||||
x *= turb;
|
xyz[0] *= turb;
|
||||||
y *= turb;
|
xyz[1] *= turb;
|
||||||
z *= turb;
|
xyz[2] *= turb;
|
||||||
y = -(float) Math.cos(x - y + z) * turb;
|
for (int m=0;m<noisedepth;++m) {
|
||||||
if (noisedepth > 1) {
|
noiseDepthFunctions[m].compute(xyz, turb);
|
||||||
x = (float) Math.cos(x - y - z) * turb;
|
|
||||||
if (noisedepth > 2) {
|
|
||||||
z = (float) Math.sin(-x - y - z) * turb;
|
|
||||||
if (noisedepth > 3) {
|
|
||||||
x = -(float) Math.cos(-x + y - z) * turb;
|
|
||||||
if (noisedepth > 4) {
|
|
||||||
y = -(float) Math.sin(-x + y + z) * turb;
|
|
||||||
if (noisedepth > 5) {
|
|
||||||
y = -(float) Math.cos(-x + y + z) * turb;
|
|
||||||
if (noisedepth > 6) {
|
|
||||||
x = (float) Math.cos(x + y + z) * turb;
|
|
||||||
if (noisedepth > 7) {
|
|
||||||
z = (float) Math.sin(x + y - z) * turb;
|
|
||||||
if (noisedepth > 8) {
|
|
||||||
x = -(float) Math.cos(-x - y + z) * turb;
|
|
||||||
if (noisedepth > 9) {
|
|
||||||
y = -(float) Math.sin(x - y + z) * turb;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (turb != 0.0f) {
|
if (turb != 0.0f) {
|
||||||
turb *= 2.0f;
|
turb *= 2.0f;
|
||||||
x /= turb;
|
xyz[0] /= turb;
|
||||||
y /= turb;
|
xyz[1] /= turb;
|
||||||
z /= turb;
|
xyz[2] /= turb;
|
||||||
}
|
}
|
||||||
texres.tr = 0.5f - x;
|
texres.red = 0.5f - xyz[0];
|
||||||
texres.tg = 0.5f - y;
|
texres.green = 0.5f - xyz[1];
|
||||||
texres.tb = 0.5f - z;
|
texres.blue = 0.5f - xyz[2];
|
||||||
}
|
}
|
||||||
noiseGenerator.brightnesAndContrastRGB(tex, texres);
|
this.applyBrightnessAndContrast(bacd, texres);
|
||||||
data.put((byte) (texres.tin * 255));
|
data[index++] = (byte) (texres.red * 255.0f);
|
||||||
data.put((byte) (texres.tb * 255));
|
data[index++] = (byte) (texres.green * 255.0f);
|
||||||
data.put((byte) (texres.tg * 255));
|
data[index++] = (byte) (texres.blue * 255.0f);
|
||||||
data.put((byte) (texres.tr * 255));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ArrayList<ByteBuffer> dataArray = new ArrayList<ByteBuffer>(1);
|
ArrayList<ByteBuffer> dataArray = new ArrayList<ByteBuffer>(1);
|
||||||
dataArray.add(data);
|
dataArray.add(BufferUtils.createByteBuffer(data));
|
||||||
return new Texture3D(new Image(Format.ABGR8, width, height, depth, dataArray));
|
return new Texture3D(new Image(Format.RGB8, width, height, depth, dataArray));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static interface NoiseDepthFunction {
|
||||||
|
void compute(float[] xyz, float turbulence);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,32 +1,33 @@
|
|||||||
/*
|
/*
|
||||||
*
|
* Copyright (c) 2009-2010 jMonkeyEngine
|
||||||
* $Id: noise.c 14611 2008-04-29 08:24:33Z campbellbarton $
|
|
||||||
*
|
|
||||||
* ***** BEGIN GPL LICENSE BLOCK *****
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or
|
|
||||||
* modify it under the terms of the GNU General Public License
|
|
||||||
* as published by the Free Software Foundation; either version 2
|
|
||||||
* of the License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program; if not, write to the Free Software Foundation,
|
|
||||||
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
||||||
*
|
|
||||||
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* The Original Code is: all of this file.
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are
|
||||||
|
* met:
|
||||||
*
|
*
|
||||||
* Contributor(s): none yet.
|
* * Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
*
|
*
|
||||||
* ***** END GPL LICENSE BLOCK *****
|
* * Redistributions 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 'jMonkeyEngine' nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||||
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||||
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||||
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||||
|
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||||
|
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||||
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
package com.jme3.scene.plugins.blender.textures;
|
package com.jme3.scene.plugins.blender.textures;
|
||||||
|
|
||||||
@ -35,8 +36,6 @@ import java.util.ArrayList;
|
|||||||
|
|
||||||
import com.jme3.scene.plugins.blender.DataRepository;
|
import com.jme3.scene.plugins.blender.DataRepository;
|
||||||
import com.jme3.scene.plugins.blender.file.Structure;
|
import com.jme3.scene.plugins.blender.file.Structure;
|
||||||
import com.jme3.scene.plugins.blender.textures.TextureHelper.ColorBand;
|
|
||||||
import com.jme3.scene.plugins.blender.textures.TextureHelper.TexResult;
|
|
||||||
import com.jme3.texture.Image;
|
import com.jme3.texture.Image;
|
||||||
import com.jme3.texture.Image.Format;
|
import com.jme3.texture.Image.Format;
|
||||||
import com.jme3.texture.Texture;
|
import com.jme3.texture.Texture;
|
||||||
@ -47,7 +46,11 @@ import com.jme3.util.BufferUtils;
|
|||||||
* This class generates the 'marble' texture.
|
* This class generates the 'marble' texture.
|
||||||
* @author Marcin Roguski (Kaelthas)
|
* @author Marcin Roguski (Kaelthas)
|
||||||
*/
|
*/
|
||||||
public class TextureGeneratorMarble extends TextureGenerator {
|
public class TextureGeneratorMarble extends TextureGeneratorWood {
|
||||||
|
// tex->stype
|
||||||
|
protected static final int TEX_SOFT = 0;
|
||||||
|
protected static final int TEX_SHARP = 1;
|
||||||
|
protected static final int TEX_SHARPER = 2;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor stores the given noise generator.
|
* Constructor stores the given noise generator.
|
||||||
@ -60,51 +63,86 @@ public class TextureGeneratorMarble extends TextureGenerator {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Texture generate(Structure tex, int width, int height, int depth, DataRepository dataRepository) {
|
protected Texture generate(Structure tex, int width, int height, int depth, DataRepository dataRepository) {
|
||||||
// preparing the proper data
|
|
||||||
float contrast = ((Number) tex.getFieldValue("contrast")).floatValue();
|
|
||||||
float bright = ((Number) tex.getFieldValue("bright")).floatValue();
|
|
||||||
float nabla = ((Number) tex.getFieldValue("nabla")).floatValue();
|
|
||||||
float wDelta = 1.0f / width, hDelta = 1.0f / height, dDelta = 1.0f / depth;
|
|
||||||
float[] texvec = new float[] { 0, 0, 0 };
|
float[] texvec = new float[] { 0, 0, 0 };
|
||||||
TexResult texres = new TexResult();
|
TextureResult texres = new TextureResult();
|
||||||
int halfW = width, halfH = height, halfD = depth;
|
int halfW = width >> 1, halfH = height >> 1, halfD = depth >> 1, index = 0;
|
||||||
width <<= 1;
|
float wDelta = 1.0f / halfW, hDelta = 1.0f / halfH, dDelta = 1.0f / halfD;
|
||||||
height <<= 1;
|
float[][] colorBand = this.computeColorband(tex, dataRepository);
|
||||||
depth <<= 1;
|
|
||||||
ColorBand colorBand = this.readColorband(tex, dataRepository);
|
|
||||||
Format format = colorBand != null ? Format.RGB8 : Format.Luminance8;
|
Format format = colorBand != null ? Format.RGB8 : Format.Luminance8;
|
||||||
int bytesPerPixel = colorBand != null ? 3 : 1;
|
int bytesPerPixel = colorBand != null ? 3 : 1;
|
||||||
|
BrightnessAndContrastData bacd = new BrightnessAndContrastData(tex);
|
||||||
|
MarbleData marbleData = new MarbleData(tex);
|
||||||
|
|
||||||
ByteBuffer data = BufferUtils.createByteBuffer(width * height * depth * bytesPerPixel);
|
byte[] data = new byte[width * height * depth * bytesPerPixel];
|
||||||
for (int i = -halfW; i < halfW; ++i) {
|
for (int i = -halfW; i < halfW; ++i) {
|
||||||
texvec[0] = wDelta * i;
|
texvec[0] = wDelta * i;
|
||||||
for (int j = -halfH; j < halfH; ++j) {
|
for (int j = -halfH; j < halfH; ++j) {
|
||||||
texvec[1] = hDelta * j;
|
texvec[1] = hDelta * j;
|
||||||
for (int k = -halfD; k < halfD; ++k) {
|
for (int k = -halfD; k < halfD; ++k) {
|
||||||
texvec[2] = dDelta * k;
|
texvec[2] = dDelta * k;
|
||||||
texres.tin = noiseGenerator.marbleInt(tex, texvec[0], texvec[1], texvec[2], dataRepository);
|
texres.intensity = this.marbleInt(marbleData, texvec[0], texvec[1], texvec[2]);
|
||||||
if (colorBand != null) {
|
if (colorBand != null) {
|
||||||
noiseGenerator.doColorband(colorBand, texres, dataRepository);
|
int colorbandIndex = (int) (texres.intensity * 1000.0f);
|
||||||
if (texres.nor != null) {// calculate bumpnormal
|
texres.red = colorBand[colorbandIndex][0];
|
||||||
texres.nor[0] = noiseGenerator.marbleInt(tex, texvec[0] + nabla, texvec[1], texvec[2], dataRepository);
|
texres.green = colorBand[colorbandIndex][1];
|
||||||
texres.nor[1] = noiseGenerator.marbleInt(tex, texvec[0], texvec[1] + nabla, texvec[2], dataRepository);
|
texres.blue = colorBand[colorbandIndex][2];
|
||||||
texres.nor[2] = noiseGenerator.marbleInt(tex, texvec[0], texvec[1], texvec[2] + nabla, dataRepository);
|
|
||||||
noiseGenerator.texNormalDerivate(colorBand, texres, dataRepository);
|
|
||||||
}
|
|
||||||
|
|
||||||
noiseGenerator.brightnesAndContrastRGB(tex, texres);
|
this.applyBrightnessAndContrast(bacd, texres);
|
||||||
data.put((byte) (texres.tr * 255.0f));
|
data[index++] = (byte) (texres.red * 255.0f);
|
||||||
data.put((byte) (texres.tg * 255.0f));
|
data[index++] = (byte) (texres.green * 255.0f);
|
||||||
data.put((byte) (texres.tb * 255.0f));
|
data[index++] = (byte) (texres.blue * 255.0f);
|
||||||
} else {
|
} else {
|
||||||
noiseGenerator.brightnesAndContrast(texres, contrast, bright);
|
this.applyBrightnessAndContrast(texres, bacd.contrast, bacd.brightness);
|
||||||
data.put((byte) (texres.tin * 255.0f));
|
data[index++] = (byte) (texres.intensity * 255.0f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ArrayList<ByteBuffer> dataArray = new ArrayList<ByteBuffer>(1);
|
ArrayList<ByteBuffer> dataArray = new ArrayList<ByteBuffer>(1);
|
||||||
dataArray.add(data);
|
dataArray.add(BufferUtils.createByteBuffer(data));
|
||||||
return new Texture3D(new Image(format, width, height, depth, dataArray));
|
return new Texture3D(new Image(format, width, height, depth, dataArray));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public float marbleInt(MarbleData marbleData, float x, float y, float z) {
|
||||||
|
int waveform;
|
||||||
|
if (marbleData.waveform > TEX_TRI || marbleData.waveform < TEX_SIN) {
|
||||||
|
waveform = 0;
|
||||||
|
} else {
|
||||||
|
waveform = marbleData.waveform;
|
||||||
|
}
|
||||||
|
|
||||||
|
float n = 5.0f * (x + y + z);
|
||||||
|
float mi = n + marbleData.turbul * NoiseGenerator.NoiseFunctions.turbulence(x, y, z, marbleData.noisesize, marbleData.noisedepth, marbleData.noisebasis, marbleData.isHard);
|
||||||
|
|
||||||
|
if (marbleData.stype >= TEX_SOFT) {
|
||||||
|
mi = waveformFunctions[waveform].execute(mi);
|
||||||
|
if (marbleData.stype == TEX_SHARP) {
|
||||||
|
mi = (float) Math.sqrt(mi);
|
||||||
|
} else if (marbleData.stype == TEX_SHARPER) {
|
||||||
|
mi = (float) Math.sqrt(Math.sqrt(mi));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return mi;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class MarbleData {
|
||||||
|
public final float noisesize;
|
||||||
|
public final int noisebasis;
|
||||||
|
public final int noisedepth;
|
||||||
|
public final int stype;
|
||||||
|
public final float turbul;
|
||||||
|
public final int waveform;
|
||||||
|
public final boolean isHard;
|
||||||
|
|
||||||
|
public MarbleData(Structure tex) {
|
||||||
|
noisesize = ((Number) tex.getFieldValue("noisesize")).floatValue();
|
||||||
|
noisebasis = ((Number) tex.getFieldValue("noisebasis")).intValue();
|
||||||
|
noisedepth = ((Number) tex.getFieldValue("noisedepth")).intValue();
|
||||||
|
stype = ((Number) tex.getFieldValue("stype")).intValue();
|
||||||
|
turbul = ((Number) tex.getFieldValue("turbul")).floatValue();
|
||||||
|
int noisetype = ((Number) tex.getFieldValue("noisetype")).intValue();
|
||||||
|
waveform = ((Number) tex.getFieldValue("noisebasis2")).intValue();
|
||||||
|
isHard = noisetype != TEX_NOISESOFT;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,32 +1,33 @@
|
|||||||
/*
|
/*
|
||||||
*
|
* Copyright (c) 2009-2010 jMonkeyEngine
|
||||||
* $Id: noise.c 14611 2008-04-29 08:24:33Z campbellbarton $
|
|
||||||
*
|
|
||||||
* ***** BEGIN GPL LICENSE BLOCK *****
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or
|
|
||||||
* modify it under the terms of the GNU General Public License
|
|
||||||
* as published by the Free Software Foundation; either version 2
|
|
||||||
* of the License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program; if not, write to the Free Software Foundation,
|
|
||||||
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
||||||
*
|
|
||||||
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* The Original Code is: all of this file.
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are
|
||||||
|
* met:
|
||||||
*
|
*
|
||||||
* Contributor(s): none yet.
|
* * Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
*
|
*
|
||||||
* ***** END GPL LICENSE BLOCK *****
|
* * Redistributions 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 'jMonkeyEngine' nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||||
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||||
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||||
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||||
|
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||||
|
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||||
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
package com.jme3.scene.plugins.blender.textures;
|
package com.jme3.scene.plugins.blender.textures;
|
||||||
|
|
||||||
@ -35,8 +36,7 @@ import java.util.ArrayList;
|
|||||||
|
|
||||||
import com.jme3.scene.plugins.blender.DataRepository;
|
import com.jme3.scene.plugins.blender.DataRepository;
|
||||||
import com.jme3.scene.plugins.blender.file.Structure;
|
import com.jme3.scene.plugins.blender.file.Structure;
|
||||||
import com.jme3.scene.plugins.blender.textures.TextureHelper.ColorBand;
|
import com.jme3.scene.plugins.blender.textures.NoiseGenerator.MusgraveFunction;
|
||||||
import com.jme3.scene.plugins.blender.textures.TextureHelper.TexResult;
|
|
||||||
import com.jme3.texture.Image;
|
import com.jme3.texture.Image;
|
||||||
import com.jme3.texture.Image.Format;
|
import com.jme3.texture.Image.Format;
|
||||||
import com.jme3.texture.Texture;
|
import com.jme3.texture.Texture;
|
||||||
@ -62,52 +62,76 @@ public class TextureGeneratorMusgrave extends TextureGenerator {
|
|||||||
protected Texture generate(Structure tex, int width, int height, int depth, DataRepository dataRepository) {
|
protected Texture generate(Structure tex, int width, int height, int depth, DataRepository dataRepository) {
|
||||||
int stype = ((Number) tex.getFieldValue("stype")).intValue();
|
int stype = ((Number) tex.getFieldValue("stype")).intValue();
|
||||||
float noisesize = ((Number) tex.getFieldValue("noisesize")).floatValue();
|
float noisesize = ((Number) tex.getFieldValue("noisesize")).floatValue();
|
||||||
TexResult texres = new TexResult();
|
TextureResult texres = new TextureResult();
|
||||||
float[] texvec = new float[] { 0, 0, 0 };
|
float[] texvec = new float[] { 0, 0, 0 };
|
||||||
float wDelta = 1.0f / width, hDelta = 1.0f / height, dDelta = 1.0f / depth;
|
int halfW = width >> 1, halfH = height >> 1, halfD = depth >> 1, index = 0;
|
||||||
int halfW = width, halfH = height, halfD = depth;
|
float wDelta = 1.0f / halfW, hDelta = 1.0f / halfH, dDelta = 1.0f / halfD;
|
||||||
width <<= 1;
|
float[][] colorBand = this.computeColorband(tex, dataRepository);
|
||||||
height <<= 1;
|
|
||||||
depth <<= 1;
|
|
||||||
ColorBand colorBand = this.readColorband(tex, dataRepository);
|
|
||||||
Format format = colorBand != null ? Format.RGB8 : Format.Luminance8;
|
Format format = colorBand != null ? Format.RGB8 : Format.Luminance8;
|
||||||
int bytesPerPixel = colorBand != null ? 3 : 1;
|
int bytesPerPixel = colorBand != null ? 3 : 1;
|
||||||
|
MusgraveData musgraveData = new MusgraveData(tex);
|
||||||
|
MusgraveFunction musgraveFunction;
|
||||||
|
BrightnessAndContrastData bacd = new BrightnessAndContrastData(tex);
|
||||||
|
|
||||||
ByteBuffer data = BufferUtils.createByteBuffer(width * height * depth * bytesPerPixel);
|
byte[] data = new byte[width * height * depth * bytesPerPixel];
|
||||||
for (int i = -halfW; i < halfW; ++i) {
|
for (int i = -halfW; i < halfW; ++i) {
|
||||||
texvec[0] = wDelta * i / noisesize;
|
texvec[0] = wDelta * i / noisesize;
|
||||||
for (int j = -halfH; j < halfH; ++j) {
|
for (int j = -halfH; j < halfH; ++j) {
|
||||||
texvec[1] = hDelta * j / noisesize;
|
texvec[1] = hDelta * j / noisesize;
|
||||||
for (int k = -halfD; k < halfD; ++k) {
|
for (int k = -halfD; k < halfD; ++k) {
|
||||||
texvec[2] = dDelta * k / noisesize;
|
texvec[2] = dDelta * k / noisesize;
|
||||||
switch (stype) {
|
musgraveFunction = NoiseGenerator.musgraveFunctions.get(Integer.valueOf(musgraveData.stype));
|
||||||
case NoiseGenerator.TEX_MFRACTAL:
|
if(musgraveFunction==null) {
|
||||||
case NoiseGenerator.TEX_FBM:
|
|
||||||
noiseGenerator.mgMFractalOrfBmTex(tex, texvec, colorBand, texres, dataRepository);
|
|
||||||
break;
|
|
||||||
case NoiseGenerator.TEX_RIDGEDMF:
|
|
||||||
case NoiseGenerator.TEX_HYBRIDMF:
|
|
||||||
noiseGenerator.mgRidgedOrHybridMFTex(tex, texvec, colorBand, texres, dataRepository);
|
|
||||||
break;
|
|
||||||
case NoiseGenerator.TEX_HTERRAIN:
|
|
||||||
noiseGenerator.mgHTerrainTex(tex, texvec, colorBand, texres, dataRepository);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw new IllegalStateException("Unknown type of musgrave texture: " + stype);
|
throw new IllegalStateException("Unknown type of musgrave texture: " + stype);
|
||||||
}
|
}
|
||||||
|
texres.intensity = musgraveData.outscale * musgraveFunction.execute(musgraveData, texvec[0], texvec[1], texvec[2]);
|
||||||
|
if(texres.intensity>1) {
|
||||||
|
texres.intensity = 1.0f;
|
||||||
|
} else if(texres.intensity < 0) {
|
||||||
|
texres.intensity = 0.0f;
|
||||||
|
}
|
||||||
|
|
||||||
if (colorBand != null) {
|
if (colorBand != null) {
|
||||||
noiseGenerator.doColorband(colorBand, texres, dataRepository);
|
int colorbandIndex = (int) (texres.intensity * 1000.0f);
|
||||||
data.put((byte) (texres.tr * 255.0f));
|
texres.red = colorBand[colorbandIndex][0];
|
||||||
data.put((byte) (texres.tg * 255.0f));
|
texres.green = colorBand[colorbandIndex][1];
|
||||||
data.put((byte) (texres.tb * 255.0f));
|
texres.blue = colorBand[colorbandIndex][2];
|
||||||
|
|
||||||
|
this.applyBrightnessAndContrast(texres, bacd.contrast, bacd.brightness);
|
||||||
|
data[index++] = (byte) (texres.red * 255.0f);
|
||||||
|
data[index++] = (byte) (texres.green * 255.0f);
|
||||||
|
data[index++] = (byte) (texres.blue * 255.0f);
|
||||||
} else {
|
} else {
|
||||||
data.put((byte) (texres.tin * 255.0f));
|
this.applyBrightnessAndContrast(bacd, texres);
|
||||||
|
data[index++] = (byte) (texres.intensity * 255.0f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ArrayList<ByteBuffer> dataArray = new ArrayList<ByteBuffer>(1);
|
ArrayList<ByteBuffer> dataArray = new ArrayList<ByteBuffer>(1);
|
||||||
dataArray.add(data);
|
dataArray.add(BufferUtils.createByteBuffer(data));
|
||||||
return new Texture3D(new Image(format, width, height, depth, dataArray));
|
return new Texture3D(new Image(format, width, height, depth, dataArray));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected static class MusgraveData {
|
||||||
|
public final int stype;
|
||||||
|
public final float outscale;
|
||||||
|
public final float h;
|
||||||
|
public final float lacunarity;
|
||||||
|
public final float octaves;
|
||||||
|
public final int noisebasis;
|
||||||
|
public final float offset;
|
||||||
|
public final float gain;
|
||||||
|
|
||||||
|
public MusgraveData(Structure tex) {
|
||||||
|
stype = ((Number) tex.getFieldValue("stype")).intValue();
|
||||||
|
outscale = ((Number) tex.getFieldValue("ns_outscale")).floatValue();
|
||||||
|
h = ((Number) tex.getFieldValue("mg_H")).floatValue();
|
||||||
|
lacunarity = ((Number) tex.getFieldValue("mg_lacunarity")).floatValue();
|
||||||
|
octaves = ((Number) tex.getFieldValue("mg_octaves")).floatValue();
|
||||||
|
noisebasis = ((Number) tex.getFieldValue("noisebasis")).intValue();
|
||||||
|
offset = ((Number) tex.getFieldValue("mg_offset")).floatValue();
|
||||||
|
gain = ((Number) tex.getFieldValue("mg_gain")).floatValue();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,32 +1,33 @@
|
|||||||
/*
|
/*
|
||||||
*
|
* Copyright (c) 2009-2010 jMonkeyEngine
|
||||||
* $Id: noise.c 14611 2008-04-29 08:24:33Z campbellbarton $
|
|
||||||
*
|
|
||||||
* ***** BEGIN GPL LICENSE BLOCK *****
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or
|
|
||||||
* modify it under the terms of the GNU General Public License
|
|
||||||
* as published by the Free Software Foundation; either version 2
|
|
||||||
* of the License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program; if not, write to the Free Software Foundation,
|
|
||||||
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
||||||
*
|
|
||||||
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* The Original Code is: all of this file.
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are
|
||||||
|
* met:
|
||||||
*
|
*
|
||||||
* Contributor(s): none yet.
|
* * Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
*
|
*
|
||||||
* ***** END GPL LICENSE BLOCK *****
|
* * Redistributions 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 'jMonkeyEngine' nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||||
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||||
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||||
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||||
|
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||||
|
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||||
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
package com.jme3.scene.plugins.blender.textures;
|
package com.jme3.scene.plugins.blender.textures;
|
||||||
|
|
||||||
@ -36,8 +37,6 @@ import java.util.ArrayList;
|
|||||||
import com.jme3.math.FastMath;
|
import com.jme3.math.FastMath;
|
||||||
import com.jme3.scene.plugins.blender.DataRepository;
|
import com.jme3.scene.plugins.blender.DataRepository;
|
||||||
import com.jme3.scene.plugins.blender.file.Structure;
|
import com.jme3.scene.plugins.blender.file.Structure;
|
||||||
import com.jme3.scene.plugins.blender.textures.TextureHelper.ColorBand;
|
|
||||||
import com.jme3.scene.plugins.blender.textures.TextureHelper.TexResult;
|
|
||||||
import com.jme3.texture.Image;
|
import com.jme3.texture.Image;
|
||||||
import com.jme3.texture.Image.Format;
|
import com.jme3.texture.Image.Format;
|
||||||
import com.jme3.texture.Texture;
|
import com.jme3.texture.Texture;
|
||||||
@ -61,49 +60,47 @@ public class TextureGeneratorNoise extends TextureGenerator {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Texture generate(Structure tex, int width, int height, int depth, DataRepository dataRepository) {
|
protected Texture generate(Structure tex, int width, int height, int depth, DataRepository dataRepository) {
|
||||||
float div = 3.0f;
|
int val, random, loop;
|
||||||
int val, ran, loop;
|
|
||||||
int noisedepth = ((Number) tex.getFieldValue("noisedepth")).intValue();
|
int noisedepth = ((Number) tex.getFieldValue("noisedepth")).intValue();
|
||||||
float contrast = ((Number) tex.getFieldValue("contrast")).floatValue();
|
TextureResult texres = new TextureResult();
|
||||||
float brightness = ((Number) tex.getFieldValue("bright")).floatValue();
|
int halfW = width >> 1, halfH = height >> 1, halfD = depth >> 1, index = 0;
|
||||||
TexResult texres = new TexResult();
|
float[][] colorBand = this.computeColorband(tex, dataRepository);
|
||||||
int halfW = width, halfH = height, halfD = depth;
|
|
||||||
width <<= 1;
|
|
||||||
height <<= 1;
|
|
||||||
depth <<= 1;
|
|
||||||
ColorBand colorBand = this.readColorband(tex, dataRepository);
|
|
||||||
Format format = colorBand != null ? Format.RGB8 : Format.Luminance8;
|
Format format = colorBand != null ? Format.RGB8 : Format.Luminance8;
|
||||||
int bytesPerPixel = colorBand != null ? 3 : 1;
|
int bytesPerPixel = colorBand != null ? 3 : 1;
|
||||||
|
BrightnessAndContrastData bacd = new BrightnessAndContrastData(tex);
|
||||||
|
|
||||||
ByteBuffer data = BufferUtils.createByteBuffer(width * height * depth * bytesPerPixel);
|
byte[] data = new byte[width * height * depth * bytesPerPixel];
|
||||||
for (int i = -halfW; i < halfW; ++i) {
|
for (int i = -halfW; i < halfW; ++i) {
|
||||||
for (int j = -halfH; j < halfH; ++j) {
|
for (int j = -halfH; j < halfH; ++j) {
|
||||||
for (int k = -halfD; k < halfD; ++k) {
|
for (int k = -halfD; k < halfD; ++k) {
|
||||||
ran = FastMath.rand.nextInt();// BLI_rand();
|
random = FastMath.rand.nextInt();
|
||||||
val = ran & 3;
|
val = random & 3;
|
||||||
|
|
||||||
loop = noisedepth;
|
loop = noisedepth;
|
||||||
while (loop-- != 0) {
|
while (loop-- != 0) {
|
||||||
ran = ran >> 2;
|
random >>= 2;
|
||||||
val *= ran & 3;
|
val *= random & 3;
|
||||||
div *= 3.0f;
|
|
||||||
}
|
}
|
||||||
texres.tin = val;// / div;
|
texres.intensity = val;
|
||||||
if (colorBand != null) {
|
if (colorBand != null) {
|
||||||
noiseGenerator.doColorband(colorBand, texres, dataRepository);
|
int colorbandIndex = (int) (texres.intensity * 1000.0f);
|
||||||
noiseGenerator.brightnesAndContrastRGB(tex, texres);
|
texres.red = colorBand[colorbandIndex][0];
|
||||||
data.put((byte) (texres.tr * 255.0f));
|
texres.green = colorBand[colorbandIndex][1];
|
||||||
data.put((byte) (texres.tg * 255.0f));
|
texres.blue = colorBand[colorbandIndex][2];
|
||||||
data.put((byte) (texres.tb * 255.0f));
|
|
||||||
|
this.applyBrightnessAndContrast(bacd, texres);
|
||||||
|
data[index++] = (byte) (texres.red * 255.0f);
|
||||||
|
data[index++] = (byte) (texres.green * 255.0f);
|
||||||
|
data[index++] = (byte) (texres.blue * 255.0f);
|
||||||
} else {
|
} else {
|
||||||
noiseGenerator.brightnesAndContrast(texres, contrast, brightness);
|
this.applyBrightnessAndContrast(texres, bacd.contrast, bacd.brightness);
|
||||||
data.put((byte) (texres.tin * 255.0f));
|
data[index++] = (byte) (texres.intensity * 255.0f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ArrayList<ByteBuffer> dataArray = new ArrayList<ByteBuffer>(1);
|
ArrayList<ByteBuffer> dataArray = new ArrayList<ByteBuffer>(1);
|
||||||
dataArray.add(data);
|
dataArray.add(BufferUtils.createByteBuffer(data));
|
||||||
return new Texture3D(new Image(format, width, height, depth, dataArray));
|
return new Texture3D(new Image(format, width, height, depth, dataArray));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,32 +1,33 @@
|
|||||||
/*
|
/*
|
||||||
*
|
* Copyright (c) 2009-2010 jMonkeyEngine
|
||||||
* $Id: noise.c 14611 2008-04-29 08:24:33Z campbellbarton $
|
|
||||||
*
|
|
||||||
* ***** BEGIN GPL LICENSE BLOCK *****
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or
|
|
||||||
* modify it under the terms of the GNU General Public License
|
|
||||||
* as published by the Free Software Foundation; either version 2
|
|
||||||
* of the License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program; if not, write to the Free Software Foundation,
|
|
||||||
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
||||||
*
|
|
||||||
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* The Original Code is: all of this file.
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are
|
||||||
|
* met:
|
||||||
*
|
*
|
||||||
* Contributor(s): none yet.
|
* * Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
*
|
*
|
||||||
* ***** END GPL LICENSE BLOCK *****
|
* * Redistributions 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 'jMonkeyEngine' nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||||
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||||
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||||
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||||
|
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||||
|
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||||
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
package com.jme3.scene.plugins.blender.textures;
|
package com.jme3.scene.plugins.blender.textures;
|
||||||
|
|
||||||
@ -35,8 +36,6 @@ import java.util.ArrayList;
|
|||||||
|
|
||||||
import com.jme3.scene.plugins.blender.DataRepository;
|
import com.jme3.scene.plugins.blender.DataRepository;
|
||||||
import com.jme3.scene.plugins.blender.file.Structure;
|
import com.jme3.scene.plugins.blender.file.Structure;
|
||||||
import com.jme3.scene.plugins.blender.textures.TextureHelper.ColorBand;
|
|
||||||
import com.jme3.scene.plugins.blender.textures.TextureHelper.TexResult;
|
|
||||||
import com.jme3.texture.Image;
|
import com.jme3.texture.Image;
|
||||||
import com.jme3.texture.Image.Format;
|
import com.jme3.texture.Image.Format;
|
||||||
import com.jme3.texture.Texture;
|
import com.jme3.texture.Texture;
|
||||||
@ -48,6 +47,7 @@ import com.jme3.util.BufferUtils;
|
|||||||
* @author Marcin Roguski (Kaelthas)
|
* @author Marcin Roguski (Kaelthas)
|
||||||
*/
|
*/
|
||||||
public class TextureGeneratorStucci extends TextureGenerator {
|
public class TextureGeneratorStucci extends TextureGenerator {
|
||||||
|
protected static final int TEX_NOISESOFT = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor stores the given noise generator.
|
* Constructor stores the given noise generator.
|
||||||
@ -64,70 +64,61 @@ public class TextureGeneratorStucci extends TextureGenerator {
|
|||||||
int noisebasis = ((Number) tex.getFieldValue("noisebasis")).intValue();
|
int noisebasis = ((Number) tex.getFieldValue("noisebasis")).intValue();
|
||||||
int noisetype = ((Number) tex.getFieldValue("noisetype")).intValue();
|
int noisetype = ((Number) tex.getFieldValue("noisetype")).intValue();
|
||||||
float turbul = ((Number) tex.getFieldValue("turbul")).floatValue();
|
float turbul = ((Number) tex.getFieldValue("turbul")).floatValue();
|
||||||
boolean isHard = noisetype != NoiseGenerator.TEX_NOISESOFT;
|
boolean isHard = noisetype != TEX_NOISESOFT;
|
||||||
int stype = ((Number) tex.getFieldValue("stype")).intValue();
|
int stype = ((Number) tex.getFieldValue("stype")).intValue();
|
||||||
|
|
||||||
|
if(noisesize<=0.001f) {//the texture goes black if this value is lower than 0.001f
|
||||||
|
noisesize = 0.001f;
|
||||||
|
}
|
||||||
|
|
||||||
float[] texvec = new float[] { 0, 0, 0 };
|
float[] texvec = new float[] { 0, 0, 0 };
|
||||||
TexResult texres = new TexResult();
|
TextureResult texres = new TextureResult();
|
||||||
float wDelta = 1.0f / width, hDelta = 1.0f / height, dDelta = 1.0f / depth, b2, ofs;
|
int halfW = width >> 1, halfH = height >> 1, halfD = depth >> 1, index = 0;
|
||||||
int halfW = width, halfH = height, halfD = depth;
|
float wDelta = 1.0f / halfW, hDelta = 1.0f / halfH, dDelta = 1.0f / halfD, noiseValue, ofs;;
|
||||||
width <<= 1;
|
float[][] colorBand = this.computeColorband(tex, dataRepository);
|
||||||
height <<= 1;
|
|
||||||
depth <<= 1;
|
|
||||||
ColorBand colorBand = this.readColorband(tex, dataRepository);
|
|
||||||
Format format = colorBand != null ? Format.RGB8 : Format.Luminance8;
|
Format format = colorBand != null ? Format.RGB8 : Format.Luminance8;
|
||||||
int bytesPerPixel = colorBand != null ? 3 : 1;
|
int bytesPerPixel = colorBand != null ? 3 : 1;
|
||||||
|
|
||||||
ByteBuffer data = BufferUtils.createByteBuffer(width * height * depth * bytesPerPixel);
|
byte[] data = new byte[width * height * depth * bytesPerPixel];
|
||||||
for (int i = -halfW; i < halfW; ++i) {
|
for (int i = -halfW; i < halfW; ++i) {
|
||||||
texvec[0] = wDelta * i;
|
texvec[0] = wDelta * i;
|
||||||
for (int j = -halfH; j < halfH; ++j) {
|
for (int j = -halfH; j < halfH; ++j) {
|
||||||
texvec[1] = hDelta * j;
|
texvec[1] = hDelta * j;
|
||||||
for (int k = -halfD; k < halfD; ++k) {
|
for (int k = -halfD; k < halfD; ++k) {
|
||||||
texvec[2] = dDelta * k;
|
texvec[2] = dDelta * k;
|
||||||
b2 = noiseGenerator.bliGNoise(noisesize, texvec[0], texvec[1], texvec[2], isHard, noisebasis);
|
noiseValue = NoiseGenerator.NoiseFunctions.noise(texvec[0], texvec[1], texvec[2], noisesize, 0, noisebasis, isHard);
|
||||||
|
|
||||||
ofs = turbul / 200.0f;
|
ofs = turbul / 200.0f;
|
||||||
|
|
||||||
if (stype != 0) {
|
if (stype != 0) {
|
||||||
ofs *= b2 * b2;
|
ofs *= noiseValue * noiseValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
texres.tin = noiseGenerator.bliGNoise(noisesize, texvec[0], texvec[1], texvec[2] + ofs, isHard, noisebasis);// ==nor[2]
|
texres.intensity = NoiseGenerator.NoiseFunctions.noise(texvec[0], texvec[1], texvec[2] + ofs, noisesize, 0, noisebasis, isHard);
|
||||||
if (colorBand != null) {
|
if (colorBand != null) {
|
||||||
noiseGenerator.doColorband(colorBand, texres, dataRepository);
|
int colorbandIndex = (int) (texres.intensity * 1000.0f);
|
||||||
if (texres.nor != null) {
|
texres.red = colorBand[colorbandIndex][0];
|
||||||
texres.nor[0] = noiseGenerator.bliGNoise(noisesize, texvec[0] + ofs, texvec[1], texvec[2], isHard, noisebasis);
|
texres.green = colorBand[colorbandIndex][1];
|
||||||
texres.nor[1] = noiseGenerator.bliGNoise(noisesize, texvec[0], texvec[1] + ofs, texvec[2], isHard, noisebasis);
|
texres.blue = colorBand[colorbandIndex][2];
|
||||||
texres.nor[2] = texres.tin;
|
|
||||||
noiseGenerator.texNormalDerivate(colorBand, texres, dataRepository);
|
|
||||||
|
|
||||||
if (stype == NoiseGenerator.TEX_WALLOUT) {
|
|
||||||
texres.nor[0] = -texres.nor[0];
|
|
||||||
texres.nor[1] = -texres.nor[1];
|
|
||||||
texres.nor[2] = -texres.nor[2];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stype == NoiseGenerator.TEX_WALLOUT) {
|
if (stype == NoiseGenerator.TEX_WALLOUT) {
|
||||||
texres.tin = 1.0f - texres.tin;
|
texres.intensity = 1.0f - texres.intensity;
|
||||||
}
|
}
|
||||||
if (texres.tin < 0.0f) {
|
if (texres.intensity < 0.0f) {
|
||||||
texres.tin = 0.0f;
|
texres.intensity = 0.0f;
|
||||||
}
|
}
|
||||||
|
//no brightness and contrast needed for stucci (it doesn't affect the texture)
|
||||||
if (colorBand != null) {
|
if (colorBand != null) {
|
||||||
data.put((byte) (texres.tr * 255.0f));
|
data[index++] = (byte) (texres.red * 255.0f);
|
||||||
data.put((byte) (texres.tg * 255.0f));
|
data[index++] = (byte) (texres.green * 255.0f);
|
||||||
data.put((byte) (texres.tb * 255.0f));
|
data[index++] = (byte) (texres.blue * 255.0f);
|
||||||
} else {
|
} else {
|
||||||
data.put((byte) (texres.tin * 255.0f));
|
data[index++] = (byte) (texres.intensity * 255.0f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ArrayList<ByteBuffer> dataArray = new ArrayList<ByteBuffer>(1);
|
ArrayList<ByteBuffer> dataArray = new ArrayList<ByteBuffer>(1);
|
||||||
dataArray.add(data);
|
dataArray.add(BufferUtils.createByteBuffer(data));
|
||||||
return new Texture3D(new Image(format, width, height, depth, dataArray));
|
return new Texture3D(new Image(format, width, height, depth, dataArray));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,32 +1,33 @@
|
|||||||
/*
|
/*
|
||||||
*
|
* Copyright (c) 2009-2010 jMonkeyEngine
|
||||||
* $Id: noise.c 14611 2008-04-29 08:24:33Z campbellbarton $
|
|
||||||
*
|
|
||||||
* ***** BEGIN GPL LICENSE BLOCK *****
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or
|
|
||||||
* modify it under the terms of the GNU General Public License
|
|
||||||
* as published by the Free Software Foundation; either version 2
|
|
||||||
* of the License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program; if not, write to the Free Software Foundation,
|
|
||||||
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
||||||
*
|
|
||||||
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* The Original Code is: all of this file.
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are
|
||||||
|
* met:
|
||||||
*
|
*
|
||||||
* Contributor(s): none yet.
|
* * Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
*
|
*
|
||||||
* ***** END GPL LICENSE BLOCK *****
|
* * Redistributions 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 'jMonkeyEngine' nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||||
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||||
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||||
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||||
|
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||||
|
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||||
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
package com.jme3.scene.plugins.blender.textures;
|
package com.jme3.scene.plugins.blender.textures;
|
||||||
|
|
||||||
@ -36,8 +37,7 @@ import java.util.ArrayList;
|
|||||||
import com.jme3.math.FastMath;
|
import com.jme3.math.FastMath;
|
||||||
import com.jme3.scene.plugins.blender.DataRepository;
|
import com.jme3.scene.plugins.blender.DataRepository;
|
||||||
import com.jme3.scene.plugins.blender.file.Structure;
|
import com.jme3.scene.plugins.blender.file.Structure;
|
||||||
import com.jme3.scene.plugins.blender.textures.TextureHelper.ColorBand;
|
import com.jme3.scene.plugins.blender.textures.NoiseGenerator.NoiseMath;
|
||||||
import com.jme3.scene.plugins.blender.textures.TextureHelper.TexResult;
|
|
||||||
import com.jme3.texture.Image;
|
import com.jme3.texture.Image;
|
||||||
import com.jme3.texture.Image.Format;
|
import com.jme3.texture.Image.Format;
|
||||||
import com.jme3.texture.Texture;
|
import com.jme3.texture.Texture;
|
||||||
@ -61,115 +61,109 @@ public class TextureGeneratorVoronoi extends TextureGenerator {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Texture generate(Structure tex, int width, int height, int depth, DataRepository dataRepository) {
|
protected Texture generate(Structure tex, int width, int height, int depth, DataRepository dataRepository) {
|
||||||
float vn_w1 = ((Number) tex.getFieldValue("vn_w1")).floatValue();
|
float voronoiWeight1 = ((Number) tex.getFieldValue("vn_w1")).floatValue();
|
||||||
float vn_w2 = ((Number) tex.getFieldValue("vn_w2")).floatValue();
|
float voronoiWeight2 = ((Number) tex.getFieldValue("vn_w2")).floatValue();
|
||||||
float vn_w3 = ((Number) tex.getFieldValue("vn_w3")).floatValue();
|
float voronoiWeight3 = ((Number) tex.getFieldValue("vn_w3")).floatValue();
|
||||||
float vn_w4 = ((Number) tex.getFieldValue("vn_w4")).floatValue();
|
float voronoiWeight4 = ((Number) tex.getFieldValue("vn_w4")).floatValue();
|
||||||
float noisesize = ((Number) tex.getFieldValue("noisesize")).floatValue();
|
float noisesize = ((Number) tex.getFieldValue("noisesize")).floatValue();
|
||||||
float nabla = ((Number) tex.getFieldValue("nabla")).floatValue();
|
float outscale = ((Number) tex.getFieldValue("ns_outscale")).floatValue();
|
||||||
float ns_outscale = ((Number) tex.getFieldValue("ns_outscale")).floatValue();
|
float mexp = ((Number) tex.getFieldValue("vn_mexp")).floatValue();
|
||||||
float vn_mexp = ((Number) tex.getFieldValue("vn_mexp")).floatValue();
|
int distm = ((Number) tex.getFieldValue("vn_distm")).intValue();
|
||||||
int vn_distm = ((Number) tex.getFieldValue("vn_distm")).intValue();
|
int voronoiColorType = ((Number) tex.getFieldValue("vn_coltype")).intValue();
|
||||||
int vn_coltype = ((Number) tex.getFieldValue("vn_coltype")).intValue();
|
|
||||||
float contrast = ((Number) tex.getFieldValue("contrast")).floatValue();
|
|
||||||
float brightness = ((Number) tex.getFieldValue("bright")).floatValue();
|
|
||||||
|
|
||||||
TexResult texres = new TexResult();
|
TextureResult texres = new TextureResult();
|
||||||
float[] texvec = new float[] { 0, 0, 0 };
|
float[] texvec = new float[] { 0, 0, 0 };
|
||||||
float wDelta = 1.0f / width, hDelta = 1.0f / height, dDelta = 1.0f / depth;
|
int halfW = width >> 1, halfH = height >> 1, halfD = depth >> 1, index = 0;
|
||||||
int halfW = width, halfH = height, halfD = depth;
|
float wDelta = 1.0f / halfW, hDelta = 1.0f / halfH, dDelta = 1.0f / halfD;
|
||||||
width <<= 1;
|
|
||||||
height <<= 1;
|
|
||||||
depth <<= 1;
|
|
||||||
ColorBand colorBand = this.readColorband(tex, dataRepository);
|
|
||||||
Format format = vn_coltype != 0 || colorBand != null ? Format.RGB8 : Format.Luminance8;
|
|
||||||
int bytesPerPixel = vn_coltype != 0 || colorBand != null ? 3 : 1;
|
|
||||||
|
|
||||||
float[] da = new float[4], pa = new float[12]; /* distance and point coordinate arrays of 4 nearest neighbours */
|
float[][] colorBand = this.computeColorband(tex, dataRepository);
|
||||||
float[] ca = vn_coltype != 0 ? new float[3] : null; // cell color
|
Format format = voronoiColorType != 0 || colorBand != null ? Format.RGB8 : Format.Luminance8;
|
||||||
float aw1 = FastMath.abs(vn_w1);
|
int bytesPerPixel = voronoiColorType != 0 || colorBand != null ? 3 : 1;
|
||||||
float aw2 = FastMath.abs(vn_w2);
|
BrightnessAndContrastData bacd = new BrightnessAndContrastData(tex);
|
||||||
float aw3 = FastMath.abs(vn_w3);
|
|
||||||
float aw4 = FastMath.abs(vn_w4);
|
float[] da = new float[4], pa = new float[12];
|
||||||
float sc = aw1 + aw2 + aw3 + aw4;
|
float[] hashPoint = voronoiColorType != 0 ? new float[3] : null;
|
||||||
if (sc != 0.f) {
|
float[] voronoiWeights = new float[] {FastMath.abs(voronoiWeight1), FastMath.abs(voronoiWeight2),
|
||||||
sc = ns_outscale / sc;
|
FastMath.abs(voronoiWeight3), FastMath.abs(voronoiWeight4)};
|
||||||
|
float weight;
|
||||||
|
float sc = voronoiWeights[0] + voronoiWeights[1] + voronoiWeights[2] + voronoiWeights[3];
|
||||||
|
if (sc != 0.0f) {
|
||||||
|
sc = outscale / sc;
|
||||||
}
|
}
|
||||||
|
|
||||||
ByteBuffer data = BufferUtils.createByteBuffer(width * height * depth * bytesPerPixel);
|
byte[] data = new byte[width * height * depth * bytesPerPixel];
|
||||||
for (int i = -halfW; i < halfW; ++i) {
|
for (int i = -halfW; i < halfW; ++i) {
|
||||||
texvec[0] = wDelta * i / noisesize;
|
texvec[0] = wDelta * i / noisesize;
|
||||||
for (int j = -halfH; j < halfH; ++j) {
|
for (int j = -halfH; j < halfH; ++j) {
|
||||||
texvec[1] = hDelta * j / noisesize;
|
texvec[1] = hDelta * j / noisesize;
|
||||||
for (int k = -halfD; k < halfD; ++k) {
|
for (int k = -halfD; k < halfD; ++k) {
|
||||||
texvec[2] = dDelta * k;
|
texvec[2] = dDelta * k;
|
||||||
noiseGenerator.voronoi(texvec[0], texvec[1], texvec[2], da, pa, vn_mexp, vn_distm);
|
NoiseGenerator.NoiseFunctions.voronoi(texvec[0], texvec[1], texvec[2], da, pa, mexp, distm);
|
||||||
texres.tin = sc * FastMath.abs(vn_w1 * da[0] + vn_w2 * da[1] + vn_w3 * da[2] + vn_w4 * da[3]);
|
texres.intensity = sc * FastMath.abs(voronoiWeight1 * da[0] + voronoiWeight2 * da[1] + voronoiWeight3 * da[2] + voronoiWeight4 * da[3]);
|
||||||
if (vn_coltype != 0) {
|
if(texres.intensity>1.0f) {
|
||||||
noiseGenerator.cellNoiseV(pa[0], pa[1], pa[2], ca);
|
texres.intensity = 1.0f;
|
||||||
texres.tr = aw1 * ca[0];
|
} else if(texres.intensity<0.0f) {
|
||||||
texres.tg = aw1 * ca[1];
|
texres.intensity = 0.0f;
|
||||||
texres.tb = aw1 * ca[2];
|
}
|
||||||
noiseGenerator.cellNoiseV(pa[3], pa[4], pa[5], ca);
|
|
||||||
texres.tr += aw2 * ca[0];
|
if (colorBand != null) {//colorband ALWAYS goes first and covers the color (if set)
|
||||||
texres.tg += aw2 * ca[1];
|
int colorbandIndex = (int) (texres.intensity * 1000.0f);
|
||||||
texres.tb += aw2 * ca[2];
|
texres.red = colorBand[colorbandIndex][0];
|
||||||
noiseGenerator.cellNoiseV(pa[6], pa[7], pa[8], ca);
|
texres.green = colorBand[colorbandIndex][1];
|
||||||
texres.tr += aw3 * ca[0];
|
texres.blue = colorBand[colorbandIndex][2];
|
||||||
texres.tg += aw3 * ca[1];
|
} else if (voronoiColorType != 0) {
|
||||||
texres.tb += aw3 * ca[2];
|
texres.red = texres.green = texres.blue = 0.0f;
|
||||||
noiseGenerator.cellNoiseV(pa[9], pa[10], pa[11], ca);
|
for(int m=0; m<12; m+=3) {
|
||||||
texres.tr += aw4 * ca[0];
|
weight = voronoiWeights[m/3];
|
||||||
texres.tg += aw4 * ca[1];
|
this.cellNoiseV(pa[m], pa[m + 1], pa[m + 2], hashPoint);
|
||||||
texres.tb += aw4 * ca[2];
|
texres.red += weight * hashPoint[0];
|
||||||
if (vn_coltype >= 2) {
|
texres.green += weight * hashPoint[1];
|
||||||
|
texres.blue += weight * hashPoint[2];
|
||||||
|
}
|
||||||
|
if (voronoiColorType >= 2) {
|
||||||
float t1 = (da[1] - da[0]) * 10.0f;
|
float t1 = (da[1] - da[0]) * 10.0f;
|
||||||
if (t1 > 1) {
|
if (t1 > 1.0f) {
|
||||||
t1 = 1.0f;
|
t1 = 1.0f;
|
||||||
}
|
}
|
||||||
if (vn_coltype == 3) {
|
if (voronoiColorType == 3) {
|
||||||
t1 *= texres.tin;
|
t1 *= texres.intensity;
|
||||||
} else {
|
} else {
|
||||||
t1 *= sc;
|
t1 *= sc;
|
||||||
}
|
}
|
||||||
texres.tr *= t1;
|
texres.red *= t1;
|
||||||
texres.tg *= t1;
|
texres.green *= t1;
|
||||||
texres.tb *= t1;
|
texres.blue *= t1;
|
||||||
} else {
|
} else {
|
||||||
texres.tr *= sc;
|
texres.red *= sc;
|
||||||
texres.tg *= sc;
|
texres.green *= sc;
|
||||||
texres.tb *= sc;
|
texres.blue *= sc;
|
||||||
}
|
|
||||||
}
|
|
||||||
if (colorBand != null) {
|
|
||||||
noiseGenerator.doColorband(colorBand, texres, dataRepository);
|
|
||||||
if (texres.nor != null) {
|
|
||||||
float offs = nabla / noisesize; // also scaling of texvec
|
|
||||||
// calculate bumpnormal
|
|
||||||
noiseGenerator.voronoi(texvec[0] + offs, texvec[1], texvec[2], da, pa, vn_mexp, vn_distm);
|
|
||||||
texres.nor[0] = sc * FastMath.abs(vn_w1 * da[0] + vn_w2 * da[1] + vn_w3 * da[2] + vn_w4 * da[3]);
|
|
||||||
noiseGenerator.voronoi(texvec[0], texvec[1] + offs, texvec[2], da, pa, vn_mexp, vn_distm);
|
|
||||||
texres.nor[1] = sc * FastMath.abs(vn_w1 * da[0] + vn_w2 * da[1] + vn_w3 * da[2] + vn_w4 * da[3]);
|
|
||||||
noiseGenerator.voronoi(texvec[0], texvec[1], texvec[2] + offs, da, pa, vn_mexp, vn_distm);
|
|
||||||
texres.nor[2] = sc * FastMath.abs(vn_w1 * da[0] + vn_w2 * da[1] + vn_w3 * da[2] + vn_w4 * da[3]);
|
|
||||||
noiseGenerator.texNormalDerivate(colorBand, texres, dataRepository);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (vn_coltype != 0 || colorBand != null) {
|
if (voronoiColorType != 0 || colorBand != null) {
|
||||||
noiseGenerator.brightnesAndContrastRGB(tex, texres);
|
this.applyBrightnessAndContrast(bacd, texres);
|
||||||
data.put((byte) (texres.tr * 255.0f));// tin or tr??
|
data[index++] = (byte) (texres.red * 255.0f);
|
||||||
data.put((byte) (texres.tg * 255.0f));
|
data[index++] = (byte) (texres.green * 255.0f);
|
||||||
data.put((byte) (texres.tb * 255.0f));
|
data[index++] = (byte) (texres.blue * 255.0f);
|
||||||
} else {
|
} else {
|
||||||
noiseGenerator.brightnesAndContrast(texres, contrast, brightness);
|
this.applyBrightnessAndContrast(texres, bacd.contrast, bacd.brightness);
|
||||||
data.put((byte) (texres.tin * 255.0f));
|
data[index++] = (byte) (texres.intensity * 255.0f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ArrayList<ByteBuffer> dataArray = new ArrayList<ByteBuffer>(1);
|
ArrayList<ByteBuffer> dataArray = new ArrayList<ByteBuffer>(1);
|
||||||
dataArray.add(data);
|
dataArray.add(BufferUtils.createByteBuffer(data));
|
||||||
return new Texture3D(new Image(format, width, height, depth, dataArray));
|
return new Texture3D(new Image(format, width, height, depth, dataArray));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a vector/point/color in ca, using point hasharray directly
|
||||||
|
*/
|
||||||
|
private void cellNoiseV(float x, float y, float z, float[] hashPoint) {
|
||||||
|
int xi = (int) Math.floor(x);
|
||||||
|
int yi = (int) Math.floor(y);
|
||||||
|
int zi = (int) Math.floor(z);
|
||||||
|
NoiseMath.hash(xi, yi, zi, hashPoint);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,10 +33,9 @@ package com.jme3.scene.plugins.blender.textures;
|
|||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import com.jme3.math.FastMath;
|
||||||
import com.jme3.scene.plugins.blender.DataRepository;
|
import com.jme3.scene.plugins.blender.DataRepository;
|
||||||
import com.jme3.scene.plugins.blender.file.Structure;
|
import com.jme3.scene.plugins.blender.file.Structure;
|
||||||
import com.jme3.scene.plugins.blender.textures.TextureHelper.ColorBand;
|
|
||||||
import com.jme3.scene.plugins.blender.textures.TextureHelper.TexResult;
|
|
||||||
import com.jme3.texture.Image;
|
import com.jme3.texture.Image;
|
||||||
import com.jme3.texture.Image.Format;
|
import com.jme3.texture.Image.Format;
|
||||||
import com.jme3.texture.Texture;
|
import com.jme3.texture.Texture;
|
||||||
@ -48,6 +47,20 @@ import com.jme3.util.BufferUtils;
|
|||||||
* @author Marcin Roguski (Kaelthas)
|
* @author Marcin Roguski (Kaelthas)
|
||||||
*/
|
*/
|
||||||
public class TextureGeneratorWood extends TextureGenerator {
|
public class TextureGeneratorWood extends TextureGenerator {
|
||||||
|
// tex->noisebasis2
|
||||||
|
protected static final int TEX_SIN = 0;
|
||||||
|
protected static final int TEX_SAW = 1;
|
||||||
|
protected static final int TEX_TRI = 2;
|
||||||
|
|
||||||
|
// tex->stype
|
||||||
|
protected static final int TEX_BAND = 0;
|
||||||
|
protected static final int TEX_RING = 1;
|
||||||
|
protected static final int TEX_BANDNOISE = 2;
|
||||||
|
protected static final int TEX_RINGNOISE = 3;
|
||||||
|
|
||||||
|
// tex->noisetype
|
||||||
|
protected static final int TEX_NOISESOFT = 0;
|
||||||
|
protected static final int TEX_NOISEPERL = 1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor stores the given noise generator.
|
* Constructor stores the given noise generator.
|
||||||
@ -59,53 +72,145 @@ public class TextureGeneratorWood extends TextureGenerator {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Texture generate(Structure tex, int width, int height, int depth, DataRepository dataRepository) {
|
protected Texture generate(Structure tex, int width, int height, int depth, DataRepository dataRepository) {
|
||||||
// preparing the proper data
|
|
||||||
float contrast = ((Number) tex.getFieldValue("contrast")).floatValue();
|
|
||||||
float bright = ((Number) tex.getFieldValue("bright")).floatValue();
|
|
||||||
float nabla = ((Number) tex.getFieldValue("nabla")).floatValue();
|
|
||||||
float wDelta = 1.0f / width, hDelta = 1.0f / height, dDelta = 1.0f / depth;
|
|
||||||
float[] texvec = new float[] { 0, 0, 0 };
|
float[] texvec = new float[] { 0, 0, 0 };
|
||||||
TexResult texres = new TexResult();
|
TextureResult texres = new TextureResult();
|
||||||
int halfW = width;
|
int halfW = width >> 1;
|
||||||
int halfH = height;
|
int halfH = height >> 1;
|
||||||
int halfD = depth;
|
int halfD = depth >> 1;
|
||||||
width <<= 1;
|
float wDelta = 1.0f / halfW, hDelta = 1.0f / halfH, dDelta = 1.0f / halfD;
|
||||||
height <<= 1;
|
|
||||||
depth <<= 1;
|
|
||||||
|
|
||||||
ColorBand colorBand = this.readColorband(tex, dataRepository);
|
float[][] colorBand = this.computeColorband(tex, dataRepository);
|
||||||
Format format = colorBand != null ? Format.RGB8 : Format.Luminance8;
|
Format format = colorBand != null ? Format.RGB8 : Format.Luminance8;
|
||||||
int bytesPerPixel = colorBand != null ? 3 : 1;
|
int bytesPerPixel = colorBand != null ? 3 : 1;
|
||||||
|
WoodIntensityData woodIntensityData = new WoodIntensityData(tex);
|
||||||
|
BrightnessAndContrastData bacd = new BrightnessAndContrastData(tex);
|
||||||
|
|
||||||
ByteBuffer data = BufferUtils.createByteBuffer(width * height * depth * bytesPerPixel);
|
int index = 0;
|
||||||
|
byte[] data = new byte[width * height * depth * bytesPerPixel];
|
||||||
for (int i = -halfW; i < halfW; ++i) {
|
for (int i = -halfW; i < halfW; ++i) {
|
||||||
texvec[0] = wDelta * i;
|
texvec[0] = wDelta * i;
|
||||||
for (int j = -halfH; j < halfH; ++j) {
|
for (int j = -halfH; j < halfH; ++j) {
|
||||||
texvec[1] = hDelta * j;
|
texvec[1] = hDelta * j;
|
||||||
for(int k = -halfD; k < halfD; ++k) {
|
for(int k = -halfD; k < halfD; ++k) {
|
||||||
texvec[2] = dDelta * k;
|
texvec[2] = dDelta * k;
|
||||||
texres.tin = noiseGenerator.woodInt(tex, texvec[0], texvec[1], texvec[2], dataRepository);
|
texres.intensity = this.woodIntensity(woodIntensityData, texvec[0], texvec[1], texvec[2]);
|
||||||
|
|
||||||
if (colorBand != null) {
|
if (colorBand != null) {
|
||||||
noiseGenerator.doColorband(colorBand, texres, dataRepository);
|
int colorbandIndex = (int) (texres.intensity * 1000.0f);
|
||||||
if (texres.nor != null) {// calculate bumpnormal
|
texres.red = colorBand[colorbandIndex][0];
|
||||||
texres.nor[0] = noiseGenerator.woodInt(tex, texvec[0] + nabla, texvec[1], texvec[2], dataRepository);
|
texres.green = colorBand[colorbandIndex][1];
|
||||||
texres.nor[1] = noiseGenerator.woodInt(tex, texvec[0], texvec[1] + nabla, texvec[2], dataRepository);
|
texres.blue = colorBand[colorbandIndex][2];
|
||||||
texres.nor[2] = noiseGenerator.woodInt(tex, texvec[0], texvec[1], texvec[2] + nabla, dataRepository);
|
|
||||||
noiseGenerator.texNormalDerivate(colorBand, texres, dataRepository);
|
this.applyBrightnessAndContrast(bacd, texres);
|
||||||
}
|
|
||||||
noiseGenerator.brightnesAndContrastRGB(tex, texres);
|
data[index++] = (byte) (texres.red * 255.0f);
|
||||||
data.put((byte) (texres.tr * 255.0f));
|
data[index++] = (byte) (texres.green * 255.0f);
|
||||||
data.put((byte) (texres.tg * 255.0f));
|
data[index++] = (byte) (texres.blue * 255.0f);
|
||||||
data.put((byte) (texres.tb * 255.0f));
|
|
||||||
} else {
|
} else {
|
||||||
noiseGenerator.brightnesAndContrast(texres, contrast, bright);
|
this.applyBrightnessAndContrast(texres, bacd.contrast, bacd.brightness);
|
||||||
data.put((byte) (texres.tin * 255));
|
data[index++] = (byte) (texres.intensity * 255.0f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ArrayList<ByteBuffer> dataArray = new ArrayList<ByteBuffer>(1);
|
ArrayList<ByteBuffer> dataArray = new ArrayList<ByteBuffer>(1);
|
||||||
dataArray.add(data);
|
dataArray.add(BufferUtils.createByteBuffer(data));
|
||||||
return new Texture3D(new Image(format, width, height, depth, dataArray));
|
return new Texture3D(new Image(format, width, height, depth, dataArray));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected static WaveForm[] waveformFunctions = new WaveForm[3];
|
||||||
|
static {
|
||||||
|
waveformFunctions[0] = new WaveForm() {// sinus (TEX_SIN)
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float execute(float x) {
|
||||||
|
return 0.5f + 0.5f * (float) Math.sin(x);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
waveformFunctions[1] = new WaveForm() {// saw (TEX_SAW)
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float execute(float x) {
|
||||||
|
int n = (int) (x * FastMath.INV_TWO_PI);
|
||||||
|
x -= n * FastMath.TWO_PI;
|
||||||
|
if (x < 0.0f) {
|
||||||
|
x += FastMath.TWO_PI;
|
||||||
|
}
|
||||||
|
return x * FastMath.INV_TWO_PI;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
waveformFunctions[2] = new WaveForm() {// triangle (TEX_TRI)
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float execute(float x) {
|
||||||
|
return 1.0f - 2.0f * FastMath.abs((float) Math.floor(x * FastMath.INV_TWO_PI + 0.5f) - x * FastMath.INV_TWO_PI);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Computes basic wood intensity value at x,y,z.
|
||||||
|
* @param woodIntData
|
||||||
|
* @param x X coordinate of the texture pixel
|
||||||
|
* @param y Y coordinate of the texture pixel
|
||||||
|
* @param z Z coordinate of the texture pixel
|
||||||
|
* @return wood intensity at position [x, y, z]
|
||||||
|
*/
|
||||||
|
public float woodIntensity(WoodIntensityData woodIntData, float x, float y, float z) {
|
||||||
|
float result;
|
||||||
|
|
||||||
|
switch(woodIntData.woodType) {
|
||||||
|
case TEX_BAND:
|
||||||
|
result = woodIntData.waveformFunction.execute((x + y + z) * 10.0f);
|
||||||
|
break;
|
||||||
|
case TEX_RING:
|
||||||
|
result = woodIntData.waveformFunction.execute((float) Math.sqrt(x * x + y * y + z * z) * 20.0f);
|
||||||
|
break;
|
||||||
|
case TEX_BANDNOISE:
|
||||||
|
result = woodIntData.turbul * NoiseGenerator.NoiseFunctions.noise(x, y, z, woodIntData.noisesize, 0, woodIntData.noisebasis, woodIntData.isHard);
|
||||||
|
result = woodIntData.waveformFunction.execute((x + y + z) * 10.0f + result);
|
||||||
|
break;
|
||||||
|
case TEX_RINGNOISE:
|
||||||
|
result = woodIntData.turbul * NoiseGenerator.NoiseFunctions.noise(x, y, z, woodIntData.noisesize, 0, woodIntData.noisebasis, woodIntData.isHard);
|
||||||
|
result = woodIntData.waveformFunction.execute((float) Math.sqrt(x * x + y * y + z * z) * 20.0f + result);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
result = 0;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A class that collects the data for wood intensity calculations.
|
||||||
|
* @author Marcin Roguski (Kaelthas)
|
||||||
|
*/
|
||||||
|
private static class WoodIntensityData {
|
||||||
|
public final WaveForm waveformFunction;
|
||||||
|
public final int noisebasis;
|
||||||
|
public final float noisesize;
|
||||||
|
public final float turbul;
|
||||||
|
public final int noiseType;
|
||||||
|
public final int woodType;
|
||||||
|
public final boolean isHard;
|
||||||
|
|
||||||
|
public WoodIntensityData(Structure tex) {
|
||||||
|
int waveform = ((Number) tex.getFieldValue("noisebasis2")).intValue();//wave form: TEX_SIN=0, TEX_SAW=1, TEX_TRI=2
|
||||||
|
if (waveform > TEX_TRI || waveform < TEX_SIN) {
|
||||||
|
waveform = 0; // check to be sure noisebasis2 is initialized ahead of time
|
||||||
|
}
|
||||||
|
waveformFunction = waveformFunctions[waveform];
|
||||||
|
noisebasis = ((Number) tex.getFieldValue("noisebasis")).intValue();
|
||||||
|
woodType = ((Number) tex.getFieldValue("stype")).intValue();
|
||||||
|
noisesize = ((Number) tex.getFieldValue("noisesize")).floatValue();
|
||||||
|
turbul = ((Number) tex.getFieldValue("turbul")).floatValue();
|
||||||
|
noiseType = ((Number) tex.getFieldValue("noisetype")).intValue();
|
||||||
|
isHard = noiseType != TEX_NOISESOFT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static interface WaveForm {
|
||||||
|
|
||||||
|
float execute(float x);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,8 +34,6 @@ package com.jme3.scene.plugins.blender.textures;
|
|||||||
import java.awt.color.ColorSpace;
|
import java.awt.color.ColorSpace;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.awt.image.ColorConvertOp;
|
import java.awt.image.ColorConvertOp;
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -58,7 +56,6 @@ import com.jme3.scene.plugins.blender.AbstractBlenderHelper;
|
|||||||
import com.jme3.scene.plugins.blender.DataRepository;
|
import com.jme3.scene.plugins.blender.DataRepository;
|
||||||
import com.jme3.scene.plugins.blender.DataRepository.LoadedFeatureDataType;
|
import com.jme3.scene.plugins.blender.DataRepository.LoadedFeatureDataType;
|
||||||
import com.jme3.scene.plugins.blender.exceptions.BlenderFileException;
|
import com.jme3.scene.plugins.blender.exceptions.BlenderFileException;
|
||||||
import com.jme3.scene.plugins.blender.file.DynamicArray;
|
|
||||||
import com.jme3.scene.plugins.blender.file.FileBlockHeader;
|
import com.jme3.scene.plugins.blender.file.FileBlockHeader;
|
||||||
import com.jme3.scene.plugins.blender.file.Pointer;
|
import com.jme3.scene.plugins.blender.file.Pointer;
|
||||||
import com.jme3.scene.plugins.blender.file.Structure;
|
import com.jme3.scene.plugins.blender.file.Structure;
|
||||||
@ -132,24 +129,6 @@ public class TextureHelper extends AbstractBlenderHelper {
|
|||||||
public static final int MTEX_BLEND_COLOR = 13;
|
public static final int MTEX_BLEND_COLOR = 13;
|
||||||
public static final int MTEX_NUM_BLENDTYPES = 14;
|
public static final int MTEX_NUM_BLENDTYPES = 14;
|
||||||
|
|
||||||
// variables used in rampBlend method
|
|
||||||
public static final int MA_RAMP_BLEND = 0;
|
|
||||||
public static final int MA_RAMP_ADD = 1;
|
|
||||||
public static final int MA_RAMP_MULT = 2;
|
|
||||||
public static final int MA_RAMP_SUB = 3;
|
|
||||||
public static final int MA_RAMP_SCREEN = 4;
|
|
||||||
public static final int MA_RAMP_DIV = 5;
|
|
||||||
public static final int MA_RAMP_DIFF = 6;
|
|
||||||
public static final int MA_RAMP_DARK = 7;
|
|
||||||
public static final int MA_RAMP_LIGHT = 8;
|
|
||||||
public static final int MA_RAMP_OVERLAY = 9;
|
|
||||||
public static final int MA_RAMP_DODGE = 10;
|
|
||||||
public static final int MA_RAMP_BURN = 11;
|
|
||||||
public static final int MA_RAMP_HUE = 12;
|
|
||||||
public static final int MA_RAMP_SAT = 13;
|
|
||||||
public static final int MA_RAMP_VAL = 14;
|
|
||||||
public static final int MA_RAMP_COLOR = 15;
|
|
||||||
|
|
||||||
protected NoiseGenerator noiseGenerator;
|
protected NoiseGenerator noiseGenerator;
|
||||||
private Map<Integer, TextureGenerator> textureGenerators = new HashMap<Integer, TextureGenerator>();
|
private Map<Integer, TextureGenerator> textureGenerators = new HashMap<Integer, TextureGenerator>();
|
||||||
|
|
||||||
@ -312,9 +291,8 @@ public class TextureHelper extends AbstractBlenderHelper {
|
|||||||
* @return texture intensity for the current pixel
|
* @return texture intensity for the current pixel
|
||||||
*/
|
*/
|
||||||
protected float setupMaterialColor(ByteBuffer data, Format imageFormat, boolean neg, float[] materialColor) {
|
protected float setupMaterialColor(ByteBuffer data, Format imageFormat, boolean neg, float[] materialColor) {
|
||||||
// at least one byte is always taken :)
|
|
||||||
float tin = 0.0f;
|
float tin = 0.0f;
|
||||||
byte pixelValue = data.get();
|
byte pixelValue = data.get();// at least one byte is always taken :)
|
||||||
float firstPixelValue = pixelValue >= 0 ? 1.0f - pixelValue / 255.0f : (~pixelValue + 1) / 255.0f;
|
float firstPixelValue = pixelValue >= 0 ? 1.0f - pixelValue / 255.0f : (~pixelValue + 1) / 255.0f;
|
||||||
switch (imageFormat) {
|
switch (imageFormat) {
|
||||||
case ABGR8:
|
case ABGR8:
|
||||||
@ -422,64 +400,59 @@ public class TextureHelper extends AbstractBlenderHelper {
|
|||||||
* the data repository
|
* the data repository
|
||||||
*/
|
*/
|
||||||
protected void blendPixel(float[] result, float[] materialColor, float[] color, float textureIntensity, float textureFactor, int blendtype, DataRepository dataRepository) {
|
protected void blendPixel(float[] result, float[] materialColor, float[] color, float textureIntensity, float textureFactor, int blendtype, DataRepository dataRepository) {
|
||||||
float facm, col;
|
float oneMinusFactor, col;
|
||||||
|
textureIntensity *= textureFactor;
|
||||||
|
|
||||||
switch (blendtype) {
|
switch (blendtype) {
|
||||||
case MTEX_BLEND:
|
case MTEX_BLEND:
|
||||||
textureIntensity *= textureFactor;
|
oneMinusFactor = 1.0f - textureIntensity;
|
||||||
facm = 1.0f - textureIntensity;
|
result[0] = textureIntensity * color[0] + oneMinusFactor * materialColor[0];
|
||||||
result[0] = textureIntensity * color[0] + facm * materialColor[0];
|
result[1] = textureIntensity * color[1] + oneMinusFactor * materialColor[1];
|
||||||
result[1] = textureIntensity * color[1] + facm * materialColor[1];
|
result[2] = textureIntensity * color[2] + oneMinusFactor * materialColor[2];
|
||||||
result[2] = textureIntensity * color[2] + facm * materialColor[2];
|
|
||||||
break;
|
break;
|
||||||
case MTEX_MUL:
|
case MTEX_MUL:
|
||||||
textureIntensity *= textureFactor;
|
oneMinusFactor = 1.0f - textureFactor;
|
||||||
facm = 1.0f - textureFactor;
|
result[0] = (oneMinusFactor + textureIntensity * materialColor[0]) * color[0];
|
||||||
result[0] = (facm + textureIntensity * materialColor[0]) * color[0];
|
result[1] = (oneMinusFactor + textureIntensity * materialColor[1]) * color[1];
|
||||||
result[1] = (facm + textureIntensity * materialColor[1]) * color[1];
|
result[2] = (oneMinusFactor + textureIntensity * materialColor[2]) * color[2];
|
||||||
result[2] = (facm + textureIntensity * materialColor[2]) * color[2];
|
|
||||||
break;
|
break;
|
||||||
case MTEX_DIV:
|
case MTEX_DIV:
|
||||||
textureIntensity *= textureFactor;
|
oneMinusFactor = 1.0f - textureIntensity;
|
||||||
facm = 1.0f - textureIntensity;
|
|
||||||
if (color[0] != 0.0) {
|
if (color[0] != 0.0) {
|
||||||
result[0] = (facm * materialColor[0] + textureIntensity * materialColor[0] / color[0]) * 0.5f;
|
result[0] = (oneMinusFactor * materialColor[0] + textureIntensity * materialColor[0] / color[0]) * 0.5f;
|
||||||
}
|
}
|
||||||
if (color[1] != 0.0) {
|
if (color[1] != 0.0) {
|
||||||
result[1] = (facm * materialColor[1] + textureIntensity * materialColor[1] / color[1]) * 0.5f;
|
result[1] = (oneMinusFactor * materialColor[1] + textureIntensity * materialColor[1] / color[1]) * 0.5f;
|
||||||
}
|
}
|
||||||
if (color[2] != 0.0) {
|
if (color[2] != 0.0) {
|
||||||
result[2] = (facm * materialColor[2] + textureIntensity * materialColor[2] / color[2]) * 0.5f;
|
result[2] = (oneMinusFactor * materialColor[2] + textureIntensity * materialColor[2] / color[2]) * 0.5f;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case MTEX_SCREEN:
|
case MTEX_SCREEN:
|
||||||
textureIntensity *= textureFactor;
|
oneMinusFactor = 1.0f - textureFactor;
|
||||||
facm = 1.0f - textureFactor;
|
result[0] = 1.0f - (oneMinusFactor + textureIntensity * (1.0f - materialColor[0])) * (1.0f - color[0]);
|
||||||
result[0] = 1.0f - (facm + textureIntensity * (1.0f - materialColor[0])) * (1.0f - color[0]);
|
result[1] = 1.0f - (oneMinusFactor + textureIntensity * (1.0f - materialColor[1])) * (1.0f - color[1]);
|
||||||
result[1] = 1.0f - (facm + textureIntensity * (1.0f - materialColor[1])) * (1.0f - color[1]);
|
result[2] = 1.0f - (oneMinusFactor + textureIntensity * (1.0f - materialColor[2])) * (1.0f - color[2]);
|
||||||
result[2] = 1.0f - (facm + textureIntensity * (1.0f - materialColor[2])) * (1.0f - color[2]);
|
|
||||||
break;
|
break;
|
||||||
case MTEX_OVERLAY:
|
case MTEX_OVERLAY:
|
||||||
textureIntensity *= textureFactor;
|
oneMinusFactor = 1.0f - textureFactor;
|
||||||
facm = 1.0f - textureFactor;
|
|
||||||
if (materialColor[0] < 0.5f) {
|
if (materialColor[0] < 0.5f) {
|
||||||
result[0] = color[0] * (facm + 2.0f * textureIntensity * materialColor[0]);
|
result[0] = color[0] * (oneMinusFactor + 2.0f * textureIntensity * materialColor[0]);
|
||||||
} else {
|
} else {
|
||||||
result[0] = 1.0f - (facm + 2.0f * textureIntensity * (1.0f - materialColor[0])) * (1.0f - color[0]);
|
result[0] = 1.0f - (oneMinusFactor + 2.0f * textureIntensity * (1.0f - materialColor[0])) * (1.0f - color[0]);
|
||||||
}
|
}
|
||||||
if (materialColor[1] < 0.5f) {
|
if (materialColor[1] < 0.5f) {
|
||||||
result[1] = color[1] * (facm + 2.0f * textureIntensity * materialColor[1]);
|
result[1] = color[1] * (oneMinusFactor + 2.0f * textureIntensity * materialColor[1]);
|
||||||
} else {
|
} else {
|
||||||
result[1] = 1.0f - (facm + 2.0f * textureIntensity * (1.0f - materialColor[1])) * (1.0f - color[1]);
|
result[1] = 1.0f - (oneMinusFactor + 2.0f * textureIntensity * (1.0f - materialColor[1])) * (1.0f - color[1]);
|
||||||
}
|
}
|
||||||
if (materialColor[2] < 0.5f) {
|
if (materialColor[2] < 0.5f) {
|
||||||
result[2] = color[2] * (facm + 2.0f * textureIntensity * materialColor[2]);
|
result[2] = color[2] * (oneMinusFactor + 2.0f * textureIntensity * materialColor[2]);
|
||||||
} else {
|
} else {
|
||||||
result[2] = 1.0f - (facm + 2.0f * textureIntensity * (1.0f - materialColor[2])) * (1.0f - color[2]);
|
result[2] = 1.0f - (oneMinusFactor + 2.0f * textureIntensity * (1.0f - materialColor[2])) * (1.0f - color[2]);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case MTEX_SUB:
|
case MTEX_SUB:
|
||||||
textureIntensity *= textureFactor;
|
|
||||||
result[0] = materialColor[0] - textureIntensity * color[0];
|
result[0] = materialColor[0] - textureIntensity * color[0];
|
||||||
result[1] = materialColor[1] - textureIntensity * color[1];
|
result[1] = materialColor[1] - textureIntensity * color[1];
|
||||||
result[2] = materialColor[2] - textureIntensity * color[2];
|
result[2] = materialColor[2] - textureIntensity * color[2];
|
||||||
@ -488,20 +461,17 @@ public class TextureHelper extends AbstractBlenderHelper {
|
|||||||
result[2] = FastMath.clamp(result[2], 0.0f, 1.0f);
|
result[2] = FastMath.clamp(result[2], 0.0f, 1.0f);
|
||||||
break;
|
break;
|
||||||
case MTEX_ADD:
|
case MTEX_ADD:
|
||||||
textureIntensity *= textureFactor;
|
|
||||||
result[0] = (textureIntensity * color[0] + materialColor[0]) * 0.5f;
|
result[0] = (textureIntensity * color[0] + materialColor[0]) * 0.5f;
|
||||||
result[1] = (textureIntensity * color[1] + materialColor[1]) * 0.5f;
|
result[1] = (textureIntensity * color[1] + materialColor[1]) * 0.5f;
|
||||||
result[2] = (textureIntensity * color[2] + materialColor[2]) * 0.5f;
|
result[2] = (textureIntensity * color[2] + materialColor[2]) * 0.5f;
|
||||||
break;
|
break;
|
||||||
case MTEX_DIFF:
|
case MTEX_DIFF:
|
||||||
textureIntensity *= textureFactor;
|
oneMinusFactor = 1.0f - textureIntensity;
|
||||||
facm = 1.0f - textureIntensity;
|
result[0] = oneMinusFactor * materialColor[0] + textureIntensity * Math.abs(materialColor[0] - color[0]);
|
||||||
result[0] = facm * color[0] + textureIntensity * Math.abs(materialColor[0] - color[0]);
|
result[1] = oneMinusFactor * materialColor[1] + textureIntensity * Math.abs(materialColor[1] - color[1]);
|
||||||
result[1] = facm * color[1] + textureIntensity * Math.abs(materialColor[1] - color[1]);
|
result[2] = oneMinusFactor * materialColor[2] + textureIntensity * Math.abs(materialColor[2] - color[2]);
|
||||||
result[2] = facm * color[2] + textureIntensity * Math.abs(materialColor[2] - color[2]);
|
|
||||||
break;
|
break;
|
||||||
case MTEX_DARK:
|
case MTEX_DARK:
|
||||||
textureIntensity *= textureFactor;
|
|
||||||
col = textureIntensity * color[0];
|
col = textureIntensity * color[0];
|
||||||
result[0] = col < materialColor[0] ? col : materialColor[0];
|
result[0] = col < materialColor[0] ? col : materialColor[0];
|
||||||
col = textureIntensity * color[1];
|
col = textureIntensity * color[1];
|
||||||
@ -510,7 +480,6 @@ public class TextureHelper extends AbstractBlenderHelper {
|
|||||||
result[2] = col < materialColor[2] ? col : materialColor[2];
|
result[2] = col < materialColor[2] ? col : materialColor[2];
|
||||||
break;
|
break;
|
||||||
case MTEX_LIGHT:
|
case MTEX_LIGHT:
|
||||||
textureIntensity *= textureFactor;
|
|
||||||
col = textureIntensity * color[0];
|
col = textureIntensity * color[0];
|
||||||
result[0] = col > materialColor[0] ? col : materialColor[0];
|
result[0] = col > materialColor[0] ? col : materialColor[0];
|
||||||
col = textureIntensity * color[1];
|
col = textureIntensity * color[1];
|
||||||
@ -519,24 +488,11 @@ public class TextureHelper extends AbstractBlenderHelper {
|
|||||||
result[2] = col > materialColor[2] ? col : materialColor[2];
|
result[2] = col > materialColor[2] ? col : materialColor[2];
|
||||||
break;
|
break;
|
||||||
case MTEX_BLEND_HUE:
|
case MTEX_BLEND_HUE:
|
||||||
textureIntensity *= textureFactor;
|
|
||||||
System.arraycopy(materialColor, 0, result, 0, 3);
|
|
||||||
this.rampBlend(MA_RAMP_HUE, result, textureIntensity, color, dataRepository);
|
|
||||||
break;
|
|
||||||
case MTEX_BLEND_SAT:
|
case MTEX_BLEND_SAT:
|
||||||
textureIntensity *= textureFactor;
|
|
||||||
System.arraycopy(materialColor, 0, result, 0, 3);
|
|
||||||
this.rampBlend(MA_RAMP_SAT, result, textureIntensity, color, dataRepository);
|
|
||||||
break;
|
|
||||||
case MTEX_BLEND_VAL:
|
case MTEX_BLEND_VAL:
|
||||||
textureIntensity *= textureFactor;
|
|
||||||
System.arraycopy(materialColor, 0, result, 0, 3);
|
|
||||||
this.rampBlend(MA_RAMP_VAL, result, textureIntensity, color, dataRepository);
|
|
||||||
break;
|
|
||||||
case MTEX_BLEND_COLOR:
|
case MTEX_BLEND_COLOR:
|
||||||
textureIntensity *= textureFactor;
|
|
||||||
System.arraycopy(materialColor, 0, result, 0, 3);
|
System.arraycopy(materialColor, 0, result, 0, 3);
|
||||||
this.rampBlend(MA_RAMP_COLOR, result, textureIntensity, color, dataRepository);
|
this.rampBlend(blendtype, result, textureIntensity, color, dataRepository);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new IllegalStateException("Unknown blend type: " + blendtype);
|
throw new IllegalStateException("Unknown blend type: " + blendtype);
|
||||||
@ -544,10 +500,10 @@ 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.
|
||||||
*
|
*
|
||||||
* @param type
|
* @param type
|
||||||
* the ramp type
|
* the blend 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
|
||||||
@ -558,241 +514,62 @@ public class TextureHelper extends AbstractBlenderHelper {
|
|||||||
* the data repository
|
* the data repository
|
||||||
*/
|
*/
|
||||||
protected void rampBlend(int type, float[] rgb, float fac, float[] col, DataRepository dataRepository) {
|
protected void rampBlend(int type, float[] rgb, float fac, float[] col, DataRepository dataRepository) {
|
||||||
float tmp, facm = 1.0f - fac;
|
float oneMinusFactor = 1.0f - fac;
|
||||||
MaterialHelper materialHelper = dataRepository.getHelper(MaterialHelper.class);
|
MaterialHelper materialHelper = dataRepository.getHelper(MaterialHelper.class);
|
||||||
|
|
||||||
|
if (rgb.length >= 3) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case MA_RAMP_HUE:
|
case MTEX_BLEND_HUE: {
|
||||||
if (rgb.length == 3) {
|
|
||||||
float[] colorTransformResult = new float[3];
|
float[] colorTransformResult = new float[3];
|
||||||
materialHelper.rgbToHsv(col[0], col[1], col[2], colorTransformResult);
|
materialHelper.rgbToHsv(col[0], col[1], col[2], colorTransformResult);
|
||||||
if (colorTransformResult[1] != 0.0f) {
|
if (colorTransformResult[1] != 0.0f) {
|
||||||
float colH = colorTransformResult[0];
|
float colH = colorTransformResult[0];
|
||||||
materialHelper.rgbToHsv(rgb[0], rgb[1], rgb[2], colorTransformResult);
|
materialHelper.rgbToHsv(rgb[0], rgb[1], rgb[2], colorTransformResult);
|
||||||
materialHelper.hsvToRgb(colH, colorTransformResult[1], colorTransformResult[2], colorTransformResult);
|
materialHelper.hsvToRgb(colH, colorTransformResult[1], colorTransformResult[2], colorTransformResult);
|
||||||
rgb[0] = facm * rgb[0] + fac * colorTransformResult[0];
|
rgb[0] = oneMinusFactor * rgb[0] + fac * colorTransformResult[0];
|
||||||
rgb[1] = facm * rgb[1] + fac * colorTransformResult[1];
|
rgb[1] = oneMinusFactor * rgb[1] + fac * colorTransformResult[1];
|
||||||
rgb[2] = facm * rgb[2] + fac * colorTransformResult[2];
|
rgb[2] = oneMinusFactor * rgb[2] + fac * colorTransformResult[2];
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case MA_RAMP_SAT:
|
}
|
||||||
if (rgb.length == 3) {
|
case MTEX_BLEND_SAT: {
|
||||||
float[] colorTransformResult = new float[3];
|
float[] colorTransformResult = new float[3];
|
||||||
materialHelper.rgbToHsv(rgb[0], rgb[1], rgb[2], colorTransformResult);
|
materialHelper.rgbToHsv(rgb[0], rgb[1], rgb[2], colorTransformResult);
|
||||||
float rH = colorTransformResult[0];
|
float h = colorTransformResult[0];
|
||||||
float rS = colorTransformResult[1];
|
float s = colorTransformResult[1];
|
||||||
float rV = colorTransformResult[2];
|
float v = colorTransformResult[2];
|
||||||
if (rS != 0) {
|
if (s != 0.0f) {
|
||||||
materialHelper.rgbToHsv(col[0], col[1], col[2], colorTransformResult);
|
materialHelper.rgbToHsv(col[0], col[1], col[2], colorTransformResult);
|
||||||
materialHelper.hsvToRgb(rH, (facm * rS + fac * colorTransformResult[1]), rV, rgb);
|
materialHelper.hsvToRgb(h, (oneMinusFactor * s + fac * colorTransformResult[1]), v, rgb);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case MA_RAMP_VAL:
|
}
|
||||||
if (rgb.length == 3) {
|
case MTEX_BLEND_VAL: {
|
||||||
float[] rgbToHsv = new float[3];
|
float[] rgbToHsv = new float[3];
|
||||||
float[] colToHsv = new float[3];
|
float[] colToHsv = new float[3];
|
||||||
materialHelper.rgbToHsv(rgb[0], rgb[1], rgb[2], rgbToHsv);
|
materialHelper.rgbToHsv(rgb[0], rgb[1], rgb[2], rgbToHsv);
|
||||||
materialHelper.rgbToHsv(col[0], col[1], col[2], colToHsv);
|
materialHelper.rgbToHsv(col[0], col[1], col[2], colToHsv);
|
||||||
materialHelper.hsvToRgb(rgbToHsv[0], rgbToHsv[1], (facm * rgbToHsv[2] + fac * colToHsv[2]), rgb);
|
materialHelper.hsvToRgb(rgbToHsv[0], rgbToHsv[1], (oneMinusFactor * rgbToHsv[2] + fac * colToHsv[2]), rgb);
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case MA_RAMP_COLOR:
|
}
|
||||||
if (rgb.length == 3) {
|
case MTEX_BLEND_COLOR: {
|
||||||
float[] rgbToHsv = new float[3];
|
float[] rgbToHsv = new float[3];
|
||||||
float[] colToHsv = new float[3];
|
float[] colToHsv = new float[3];
|
||||||
materialHelper.rgbToHsv(col[0], col[1], col[2], colToHsv);
|
materialHelper.rgbToHsv(col[0], col[1], col[2], colToHsv);
|
||||||
if (colToHsv[2] != 0) {
|
if (colToHsv[2] != 0) {
|
||||||
materialHelper.rgbToHsv(rgb[0], rgb[1], rgb[2], rgbToHsv);
|
materialHelper.rgbToHsv(rgb[0], rgb[1], rgb[2], rgbToHsv);
|
||||||
materialHelper.hsvToRgb(colToHsv[0], colToHsv[1], rgbToHsv[2], rgbToHsv);
|
materialHelper.hsvToRgb(colToHsv[0], colToHsv[1], rgbToHsv[2], rgbToHsv);
|
||||||
rgb[0] = facm * rgb[0] + fac * rgbToHsv[0];
|
rgb[0] = oneMinusFactor * rgb[0] + fac * rgbToHsv[0];
|
||||||
rgb[1] = facm * rgb[1] + fac * rgbToHsv[1];
|
rgb[1] = oneMinusFactor * rgb[1] + fac * rgbToHsv[1];
|
||||||
rgb[2] = facm * rgb[2] + fac * rgbToHsv[2];
|
rgb[2] = oneMinusFactor * rgb[2] + fac * rgbToHsv[2];
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case MA_RAMP_BLEND:
|
|
||||||
rgb[0] = facm * rgb[0] + fac * col[0];
|
|
||||||
if (rgb.length == 3) {
|
|
||||||
rgb[1] = facm * rgb[1] + fac * col[1];
|
|
||||||
rgb[2] = facm * rgb[2] + fac * col[2];
|
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
case MA_RAMP_ADD:
|
|
||||||
rgb[0] += fac * col[0];
|
|
||||||
if (rgb.length == 3) {
|
|
||||||
rgb[1] += fac * col[1];
|
|
||||||
rgb[2] += fac * col[2];
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case MA_RAMP_MULT:
|
|
||||||
rgb[0] *= facm + fac * col[0];
|
|
||||||
if (rgb.length == 3) {
|
|
||||||
rgb[1] *= facm + fac * col[1];
|
|
||||||
rgb[2] *= facm + fac * col[2];
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case MA_RAMP_SCREEN:
|
|
||||||
rgb[0] = 1.0f - (facm + fac * (1.0f - col[0])) * (1.0f - rgb[0]);
|
|
||||||
if (rgb.length == 3) {
|
|
||||||
rgb[1] = 1.0f - (facm + fac * (1.0f - col[1])) * (1.0f - rgb[1]);
|
|
||||||
rgb[2] = 1.0f - (facm + fac * (1.0f - col[2])) * (1.0f - rgb[2]);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case MA_RAMP_OVERLAY:
|
|
||||||
if (rgb[0] < 0.5f) {
|
|
||||||
rgb[0] *= facm + 2.0f * fac * col[0];
|
|
||||||
} else {
|
|
||||||
rgb[0] = 1.0f - (facm + 2.0f * fac * (1.0f - col[0])) * (1.0f - rgb[0]);
|
|
||||||
}
|
|
||||||
if (rgb.length == 3) {
|
|
||||||
if (rgb[1] < 0.5f) {
|
|
||||||
rgb[1] *= facm + 2.0f * fac * col[1];
|
|
||||||
} else {
|
|
||||||
rgb[1] = 1.0f - (facm + 2.0f * fac * (1.0f - col[1])) * (1.0f - rgb[1]);
|
|
||||||
}
|
|
||||||
if (rgb[2] < 0.5f) {
|
|
||||||
rgb[2] *= facm + 2.0f * fac * col[2];
|
|
||||||
} else {
|
|
||||||
rgb[2] = 1.0f - (facm + 2.0f * fac * (1.0f - col[2])) * (1.0f - rgb[2]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case MA_RAMP_SUB:
|
|
||||||
rgb[0] -= fac * col[0];
|
|
||||||
if (rgb.length == 3) {
|
|
||||||
rgb[1] -= fac * col[1];
|
|
||||||
rgb[2] -= fac * col[2];
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case MA_RAMP_DIV:
|
|
||||||
if (col[0] != 0.0) {
|
|
||||||
rgb[0] = facm * rgb[0] + fac * rgb[0] / col[0];
|
|
||||||
}
|
|
||||||
if (rgb.length == 3) {
|
|
||||||
if (col[1] != 0.0) {
|
|
||||||
rgb[1] = facm * rgb[1] + fac * rgb[1] / col[1];
|
|
||||||
}
|
|
||||||
if (col[2] != 0.0) {
|
|
||||||
rgb[2] = facm * rgb[2] + fac * rgb[2] / col[2];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case MA_RAMP_DIFF:
|
|
||||||
rgb[0] = facm * rgb[0] + fac * Math.abs(rgb[0] - col[0]);
|
|
||||||
if (rgb.length == 3) {
|
|
||||||
rgb[1] = facm * rgb[1] + fac * Math.abs(rgb[1] - col[1]);
|
|
||||||
rgb[2] = facm * rgb[2] + fac * Math.abs(rgb[2] - col[2]);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case MA_RAMP_DARK:
|
|
||||||
tmp = fac * col[0];
|
|
||||||
if (tmp < rgb[0]) {
|
|
||||||
rgb[0] = tmp;
|
|
||||||
}
|
|
||||||
if (rgb.length == 3) {
|
|
||||||
tmp = fac * col[1];
|
|
||||||
if (tmp < rgb[1]) {
|
|
||||||
rgb[1] = tmp;
|
|
||||||
}
|
|
||||||
tmp = fac * col[2];
|
|
||||||
if (tmp < rgb[2]) {
|
|
||||||
rgb[2] = tmp;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case MA_RAMP_LIGHT:
|
|
||||||
tmp = fac * col[0];
|
|
||||||
if (tmp > rgb[0]) {
|
|
||||||
rgb[0] = tmp;
|
|
||||||
}
|
|
||||||
if (rgb.length == 3) {
|
|
||||||
tmp = fac * col[1];
|
|
||||||
if (tmp > rgb[1]) {
|
|
||||||
rgb[1] = tmp;
|
|
||||||
}
|
|
||||||
tmp = fac * col[2];
|
|
||||||
if (tmp > rgb[2]) {
|
|
||||||
rgb[2] = tmp;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case MA_RAMP_DODGE:
|
|
||||||
if (rgb[0] != 0.0) {
|
|
||||||
tmp = 1.0f - fac * col[0];
|
|
||||||
if (tmp <= 0.0) {
|
|
||||||
rgb[0] = 1.0f;
|
|
||||||
} else if ((tmp = rgb[0] / tmp) > 1.0) {
|
|
||||||
rgb[0] = 1.0f;
|
|
||||||
} else {
|
|
||||||
rgb[0] = tmp;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (rgb.length == 3) {
|
|
||||||
if (rgb[1] != 0.0) {
|
|
||||||
tmp = 1.0f - fac * col[1];
|
|
||||||
if (tmp <= 0.0) {
|
|
||||||
rgb[1] = 1.0f;
|
|
||||||
} else if ((tmp = rgb[1] / tmp) > 1.0) {
|
|
||||||
rgb[1] = 1.0f;
|
|
||||||
} else {
|
|
||||||
rgb[1] = tmp;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (rgb[2] != 0.0) {
|
|
||||||
tmp = 1.0f - fac * col[2];
|
|
||||||
if (tmp <= 0.0) {
|
|
||||||
rgb[2] = 1.0f;
|
|
||||||
} else if ((tmp = rgb[2] / tmp) > 1.0) {
|
|
||||||
rgb[2] = 1.0f;
|
|
||||||
} else {
|
|
||||||
rgb[2] = tmp;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case MA_RAMP_BURN:
|
|
||||||
tmp = facm + fac * col[0];
|
|
||||||
if (tmp <= 0.0) {
|
|
||||||
rgb[0] = 0.0f;
|
|
||||||
} else if ((tmp = 1.0f - (1.0f - rgb[0]) / tmp) < 0.0) {
|
|
||||||
rgb[0] = 0.0f;
|
|
||||||
} else if (tmp > 1.0) {
|
|
||||||
rgb[0] = 1.0f;
|
|
||||||
} else {
|
|
||||||
rgb[0] = tmp;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (rgb.length == 3) {
|
|
||||||
tmp = facm + fac * col[1];
|
|
||||||
if (tmp <= 0.0) {
|
|
||||||
rgb[1] = 0.0f;
|
|
||||||
} else if ((tmp = 1.0f - (1.0f - rgb[1]) / tmp) < 0.0) {
|
|
||||||
rgb[1] = 0.0f;
|
|
||||||
} else if (tmp > 1.0) {
|
|
||||||
rgb[1] = 1.0f;
|
|
||||||
} else {
|
|
||||||
rgb[1] = tmp;
|
|
||||||
}
|
|
||||||
|
|
||||||
tmp = facm + fac * col[2];
|
|
||||||
if (tmp <= 0.0) {
|
|
||||||
rgb[2] = 0.0f;
|
|
||||||
} else if ((tmp = 1.0f - (1.0f - rgb[2]) / tmp) < 0.0) {
|
|
||||||
rgb[2] = 0.0f;
|
|
||||||
} else if (tmp > 1.0) {
|
|
||||||
rgb[2] = 1.0f;
|
|
||||||
} else {
|
|
||||||
rgb[2] = tmp;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
throw new IllegalStateException("Unknown ramp type: " + type);
|
throw new IllegalStateException("Unknown ramp type: " + type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method converts the given texture into normal-map texture.
|
* This method converts the given texture into normal-map texture.
|
||||||
@ -966,107 +743,8 @@ public class TextureHelper extends AbstractBlenderHelper {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* This method closes the given stream.
|
|
||||||
*
|
|
||||||
* @param is
|
|
||||||
* the input stream that is to be closed
|
|
||||||
*/
|
|
||||||
protected void closeStream(InputStream is) {
|
|
||||||
if (is != null) {
|
|
||||||
try {
|
|
||||||
is.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
LOGGER.log(Level.SEVERE, e.getLocalizedMessage(), e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean shouldBeLoaded(Structure structure, DataRepository dataRepository) {
|
public boolean shouldBeLoaded(Structure structure, DataRepository dataRepository) {
|
||||||
return (dataRepository.getBlenderKey().getFeaturesToLoad() & FeaturesToLoad.TEXTURES) != 0;
|
return (dataRepository.getBlenderKey().getFeaturesToLoad() & FeaturesToLoad.TEXTURES) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Image types that can be loaded. AWT: png, jpg, jped or bmp TGA: tga DDS: DirectX image files
|
|
||||||
*
|
|
||||||
* @author Marcin Roguski (Kaelthas)
|
|
||||||
*/
|
|
||||||
public static enum ImageType {
|
|
||||||
AWT, TGA, DDS;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The result pixel of generated texture computations;
|
|
||||||
*
|
|
||||||
* @author Marcin Roguski (Kaelthas)
|
|
||||||
*/
|
|
||||||
protected static class TexResult implements Cloneable {
|
|
||||||
public float tin, tr, tg, tb, ta;
|
|
||||||
public int talpha;
|
|
||||||
public float[] nor;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object clone() throws CloneNotSupportedException {
|
|
||||||
return super.clone();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A class constaining the colorband data.
|
|
||||||
*
|
|
||||||
* @author Marcin Roguski (Kaelthas)
|
|
||||||
*/
|
|
||||||
protected static class ColorBand {
|
|
||||||
public int flag, tot, cur, ipotype;
|
|
||||||
public CBData[] data = new CBData[32];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructor. Loads the data from the given structure.
|
|
||||||
*
|
|
||||||
* @param cbdataStructure
|
|
||||||
* the colorband structure
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public ColorBand(Structure colorbandStructure) {
|
|
||||||
this.flag = ((Number) colorbandStructure.getFieldValue("flag")).intValue();
|
|
||||||
this.tot = ((Number) colorbandStructure.getFieldValue("tot")).intValue();
|
|
||||||
this.cur = ((Number) colorbandStructure.getFieldValue("cur")).intValue();
|
|
||||||
this.ipotype = ((Number) colorbandStructure.getFieldValue("ipotype")).intValue();
|
|
||||||
DynamicArray<Structure> data = (DynamicArray<Structure>) colorbandStructure.getFieldValue("data");
|
|
||||||
for (int i = 0; i < data.getTotalSize(); ++i) {
|
|
||||||
this.data[i] = new CBData(data.get(i));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class to store the single colorband unit data.
|
|
||||||
*
|
|
||||||
* @author Marcin Roguski (Kaelthas)
|
|
||||||
*/
|
|
||||||
protected static class CBData implements Cloneable {
|
|
||||||
public float r, g, b, a, pos;
|
|
||||||
public int cur;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructor. Loads the data from the given structure.
|
|
||||||
*
|
|
||||||
* @param cbdataStructure
|
|
||||||
* the structure containing the CBData object
|
|
||||||
*/
|
|
||||||
public CBData(Structure cbdataStructure) {
|
|
||||||
this.r = ((Number) cbdataStructure.getFieldValue("r")).floatValue();
|
|
||||||
this.g = ((Number) cbdataStructure.getFieldValue("g")).floatValue();
|
|
||||||
this.b = ((Number) cbdataStructure.getFieldValue("b")).floatValue();
|
|
||||||
this.a = ((Number) cbdataStructure.getFieldValue("a")).floatValue();
|
|
||||||
this.pos = ((Number) cbdataStructure.getFieldValue("pos")).floatValue();
|
|
||||||
this.cur = ((Number) cbdataStructure.getFieldValue("cur")).intValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object clone() throws CloneNotSupportedException {
|
|
||||||
return super.clone();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -320,7 +320,54 @@ public class UVCoordinatesGenerator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void merge(BoundingTube boundingTube) {
|
public void merge(BoundingTube boundingTube) {
|
||||||
// TODO: implement
|
//get tubes (tube1.radius >= tube2.radius)
|
||||||
|
BoundingTube tube1, tube2;
|
||||||
|
if(this.radius>=boundingTube.radius) {
|
||||||
|
tube1 = this;
|
||||||
|
tube2 = boundingTube;
|
||||||
|
} else {
|
||||||
|
tube1 = boundingTube;
|
||||||
|
tube2 = this;
|
||||||
|
}
|
||||||
|
float r1 = tube1.radius;
|
||||||
|
float r2 = tube2.radius;
|
||||||
|
|
||||||
|
//get the distance between tubes projected on XY plane
|
||||||
|
Vector3f distance = boundingTube.center.subtract(this.center);
|
||||||
|
distance.z = 0;
|
||||||
|
float d = distance.length();
|
||||||
|
|
||||||
|
//calculate union depending on tubes location
|
||||||
|
if(d>=r1+r2) {//tube2 is outside or touches tube1
|
||||||
|
|
||||||
|
} else if(d<r1+r2 && d>r1-r2) {//tube2 crosses tube1
|
||||||
|
|
||||||
|
} else {//tube2 is inside tube1
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if(d >= this.radius + boundingTube.radius ||
|
||||||
|
(d < this.radius + boundingTube.radius && d > this.radius - boundingTube.radius)) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
float centerZ = distance.z;
|
||||||
|
|
||||||
|
float maxz = this.center.z + height*0.5f;
|
||||||
|
float minz = this.center.z - height*0.5f;
|
||||||
|
|
||||||
|
distance.z = this.center.z = 0;
|
||||||
|
|
||||||
|
Vector3f distanceNormal = distance.normalize();
|
||||||
|
Vector3f start = this.center.subtract(distanceNormal.multLocal(this.radius));
|
||||||
|
distanceNormal.normalizeLocal();
|
||||||
|
Vector3f stop = start.add(distance).addLocal(distanceNormal.multLocal(this.radius+boundingTube.radius));
|
||||||
|
this.center = start.add(stop.subtractLocal(start)).multLocal(0.5f);
|
||||||
|
this.center.z = centerZ;
|
||||||
|
this.radius = this.center.subtract(start).length();
|
||||||
|
maxz = Math.max(maxz, boundingTube.center.z + boundingTube.height*0.5f);
|
||||||
|
minz = Math.min(minz, boundingTube.center.z - boundingTube.height*0.5f);
|
||||||
|
this.height = maxz - minz;
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getRadius() {
|
public float getRadius() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user