OSDN Git Service

Textures importing refactoring in blender loader.
authorKaelthas_Spellsinger@o2.pl <Kaelthas_Spellsinger@o2.pl@75d07b2b-3a1a-0410-a2c5-0572b91ccdca>
Thu, 4 Aug 2011 21:39:35 +0000 (21:39 +0000)
committerKaelthas_Spellsinger@o2.pl <Kaelthas_Spellsinger@o2.pl@75d07b2b-3a1a-0410-a2c5-0572b91ccdca>
Thu, 4 Aug 2011 21:39:35 +0000 (21:39 +0000)
Each generated texture has now its own generator class.

git-svn-id: http://jmonkeyengine.googlecode.com/svn/trunk@7975 75d07b2b-3a1a-0410-a2c5-0572b91ccdca

14 files changed:
engine/src/blender/com/jme3/scene/plugins/blender/textures/ImageLoader.java [new file with mode: 0644]
engine/src/blender/com/jme3/scene/plugins/blender/textures/NoiseGenerator.java
engine/src/blender/com/jme3/scene/plugins/blender/textures/TextureGenerator.java [new file with mode: 0644]
engine/src/blender/com/jme3/scene/plugins/blender/textures/TextureGeneratorBlend.java [new file with mode: 0644]
engine/src/blender/com/jme3/scene/plugins/blender/textures/TextureGeneratorClouds.java [new file with mode: 0644]
engine/src/blender/com/jme3/scene/plugins/blender/textures/TextureGeneratorDistnoise.java [new file with mode: 0644]
engine/src/blender/com/jme3/scene/plugins/blender/textures/TextureGeneratorMagic.java [new file with mode: 0644]
engine/src/blender/com/jme3/scene/plugins/blender/textures/TextureGeneratorMarble.java [new file with mode: 0644]
engine/src/blender/com/jme3/scene/plugins/blender/textures/TextureGeneratorMusgrave.java [new file with mode: 0644]
engine/src/blender/com/jme3/scene/plugins/blender/textures/TextureGeneratorNoise.java [new file with mode: 0644]
engine/src/blender/com/jme3/scene/plugins/blender/textures/TextureGeneratorStucci.java [new file with mode: 0644]
engine/src/blender/com/jme3/scene/plugins/blender/textures/TextureGeneratorVoronoi.java [new file with mode: 0644]
engine/src/blender/com/jme3/scene/plugins/blender/textures/TextureGeneratorWood.java [new file with mode: 0644]
engine/src/blender/com/jme3/scene/plugins/blender/textures/TextureHelper.java

diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/textures/ImageLoader.java b/engine/src/blender/com/jme3/scene/plugins/blender/textures/ImageLoader.java
new file mode 100644 (file)
index 0000000..dd99a81
--- /dev/null
@@ -0,0 +1,97 @@
+package com.jme3.scene.plugins.blender.textures;
+
+import java.io.InputStream;
+import java.util.logging.Logger;
+
+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.plugins.AWTLoader;
+import com.jme3.texture.plugins.DDSLoader;
+import com.jme3.texture.plugins.TGALoader;
+
+/**
+ * An image loader class. It uses three loaders (AWTLoader, TGALoader and DDSLoader) in an attempt to load the image from the given
+ * input stream.
+ * 
+ * @author Marcin Roguski (Kaelthas)
+ */
+/*package*/ class ImageLoader extends AWTLoader {
+       private static final Logger     LOGGER          = Logger.getLogger(ImageLoader.class.getName());
+
+       protected DDSLoader                     ddsLoader       = new DDSLoader();                                                                      // DirectX image loader
+
+       /**
+        * This method loads the image from the blender file itself. It tries each loader to load the image.
+        * 
+        * @param inputStream
+        *        blender input stream
+        * @param startPosition
+        *        position in the stream where the image data starts
+        * @param flipY
+        *        if the image should be flipped (does not work with DirectX image)
+        * @return loaded image or null if it could not be loaded
+        */
+       public Image loadImage(BlenderInputStream inputStream, int startPosition, boolean flipY) {
+               // loading using AWT loader
+               inputStream.setPosition(startPosition);
+               Image result = this.loadImage(inputStream, ImageType.AWT, flipY);
+               // loading using TGA loader
+               if (result == null) {
+                       inputStream.setPosition(startPosition);
+                       result = this.loadImage(inputStream, ImageType.TGA, flipY);
+               }
+               // loading using DDS loader
+               if (result == null) {
+                       inputStream.setPosition(startPosition);
+                       result = this.loadImage(inputStream, ImageType.DDS, flipY);
+               }
+
+               if (result == null) {
+                       LOGGER.warning("Image could not be loaded by none of available loaders!");
+               }
+
+               return result;
+       }
+
+       /**
+        * This method loads an image of a specified type from the given input stream.
+        * 
+        * @param inputStream
+        *        the input stream we read the image from
+        * @param imageType
+        *        the type of the image {@link ImageType}
+        * @param flipY
+        *        if the image should be flipped (does not work with DirectX image)
+        * @return loaded image or null if it could not be loaded
+        */
+       public Image loadImage(InputStream inputStream, ImageType imageType, boolean flipY) {
+               Image result = null;
+               switch (imageType) {
+                       case AWT:
+                               try {
+                                       result = this.load(inputStream, flipY);
+                               } catch (Exception e) {
+                                       LOGGER.info("Unable to load image using AWT loader!");
+                               }
+                               break;
+                       case DDS:
+                               try {
+                                       result = ddsLoader.load(inputStream);
+                               } catch (Exception e) {
+                                       LOGGER.info("Unable to load image using DDS loader!");
+                               }
+                               break;
+                       case TGA:
+                               try {
+                                       result = TGALoader.load(inputStream, flipY);
+                               } catch (Exception e) {
+                                       LOGGER.info("Unable to load image using TGA loader!");
+                               }
+                               break;
+                       default:
+                               throw new IllegalStateException("Unknown image type: " + imageType);
+               }
+               return result;
+       }
+}
index 8b3def7..e441cd1 100644 (file)
@@ -57,20 +57,20 @@ import com.jme3.scene.plugins.blender.textures.TextureHelper.TexResult;
 \r
     private static final Logger LOGGER = Logger.getLogger(NoiseGenerator.class.getName());\r
 \r
-    /* return value */\r
+    // return value\r
     protected static final int TEX_INT = 0;\r
     protected static final int TEX_RGB = 1;\r
     protected static final int TEX_NOR = 2;\r
 \r
-    /* noisetype */\r
+    // noisetype\r
     protected static final int TEX_NOISESOFT = 0;\r
     protected static final int TEX_NOISEPERL = 1;\r
 \r
-    /* tex->stype in texture.c - cloud types */\r
+    // tex->stype\r
     protected static final int TEX_DEFAULT = 0;\r
     protected static final int TEX_COLOR = 1;\r
 \r
-    /* flag */\r
+    // flag\r
     protected static final int TEX_COLORBAND = 1;\r
     protected static final int TEX_FLIPBLEND = 2;\r
     protected static final int TEX_NEGALPHA = 4;\r
@@ -82,23 +82,23 @@ import com.jme3.scene.plugins.blender.textures.TextureHelper.TexResult;
     protected static final int TEX_REPEAT_YMIR = 256;\r
     protected static final int TEX_FLAG_MASK = TEX_COLORBAND | TEX_FLIPBLEND | TEX_NEGALPHA | TEX_CHECKER_ODD | TEX_CHECKER_EVEN | TEX_PRV_ALPHA | TEX_PRV_NOR | TEX_REPEAT_XMIR | TEX_REPEAT_YMIR;\r
 \r
-    /* tex->noisebasis2 in texture.c - wood waveforms */\r
+    // tex->noisebasis2\r
     protected static final int TEX_SIN = 0;\r
     protected static final int TEX_SAW = 1;\r
     protected static final int TEX_TRI = 2;\r
 \r
-    /* tex->stype in texture.c - marble types */\r
+    // tex->stype\r
     protected static final int TEX_SOFT = 0;\r
     protected static final int TEX_SHARP = 1;\r
     protected static final int TEX_SHARPER = 2;\r
 \r
-    /* tex->stype in texture.c - wood types */\r
+    // tex->stype\r
     protected static final int TEX_BAND = 0;\r
     protected static final int TEX_RING = 1;\r
     protected static final int TEX_BANDNOISE = 2;\r
     protected static final int TEX_RINGNOISE = 3;\r
 \r
-    /* tex->stype in texture.c - blend types */\r
+    // tex->stype\r
     protected static final int TEX_LIN = 0;\r
     protected static final int TEX_QUAD = 1;\r
     protected static final int TEX_EASE = 2;\r
@@ -107,24 +107,24 @@ import com.jme3.scene.plugins.blender.textures.TextureHelper.TexResult;
     protected static final int TEX_HALO = 5;\r
     protected static final int TEX_RAD = 6;\r
 \r
-    /* tex->stype in texture.c - stucci types */\r
+    // tex->stype\r
     protected static final int TEX_PLASTIC = 0;\r
     protected static final int TEX_WALLIN = 1;\r
     protected static final int TEX_WALLOUT = 2;\r
 \r
-    /* musgrave stype */\r
+    // musgrave stype\r
     protected static final int TEX_MFRACTAL = 0;\r
     protected static final int TEX_RIDGEDMF = 1;\r
     protected static final int TEX_HYBRIDMF = 2;\r
     protected static final int TEX_FBM = 3;\r
     protected static final int TEX_HTERRAIN = 4;\r
 \r
-    /* keyblock->type */\r
+    // keyblock->type\r
     protected static final int KEY_LINEAR = 0;\r
     protected static final int KEY_CARDINAL = 1;\r
     protected static final int KEY_BSPLINE = 2;\r
 \r
-    /* CONSTANTS (read from file) */\r
+    // CONSTANTS (read from file)\r
     protected static float[] hashpntf;\r
     protected static short[] hash;\r
     protected static float[] hashvectf;\r
@@ -1288,10 +1288,7 @@ import com.jme3.scene.plugins.blender.textures.TextureHelper.TexResult;
             }\r
         }\r
 \r
-        // #define HASHVEC(x,y,z) hashvectf+3*hash[ (hash[ (hash[(z) & 255]+(y)) & 255]+(x)) & 255]\r
-\r
-        /* needed for voronoi */\r
-        // #define HASHPNT(x,y,z) hashpntf+3*hash[ (hash[ (hash[(z) & 255]+(y)) & 255]+(x)) & 255]\r
+        // needed for voronoi\r
         protected static float[] hashPoint(int x, int y, int z) {\r
             float[] result = new float[3];\r
             result[0] = hashpntf[3 * hash[hash[hash[z & 255] + y & 255] + x & 255]];\r
@@ -1300,31 +1297,23 @@ import com.jme3.scene.plugins.blender.textures.TextureHelper.TexResult;
             return result;\r
         }\r
 \r
