From 1bad383be25cbcc74167fbc3ab1d76834d28d107 Mon Sep 17 00:00:00 2001 From: "Kae..pl" Date: Tue, 28 Aug 2012 18:34:49 +0000 Subject: [PATCH] Added and entry to the blender key that allows to disable loading of generated textures. The value is set to false by default because generated textures need extra care when being loaded. git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9694 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../blender/com/jme3/asset/BlenderKey.java | 17 +++++++++++ .../blender/textures/CombinedTexture.java | 30 ++++++++++--------- 2 files changed, 33 insertions(+), 14 deletions(-) diff --git a/engine/src/blender/com/jme3/asset/BlenderKey.java b/engine/src/blender/com/jme3/asset/BlenderKey.java index b8fd35fce..c82da1083 100644 --- a/engine/src/blender/com/jme3/asset/BlenderKey.java +++ b/engine/src/blender/com/jme3/asset/BlenderKey.java @@ -100,6 +100,8 @@ public class BlenderKey extends ModelKey { protected boolean loadObjectProperties = true; /** Maximum texture size. Might be dependant on the graphic card.*/ protected int maxTextureSize = -1; + /** Allows to toggle generated textures loading. Disabled by default because it very often takes too much memory and needs to be used wisely. */ + protected boolean loadGeneratedTextures; /** * Constructor used by serialization mechanisms. @@ -205,6 +207,21 @@ public class BlenderKey extends ModelKey { this.maxTextureSize = maxTextureSize; } + /** + * This method sets the flag that toggles the generated textures loading. + * @param loadGeneratedTextures true if generated textures should be loaded and false otherwise + */ + public void setLoadGeneratedTextures(boolean loadGeneratedTextures) { + this.loadGeneratedTextures = loadGeneratedTextures; + } + + /** + * @return tells if the generated textures should be loaded (false is the default value) + */ + public boolean isLoadGeneratedTextures() { + return loadGeneratedTextures; + } + /** * This method sets the asset root path. * @param assetRootPath 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 eedd5f19c..70dae5be0 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 @@ -84,21 +84,23 @@ public class CombinedTexture { if (!(texture instanceof GeneratedTexture) && !(texture instanceof Texture2D)) { throw new IllegalArgumentException("Unsupported texture type: " + (texture == null ? "null" : texture.getClass())); } - if(UVCoordinatesGenerator.isTextureCoordinateTypeSupported(UVCoordinatesType.valueOf(uvCoordinatesType))) { - TextureData textureData = new TextureData(); - textureData.texture = texture; - textureData.textureBlender = textureBlender; - textureData.uvCoordinatesType = UVCoordinatesType.valueOf(uvCoordinatesType); - textureData.projectionType = UVProjectionType.valueOf(projectionType); - textureData.textureStructure = textureStructure; - - if (this.isWithoutAlpha(textureData, blenderContext)) { - textureDatas.clear();// clear previous textures, they will be covered anyway + if(!(texture instanceof GeneratedTexture) || blenderContext.getBlenderKey().isLoadGeneratedTextures()) { + if(UVCoordinatesGenerator.isTextureCoordinateTypeSupported(UVCoordinatesType.valueOf(uvCoordinatesType))) { + TextureData textureData = new TextureData(); + textureData.texture = texture; + textureData.textureBlender = textureBlender; + textureData.uvCoordinatesType = UVCoordinatesType.valueOf(uvCoordinatesType); + textureData.projectionType = UVProjectionType.valueOf(projectionType); + textureData.textureStructure = textureStructure; + + if (this.isWithoutAlpha(textureData, blenderContext)) { + textureDatas.clear();// clear previous textures, they will be covered anyway + } + textureDatas.add(textureData); + } else { + LOGGER.warning("The texture coordinates type is not supported: " + UVCoordinatesType.valueOf(uvCoordinatesType) + ". The texture '" + textureStructure.getName() + "'."); } - textureDatas.add(textureData); - } else { - LOGGER.warning("The texture coordinates type is not supported: " + UVCoordinatesType.valueOf(uvCoordinatesType) + ". The texture '" + textureStructure.getName() + "'."); - } + } } /**