From f9593adee1b685a4c662121abc8d52ad8cab53da Mon Sep 17 00:00:00 2001 From: "Kae..pl" Date: Wed, 2 May 2012 16:45:38 +0000 Subject: [PATCH] Fixed NPE error when using a single 'None' texture type in the material definition. git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9342 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../blender/materials/MaterialContext.java | 27 ++++++++++--------- .../blender/textures/CombinedTexture.java | 7 +++++ 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/materials/MaterialContext.java b/engine/src/blender/com/jme3/scene/plugins/blender/materials/MaterialContext.java index 6799f4877..2231c6796 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/materials/MaterialContext.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/materials/MaterialContext.java @@ -126,23 +126,24 @@ public final class MaterialContext { TextureHelper textureHelper = blenderContext.getHelper(TextureHelper.class); for(Entry> entry : textureDataMap.entrySet()) { if(entry.getValue().size()>0) { - CombinedTexture combinedTexture = loadedTextures.get(entry.getKey()); - if(combinedTexture == null) { - combinedTexture = new CombinedTexture(); - loadedTextures.put(entry.getKey(), combinedTexture); - } + CombinedTexture combinedTexture = new CombinedTexture(); for(TextureData textureData : entry.getValue()) { int texflag = ((Number) textureData.mtex.getFieldValue("texflag")).intValue(); boolean negateTexture = (texflag & 0x04) != 0; Texture texture = textureHelper.getTexture(textureData.textureStructure, textureData.mtex, blenderContext); - int blendType = ((Number) textureData.mtex.getFieldValue("blendtype")).intValue(); - float[] color = new float[] { ((Number) textureData.mtex.getFieldValue("r")).floatValue(), - ((Number) textureData.mtex.getFieldValue("g")).floatValue(), - ((Number) textureData.mtex.getFieldValue("b")).floatValue() }; - float colfac = ((Number) textureData.mtex.getFieldValue("colfac")).floatValue(); - TextureBlender textureBlender = TextureBlenderFactory.createTextureBlender(texture.getImage().getFormat(), - texflag, negateTexture, blendType, diffuseColorArray, color, colfac); - combinedTexture.add(texture, textureBlender, textureData.uvCoordinatesType, textureData.projectionType, textureData.textureStructure, blenderContext); + if(texture != null) { + int blendType = ((Number) textureData.mtex.getFieldValue("blendtype")).intValue(); + float[] color = new float[] { ((Number) textureData.mtex.getFieldValue("r")).floatValue(), + ((Number) textureData.mtex.getFieldValue("g")).floatValue(), + ((Number) textureData.mtex.getFieldValue("b")).floatValue() }; + float colfac = ((Number) textureData.mtex.getFieldValue("colfac")).floatValue(); + TextureBlender textureBlender = TextureBlenderFactory.createTextureBlender(texture.getImage().getFormat(), + texflag, negateTexture, blendType, diffuseColorArray, color, colfac); + combinedTexture.add(texture, textureBlender, textureData.uvCoordinatesType, textureData.projectionType, textureData.textureStructure, blenderContext); + } + } + if(combinedTexture.getTexturesCount() > 0) { + loadedTextures.put(entry.getKey(), combinedTexture); } } } diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/textures/CombinedTexture.java b/engine/src/blender/com/jme3/scene/plugins/blender/textures/CombinedTexture.java index c78019cb4..5394a2cbf 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/textures/CombinedTexture.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/textures/CombinedTexture.java @@ -210,6 +210,13 @@ public class CombinedTexture { public List getResultUVS() { return resultUVS; } + + /** + * @return the amount of added textures + */ + public int getTexturesCount() { + return textureDatas.size(); + } /** * This method merges two given textures. The result is stored in the