-        // #define setup(i,b0,b1,r0,r1) \\r
-        // t = vec[i] + 10000.; \\r
-        // b0 = ((int)t) & 255; \\r
-        // b1 = (b0+1) & 255; \\r
-        // r0 = t - (int)t; \\r
-        // r1 = r0 - 1.;\r
-        // vec[3]\r
         public float noise3Perlin(float[] vec) {\r
             int bx0, bx1, by0, by1, bz0, bz1, b00, b10, b01, b11;\r
             float rx0, rx1, ry0, ry1, rz0, rz1, sx, sy, sz, a, b, c, d, t, u, v;\r
             int i, j;\r
 \r
-            // setup(0, bx0,bx1, rx0,rx1);\r
             t = vec[0] + 10000.0f;\r
             bx0 = (int) t & 255;\r
             bx1 = bx0 + 1 & 255;\r
             rx0 = t - (int) t;\r
             rx1 = rx0 - 1.0f;\r
-            // setup(1, by0,by1, ry0,ry1);\r
+            \r
             t = vec[0] + 10000.0f;\r
             by0 = (int) t & 255;\r
             by1 = by0 + 1 & 255;\r
             ry0 = t - (int) t;\r
             ry1 = ry0 - 1.0f;\r
-            // setup(2, bz0,bz1, rz0,rz1);\r
+            \r
             t = vec[0] + 10000.0f;\r
             bz0 = (int) t & 255;\r
             bz1 = bz0 + 1 & 255;\r
@@ -1339,7 +1328,7 @@ import com.jme3.scene.plugins.blender.textures.TextureHelper.TexResult;
             b01 = p[i + by1];\r
             b11 = p[j + by1];\r
 \r
-            /* lerp moved to improved perlin above */\r
+            // lerp moved to improved perlin above\r
 \r
             sx = this.surve(rx0);\r
             sy = this.surve(ry0);\r
@@ -1358,7 +1347,7 @@ import com.jme3.scene.plugins.blender.textures.TextureHelper.TexResult;
             v = this.at(rx1, ry1, rz0, q);\r
             b = this.lerp(sx, u, v);\r
 \r
-            c = this.lerp(sy, a, b); /* interpolate in y at lo x */\r
+            c = this.lerp(sy, a, b); // interpolate in y at lo x\r
 \r
             q = g[b00 + bz1];\r
             u = this.at(rx0, ry0, rz1, q);\r
@@ -1372,31 +1361,32 @@ import com.jme3.scene.plugins.blender.textures.TextureHelper.TexResult;
             v = this.at(rx1, ry1, rz1, q);\r
             b = this.lerp(sx, u, v);\r
 \r
-            d = this.lerp(sy, a, b); /* interpolate in y at hi x */\r
+            d = this.lerp(sy, a, b); // interpolate in y at hi x\r
 \r
-            return 1.5f * this.lerp(sz, c, d); /* interpolate in z */\r
+            return 1.5f * this.lerp(sz, c, d); // interpolate in z\r
         }\r
 \r
         public float orgBlenderNoise(float x, float y, float z) {\r
-            float cn1, cn2, cn3, cn4, cn5, cn6, i;\r
-            float ox, oy, oz, jx, jy, jz;\r
             float n = 0.5f;\r
-            int ix, iy, iz, b00, b01, b10, b11, b20, b21;\r
-\r
-            ox = x - (ix = (int) Math.floor(x));\r
-            oy = y - (iy = (int) Math.floor(y));\r
-            oz = z - (iz = (int) Math.floor(z));\r
-\r
-            jx = ox - 1;\r
-            jy = oy - 1;\r
-            jz = oz - 1;\r
 \r
-            cn1 = ox * ox;\r
-            cn2 = oy * oy;\r
-            cn3 = oz * oz;\r
-            cn4 = jx * jx;\r
-            cn5 = jy * jy;\r
-            cn6 = jz * jz;\r
+            int ix = (int) Math.floor(x);\r
+            int iy = (int) Math.floor(y);\r
+            int iz = (int) Math.floor(z);\r
+            \r
+            float ox = x - ix;\r
+            float oy = y - iy;\r
+            float oz = z - iz;\r
+\r
+            float jx = ox - 1;\r
+            float jy = oy - 1;\r
+            float jz = oz - 1;\r
+\r
+            float cn1 = ox * ox;\r
+            float cn2 = oy * oy;\r
+            float cn3 = oz * oz;\r
+            float cn4 = jx * jx;\r
+            float cn5 = jy * jy;\r
+            float cn6 = jz * jz;\r
 \r
             cn1 = 1.0f - 3.0f * cn1 + 2.0f * cn1 * ox;\r
             cn2 = 1.0f - 3.0f * cn2 + 2.0f * cn2 * oy;\r
@@ -1405,43 +1395,43 @@ import com.jme3.scene.plugins.blender.textures.TextureHelper.TexResult;
             cn5 = 1.0f - 3.0f * cn5 - 2.0f * cn5 * jy;\r
             cn6 = 1.0f - 3.0f * cn6 - 2.0f * cn6 * jz;\r
 \r
-            b00 = hash[hash[ix & 255] + (iy & 255)];\r
-            b10 = hash[hash[ix + 1 & 255] + (iy & 255)];\r
-            b01 = hash[hash[ix & 255] + (iy + 1 & 255)];\r
-            b11 = hash[hash[ix + 1 & 255] + (iy + 1 & 255)];\r
+            int b00 = hash[hash[ix & 255] + (iy & 255)];\r
+            int b10 = hash[hash[ix + 1 & 255] + (iy & 255)];\r
+            int b01 = hash[hash[ix & 255] + (iy + 1 & 255)];\r
+            int b11 = hash[hash[ix + 1 & 255] + (iy + 1 & 255)];\r
 \r
-            b20 = iz & 255;\r
-            b21 = iz + 1 & 255;\r
+            int b20 = iz & 255;\r
+            int b21 = iz + 1 & 255;\r
 \r
-            /* 0 */\r
-            i = cn1 * cn2 * cn3;\r
+            // 0\r
+            float i = cn1 * cn2 * cn3;\r
             int hIndex = 3 * hash[b20 + b00];\r
             n += i * (hashvectf[hIndex] * ox + hashvectf[hIndex + 1] * oy + hashvectf[hIndex + 2] * oz);\r
-            /* 1 */\r
+            // 1\r
             i = cn1 * cn2 * cn6;\r
             hIndex = 3 * hash[b21 + b00];\r
             n += i * (hashvectf[hIndex] * ox + hashvectf[hIndex + 1] * oy + hashvectf[hIndex + 2] * jz);\r
-            /* 2 */\r
+            // 2\r
             i = cn1 * cn5 * cn3;\r
             hIndex = 3 * hash[b20 + b01];\r
             n += i * (hashvectf[hIndex] * ox + hashvectf[hIndex + 1] * jy + hashvectf[hIndex + 2] * oz);\r
-            /* 3 */\r
+            // 3\r
             i = cn1 * cn5 * cn6;\r
             hIndex = 3 * hash[b21 + b01];\r
             n += i * (hashvectf[hIndex] * ox + hashvectf[hIndex + 1] * jy + hashvectf[hIndex + 2] * jz);\r
-            /* 4 */\r
+            // 4\r
             i = cn4 * cn2 * cn3;\r
             hIndex = 3 * hash[b20 + b10];\r
             n += i * (hashvectf[hIndex] * jx + hashvectf[hIndex + 1] * oy + hashvectf[hIndex + 2] * oz);\r
-            /* 5 */\r
+            // 5\r
             i = cn4 * cn2 * cn6;\r
             hIndex = 3 * hash[b21 + b10];\r
             n += i * (hashvectf[hIndex] * jx + hashvectf[hIndex + 1] * oy + hashvectf[hIndex + 2] * jz);\r
-            /* 6 */\r
+            // 6\r
             i = cn4 * cn5 * cn3;\r
             hIndex = 3 * hash[b20 + b11];\r
             n += i * (hashvectf[hIndex] * jx + hashvectf[hIndex + 1] * jy + hashvectf[hIndex + 2] * oz);\r
-            /* 7 */\r
+            // 7\r
             i = cn4 * cn5 * cn6;\r
             hIndex = 3 * hash[b21 + b11];\r
             n += i * (hashvectf[hIndex] * jx + hashvectf[hIndex + 1] * jy + hashvectf[hIndex + 2] * jz);\r
@@ -1454,7 +1444,7 @@ import com.jme3.scene.plugins.blender.textures.TextureHelper.TexResult;
             return n;\r
         }\r
 \r
