From 3081862ced9975f410b8b3d8260d08d8e2adde71 Mon Sep 17 00:00:00 2001 From: "nor..67" Date: Wed, 10 Aug 2011 12:12:53 +0000 Subject: [PATCH] - add support for material name mappings to MaterialExtensionLoader git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7997 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../ogre/matext/MaterialExtensionLoader.java | 10 +++++++-- .../ogre/matext/MaterialExtensionSet.java | 21 +++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/engine/src/ogre/com/jme3/scene/plugins/ogre/matext/MaterialExtensionLoader.java b/engine/src/ogre/com/jme3/scene/plugins/ogre/matext/MaterialExtensionLoader.java index 33ab787cd..c43d0b0cf 100644 --- a/engine/src/ogre/com/jme3/scene/plugins/ogre/matext/MaterialExtensionLoader.java +++ b/engine/src/ogre/com/jme3/scene/plugins/ogre/matext/MaterialExtensionLoader.java @@ -40,6 +40,7 @@ import com.jme3.scene.plugins.ogre.MaterialLoader; import com.jme3.texture.Texture; import com.jme3.texture.Texture.WrapMode; import java.io.IOException; +import java.util.List; import java.util.Scanner; import java.util.logging.Level; import java.util.logging.Logger; @@ -79,10 +80,9 @@ public class MaterialExtensionLoader { key.setGenerateMips(true); key.setAsCube(false); Texture tex = assetManager.loadTexture(key); - // XXX: Is this really neccessary? - tex.setWrap(WrapMode.Repeat); if (tex == null) throw new IOException("Cannot load texture: " + texturePath); + tex.setWrap(WrapMode.Repeat); material.setTexture(jmeParamName, tex); @@ -140,6 +140,12 @@ public class MaterialExtensionLoader { Material material = readExtendingMaterial(); list.put(matName, material); + List matAliases = matExts.getNameMappings(matName); + if(matAliases != null){ + for (String string : matAliases) { + list.put(string, material); + } + } } return list; diff --git a/engine/src/ogre/com/jme3/scene/plugins/ogre/matext/MaterialExtensionSet.java b/engine/src/ogre/com/jme3/scene/plugins/ogre/matext/MaterialExtensionSet.java index c044fb8a6..2c81e7bf9 100644 --- a/engine/src/ogre/com/jme3/scene/plugins/ogre/matext/MaterialExtensionSet.java +++ b/engine/src/ogre/com/jme3/scene/plugins/ogre/matext/MaterialExtensionSet.java @@ -32,7 +32,9 @@ package com.jme3.scene.plugins.ogre.matext; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; /** * MaterialExtensionSet is simply a container for several @@ -42,6 +44,7 @@ import java.util.HashMap; public class MaterialExtensionSet { private HashMap extensions = new HashMap(); + private HashMap> nameMappings = new HashMap>(); /** * Adds a new material extension to the set of extensions. @@ -61,4 +64,22 @@ public class MaterialExtensionSet { public MaterialExtension getMaterialExtension(String baseMatName){ return extensions.get(baseMatName); } + + /** + * Adds an alternative name for a material + * @param name The material name to be found in a .mesh.xml file + * @param alias The material name to be found in a .material file + */ + public void setNameMapping(String name, String alias){ + List list = nameMappings.get(name); + if(list==null){ + list = new ArrayList(); + nameMappings.put(name, list); + } + list.add(alias); + } + + public List getNameMappings(String name){ + return nameMappings.get(name); + } }