From 535a6dd8cee2825c311e8ef335d21444fa0bc309 Mon Sep 17 00:00:00 2001 From: "Kae..pl" Date: Fri, 4 Oct 2013 18:29:34 +0000 Subject: [PATCH] Bugfix: fixed an issue when UV coordinates were not applied even though the mesh had them defined (the bug occured when the mesh had materials, UV's and no textures). git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@10818 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../blender/materials/MaterialContext.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) 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 ca8377cd6..c56276b12 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 @@ -159,7 +159,7 @@ public final class MaterialContext { // applying textures if (loadedTextures != null && loadedTextures.size() > 0) { int textureIndex = 0; - if(loadedTextures.size() > 8) { + if(loadedTextures.size() > TextureHelper.TEXCOORD_TYPES.length) { LOGGER.log(Level.WARNING, "The blender file has defined more than {0} different textures. JME supports only {0} UV mappings.", TextureHelper.TEXCOORD_TYPES.length); } for (Entry entry : loadedTextures.entrySet()) { @@ -176,6 +176,22 @@ public final class MaterialContext { LOGGER.log(Level.WARNING, "The texture could not be applied because JME only supports up to {0} different UV's.", TextureHelper.TEXCOORD_TYPES.length); } } + } else if(userDefinedUVCoordinates != null && userDefinedUVCoordinates.size() > 0) { + LOGGER.fine("No textures found for the mesh, but UV coordinates are applied."); + int textureIndex = 0; + if(userDefinedUVCoordinates.size() > TextureHelper.TEXCOORD_TYPES.length) { + LOGGER.log(Level.WARNING, "The blender file has defined more than {0} different UV coordinates for the mesh. JME supports only {0} UV coordinates buffers.", TextureHelper.TEXCOORD_TYPES.length); + } + for(Entry> entry : userDefinedUVCoordinates.entrySet()) { + if(textureIndex < TextureHelper.TEXCOORD_TYPES.length) { + List uvs = entry.getValue(); + VertexBuffer uvCoordsBuffer = new VertexBuffer(TextureHelper.TEXCOORD_TYPES[textureIndex++]); + uvCoordsBuffer.setupData(Usage.Static, 2, Format.Float, BufferUtils.createFloatBuffer(uvs.toArray(new Vector2f[uvs.size()]))); + geometry.getMesh().setBuffer(uvCoordsBuffer); + } else { + LOGGER.log(Level.WARNING, "The texture could not be applied because JME only supports up to {0} different UV's.", TextureHelper.TEXCOORD_TYPES.length); + } + } } // applying additional data