From de75b794c2a49668a1d415216f5ea16e1be14cec Mon Sep 17 00:00:00 2001 From: "sha..rd" Date: Tue, 8 Nov 2011 03:09:22 +0000 Subject: [PATCH] * Remove duplicate code in MeshLoader that handles loading the material list * Added javadoc in OgreMeshKey git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@8594 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../jme3/scene/plugins/ogre/MeshLoader.java | 48 +++++++++---------- .../jme3/scene/plugins/ogre/OgreMeshKey.java | 12 +++++ 2 files changed, 36 insertions(+), 24 deletions(-) diff --git a/engine/src/ogre/com/jme3/scene/plugins/ogre/MeshLoader.java b/engine/src/ogre/com/jme3/scene/plugins/ogre/MeshLoader.java index 016c30c44..ba1a8f158 100644 --- a/engine/src/ogre/com/jme3/scene/plugins/ogre/MeshLoader.java +++ b/engine/src/ogre/com/jme3/scene/plugins/ogre/MeshLoader.java @@ -790,38 +790,38 @@ public class MeshLoader extends DefaultHandler implements AssetLoader { } assetManager = info.getManager(); - OgreMeshKey meshKey = null; if (key instanceof OgreMeshKey) { - meshKey = (OgreMeshKey) key; + // OgreMeshKey is being used, try getting the material list + // from it + OgreMeshKey meshKey = (OgreMeshKey) key; materialList = meshKey.getMaterialList(); String materialName = meshKey.getMaterialName(); - if (materialList == null) { - if (materialName != null) { - try { - materialList = (MaterialList) assetManager.loadAsset(new OgreMaterialKey(folderName + materialName + ".material")); - } catch (AssetNotFoundException e) { - logger.log(Level.WARNING, "Cannot locate {0}{1}.material for model {2}{3}.{4}", new Object[]{folderName, materialName, folderName, meshName, ext}); - logger.log(Level.WARNING, "", e); - } - } else { - try { - materialList = (MaterialList) assetManager.loadAsset(new OgreMaterialKey(folderName + meshName + ".material")); - } catch (AssetNotFoundException e) { - logger.log(Level.WARNING, "Cannot locate {0}{1}.material for model {2}{3}.{4}", new Object[]{folderName, meshName, folderName, meshName, ext}); - logger.log(Level.WARNING, "", e); - } + + // Material list not set but material name is available + if (materialList == null && materialName != null) { + OgreMaterialKey materialKey = new OgreMaterialKey(folderName + materialName + ".material"); + try { + materialList = (MaterialList) assetManager.loadAsset(materialKey); + } catch (AssetNotFoundException e) { + logger.log(Level.WARNING, "Cannot locate {0} for model {1}", new Object[]{materialKey, key}); + logger.log(Level.WARNING, "", e); } } - } else { + } + + // If for some reason material list could not be found through + // OgreMeshKey, or if regular ModelKey specified, load using + // default method. + if (materialList == null){ + OgreMaterialKey materialKey = new OgreMaterialKey(folderName + meshName + ".material"); try { - materialList = (MaterialList) assetManager.loadAsset(new OgreMaterialKey(folderName + meshName + ".material")); + materialList = (MaterialList) assetManager.loadAsset(materialKey); } catch (AssetNotFoundException e) { - logger.log(Level.WARNING, "Cannot locate {0}{1}.material for model {2}{3}.{4}", new Object[]{folderName, meshName, folderName, meshName, ext}); - logger.log(Level.WARNING, "", e); - } - + logger.log(Level.WARNING, "Cannot locate {0} for model {1}", new Object[]{ materialKey, key }); + logger.log(Level.WARNING, "", e); + } } - + // Added by larynx 25.06.2011 // Android needs the namespace aware flag set to true // Kirill 30.06.2011 diff --git a/engine/src/ogre/com/jme3/scene/plugins/ogre/OgreMeshKey.java b/engine/src/ogre/com/jme3/scene/plugins/ogre/OgreMeshKey.java index a2b54f087..1141944b2 100644 --- a/engine/src/ogre/com/jme3/scene/plugins/ogre/OgreMeshKey.java +++ b/engine/src/ogre/com/jme3/scene/plugins/ogre/OgreMeshKey.java @@ -35,6 +35,14 @@ package com.jme3.scene.plugins.ogre; import com.jme3.asset.ModelKey; import com.jme3.material.MaterialList; +/** + * OgreMeshKey is used to load Ogre3D mesh.xml models with a specific + * material file or list. This allows customizing from where the materials + * are retrieved, instead of loading the material file as the same + * name as the model (the default). + * + * @author Kirill Vainer + */ public class OgreMeshKey extends ModelKey { private MaterialList materialList; @@ -62,6 +70,10 @@ public class OgreMeshKey extends ModelKey { return materialList; } + public void setMaterialList(MaterialList materialList){ + this.materialList = materialList; + } + public String getMaterialName() { return materialName; }