* 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
3.0
sha..rd 13 years ago
parent cfd13e8d33
commit de75b794c2
  1. 34
      engine/src/ogre/com/jme3/scene/plugins/ogre/MeshLoader.java
  2. 12
      engine/src/ogre/com/jme3/scene/plugins/ogre/OgreMeshKey.java

@ -790,36 +790,36 @@ public class MeshLoader extends DefaultHandler implements AssetLoader {
} }
assetManager = info.getManager(); assetManager = info.getManager();
OgreMeshKey meshKey = null;
if (key instanceof OgreMeshKey) { 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(); materialList = meshKey.getMaterialList();
String materialName = meshKey.getMaterialName(); String materialName = meshKey.getMaterialName();
if (materialList == null) {
if (materialName != null) { // Material list not set but material name is available
try { if (materialList == null && materialName != null) {
materialList = (MaterialList) assetManager.loadAsset(new OgreMaterialKey(folderName + materialName + ".material")); OgreMaterialKey materialKey = 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 { try {
materialList = (MaterialList) assetManager.loadAsset(new OgreMaterialKey(folderName + meshName + ".material")); materialList = (MaterialList) assetManager.loadAsset(materialKey);
} catch (AssetNotFoundException e) { } 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, "Cannot locate {0} for model {1}", new Object[]{materialKey, key});
logger.log(Level.WARNING, "", e); 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 { try {
materialList = (MaterialList) assetManager.loadAsset(new OgreMaterialKey(folderName + meshName + ".material")); materialList = (MaterialList) assetManager.loadAsset(materialKey);
} catch (AssetNotFoundException e) { } 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, "Cannot locate {0} for model {1}", new Object[]{ materialKey, key });
logger.log(Level.WARNING, "", e); logger.log(Level.WARNING, "", e);
} }
} }
// Added by larynx 25.06.2011 // Added by larynx 25.06.2011

@ -35,6 +35,14 @@ package com.jme3.scene.plugins.ogre;
import com.jme3.asset.ModelKey; import com.jme3.asset.ModelKey;
import com.jme3.material.MaterialList; 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 { public class OgreMeshKey extends ModelKey {
private MaterialList materialList; private MaterialList materialList;
@ -62,6 +70,10 @@ public class OgreMeshKey extends ModelKey {
return materialList; return materialList;
} }
public void setMaterialList(MaterialList materialList){
this.materialList = materialList;
}
public String getMaterialName() { public String getMaterialName() {
return materialName; return materialName;
} }

Loading…
Cancel
Save