-        /* instead of adding another permutation array, just use hash table defined above */\r
+        // instead of adding another permutation array, just use hash table defined above\r
         public float newPerlin(float x, float y, float z) {\r
             int A, AA, AB, B, BA, BB;\r
             float u = (float) Math.floor(x), v = (float) Math.floor(y), w = (float) Math.floor(z);\r
diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/textures/TextureGenerator.java b/engine/src/blender/com/jme3/scene/plugins/blender/textures/TextureGenerator.java
new file mode 100644 (file)
index 0000000..1629290
--- /dev/null
@@ -0,0 +1,64 @@
+package com.jme3.scene.plugins.blender.textures;
+
+import java.util.logging.Logger;
+
+import com.jme3.scene.plugins.blender.DataRepository;
+import com.jme3.scene.plugins.blender.exceptions.BlenderFileException;
+import com.jme3.scene.plugins.blender.file.Pointer;
+import com.jme3.scene.plugins.blender.file.Structure;
+import com.jme3.scene.plugins.blender.textures.TextureHelper.ColorBand;
+import com.jme3.texture.Texture;
+
+/**
+ * This class is a base class for texture generators.
+ * @author Marcin Roguski (Kaelthas)
+ */
+/* package */abstract class TextureGenerator {
+       private static final Logger LOGGER = Logger.getLogger(TextureGenerator.class.getName());
+       
+       protected NoiseGenerator noiseGenerator;
+       
+       public TextureGenerator(NoiseGenerator noiseGenerator) {
+               this.noiseGenerator = noiseGenerator;
+       }
+       
+       /**
+        * This method generates the texture.
+        * @param tex
+        *        texture's structure
+        * @param width
+        *        the width of the result texture
+        * @param height
+        *        the height of the result texture
+        * @param dataRepository
+        *        the data repository
+        * @return newly generated texture
+        */
+       protected abstract Texture generate(Structure tex, int width, int height, DataRepository dataRepository);
+       
+       /**
+        * This method reads the colorband data from the given texture structure.
+        * 
+        * @param tex
+        *        the texture structure
+        * @param dataRepository
+        *        the data repository
+        * @return read colorband or null if not present
+        */
+       protected ColorBand readColorband(Structure tex, DataRepository dataRepository) {
+               ColorBand result = null;
+               int flag = ((Number) tex.getFieldValue("flag")).intValue();
+               if ((flag & NoiseGenerator.TEX_COLORBAND) != 0) {
+                       Pointer pColorband = (Pointer) tex.getFieldValue("coba");
+                       Structure colorbandStructure;
+                       try {
+                               colorbandStructure = pColorband.fetchData(dataRepository.getInputStream()).get(0);
+                               result = new ColorBand(colorbandStructure);
+                       } catch (BlenderFileException e) {
+                               LOGGER.warning("Cannot fetch the colorband structure. The reason: " + e.getLocalizedMessage());
+                               // TODO: throw an exception here ???
+                       }
+               }
+               return result;
+       }
+}
diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/textures/TextureGeneratorBlend.java b/engine/src/blender/com/jme3/scene/plugins/blender/textures/TextureGeneratorBlend.java
new file mode 100644 (file)
index 0000000..52e4ecb
--- /dev/null
@@ -0,0 +1,105 @@
+package com.jme3.scene.plugins.blender.textures;
+
+import java.nio.ByteBuffer;
+
+import com.jme3.math.FastMath;
+import com.jme3.scene.plugins.blender.DataRepository;
+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.Texture;
+import com.jme3.texture.Texture2D;
+import com.jme3.texture.Image.Format;
+import com.jme3.util.BufferUtils;
+
+/**
+ * This class generates the 'blend' texture.
+ * @author Marcin Roguski (Kaelthas)
+ */
+public final class TextureGeneratorBlend extends TextureGenerator {
+
+       /**
+        * Constructor stores the given noise generator.
+        * @param noiseGenerator the noise generator
+        */
+       public TextureGeneratorBlend(NoiseGenerator noiseGenerator) {
+               super(noiseGenerator);
+       }
+
+       @Override
+       protected Texture generate(Structure tex, int width, int height, DataRepository dataRepository) {
+               int flag = ((Number) tex.getFieldValue("flag")).intValue();
+               int stype = ((Number) tex.getFieldValue("stype")).intValue();
+               float contrast = ((Number) tex.getFieldValue("contrast")).floatValue();
+               float brightness = ((Number) tex.getFieldValue("bright")).floatValue();
+               float wDelta = 1.0f / width, hDelta = 1.0f / height, x, y, t;
+               float[] texvec = new float[] { 0, 0, 0 };
+               TexResult texres = new TexResult();
+               int halfW = width, halfH = height;
+               width <<= 1;
+               height <<= 1;
+               ColorBand colorBand = this.readColorband(tex, dataRepository);
+               Format format = colorBand != null ? Format.RGB8 : Format.Luminance8;
+               int bytesPerPixel = colorBand != null ? 3 : 1;
+
+               ByteBuffer data = BufferUtils.createByteBuffer(width * height * bytesPerPixel);
+               for (int i = -halfW; i < halfW; ++i) {
+                       texvec[0] = wDelta * i;
+                       for (int j = -halfH; j < halfH; ++j) {
+                               texvec[1] = hDelta * j;
+                               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) {
+                                       noiseGenerator.doColorband(colorBand, texres, dataRepository);
+                                       noiseGenerator.brightnesAndContrastRGB(tex, texres);
+                                       data.put((byte) (texres.tr * 255.0f));
+                                       data.put((byte) (texres.tg * 255.0f));
+                                       data.put((byte) (texres.tb * 255.0f));
+                               } else {
+                                       noiseGenerator.brightnesAndContrast(texres, contrast, brightness);
+                                       data.put((byte) (texres.tin * 255.0f));
+                               }
+                       }
+               }
+               return new Texture2D(new Image(format, width, height, data));
+       }
+}
diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/textures/TextureGeneratorClouds.java b/engine/src/blender/com/jme3/scene/plugins/blender/textures/TextureGeneratorClouds.java
new file mode 100644 (file)
index 0000000..5c3af9e
--- /dev/null
@@ -0,0 +1,91 @@
+package com.jme3.scene.plugins.blender.textures;
+
+import java.nio.ByteBuffer;
+
+import com.jme3.scene.plugins.blender.DataRepository;
+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.Texture;
+import com.jme3.texture.Texture2D;
+import com.jme3.texture.Image.Format;
+import com.jme3.util.BufferUtils;
+
+/**
+ * This class generates the 'clouds' texture.
+ * @author Marcin Roguski (Kaelthas)
+ */
+public class TextureGeneratorClouds extends TextureGenerator {
+
+       /**
+        * Constructor stores the given noise generator.
+        * @param noiseGenerator the noise generator
+        */
+       public TextureGeneratorClouds(NoiseGenerator noiseGenerator) {
+               super(noiseGenerator);
+       }
+
+       @Override
+       protected Texture generate(Structure tex, int width, int height, DataRepository dataRepository) {
+               // preparing the proper data
+               float wDelta = 1.0f / width, hDelta = 1.0f / height;
+               float[] texvec = new float[] { 0, 0, 0 };
+               TexResult texres = new TexResult();
+
+               // reading the data from the texture structure
+               float noisesize = ((Number) tex.getFieldValue("noisesize")).floatValue();
+               int noiseDepth = ((Number) tex.getFieldValue("noisedepth")).intValue();
+               int noiseBasis = ((Number) tex.getFieldValue("noisebasis")).intValue();
+               int noiseType = ((Number) tex.getFieldValue("noisetype")).intValue();
+               float contrast = ((Number) tex.getFieldValue("contrast")).floatValue();
+               float bright = ((Number) tex.getFieldValue("bright")).floatValue();
+               boolean isHard = noiseType != NoiseGenerator.TEX_NOISESOFT;
+               int sType = ((Number) tex.getFieldValue("stype")).intValue();
+               int halfW = width, halfH = height;
+               width <<= 1;
+               height <<= 1;
+               ColorBand colorBand = this.readColorband(tex, dataRepository);
+               Format format = sType == NoiseGenerator.TEX_COLOR || colorBand != null ? Format.RGB8 : Format.Luminance8;
+               int bytesPerPixel = sType == NoiseGenerator.TEX_COLOR || colorBand != null ? 3 : 1;
+
+               ByteBuffer data = BufferUtils.createByteBuffer(width * height * bytesPerPixel);
+               for (int i = -halfW; i < halfW; ++i) {
+                       texvec[0] = wDelta * i;// x
+                       for (int j = -halfH; j < halfH; ++j) {
+                               texvec[1] = hDelta * j;// y (z is always = 0)
+
+                               texres.tin = noiseGenerator.bliGTurbulence(noisesize, texvec[0], texvec[1], texvec[2], noiseDepth, isHard, noiseBasis);
+                               if (colorBand != null) {
+                                       noiseGenerator.doColorband(colorBand, texres, dataRepository);
+                                       if (texres.nor != null) {
+                                               float nabla = ((Number) tex.getFieldValue("nabla")).floatValue();
+                                               // calculate bumpnormal
+                                               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);
+                                               texres.nor[2] = noiseGenerator.bliGTurbulence(noisesize, texvec[0], texvec[1], texvec[2] + nabla, noiseDepth, isHard, noiseBasis);
+                                               noiseGenerator.texNormalDerivate(colorBand, texres, dataRepository);
+                                       }
+                                       noiseGenerator.brightnesAndContrastRGB(tex, texres);
+                                       data.put((byte) (texres.tr * 255.0f));
+                                       data.put((byte) (texres.tg * 255.0f));
+                                       data.put((byte) (texres.tb * 255.0f));
+                               } else if (sType == NoiseGenerator.TEX_COLOR) {
+                                       // in this case, int. value should really be computed from color,
+                                       // and bumpnormal from that, would be too slow, looks ok as is
+                                       texres.tr = texres.tin;
+                                       texres.tg = noiseGenerator.bliGTurbulence(noisesize, texvec[1], texvec[0], texvec[2], noiseDepth, isHard, noiseBasis);
+                                       texres.tb = noiseGenerator.bliGTurbulence(noisesize, texvec[1], texvec[2], texvec[0], noiseDepth, isHard, noiseBasis);
+                                       noiseGenerator.brightnesAndContrastRGB(tex, texres);
+                                       data.put((byte) (texres.tr * 255.0f));
+                                       data.put((byte) (texres.tg * 255.0f));
+                                       data.put((byte) (texres.tb * 255.0f));
+                               } else {
+                                       noiseGenerator.brightnesAndContrast(texres, contrast, bright);
+                                       data.put((byte) (texres.tin * 255));
+                               }
+                       }
+               }
+               return new Texture2D(new Image(format, width, height, data));
+       }
+}
diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/textures/TextureGeneratorDistnoise.java b/engine/src/blender/com/jme3/scene/plugins/blender/textures/TextureGeneratorDistnoise.java
new file mode 100644 (file)
index 0000000..8fb9b69
--- /dev/null
@@ -0,0 +1,79 @@
+package com.jme3.scene.plugins.blender.textures;
+
+import java.nio.ByteBuffer;
+
+import com.jme3.scene.plugins.blender.DataRepository;
+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.Texture;
+import com.jme3.texture.Texture2D;
+import com.jme3.texture.Image.Format;
+import com.jme3.util.BufferUtils;
+
+/**
+ * This class generates the 'distorted noise' texture.
+ * @author Marcin Roguski (Kaelthas)
+ */
+public class TextureGeneratorDistnoise extends TextureGenerator {
+
+       /**
+        * Constructor stores the given noise generator.
+        * @param noiseGenerator the noise generator
+        */
+       public TextureGeneratorDistnoise(NoiseGenerator noiseGenerator) {
+               super(noiseGenerator);
+       }
+
+       @Override
+       protected Texture generate(Structure tex, int width, int height, DataRepository dataRepository) {
+               float noisesize = ((Number) tex.getFieldValue("noisesize")).floatValue();
+               float nabla = ((Number) tex.getFieldValue("nabla")).floatValue();
+               float distAmount = ((Number) tex.getFieldValue("dist_amount")).floatValue();
+               int noisebasis = ((Number) tex.getFieldValue("noisebasis")).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();
+               float[] texvec = new float[] { 0, 0, 0 };
+               float wDelta = 1.0f / width, hDelta = 1.0f / height;
+               int halfW = width, halfH = height;
+               width <<= 1;
+               height <<= 1;
+               ColorBand colorBand = this.readColorband(tex, dataRepository);
+               Format format = colorBand != null ? Format.RGB8 : Format.Luminance8;
+               int bytesPerPixel = colorBand != null ? 3 : 1;
+
+               ByteBuffer data = BufferUtils.createByteBuffer(width * height * bytesPerPixel);
+               for (int i = -halfW; i < halfW; ++i) {
+                       texvec[0] = wDelta * i / noisesize;
+                       for (int j = -halfH; j < halfH; ++j) {
+                               texvec[1] = hDelta * j / noisesize;
+
+                               texres.tin = noiseGenerator.mgVLNoise(texvec[0], texvec[1], texvec[2], distAmount, noisebasis, noisebasis2);
+                               if (colorBand != null) {
+                                       noiseGenerator.doColorband(colorBand, texres, dataRepository);
+                                       if (texres.nor != null) {
+                                               float offs = nabla / noisesize; // also scaling of texvec
+                                               /* calculate bumpnormal */
+                                               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);
+                                       data.put((byte) (texres.tr * 255.0f));
+                                       data.put((byte) (texres.tg * 255.0f));
+                                       data.put((byte) (texres.tb * 255.0f));
+                               } else {
+                                       noiseGenerator.brightnesAndContrast(texres, contrast, brightness);
+                                       data.put((byte) (texres.tin * 255.0f));
+                               }
+                       }
+               }
+               return new Texture2D(new Image(format, width, height, data));
+       }
+}
diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/textures/TextureGeneratorMagic.java b/engine/src/blender/com/jme3/scene/plugins/blender/textures/TextureGeneratorMagic.java
new file mode 100644 (file)
index 0000000..7cecf76
--- /dev/null
@@ -0,0 +1,109 @@
+package com.jme3.scene.plugins.blender.textures;
+
+import java.nio.ByteBuffer;
+
+import com.jme3.scene.plugins.blender.DataRepository;
+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.Texture;
+import com.jme3.texture.Texture2D;
+import com.jme3.texture.Image.Format;
+import com.jme3.util.BufferUtils;
+
+/**
+ * This class generates the 'magic' texture.
+ * @author Marcin Roguski (Kaelthas)
+ */
+public class TextureGeneratorMagic extends TextureGenerator {
+
+       /**
+        * Constructor stores the given noise generator.
+        * @param noiseGenerator the noise generator
+        */
+       public TextureGeneratorMagic(NoiseGenerator noiseGenerator) {
+               super(noiseGenerator);
+       }
+
+       @Override
+       protected Texture generate(Structure tex, int width, int height, DataRepository dataRepository) {
+               float x, y, z, turb;
+               int noisedepth = ((Number) tex.getFieldValue("noisedepth")).intValue();
+               float turbul = ((Number) tex.getFieldValue("turbul")).floatValue() / 5.0f;
+               float[] texvec = new float[] { 0, 0, 0 };
+               TexResult texres = new TexResult();
+               float wDelta = 1.0f / width, hDelta = 1.0f / height;
+               int halfW = width, halfH = height;
+               width <<= 1;
+               height <<= 1;
+               ColorBand colorBand = this.readColorband(tex, dataRepository);
+
+               ByteBuffer data = BufferUtils.createByteBuffer(width * height * 4);
+               for (int i = -halfW; i < halfW; ++i) {
+                       texvec[0] = wDelta * i;
+                       for (int j = -halfH; j < halfH; ++j) {
+                               turb = turbul;
+                               texvec[1] = hDelta * j;
+                               x = (float) Math.sin((texvec[0] + texvec[1]) * 5.0f);// in blender: Math.sin((texvec[0] + texvec[1] + texvec[2]) * 5.0f);
+                               y = (float) Math.cos((-texvec[0] + texvec[1]) * 5.0f);// in blender: Math.cos((-texvec[0] + texvec[1] - texvec[2]) * 5.0f);
+                               z = -(float) Math.cos((-texvec[0] - texvec[1]) * 5.0f);// in blender: Math.cos((-texvec[0] - texvec[1] + texvec[2]) * 5.0f);
+
+                               if (colorBand != null) {
+                                       texres.tin = 0.3333f * (x + y + z);
+                                       noiseGenerator.doColorband(colorBand, texres, dataRepository);
+                               } else {
+                                       if (noisedepth > 0) {
+                                               x *= turb;
+                                               y *= turb;
+                                               z *= turb;
+                                               y = -(float) Math.cos(x - y + z) * turb;
+                                               if (noisedepth > 1) {
+                                                       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) {
+                                               turb *= 2.0f;
+                                               x /= turb;
+                                               y /= turb;
+                                               z /= turb;
+                                       }
+                                       texres.tr = 0.5f - x;
+                                       texres.tg = 0.5f - y;
+                                       texres.tb = 0.5f - z;
+                               }
+                               noiseGenerator.brightnesAndContrastRGB(tex, texres);
+                               data.put((byte) (texres.tin * 255));
+                               data.put((byte) (texres.tb * 255));
+                               data.put((byte) (texres.tg * 255));
+                               data.put((byte) (texres.tr * 255));
+                       }
+               }
+               return new Texture2D(new Image(Format.ABGR8, width, height, data));
+       }
+}
diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/textures/TextureGeneratorMarble.java b/engine/src/blender/com/jme3/scene/plugins/blender/textures/TextureGeneratorMarble.java
new file mode 100644 (file)
index 0000000..7e77469
--- /dev/null
@@ -0,0 +1,72 @@
+package com.jme3.scene.plugins.blender.textures;
+
+import java.nio.ByteBuffer;
+
+import com.jme3.scene.plugins.blender.DataRepository;
+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.Texture;
+import com.jme3.texture.Texture2D;
+import com.jme3.texture.Image.Format;
+import com.jme3.util.BufferUtils;
+
+/**
+ * This class generates the 'marble' texture.
+ * @author Marcin Roguski (Kaelthas)
+ */
+public class TextureGeneratorMarble extends TextureGenerator {
+       
+       /**
+        * Constructor stores the given noise generator.
+        * @param noiseGenerator the noise generator
+        */
+       public TextureGeneratorMarble(NoiseGenerator noiseGenerator) {
+               super(noiseGenerator);
+       }
+
+       @Override
+       protected Texture generate(Structure tex, int width, int height, 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;
+               float[] texvec = new float[] { 0, 0, 0 };
+               TexResult texres = new TexResult();
+               int halfW = width, halfH = height;
+               width <<= 1;
+               height <<= 1;
+               ColorBand colorBand = this.readColorband(tex, dataRepository);
+               Format format = colorBand != null ? Format.RGB8 : Format.Luminance8;
+               int bytesPerPixel = colorBand != null ? 3 : 1;
+
+               ByteBuffer data = BufferUtils.createByteBuffer(width * height * bytesPerPixel);
+               for (int i = -halfW; i < halfW; ++i) {
+                       texvec[0] = wDelta * i;
+                       for (int j = -halfH; j < halfH; ++j) {
+                               texvec[1] = hDelta * j;
+                               texres.tin = noiseGenerator.marbleInt(tex, texvec[0], texvec[1], texvec[2], dataRepository);
+                               if (colorBand != null) {
+                                       noiseGenerator.doColorband(colorBand, texres, dataRepository);
+                                       if (texres.nor != null) {// calculate bumpnormal
+                                               texres.nor[0] = noiseGenerator.marbleInt(tex, texvec[0] + nabla, texvec[1], texvec[2], dataRepository);
+                                               texres.nor[1] = noiseGenerator.marbleInt(tex, texvec[0], texvec[1] + nabla, texvec[2], dataRepository);
+                                               texres.nor[2] = noiseGenerator.marbleInt(tex, texvec[0], texvec[1], texvec[2] + nabla, dataRepository);
+                                               noiseGenerator.texNormalDerivate(colorBand, texres, dataRepository);
+                                       }
+
+                                       noiseGenerator.brightnesAndContrastRGB(tex, texres);
+                                       data.put((byte) (texres.tr * 255.0f));
+                                       data.put((byte) (texres.tg * 255.0f));
+                                       data.put((byte) (texres.tb * 255.0f));
+                               } else {
+                                       noiseGenerator.brightnesAndContrast(texres, contrast, bright);
+                                       data.put((byte) (texres.tin * 255.0f));
+                               }
+                       }
+               }
+               return new Texture2D(new Image(format, width, height, data));
+       }
+}
diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/textures/TextureGeneratorMusgrave.java b/engine/src/blender/com/jme3/scene/plugins/blender/textures/TextureGeneratorMusgrave.java
new file mode 100644 (file)
index 0000000..8289d4d
--- /dev/null
@@ -0,0 +1,75 @@
+package com.jme3.scene.plugins.blender.textures;
+
+import java.nio.ByteBuffer;
+
+import com.jme3.scene.plugins.blender.DataRepository;
+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.Texture;
+import com.jme3.texture.Texture2D;
+import com.jme3.texture.Image.Format;
+import com.jme3.util.BufferUtils;
+
+/**
+ * This class generates the 'musgrave' texture.
+ * @author Marcin Roguski (Kaelthas)
+ */
+public class TextureGeneratorMusgrave extends TextureGenerator {
+
+       /**
+        * Constructor stores the given noise generator.
+        * @param noiseGenerator the noise generator
+        */
+       public TextureGeneratorMusgrave(NoiseGenerator noiseGenerator) {
+               super(noiseGenerator);
+       }
+
+       @Override
+       protected Texture generate(Structure tex, int width, int height, DataRepository dataRepository) {
+               int stype = ((Number) tex.getFieldValue("stype")).intValue();
+               float noisesize = ((Number) tex.getFieldValue("noisesize")).floatValue();
+               TexResult texres = new TexResult();
+               float[] texvec = new float[] { 0, 0, 0 };
+               float wDelta = 1.0f / width, hDelta = 1.0f / height;
+               int halfW = width, halfH = height;
+               width <<= 1;
+               height <<= 1;
+               ColorBand colorBand = this.readColorband(tex, dataRepository);
+               Format format = colorBand != null ? Format.RGB8 : Format.Luminance8;
+               int bytesPerPixel = colorBand != null ? 3 : 1;
+
+               ByteBuffer data = BufferUtils.createByteBuffer(width * height * bytesPerPixel);
+               for (int i = -halfW; i < halfW; ++i) {
+                       texvec[0] = wDelta * i / noisesize;
+                       for (int j = -halfH; j < halfH; ++j) {
+                               texvec[1] = hDelta * j / noisesize;
+                               switch (stype) {
+                                       case NoiseGenerator.TEX_MFRACTAL:
+                                       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);
+                               }
+                               if (colorBand != null) {
+                                       noiseGenerator.doColorband(colorBand, texres, dataRepository);
+                                       data.put((byte) (texres.tr * 255.0f));
+                                       data.put((byte) (texres.tg * 255.0f));
+                                       data.put((byte) (texres.tb * 255.0f));
+                               } else {
+                                       data.put((byte) (texres.tin * 255.0f));
+                               }
+                       }
+               }
+               return new Texture2D(new Image(format, width, height, data));
+       }
+}
diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/textures/TextureGeneratorNoise.java b/engine/src/blender/com/jme3/scene/plugins/blender/textures/TextureGeneratorNoise.java
new file mode 100644 (file)
index 0000000..413f1cb
--- /dev/null
@@ -0,0 +1,72 @@
+package com.jme3.scene.plugins.blender.textures;
+
+import java.nio.ByteBuffer;
+
+import com.jme3.math.FastMath;
+import com.jme3.scene.plugins.blender.DataRepository;
+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.Texture;
+import com.jme3.texture.Texture2D;
+import com.jme3.texture.Image.Format;
+import com.jme3.util.BufferUtils;
+
+/**
+ * This class generates the 'noise' texture.
+ * @author Marcin Roguski (Kaelthas)
+ */
+public class TextureGeneratorNoise extends TextureGenerator {
+
+       /**
+        * Constructor stores the given noise generator.
+        * @param noiseGenerator the noise generator
+        */
+       public TextureGeneratorNoise(NoiseGenerator noiseGenerator) {
+               super(noiseGenerator);
+       }
+
+       @Override
+       protected Texture generate(Structure tex, int width, int height, DataRepository dataRepository) {
+               float div = 3.0f;
+               int val, ran, loop;
+               int noisedepth = ((Number) tex.getFieldValue("noisedepth")).intValue();
+               float contrast = ((Number) tex.getFieldValue("contrast")).floatValue();
+               float brightness = ((Number) tex.getFieldValue("bright")).floatValue();
+               TexResult texres = new TexResult();
+               int halfW = width, halfH = height;
+               width <<= 1;
+               height <<= 1;
+               ColorBand colorBand = this.readColorband(tex, dataRepository);
+               Format format = colorBand != null ? Format.RGB8 : Format.Luminance8;
+               int bytesPerPixel = colorBand != null ? 3 : 1;
+
+               ByteBuffer data = BufferUtils.createByteBuffer(width * height * bytesPerPixel);
+               for (int i = -halfW; i < halfW; ++i) {
+                       for (int j = -halfH; j < halfH; ++j) {
+                               ran = FastMath.rand.nextInt();// BLI_rand();
+                               val = ran & 3;
+
+                               loop = noisedepth;
+                               while (loop-- != 0) {
+                                       ran = ran >> 2;
+                                       val *= ran & 3;
+                                       div *= 3.0f;
+                               }
+                               texres.tin = val;// / div;
+                               if (colorBand != null) {
+                                       noiseGenerator.doColorband(colorBand, texres, dataRepository);
+                                       noiseGenerator.brightnesAndContrastRGB(tex, texres);
+                                       data.put((byte) (texres.tr * 255.0f));
+                                       data.put((byte) (texres.tg * 255.0f));
+                                       data.put((byte) (texres.tb * 255.0f));
+                               } else {
+                                       noiseGenerator.brightnesAndContrast(texres, contrast, brightness);
+                                       data.put((byte) (texres.tin * 255.0f));
+                               }
+                       }
+               }
+               return new Texture2D(new Image(format, width, height, data));
+       }
+}
diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/textures/TextureGeneratorStucci.java b/engine/src/blender/com/jme3/scene/plugins/blender/textures/TextureGeneratorStucci.java
new file mode 100644 (file)
index 0000000..696c902
--- /dev/null
@@ -0,0 +1,95 @@
+package com.jme3.scene.plugins.blender.textures;
+
+import java.nio.ByteBuffer;
+
+import com.jme3.scene.plugins.blender.DataRepository;
+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.Texture;
+import com.jme3.texture.Texture2D;
+import com.jme3.texture.Image.Format;
+import com.jme3.util.BufferUtils;
+
+/**
+ * This class generates the 'stucci' texture.
+ * @author Marcin Roguski (Kaelthas)
+ */
+public class TextureGeneratorStucci extends TextureGenerator {
+
+       /**
+        * Constructor stores the given noise generator.
+        * @param noiseGenerator the noise generator
+        */
+       public TextureGeneratorStucci(NoiseGenerator noiseGenerator) {
+               super(noiseGenerator);
+       }
+
+       @Override
+       protected Texture generate(Structure tex, int width, int height, DataRepository dataRepository) {
+               float noisesize = ((Number) tex.getFieldValue("noisesize")).floatValue();
+               int noisebasis = ((Number) tex.getFieldValue("noisebasis")).intValue();
+               int noisetype = ((Number) tex.getFieldValue("noisetype")).intValue();
+               float turbul = ((Number) tex.getFieldValue("turbul")).floatValue();
+               boolean isHard = noisetype != NoiseGenerator.TEX_NOISESOFT;
+               int stype = ((Number) tex.getFieldValue("stype")).intValue();
+
+               float[] texvec = new float[] { 0, 0, 0 };
+               TexResult texres = new TexResult();
+               float wDelta = 1.0f / width, hDelta = 1.0f / height, b2, ofs;
+               int halfW = width, halfH = height;
+               width <<= 1;
+               height <<= 1;
+               ColorBand colorBand = this.readColorband(tex, dataRepository);
+               Format format = colorBand != null ? Format.RGB8 : Format.Luminance8;
+               int bytesPerPixel = colorBand != null ? 3 : 1;
+
+               ByteBuffer data = BufferUtils.createByteBuffer(width * height * bytesPerPixel);
+               for (int i = -halfW; i < halfW; ++i) {
+                       texvec[0] = wDelta * i;// x
+                       for (int j = -halfH; j < halfH; ++j) {
+                               texvec[1] = hDelta * j;// y (z is always = 0)
+                               b2 = noiseGenerator.bliGNoise(noisesize, texvec[0], texvec[1], texvec[2], isHard, noisebasis);
+
+                               ofs = turbul / 200.0f;
+
+                               if (stype != 0) {
+                                       ofs *= b2 * b2;
+                               }
+
+                               texres.tin = noiseGenerator.bliGNoise(noisesize, texvec[0], texvec[1], texvec[2] + ofs, isHard, noisebasis);// ==nor[2]
+                               if (colorBand != null) {
+                                       noiseGenerator.doColorband(colorBand, texres, dataRepository);
+                                       if (texres.nor != null) {
+                                               texres.nor[0] = noiseGenerator.bliGNoise(noisesize, texvec[0] + ofs, texvec[1], texvec[2], isHard, noisebasis);
+                                               texres.nor[1] = noiseGenerator.bliGNoise(noisesize, texvec[0], texvec[1] + ofs, texvec[2], isHard, noisebasis);
+                                               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) {
+                                       texres.tin = 1.0f - texres.tin;
+                               }
+                               if (texres.tin < 0.0f) {
+                                       texres.tin = 0.0f;
+                               }
+                               if (colorBand != null) {
+                                       data.put((byte) (texres.tr * 255.0f));
+                                       data.put((byte) (texres.tg * 255.0f));
+                                       data.put((byte) (texres.tb * 255.0f));
+                               } else {
+                                       data.put((byte) (texres.tin * 255.0f));
+                               }
+                       }
+               }
+               return new Texture2D(new Image(format, width, height, data));
+       }
+}
diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/textures/TextureGeneratorVoronoi.java b/engine/src/blender/com/jme3/scene/plugins/blender/textures/TextureGeneratorVoronoi.java
new file mode 100644 (file)
index 0000000..809e5ca
--- /dev/null
@@ -0,0 +1,138 @@
+package com.jme3.scene.plugins.blender.textures;
+
+import java.nio.ByteBuffer;
+
+import com.jme3.math.FastMath;
+import com.jme3.scene.plugins.blender.DataRepository;
+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.Texture;
+import com.jme3.texture.Texture2D;
+import com.jme3.texture.Image.Format;
+import com.jme3.util.BufferUtils;
+
+/**
+ * This class generates the 'voronoi' texture.
+ * @author Marcin Roguski (Kaelthas)
+ */
+public class TextureGeneratorVoronoi extends TextureGenerator {
+
+       /**
+        * Constructor stores the given noise generator.
+        * @param noiseGenerator the noise generator
+        */
+       public TextureGeneratorVoronoi(NoiseGenerator noiseGenerator) {
+               super(noiseGenerator);
+       }
+
+       @Override
+       protected Texture generate(Structure tex, int width, int height, DataRepository dataRepository) {
+               float vn_w1 = ((Number) tex.getFieldValue("vn_w1")).floatValue();
+               float vn_w2 = ((Number) tex.getFieldValue("vn_w2")).floatValue();
+               float vn_w3 = ((Number) tex.getFieldValue("vn_w3")).floatValue();
+               float vn_w4 = ((Number) tex.getFieldValue("vn_w4")).floatValue();
+               float noisesize = ((Number) tex.getFieldValue("noisesize")).floatValue();
+               float nabla = ((Number) tex.getFieldValue("nabla")).floatValue();
+               float ns_outscale = ((Number) tex.getFieldValue("ns_outscale")).floatValue();
+               float vn_mexp = ((Number) tex.getFieldValue("vn_mexp")).floatValue();
+               int vn_distm = ((Number) tex.getFieldValue("vn_distm")).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();
+               float[] texvec = new float[] { 0, 0, 0 };
+               float wDelta = 1.0f / width, hDelta = 1.0f / height;
+               int halfW = width, halfH = height;
+               width <<= 1;
+               height <<= 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[] ca = vn_coltype != 0 ? new float[3] : null; // cell color
+               float aw1 = FastMath.abs(vn_w1);
+               float aw2 = FastMath.abs(vn_w2);
+               float aw3 = FastMath.abs(vn_w3);
+               float aw4 = FastMath.abs(vn_w4);
+               float sc = aw1 + aw2 + aw3 + aw4;
+               if (sc != 0.f) {
+                       sc = ns_outscale / sc;
+               }
+
+               ByteBuffer data = BufferUtils.createByteBuffer(width * height * bytesPerPixel);
+               for (int i = -halfW; i < halfW; ++i) {
+                       texvec[0] = wDelta * i / noisesize;
+                       for (int j = -halfH; j < halfH; ++j) {
+                               texvec[1] = hDelta * j / noisesize;
+
+                               noiseGenerator.voronoi(texvec[0], texvec[1], texvec[2], da, pa, vn_mexp, vn_distm);
+                               texres.tin = sc * FastMath.abs(vn_w1 * da[0] + vn_w2 * da[1] + vn_w3 * da[2] + vn_w4 * da[3]);
+                               if (vn_coltype != 0) {
+                                       noiseGenerator.cellNoiseV(pa[0], pa[1], pa[2], ca);
+                                       texres.tr = aw1 * ca[0];
+                                       texres.tg = aw1 * ca[1];
+                                       texres.tb = aw1 * ca[2];
+                                       noiseGenerator.cellNoiseV(pa[3], pa[4], pa[5], ca);
+                                       texres.tr += aw2 * ca[0];
+                                       texres.tg += aw2 * ca[1];
+                                       texres.tb += aw2 * ca[2];
+                                       noiseGenerator.cellNoiseV(pa[6], pa[7], pa[8], ca);
+                                       texres.tr += aw3 * ca[0];
+                                       texres.tg += aw3 * ca[1];
+                                       texres.tb += aw3 * ca[2];
+                                       noiseGenerator.cellNoiseV(pa[9], pa[10], pa[11], ca);
+                                       texres.tr += aw4 * ca[0];
+                                       texres.tg += aw4 * ca[1];
+                                       texres.tb += aw4 * ca[2];
+                                       if (vn_coltype >= 2) {
+                                               float t1 = (da[1] - da[0]) * 10.0f;
+                                               if (t1 > 1) {
+                                                       t1 = 1.0f;
+                                               }
+                                               if (vn_coltype == 3) {
+                                                       t1 *= texres.tin;
+                                               } else {
+                                                       t1 *= sc;
+                                               }
+                                               texres.tr *= t1;
+                                               texres.tg *= t1;
+                                               texres.tb *= t1;
+                                       } else {
+                                               texres.tr *= sc;
+                                               texres.tg *= sc;
+                                               texres.tb *= 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) {
+                                       noiseGenerator.brightnesAndContrastRGB(tex, texres);
+                                       data.put((byte) (texres.tr * 255.0f));// tin or tr??
+                                       data.put((byte) (texres.tg * 255.0f));
+                                       data.put((byte) (texres.tb * 255.0f));
+                               } else {
+                                       noiseGenerator.brightnesAndContrast(texres, contrast, brightness);
+                                       data.put((byte) (texres.tin * 255.0f));
+                               }
+                       }
+               }
+               return new Texture2D(new Image(format, width, height, data));
+       }
+}
diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/textures/TextureGeneratorWood.java b/engine/src/blender/com/jme3/scene/plugins/blender/textures/TextureGeneratorWood.java
new file mode 100644 (file)
index 0000000..db2461f
--- /dev/null
@@ -0,0 +1,72 @@
+package com.jme3.scene.plugins.blender.textures;
+
+import java.nio.ByteBuffer;
+
+import com.jme3.scene.plugins.blender.DataRepository;
+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.Format;
+import com.jme3.texture.Texture;
+import com.jme3.texture.Texture2D;
+import com.jme3.util.BufferUtils;
+
+/**
+ * This class generates the 'wood' texture.
+ * @author Marcin Roguski (Kaelthas)
+ */
+public class TextureGeneratorWood extends TextureGenerator {
+
+       /**
+        * Constructor stores the given noise generator.
+        * @param noiseGenerator the noise generator
+        */
+       public TextureGeneratorWood(NoiseGenerator noiseGenerator) {
+               super(noiseGenerator);
+       }
+
+       @Override
+       protected Texture generate(Structure tex, int width, int height, 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;
+               float[] texvec = new float[] { 0, 0, 0 };
+               TexResult texres = new TexResult();
+               int halfW = width;
+               int halfH = height;
+               width <<= 1;
+               height <<= 1;
+               ColorBand colorBand = this.readColorband(tex, dataRepository);
+               Format format = colorBand != null ? Format.RGB8 : Format.Luminance8;
+               int bytesPerPixel = colorBand != null ? 3 : 1;
+
+               ByteBuffer data = BufferUtils.createByteBuffer(width * height * bytesPerPixel);
+               for (int i = -halfW; i < halfW; ++i) {
+                       texvec[0] = wDelta * i;
+                       for (int j = -halfH; j < halfH; ++j) {
+                               texvec[1] = hDelta * j;
+                               texres.tin = noiseGenerator.woodInt(tex, texvec[0], texvec[1], texvec[2], dataRepository);
+                               if (colorBand != null) {
+                                       noiseGenerator.doColorband(colorBand, texres, dataRepository);
+                                       if (texres.nor != null) {// calculate bumpnormal
+                                               texres.nor[0] = noiseGenerator.woodInt(tex, texvec[0] + nabla, texvec[1], texvec[2], dataRepository);
+                                               texres.nor[1] = noiseGenerator.woodInt(tex, texvec[0], texvec[1] + nabla, texvec[2], dataRepository);
+                                               texres.nor[2] = noiseGenerator.woodInt(tex, texvec[0], texvec[1], texvec[2] + nabla, dataRepository);
+                                               noiseGenerator.texNormalDerivate(colorBand, texres, dataRepository);
+                                       }
+                                       noiseGenerator.brightnesAndContrastRGB(tex, texres);
+                                       data.put((byte) (texres.tr * 255.0f));
+                                       data.put((byte) (texres.tg * 255.0f));
+                                       data.put((byte) (texres.tb * 255.0f));
+                               } else {
+                                       noiseGenerator.brightnesAndContrast(texres, contrast, bright);
+                                       data.put((byte) (texres.tin * 255));
+                               }
+                       }
+               }
+               return new Texture2D(new Image(format, width, height, data));
+       }
+}
index fc9276e..5452772 100644 (file)
@@ -41,6 +41,8 @@ import java.io.FileNotFoundException;
 import java.io.IOException;\r
 import java.io.InputStream;\r
 import java.nio.ByteBuffer;\r
+import java.util.HashMap;\r
+import java.util.Map;\r
 import java.util.logging.Level;\r
 import java.util.logging.Logger;\r
 \r
@@ -56,7 +58,6 @@ import com.jme3.scene.plugins.blender.AbstractBlenderHelper;
 import com.jme3.scene.plugins.blender.DataRepository;\r
 import com.jme3.scene.plugins.blender.DataRepository.LoadedFeatureDataType;\r
 import com.jme3.scene.plugins.blender.exceptions.BlenderFileException;\r
-import com.jme3.scene.plugins.blender.file.BlenderInputStream;\r
 import com.jme3.scene.plugins.blender.file.DynamicArray;\r
 import com.jme3.scene.plugins.blender.file.FileBlockHeader;\r
 import com.jme3.scene.plugins.blender.file.Pointer;\r
@@ -67,9 +68,6 @@ import com.jme3.texture.Image.Format;
 import com.jme3.texture.Texture;\r
 import com.jme3.texture.Texture.WrapMode;\r
 import com.jme3.texture.Texture2D;\r
-import com.jme3.texture.plugins.AWTLoader;\r
-import com.jme3.texture.plugins.DDSLoader;\r
-import com.jme3.texture.plugins.TGALoader;\r
 import com.jme3.util.BufferUtils;\r
 \r
 /**\r
@@ -79,7 +77,7 @@ import com.jme3.util.BufferUtils;
  */\r
 public class TextureHelper extends AbstractBlenderHelper {\r
        private static final Logger     LOGGER                          = Logger.getLogger(TextureHelper.class.getName());\r
-\r
+       \r
        // texture types\r
        public static final int         TEX_NONE                        = 0;\r
        public static final int         TEX_CLOUDS                      = 1;\r
@@ -151,18 +149,29 @@ public class TextureHelper extends AbstractBlenderHelper {
        public static final int         MA_RAMP_VAL                     = 14;\r
        public static final int         MA_RAMP_COLOR           = 15;\r
 \r
-       protected NoiseGenerator noiseHelper;\r
+       protected NoiseGenerator noiseGenerator;\r
+       private Map<Integer, TextureGenerator> textureGenerators = new HashMap<Integer, TextureGenerator>();\r
        \r
        /**\r
-        * This constructor parses the given blender version and stores the result. Some functionalities may differ in different blender\r
-        * versions.\r
+        * This constructor parses the given blender version and stores the result.\r
+        * It creates noise generator and texture generators.\r
         * \r
         * @param blenderVersion\r
         *        the version read from the blend file\r
         */\r
        public TextureHelper(String blenderVersion) {\r
                super(blenderVersion);\r
-               noiseHelper = new NoiseGenerator(blenderVersion);\r
+               noiseGenerator = new NoiseGenerator(blenderVersion);\r
+               textureGenerators.put(Integer.valueOf(TEX_BLEND), new TextureGeneratorBlend(noiseGenerator));\r
+               textureGenerators.put(Integer.valueOf(TEX_CLOUDS), new TextureGeneratorClouds(noiseGenerator));\r
+               textureGenerators.put(Integer.valueOf(TEX_DISTNOISE), new TextureGeneratorDistnoise(noiseGenerator));\r
+               textureGenerators.put(Integer.valueOf(TEX_MAGIC), new TextureGeneratorMagic(noiseGenerator));\r
+               textureGenerators.put(Integer.valueOf(TEX_MARBLE), new TextureGeneratorMarble(noiseGenerator));\r
+               textureGenerators.put(Integer.valueOf(TEX_MUSGRAVE), new TextureGeneratorMusgrave(noiseGenerator));\r
+               textureGenerators.put(Integer.valueOf(TEX_NOISE), new TextureGeneratorNoise(noiseGenerator));\r
+               textureGenerators.put(Integer.valueOf(TEX_STUCCI), new TextureGeneratorStucci(noiseGenerator));\r
+               textureGenerators.put(Integer.valueOf(TEX_VORONOI), new TextureGeneratorVoronoi(noiseGenerator));\r
+               textureGenerators.put(Integer.valueOf(TEX_WOOD), new TextureGeneratorWood(noiseGenerator));\r
        }\r
 \r
        /**\r
@@ -195,34 +204,17 @@ public class TextureHelper extends AbstractBlenderHelper {
                 }\r
                                break;\r
                        case TEX_CLOUDS:\r
-                               result = this.clouds(tex, width, height, dataRepository);\r
-                               break;\r
                        case TEX_WOOD:\r
-                               result = this.wood(tex, width, height, dataRepository);\r
-                               break;\r
                        case TEX_MARBLE:\r
-                               result = this.marble(tex, width, height, dataRepository);\r
-                               break;\r
                        case TEX_MAGIC:\r
-                               result = this.magic(tex, width, height, dataRepository);\r
-                               break;\r
                        case TEX_BLEND:\r
-                               result = this.blend(tex, width, height, dataRepository);\r
-                               break;\r
                        case TEX_STUCCI:\r
-                               result = this.stucci(tex, width, height, dataRepository);\r
-                               break;\r
                        case TEX_NOISE:\r
-                               result = this.texnoise(tex, width, height, dataRepository);\r
-                               break;\r
                        case TEX_MUSGRAVE:\r
-                               result = this.musgrave(tex, width, height, dataRepository);\r
-                               break;\r
                        case TEX_VORONOI:\r
-                               result = this.voronoi(tex, width, height, dataRepository);\r
-                               break;\r
                        case TEX_DISTNOISE:\r
-                               result = this.distnoise(tex, width, height, dataRepository);\r
+                               TextureGenerator textureGenerator = textureGenerators.get(Integer.valueOf(type));\r
+                               result = textureGenerator.generate(tex, width, height, dataRepository);\r
                                break;\r
                        case TEX_NONE:// No texture, do nothing\r
                                break;\r
@@ -250,778 +242,6 @@ public class TextureHelper extends AbstractBlenderHelper {
        }\r
 \r
        /**\r
-        * This method generates the clouds texture. The result is one pixel.\r
-        * \r
-        * @param tex\r
-        *        the texture structure\r
-        * @param width\r
-        *        the width of texture (in pixels)\r
-        * @param height\r
-        *        the height of texture (in pixels)\r
-        * @param dataRepository\r
-        *        the data repository\r
-        * @return generated texture\r
-        */\r
-       protected Texture clouds(Structure tex, int width, int height, DataRepository dataRepository) {\r
-               // preparing the proper data\r
-               float wDelta = 1.0f / width, hDelta = 1.0f / height;\r
-               float[] texvec = new float[] { 0, 0, 0 };\r
-               TexResult texres = new TexResult();\r
-\r
-               // reading the data from the texture structure\r
-               float noisesize = ((Number) tex.getFieldValue("noisesize")).floatValue();\r
-               int noiseDepth = ((Number) tex.getFieldValue("noisedepth")).intValue();\r
-               int noiseBasis = ((Number) tex.getFieldValue("noisebasis")).intValue();\r
-               int noiseType = ((Number) tex.getFieldValue("noisetype")).intValue();\r
-               float contrast = ((Number) tex.getFieldValue("contrast")).floatValue();\r
-               float bright = ((Number) tex.getFieldValue("bright")).floatValue();\r
-               boolean isHard = noiseType != NoiseGenerator.TEX_NOISESOFT;\r
-               int sType = ((Number) tex.getFieldValue("stype")).intValue();\r
-               int halfW = width, halfH = height;\r
-               width <<= 1;\r
-               height <<= 1;\r
-               ColorBand colorBand = this.readColorband(tex, dataRepository);\r
-               Format format = sType == NoiseGenerator.TEX_COLOR || colorBand != null ? Format.RGB8 : Format.Luminance8;\r
-               int bytesPerPixel = sType == NoiseGenerator.TEX_COLOR || colorBand != null ? 3 : 1;\r
-\r
-               ByteBuffer data = BufferUtils.createByteBuffer(width * height * bytesPerPixel);\r
-               for (int i = -halfW; i < halfW; ++i) {\r
-                       texvec[0] = wDelta * i;// x\r
-                       for (int j = -halfH; j < halfH; ++j) {\r
-                               texvec[1] = hDelta * j;// y (z is always = 0)\r
-\r
-                               texres.tin = noiseHelper.bliGTurbulence(noisesize, texvec[0], texvec[1], texvec[2], noiseDepth, isHard, noiseBasis);\r
-                               if (colorBand != null) {\r
-                                       noiseHelper.doColorband(colorBand, texres, dataRepository);\r
-                                       if (texres.nor != null) {\r
-                                               float nabla = ((Number) tex.getFieldValue("nabla")).floatValue();\r
-                                               // calculate bumpnormal\r
-                                               texres.nor[0] = noiseHelper.bliGTurbulence(noisesize, texvec[0] + nabla, texvec[1], texvec[2], noiseDepth, isHard, noiseBasis);\r
-                                               texres.nor[1] = noiseHelper.bliGTurbulence(noisesize, texvec[0], texvec[1] + nabla, texvec[2], noiseDepth, isHard, noiseBasis);\r
-                                               texres.nor[2] = noiseHelper.bliGTurbulence(noisesize, texvec[0], texvec[1], texvec[2] + nabla, noiseDepth, isHard, noiseBasis);\r
-                                               noiseHelper.texNormalDerivate(colorBand, texres, dataRepository);\r
-                                       }\r
-                                       noiseHelper.brightnesAndContrastRGB(tex, texres);\r
-                                       data.put((byte) (texres.tr * 255.0f));\r
-                                       data.put((byte) (texres.tg * 255.0f));\r
-                                       data.put((byte) (texres.tb * 255.0f));\r
-                               } else if (sType == NoiseGenerator.TEX_COLOR) {\r
-                                       // in this case, int. value should really be computed from color,\r
-                                       // and bumpnormal from that, would be too slow, looks ok as is\r
-                                       texres.tr = texres.tin;\r
-                                       texres.tg = noiseHelper.bliGTurbulence(noisesize, texvec[1], texvec[0], texvec[2], noiseDepth, isHard, noiseBasis);\r
-                                       texres.tb = noiseHelper.bliGTurbulence(noisesize, texvec[1], texvec[2], texvec[0], noiseDepth, isHard, noiseBasis);\r
-                                       noiseHelper.brightnesAndContrastRGB(tex, texres);\r
-                                       data.put((byte) (texres.tr * 255.0f));\r
-                                       data.put((byte) (texres.tg * 255.0f));\r
-                                       data.put((byte) (texres.tb * 255.0f));\r
-                               } else {\r
-                                       noiseHelper.brightnesAndContrast(texres, contrast, bright);\r
-                                       data.put((byte) (texres.tin * 255));\r
-                               }\r
-                       }\r
-               }\r
-               return new Texture2D(new Image(format, width, height, data));\r
-       }\r
-\r
-       /**\r
-        * This method generates the wood texture.\r
-        * \r
-        * @param tex\r
-        *        the texture structure\r
-        * @param width\r
-        *        the width of the texture\r
-        * @param height\r
-        *        the height of the texture\r
-        * @param dataRepository\r
-        *        the data repository\r
-        * @return the generated texture\r
-        */\r
-       protected Texture wood(Structure tex, int width, int height, DataRepository dataRepository) {\r
-               // preparing the proper data\r
-               float contrast = ((Number) tex.getFieldValue("contrast")).floatValue();\r
-               float bright = ((Number) tex.getFieldValue("bright")).floatValue();\r
-               float nabla = ((Number) tex.getFieldValue("nabla")).floatValue();\r
-               float wDelta = 1.0f / width, hDelta = 1.0f / height;\r
-               float[] texvec = new float[] { 0, 0, 0 };\r
-               TexResult texres = new TexResult();\r
-               int halfW = width;\r
-               int halfH = height;\r
-               width <<= 1;\r
-               height <<= 1;\r
-               ColorBand colorBand = this.readColorband(tex, dataRepository);\r
-               Format format = colorBand != null ? Format.RGB8 : Format.Luminance8;\r
-               int bytesPerPixel = colorBand != null ? 3 : 1;\r
-\r
-               ByteBuffer data = BufferUtils.createByteBuffer(width * height * bytesPerPixel);\r
-               for (int i = -halfW; i < halfW; ++i) {\r
-                       texvec[0] = wDelta * i;\r
-                       for (int j = -halfH; j < halfH; ++j) {\r
-                               texvec[1] = hDelta * j;\r
-                               texres.tin = noiseHelper.woodInt(tex, texvec[0], texvec[1], texvec[2], dataRepository);\r
-                               if (colorBand != null) {\r
-                                       noiseHelper.doColorband(colorBand, texres, dataRepository);\r
-                                       if (texres.nor != null) {// calculate bumpnormal\r
-                                               texres.nor[0] = noiseHelper.woodInt(tex, texvec[0] + nabla, texvec[1], texvec[2], dataRepository);\r
-                                               texres.nor[1] = noiseHelper.woodInt(tex, texvec[0], texvec[1] + nabla, texvec[2], dataRepository);\r
-                                               texres.nor[2] = noiseHelper.woodInt(tex, texvec[0], texvec[1], texvec[2] + nabla, dataRepository);\r
-                                               noiseHelper.texNormalDerivate(colorBand, texres, dataRepository);\r
-                                       }\r
-                                       noiseHelper.brightnesAndContrastRGB(tex, texres);\r
-                                       data.put((byte) (texres.tr * 255.0f));\r
-                                       data.put((byte) (texres.tg * 255.0f));\r
-                                       data.put((byte) (texres.tb * 255.0f));\r
-                               } else {\r
-                                       noiseHelper.brightnesAndContrast(texres, contrast, bright);\r
-                                       data.put((byte) (texres.tin * 255));\r
-                               }\r
-                       }\r
-               }\r
-               return new Texture2D(new Image(format, width, height, data));\r
-       }\r
-\r
-       /**\r
-        * This method generates the marble texture.\r
-        * \r
-        * @param tex\r
-        *        the texture structure\r
-        * @param width\r
-        *        the width of the texture\r
-        * @param height\r
-        *        the height of the texture\r
-        * @param dataRepository\r
-        *        the data repository\r
-        * @return the generated texture\r
-        */\r
-       protected Texture marble(Structure tex, int width, int height, DataRepository dataRepository) {\r
-               // preparing the proper data\r
-               float contrast = ((Number) tex.getFieldValue("contrast")).floatValue();\r
-               float bright = ((Number) tex.getFieldValue("bright")).floatValue();\r
-               float nabla = ((Number) tex.getFieldValue("nabla")).floatValue();\r
-               float wDelta = 1.0f / width, hDelta = 1.0f / height;\r
-               float[] texvec = new float[] { 0, 0, 0 };\r
-               TexResult texres = new TexResult();\r
-               int halfW = width, halfH = height;\r
-               width <<= 1;\r
-               height <<= 1;\r
-               ColorBand colorBand = this.readColorband(tex, dataRepository);\r
-               Format format = colorBand != null ? Format.RGB8 : Format.Luminance8;\r
-               int bytesPerPixel = colorBand != null ? 3 : 1;\r
-\r
-               ByteBuffer data = BufferUtils.createByteBuffer(width * height * bytesPerPixel);\r
-               for (int i = -halfW; i < halfW; ++i) {\r
-                       texvec[0] = wDelta * i;\r
-                       for (int j = -halfH; j < halfH; ++j) {\r
-                               texvec[1] = hDelta * j;\r
-                               texres.tin = noiseHelper.marbleInt(tex, texvec[0], texvec[1], texvec[2], dataRepository);\r
-                               if (colorBand != null) {\r
-                                       noiseHelper.doColorband(colorBand, texres, dataRepository);\r
-                                       if (texres.nor != null) {// calculate bumpnormal\r
-                                               texres.nor[0] = noiseHelper.marbleInt(tex, texvec[0] + nabla, texvec[1], texvec[2], dataRepository);\r
-                                               texres.nor[1] = noiseHelper.marbleInt(tex, texvec[0], texvec[1] + nabla, texvec[2], dataRepository);\r
-                                               texres.nor[2] = noiseHelper.marbleInt(tex, texvec[0], texvec[1], texvec[2] + nabla, dataRepository);\r
-                                               noiseHelper.texNormalDerivate(colorBand, texres, dataRepository);\r
-                                       }\r
-\r
-                                       noiseHelper.brightnesAndContrastRGB(tex, texres);\r
-                                       data.put((byte) (texres.tr * 255.0f));\r
-                                       data.put((byte) (texres.tg * 255.0f));\r
-                                       data.put((byte) (texres.tb * 255.0f));\r
-                               } else {\r
-                                       noiseHelper.brightnesAndContrast(texres, contrast, bright);\r
-                                       data.put((byte) (texres.tin * 255.0f));\r
-                               }\r
-                       }\r
-               }\r
-               return new Texture2D(new Image(format, width, height, data));\r
-       }\r
-\r
-       /**\r
-        * This method generates the magic texture.\r
-        * \r
-        * @param tex\r
-        *        the texture structure\r
-        * @param width\r
-        *        the width of the texture\r
-        * @param height\r
-        *        the height of the texture\r
-        * @param dataRepository\r
-        *        the data repository\r
-        * @return the generated texture\r
-        */\r
-       protected Texture magic(Structure tex, int width, int height, DataRepository dataRepository) {\r
-               float x, y, z, turb;\r
-               int noisedepth = ((Number) tex.getFieldValue("noisedepth")).intValue();\r
-               float turbul = ((Number) tex.getFieldValue("turbul")).floatValue() / 5.0f;\r
-               float[] texvec = new float[] { 0, 0, 0 };\r
-               TexResult texres = new TexResult();\r
-               float wDelta = 1.0f / width, hDelta = 1.0f / height;\r
-               int halfW = width, halfH = height;\r
-               width <<= 1;\r
-               height <<= 1;\r
-               ColorBand colorBand = this.readColorband(tex, dataRepository);\r
-\r
-               ByteBuffer data = BufferUtils.createByteBuffer(width * height * 4);\r
-               for (int i = -halfW; i < halfW; ++i) {\r
-                       texvec[0] = wDelta * i;\r
-                       for (int j = -halfH; j < halfH; ++j) {\r
-                               turb = turbul;\r
-                               texvec[1] = hDelta * j;\r
-                               x = (float) Math.sin((texvec[0] + texvec[1]) * 5.0f);// in blender: Math.sin((texvec[0] + texvec[1] + texvec[2]) * 5.0f);\r
-                               y = (float) Math.cos((-texvec[0] + texvec[1]) * 5.0f);// in blender: Math.cos((-texvec[0] + texvec[1] - texvec[2]) * 5.0f);\r
-                               z = -(float) Math.cos((-texvec[0] - texvec[1]) * 5.0f);// in blender: Math.cos((-texvec[0] - texvec[1] + texvec[2]) * 5.0f);\r
-\r
-                               if (colorBand != null) {\r
-                                       texres.tin = 0.3333f * (x + y + z);\r
-                                       noiseHelper.doColorband(colorBand, texres, dataRepository);\r
-                               } else {\r
-                                       if (noisedepth > 0) {\r
-                                               x *= turb;\r
-                                               y *= turb;\r
-                                               z *= turb;\r
-                                               y = -(float) Math.cos(x - y + z) * turb;\r
-                                               if (noisedepth > 1) {\r
-                                                       x = (float) Math.cos(x - y - z) * turb;\r
-                                                       if (noisedepth > 2) {\r
-                                                               z = (float) Math.sin(-x - y - z) * turb;\r
-                                                               if (noisedepth > 3) {\r
-                                                                       x = -(float) Math.cos(-x + y - z) * turb;\r
-                                                                       if (noisedepth > 4) {\r
-                                                                               y = -(float) Math.sin(-x + y + z) * turb;\r
-                                                                               if (noisedepth > 5) {\r
-                                                                                       y = -(float) Math.cos(-x + y + z) * turb;\r
-                                                                                       if (noisedepth > 6) {\r
-                                                                                               x = (float) Math.cos(x + y + z) * turb;\r
-                                                                                               if (noisedepth > 7) {\r
-                                                                                                       z = (float) Math.sin(x + y - z) * turb;\r
-                                                                                                       if (noisedepth > 8) {\r
-                                                                                                               x = -(float) Math.cos(-x - y + z) * turb;\r
-                                                                                                               if (noisedepth > 9) {\r
-                                                                                                                       y = -(float) Math.sin(x - y + z) * turb;\r
-                                                                                                               }\r
-                                                                                                       }\r
-                                                                                               }\r
-                                                                                       }\r
-                                                                               }\r
-                                                                       }\r
-                                                               }\r
-                                                       }\r
-                                               }\r
-                                       }\r
-\r
-                                       if (turb != 0.0f) {\r
-                                               turb *= 2.0f;\r
-                                               x /= turb;\r
-                                               y /= turb;\r
-                                               z /= turb;\r
-                                       }\r
-                                       texres.tr = 0.5f - x;\r
-                                       texres.tg = 0.5f - y;\r
-                                       texres.tb = 0.5f - z;\r
-                               }\r
-                               noiseHelper.brightnesAndContrastRGB(tex, texres);\r
-                               data.put((byte) (texres.tin * 255));\r
-                               data.put((byte) (texres.tb * 255));\r
-                               data.put((byte) (texres.tg * 255));\r
-                               data.put((byte) (texres.tr * 255));\r
-                       }\r
-               }\r
-               return new Texture2D(new Image(Format.ABGR8, width, height, data));\r
-       }\r
-\r
-       /**\r
-        * This method generates the blend texture.\r
-        * \r
-        * @param tex\r
-        *        the texture structure\r
-        * @param width\r
-        *        the width of the texture\r
-        * @param height\r
-        *        the height of the texture\r
-        * @param dataRepository\r
-        *        the data repository\r
-        * @return the generated texture\r
-        */\r
-       protected Texture blend(Structure tex, int width, int height, DataRepository dataRepository) {\r
-               int flag = ((Number) tex.getFieldValue("flag")).intValue();\r
-               int stype = ((Number) tex.getFieldValue("stype")).intValue();\r
-               float contrast = ((Number) tex.getFieldValue("contrast")).floatValue();\r
-               float brightness = ((Number) tex.getFieldValue("bright")).floatValue();\r
-               float wDelta = 1.0f / width, hDelta = 1.0f / height, x, y, t;\r
-               float[] texvec = new float[] { 0, 0, 0 };\r
-               TexResult texres = new TexResult();\r
-               int halfW = width, halfH = height;\r
-               width <<= 1;\r
-               height <<= 1;\r
-               ColorBand colorBand = this.readColorband(tex, dataRepository);\r
-               Format format = colorBand != null ? Format.RGB8 : Format.Luminance8;\r
-               int bytesPerPixel = colorBand != null ? 3 : 1;\r
-\r
-               ByteBuffer data = BufferUtils.createByteBuffer(width * height * bytesPerPixel);\r
-               for (int i = -halfW; i < halfW; ++i) {\r
-                       texvec[0] = wDelta * i;\r
-                       for (int j = -halfH; j < halfH; ++j) {\r
-                               texvec[1] = hDelta * j;\r
-                               if ((flag & NoiseGenerator.TEX_FLIPBLEND) != 0) {\r
-                                       x = texvec[1];\r
-                                       y = texvec[0];\r
-                               } else {\r
-                                       x = texvec[0];\r
-                                       y = texvec[1];\r
-                               }\r
-\r
-                               if (stype == NoiseGenerator.TEX_LIN) { /* lin */\r
-                                       texres.tin = (1.0f + x) / 2.0f;\r
-                               } else if (stype == NoiseGenerator.TEX_QUAD) { /* quad */\r
-                                       texres.tin = (1.0f + x) / 2.0f;\r
-                                       if (texres.tin < 0.0f) {\r
-                                               texres.tin = 0.0f;\r
-                                       } else {\r
-                                               texres.tin *= texres.tin;\r
-                                       }\r
-                               } else if (stype == NoiseGenerator.TEX_EASE) { /* ease */\r
-                                       texres.tin = (1.0f + x) / 2.0f;\r
-                                       if (texres.tin <= 0.0f) {\r
-                                               texres.tin = 0.0f;\r
-                                       } else if (texres.tin >= 1.0f) {\r
-                                               texres.tin = 1.0f;\r
-                                       } else {\r
-                                               t = texres.tin * texres.tin;\r
-                                               texres.tin = 3.0f * t - 2.0f * t * texres.tin;\r
-                                       }\r
-                               } else if (stype == NoiseGenerator.TEX_DIAG) { /* diag */\r
-                                       texres.tin = (2.0f + x + y) / 4.0f;\r
-                               } else if (stype == NoiseGenerator.TEX_RAD) { /* radial */\r
-                                       texres.tin = (float) Math.atan2(y, x) / FastMath.TWO_PI + 0.5f;\r
-                               } else { /* sphere TEX_SPHERE */\r
-                                       texres.tin = 1.0f - (float) Math.sqrt(x * x + y * y + texvec[2] * texvec[2]);\r
-                                       if (texres.tin < 0.0f) {\r
-                                               texres.tin = 0.0f;\r
-                                       }\r
-                                       if (stype == NoiseGenerator.TEX_HALO) {\r
-                                               texres.tin *= texres.tin;\r
-                                       } /* halo */\r
-                               }\r
-                               if (colorBand != null) {\r
-                                       noiseHelper.doColorband(colorBand, texres, dataRepository);\r
-                                       noiseHelper.brightnesAndContrastRGB(tex, texres);\r
-                                       data.put((byte) (texres.tr * 255.0f));\r
-                                       data.put((byte) (texres.tg * 255.0f));\r
-                                       data.put((byte) (texres.tb * 255.0f));\r
-                               } else {\r
-                                       noiseHelper.brightnesAndContrast(texres, contrast, brightness);\r
-                                       data.put((byte) (texres.tin * 255.0f));\r
-                               }\r
-                       }\r
-               }\r
-               return new Texture2D(new Image(format, width, height, data));\r
-       }\r
-\r
-       /**\r
-        * This method generates the stucci texture.\r
-        * \r
-        * @param tex\r
-        *        the texture structure\r
-        * @param width\r
-        *        the width of the texture\r
-        * @param height\r
-        *        the height of the texture\r
-        * @param dataRepository\r
-        *        the data repository\r
-        * @return the generated texture\r
-        */\r
-       protected Texture stucci(Structure tex, int width, int height, DataRepository dataRepository) {\r
-               float noisesize = ((Number) tex.getFieldValue("noisesize")).floatValue();\r
-               int noisebasis = ((Number) tex.getFieldValue("noisebasis")).intValue();\r
-               int noisetype = ((Number) tex.getFieldValue("noisetype")).intValue();\r
-               float turbul = ((Number) tex.getFieldValue("turbul")).floatValue();\r
-               boolean isHard = noisetype != NoiseGenerator.TEX_NOISESOFT;\r
-               int stype = ((Number) tex.getFieldValue("stype")).intValue();\r
-\r
-               float[] texvec = new float[] { 0, 0, 0 };\r
-               TexResult texres = new TexResult();\r
-               float wDelta = 1.0f / width, hDelta = 1.0f / height, b2, ofs;\r
-               int halfW = width, halfH = height;\r
-               width <<= 1;\r
-               height <<= 1;\r
-               ColorBand colorBand = this.readColorband(tex, dataRepository);\r
-               Format format = colorBand != null ? Format.RGB8 : Format.Luminance8;\r
-               int bytesPerPixel = colorBand != null ? 3 : 1;\r
-\r
-               ByteBuffer data = BufferUtils.createByteBuffer(width * height * bytesPerPixel);\r
-               for (int i = -halfW; i < halfW; ++i) {\r
-                       texvec[0] = wDelta * i;// x\r
-                       for (int j = -halfH; j < halfH; ++j) {\r
-                               texvec[1] = hDelta * j;// y (z is always = 0)\r
-                               b2 = noiseHelper.bliGNoise(noisesize, texvec[0], texvec[1], texvec[2], isHard, noisebasis);\r
-\r
-                               ofs = turbul / 200.0f;\r
-\r
-                               if (stype != 0) {\r
-                                       ofs *= b2 * b2;\r
-                               }\r
-\r
-                               texres.tin = noiseHelper.bliGNoise(noisesize, texvec[0], texvec[1], texvec[2] + ofs, isHard, noisebasis);// ==nor[2]\r
-                               if (colorBand != null) {\r
-                                       noiseHelper.doColorband(colorBand, texres, dataRepository);\r
-                                       if (texres.nor != null) {\r
-                                               texres.nor[0] = noiseHelper.bliGNoise(noisesize, texvec[0] + ofs, texvec[1], texvec[2], isHard, noisebasis);\r
-                                               texres.nor[1] = noiseHelper.bliGNoise(noisesize, texvec[0], texvec[1] + ofs, texvec[2], isHard, noisebasis);\r
-                                               texres.nor[2] = texres.tin;\r
-                                               noiseHelper.texNormalDerivate(colorBand, texres, dataRepository);\r
-\r
-                                               if (stype == NoiseGenerator.TEX_WALLOUT) {\r
-                                                       texres.nor[0] = -texres.nor[0];\r
-                                                       texres.nor[1] = -texres.nor[1];\r
-                                                       texres.nor[2] = -texres.nor[2];\r
-                                               }\r
-                                       }\r
-                               }\r
-\r
-                               if (stype == NoiseGenerator.TEX_WALLOUT) {\r
-                                       texres.tin = 1.0f - texres.tin;\r
-                               }\r
-                               if (texres.tin < 0.0f) {\r
-                                       texres.tin = 0.0f;\r
-                               }\r
-                               if (colorBand != null) {\r
-                                       data.put((byte) (texres.tr * 255.0f));\r
-                                       data.put((byte) (texres.tg * 255.0f));\r
-                                       data.put((byte) (texres.tb * 255.0f));\r
-                               } else {\r
-                                       data.put((byte) (texres.tin * 255.0f));\r
-                               }\r
-                       }\r
-               }\r
-               return new Texture2D(new Image(format, width, height, data));\r
-       }\r
-\r
-       /**\r
-        * This method generates the noise texture.\r
-        * \r
-        * @param tex\r
-        *        the texture structure\r
-        * @param width\r
-        *        the width of the texture\r
-        * @param height\r
-        *        the height of the texture\r
-        * @param dataRepository\r
-        *        the data repository\r
-        * @return the generated texture\r
-        */\r
-       // TODO: correct this one, so it looks more like the texture generated by blender\r
-       protected Texture texnoise(Structure tex, int width, int height, DataRepository dataRepository) {\r
-               float div = 3.0f;\r
-               int val, ran, loop;\r
-               int noisedepth = ((Number) tex.getFieldValue("noisedepth")).intValue();\r
-               float contrast = ((Number) tex.getFieldValue("contrast")).floatValue();\r
-               float brightness = ((Number) tex.getFieldValue("bright")).floatValue();\r
-               TexResult texres = new TexResult();\r
-               int halfW = width, halfH = height;\r
-               width <<= 1;\r
-               height <<= 1;\r
-               ColorBand colorBand = this.readColorband(tex, dataRepository);\r
-               Format format = colorBand != null ? Format.RGB8 : Format.Luminance8;\r
-               int bytesPerPixel = colorBand != null ? 3 : 1;\r
-\r
-               ByteBuffer data = BufferUtils.createByteBuffer(width * height * bytesPerPixel);\r
-               for (int i = -halfW; i < halfW; ++i) {\r
-                       for (int j = -halfH; j < halfH; ++j) {\r
-                               ran = FastMath.rand.nextInt();// BLI_rand();\r
-                               val = ran & 3;\r
-\r
-                               loop = noisedepth;\r
-                               while (loop-- != 0) {\r
-                                       ran = ran >> 2;\r
-                                       val *= ran & 3;\r
-                                       div *= 3.0f;\r
-                               }\r
-                               texres.tin = val;// / div;\r
-                               if (colorBand != null) {\r
-                                       noiseHelper.doColorband(colorBand, texres, dataRepository);\r
-                                       noiseHelper.brightnesAndContrastRGB(tex, texres);\r
-                                       data.put((byte) (texres.tr * 255.0f));\r
-                                       data.put((byte) (texres.tg * 255.0f));\r
-                                       data.put((byte) (texres.tb * 255.0f));\r
-                               } else {\r
-                                       noiseHelper.brightnesAndContrast(texres, contrast, brightness);\r
-                                       data.put((byte) (texres.tin * 255.0f));\r
-                               }\r
-                       }\r
-               }\r
-               return new Texture2D(new Image(format, width, height, data));\r
-       }\r
-\r
-       /**\r
-        * This method generates the musgrave texture.\r
-        * \r
-        * @param tex\r
-        *        the texture structure\r
-        * @param width\r
-        *        the width of the texture\r
-        * @param height\r
-        *        the height of the texture\r
-        * @param dataRepository\r
-        *        the data repository\r
-        * @return the generated texture\r
-        */\r
-       protected Texture musgrave(Structure tex, int width, int height, DataRepository dataRepository) {\r
-               int stype = ((Number) tex.getFieldValue("stype")).intValue();\r
-               float noisesize = ((Number) tex.getFieldValue("noisesize")).floatValue();\r
-               TexResult texres = new TexResult();\r
-               float[] texvec = new float[] { 0, 0, 0 };\r
-               float wDelta = 1.0f / width, hDelta = 1.0f / height;\r
-               int halfW = width, halfH = height;\r
-               width <<= 1;\r
-               height <<= 1;\r
-               ColorBand colorBand = this.readColorband(tex, dataRepository);\r
-               Format format = colorBand != null ? Format.RGB8 : Format.Luminance8;\r
-               int bytesPerPixel = colorBand != null ? 3 : 1;\r
-\r
-               ByteBuffer data = BufferUtils.createByteBuffer(width * height * bytesPerPixel);\r
-               for (int i = -halfW; i < halfW; ++i) {\r
-                       texvec[0] = wDelta * i / noisesize;\r
-                       for (int j = -halfH; j < halfH; ++j) {\r
-                               texvec[1] = hDelta * j / noisesize;\r
-                               switch (stype) {\r
-                                       case NoiseGenerator.TEX_MFRACTAL:\r
-                                       case NoiseGenerator.TEX_FBM:\r
-                                               noiseHelper.mgMFractalOrfBmTex(tex, texvec, colorBand, texres, dataRepository);\r
-                                               break;\r
-                                       case NoiseGenerator.TEX_RIDGEDMF:\r
-                                       case NoiseGenerator.TEX_HYBRIDMF:\r
-                                               noiseHelper.mgRidgedOrHybridMFTex(tex, texvec, colorBand, texres, dataRepository);\r
-                                               break;\r
-                                       case NoiseGenerator.TEX_HTERRAIN:\r
-                                               noiseHelper.mgHTerrainTex(tex, texvec, colorBand, texres, dataRepository);\r
-                                               break;\r
-                                       default:\r
-                                               throw new IllegalStateException("Unknown type of musgrave texture: " + stype);\r
-                               }\r
-                               if (colorBand != null) {\r
-                                       noiseHelper.doColorband(colorBand, texres, dataRepository);\r
-                                       data.put((byte) (texres.tr * 255.0f));\r
-                                       data.put((byte) (texres.tg * 255.0f));\r
-                                       data.put((byte) (texres.tb * 255.0f));\r
-                               } else {\r
-                                       data.put((byte) (texres.tin * 255.0f));\r
-                               }\r
-                       }\r
-               }\r
-               return new Texture2D(new Image(format, width, height, data));\r
-       }\r
-\r
-       /**\r
-        * This method generates the voronoi texture.\r
-        * \r
-        * @param tex\r
-        *        the texture structure\r
-        * @param width\r
-        *        the width of the texture\r
-        * @param height\r
-        *        the height of the texture\r
-        * @param dataRepository\r
-        *        the data repository\r
-        * @return the generated texture\r
-        */\r
-       protected Texture voronoi(Structure tex, int width, int height, DataRepository dataRepository) {\r
-               float vn_w1 = ((Number) tex.getFieldValue("vn_w1")).floatValue();\r
-               float vn_w2 = ((Number) tex.getFieldValue("vn_w2")).floatValue();\r
-               float vn_w3 = ((Number) tex.getFieldValue("vn_w3")).floatValue();\r
-               float vn_w4 = ((Number) tex.getFieldValue("vn_w4")).floatValue();\r
-               float noisesize = ((Number) tex.getFieldValue("noisesize")).floatValue();\r
-               float nabla = ((Number) tex.getFieldValue("nabla")).floatValue();\r
-               float ns_outscale = ((Number) tex.getFieldValue("ns_outscale")).floatValue();\r
-               float vn_mexp = ((Number) tex.getFieldValue("vn_mexp")).floatValue();\r
-               int vn_distm = ((Number) tex.getFieldValue("vn_distm")).intValue();\r
-               int vn_coltype = ((Number) tex.getFieldValue("vn_coltype")).intValue();\r
-               float contrast = ((Number) tex.getFieldValue("contrast")).floatValue();\r
-               float brightness = ((Number) tex.getFieldValue("bright")).floatValue();\r
-\r
-               TexResult texres = new TexResult();\r
-               float[] texvec = new float[] { 0, 0, 0 };\r
-               float wDelta = 1.0f / width, hDelta = 1.0f / height;\r
-               int halfW = width, halfH = height;\r
-               width <<= 1;\r
-               height <<= 1;\r
-               ColorBand colorBand = this.readColorband(tex, dataRepository);\r
-               Format format = vn_coltype != 0 || colorBand != null ? Format.RGB8 : Format.Luminance8;\r
-               int bytesPerPixel = vn_coltype != 0 || colorBand != null ? 3 : 1;\r
-\r
-               float[] da = new float[4], pa = new float[12]; /* distance and point coordinate arrays of 4 nearest neighbours */\r
-               float[] ca = vn_coltype != 0 ? new float[3] : null; // cell color\r
-               float aw1 = FastMath.abs(vn_w1);\r
-               float aw2 = FastMath.abs(vn_w2);\r
-               float aw3 = FastMath.abs(vn_w3);\r
-               float aw4 = FastMath.abs(vn_w4);\r
-               float sc = aw1 + aw2 + aw3 + aw4;\r
-               if (sc != 0.f) {\r
-                       sc = ns_outscale / sc;\r
-               }\r
-\r
-               ByteBuffer data = BufferUtils.createByteBuffer(width * height * bytesPerPixel);\r
-               for (int i = -halfW; i < halfW; ++i) {\r
-                       texvec[0] = wDelta * i / noisesize;\r
-                       for (int j = -halfH; j < halfH; ++j) {\r
-                               texvec[1] = hDelta * j / noisesize;\r
-\r
-                               noiseHelper.voronoi(texvec[0], texvec[1], texvec[2], da, pa, vn_mexp, vn_distm);\r
-                               texres.tin = sc * FastMath.abs(vn_w1 * da[0] + vn_w2 * da[1] + vn_w3 * da[2] + vn_w4 * da[3]);\r
-                               if (vn_coltype != 0) {\r
-                                       noiseHelper.cellNoiseV(pa[0], pa[1], pa[2], ca);\r
-                                       texres.tr = aw1 * ca[0];\r
-                                       texres.tg = aw1 * ca[1];\r
-                                       texres.tb = aw1 * ca[2];\r
-                                       noiseHelper.cellNoiseV(pa[3], pa[4], pa[5], ca);\r
-                                       texres.tr += aw2 * ca[0];\r
-                                       texres.tg += aw2 * ca[1];\r
-                                       texres.tb += aw2 * ca[2];\r
-                                       noiseHelper.cellNoiseV(pa[6], pa[7], pa[8], ca);\r
-                                       texres.tr += aw3 * ca[0];\r
-                                       texres.tg += aw3 * ca[1];\r
-                                       texres.tb += aw3 * ca[2];\r
-                                       noiseHelper.cellNoiseV(pa[9], pa[10], pa[11], ca);\r
-                                       texres.tr += aw4 * ca[0];\r
-                                       texres.tg += aw4 * ca[1];\r
-                                       texres.tb += aw4 * ca[2];\r
-                                       if (vn_coltype >= 2) {\r
-                                               float t1 = (da[1] - da[0]) * 10.0f;\r
-                                               if (t1 > 1) {\r
-                                                       t1 = 1.0f;\r
-                                               }\r
-                                               if (vn_coltype == 3) {\r
-                                                       t1 *= texres.tin;\r
-                                               } else {\r
-                                                       t1 *= sc;\r
-                                               }\r
-                                               texres.tr *= t1;\r
-                                               texres.tg *= t1;\r
-                                               texres.tb *= t1;\r
-                                       } else {\r
-                                               texres.tr *= sc;\r
-                                               texres.tg *= sc;\r
-                                               texres.tb *= sc;\r
-                                       }\r
-                               }\r
-                               if (colorBand != null) {\r
-                                       noiseHelper.doColorband(colorBand, texres, dataRepository);\r
-                                       if (texres.nor != null) {\r
-                                               float offs = nabla / noisesize; // also scaling of texvec\r
-                                               // calculate bumpnormal\r
-                                               noiseHelper.voronoi(texvec[0] + offs, texvec[1], texvec[2], da, pa, vn_mexp, vn_distm);\r
-                                               texres.nor[0] = sc * FastMath.abs(vn_w1 * da[0] + vn_w2 * da[1] + vn_w3 * da[2] + vn_w4 * da[3]);\r
-                                               noiseHelper.voronoi(texvec[0], texvec[1] + offs, texvec[2], da, pa, vn_mexp, vn_distm);\r
-                                               texres.nor[1] = sc * FastMath.abs(vn_w1 * da[0] + vn_w2 * da[1] + vn_w3 * da[2] + vn_w4 * da[3]);\r
-                                               noiseHelper.voronoi(texvec[0], texvec[1], texvec[2] + offs, da, pa, vn_mexp, vn_distm);\r
-                                               texres.nor[2] = sc * FastMath.abs(vn_w1 * da[0] + vn_w2 * da[1] + vn_w3 * da[2] + vn_w4 * da[3]);\r
-                                               noiseHelper.texNormalDerivate(colorBand, texres, dataRepository);\r
-                                       }\r
-                               }\r
-\r
-                               if (vn_coltype != 0 || colorBand != null) {\r
-                                       noiseHelper.brightnesAndContrastRGB(tex, texres);\r
-                                       data.put((byte) (texres.tr * 255.0f));// tin or tr??\r
-                                       data.put((byte) (texres.tg * 255.0f));\r
-                                       data.put((byte) (texres.tb * 255.0f));\r
-                               } else {\r
-                                       noiseHelper.brightnesAndContrast(texres, contrast, brightness);\r
-                                       data.put((byte) (texres.tin * 255.0f));\r
-                               }\r
-                       }\r
-               }\r
-               return new Texture2D(new Image(format, width, height, data));\r
-       }\r
-\r
-       /**\r
-        * This method generates the distorted noise texture.\r
-        * \r
-        * @param tex\r
-        *        the texture structure\r
-        * @param width\r
-        *        the width of the texture\r
-        * @param height\r
-        *        the height of the texture\r
-        * @param dataRepository\r
-        *        the data repository\r
-        * @return the generated texture\r
-        */\r
-       protected Texture distnoise(Structure tex, int width, int height, DataRepository dataRepository) {\r
-               float noisesize = ((Number) tex.getFieldValue("noisesize")).floatValue();\r
-               float nabla = ((Number) tex.getFieldValue("nabla")).floatValue();\r
-               float distAmount = ((Number) tex.getFieldValue("dist_amount")).floatValue();\r
-               int noisebasis = ((Number) tex.getFieldValue("noisebasis")).intValue();\r
-               int noisebasis2 = ((Number) tex.getFieldValue("noisebasis2")).intValue();\r
-               float contrast = ((Number) tex.getFieldValue("contrast")).floatValue();\r
-               float brightness = ((Number) tex.getFieldValue("bright")).floatValue();\r
-\r
-               TexResult texres = new TexResult();\r
-               float[] texvec = new float[] { 0, 0, 0 };\r
-               float wDelta = 1.0f / width, hDelta = 1.0f / height;\r
-               int halfW = width, halfH = height;\r
-               width <<= 1;\r
-               height <<= 1;\r
-               ColorBand colorBand = this.readColorband(tex, dataRepository);\r
-               Format format = colorBand != null ? Format.RGB8 : Format.Luminance8;\r
-               int bytesPerPixel = colorBand != null ? 3 : 1;\r
-\r
-               ByteBuffer data = BufferUtils.createByteBuffer(width * height * bytesPerPixel);\r
-               for (int i = -halfW; i < halfW; ++i) {\r
-                       texvec[0] = wDelta * i / noisesize;\r
-                       for (int j = -halfH; j < halfH; ++j) {\r
-                               texvec[1] = hDelta * j / noisesize;\r
-\r
-                               texres.tin = noiseHelper.mgVLNoise(texvec[0], texvec[1], texvec[2], distAmount, noisebasis, noisebasis2);\r
-                               if (colorBand != null) {\r
-                                       noiseHelper.doColorband(colorBand, texres, dataRepository);\r
-                                       if (texres.nor != null) {\r
-                                               float offs = nabla / noisesize; // also scaling of texvec\r
-                                               /* calculate bumpnormal */\r
-                                               texres.nor[0] = noiseHelper.mgVLNoise(texvec[0] + offs, texvec[1], texvec[2], distAmount, noisebasis, noisebasis2);\r
-                                               texres.nor[1] = noiseHelper.mgVLNoise(texvec[0], texvec[1] + offs, texvec[2], distAmount, noisebasis, noisebasis2);\r
-                                               texres.nor[2] = noiseHelper.mgVLNoise(texvec[0], texvec[1], texvec[2] + offs, distAmount, noisebasis, noisebasis2);\r
-                                               noiseHelper.texNormalDerivate(colorBand, texres, dataRepository);\r
-                                       }\r
-\r
-                                       noiseHelper.brightnesAndContrastRGB(tex, texres);\r
-                                       data.put((byte) (texres.tr * 255.0f));\r
-                                       data.put((byte) (texres.tg * 255.0f));\r
-                                       data.put((byte) (texres.tb * 255.0f));\r
-                               } else {\r
-                                       noiseHelper.brightnesAndContrast(texres, contrast, brightness);\r
-                                       data.put((byte) (texres.tin * 255.0f));\r
-                               }\r
-                       }\r
-               }\r
-               return new Texture2D(new Image(format, width, height, data));\r
-       }\r
-\r
-       /**\r
-        * This method reads the colorband data from the given texture structure.\r
-        * \r
-        * @param tex\r
-        *        the texture structure\r
-        * @param dataRepository\r
-        *        the data repository\r
-        * @return read colorband or null if not present\r
-        */\r
-       protected ColorBand readColorband(Structure tex, DataRepository dataRepository) {\r
-               ColorBand result = null;\r
-               int flag = ((Number) tex.getFieldValue("flag")).intValue();\r
-               if ((flag & NoiseGenerator.TEX_COLORBAND) != 0) {\r
-                       Pointer pColorband = (Pointer) tex.getFieldValue("coba");\r
-                       Structure colorbandStructure;\r
-                       try {\r
-                               colorbandStructure = pColorband.fetchData(dataRepository.getInputStream()).get(0);\r
-                               result = new ColorBand(colorbandStructure);\r
-                       } catch (BlenderFileException e) {\r
-                               LOGGER.warning("Cannot fetch the colorband structure. The reason: " + e.getLocalizedMessage());\r
-                               // TODO: throw an exception here ???\r
-                       }\r
-               }\r
-               return result;\r
-       }\r
-\r
-       /**\r
         * This method blends the given texture with material color and the defined color in 'map to' panel. As a result of this method a new\r
         * texture is created. The input texture is NOT.\r
         * \r
@@ -1189,7 +409,7 @@ public class TextureHelper extends AbstractBlenderHelper {
         * @param dataRepository\r
         *        the data repository\r
         */\r
-       public void blendPixel(float[] result, float[] materialColor, float[] color, float textureIntensity, float textureFactor, int blendtype, DataRepository dataRepository) {\r
+       protected void blendPixel(float[] result, float[] materialColor, float[] color, float textureIntensity, float textureFactor, int blendtype, DataRepository dataRepository) {\r
                float facm, col;\r
 \r
                switch (blendtype) {\r
@@ -1325,7 +545,7 @@ public class TextureHelper extends AbstractBlenderHelper {
         * @param dataRepository\r
         *        the data repository\r
         */\r
-       public void rampBlend(int type, float[] rgb, float fac, float[] col, DataRepository dataRepository) {\r
+       protected void rampBlend(int type, float[] rgb, float fac, float[] col, DataRepository dataRepository) {\r
                float tmp, facm = 1.0f - fac;\r
                MaterialHelper materialHelper = dataRepository.getHelper(MaterialHelper.class);\r
 \r
@@ -1792,92 +1012,6 @@ public class TextureHelper extends AbstractBlenderHelper {
                        }\r
                }\r
        }\r
-\r
-       /**\r
-        * An image loader class. It uses three loaders (AWTLoader, TGALoader and DDSLoader) in an attempt to load the image from the given\r
-        * input stream.\r
-        * \r
-        * @author Marcin Roguski (Kaelthas)\r
-        */\r
-       protected static class ImageLoader extends AWTLoader {\r
-               private static final Logger     LOGGER          = Logger.getLogger(ImageLoader.class.getName());\r
-\r
-               protected DDSLoader                     ddsLoader       = new DDSLoader();                                                                      // DirectX image loader\r
-\r
-               /**\r
-                * This method loads the image from the blender file itself. It tries each loader to load the image.\r
-                * \r
-                * @param inputStream\r
-                *        blender input stream\r
-                * @param startPosition\r
-                *        position in the stream where the image data starts\r
-                * @param flipY\r
-                *        if the image should be flipped (does not work with DirectX image)\r
-                * @return loaded image or null if it could not be loaded\r
-                */\r
-               public Image loadImage(BlenderInputStream inputStream, int startPosition, boolean flipY) {\r
-                       // loading using AWT loader\r
-                       inputStream.setPosition(startPosition);\r
-                       Image result = this.loadImage(inputStream, ImageType.AWT, flipY);\r
-                       // loading using TGA loader\r
-                       if (result == null) {\r
-                               inputStream.setPosition(startPosition);\r
-                               result = this.loadImage(inputStream, ImageType.TGA, flipY);\r
-                       }\r
-                       // loading using DDS loader\r
-                       if (result == null) {\r
-                               inputStream.setPosition(startPosition);\r
-                               result = this.loadImage(inputStream, ImageType.DDS, flipY);\r
-                       }\r
-\r
-                       if (result == null) {\r
-                               LOGGER.warning("Image could not be loaded by none of available loaders!");\r
-                       }\r
-\r
-                       return result;\r
-               }\r
-\r
-               /**\r
-                * This method loads an image of a specified type from the given input stream.\r
-                * \r
-                * @param inputStream\r
-                *        the input stream we read the image from\r
-                * @param imageType\r
-                *        the type of the image {@link ImageType}\r
-                * @param flipY\r
-                *        if the image should be flipped (does not work with DirectX image)\r
-                * @return loaded image or null if it could not be loaded\r
-                */\r
-               public Image loadImage(InputStream inputStream, ImageType imageType, boolean flipY) {\r
-                       Image result = null;\r
-                       switch (imageType) {\r
-                               case AWT:\r
-                                       try {\r
-                                               result = this.load(inputStream, flipY);\r
-                                       } catch (Exception e) {\r
-                                               LOGGER.info("Unable to load image using AWT loader!");\r
-                                       }\r
-                                       break;\r
-                               case DDS:\r
-                                       try {\r
-                                               result = ddsLoader.load(inputStream);\r
-                                       } catch (Exception e) {\r
-                                               LOGGER.info("Unable to load image using DDS loader!");\r
-                                       }\r
-                                       break;\r
-                               case TGA:\r
-                                       try {\r
-                                               result = TGALoader.load(inputStream, flipY);\r
-                                       } catch (Exception e) {\r
-                                               LOGGER.info("Unable to load image using TGA loader!");\r
-                                       }\r
-                                       break;\r
-                               default:\r
-                                       throw new IllegalStateException("Unknown image type: " + imageType);\r
-                       }\r
-                       return result;\r
-               }\r
-       }\r
        \r
        @Override\r
        public boolean shouldBeLoaded(Structure structure, DataRepository dataRepository) {\r