Search in sources :

Example 1 with MaterialExtensionSet

use of com.jme3.scene.plugins.ogre.matext.MaterialExtensionSet in project jmonkeyengine by jMonkeyEngine.

the class MaterialExtensionLoader method load.

public MaterialList load(AssetManager assetManager, AssetKey key, MaterialExtensionSet matExts, List<Statement> statements) throws IOException {
    this.assetManager = assetManager;
    this.matExts = matExts;
    this.key = key;
    list = new MaterialList();
    for (Statement statement : statements) {
        if (statement.getLine().startsWith("import")) {
            // ignore
            continue;
        } else if (statement.getLine().startsWith("material")) {
            Material material = readExtendingMaterial(statement);
            list.put(matName, material);
            List<String> matAliases = matExts.getNameMappings(matName);
            if (matAliases != null) {
                for (String string : matAliases) {
                    list.put(string, material);
                }
            }
        }
    }
    return list;
}
Also used : Statement(com.jme3.util.blockparser.Statement) MaterialList(com.jme3.material.MaterialList) Material(com.jme3.material.Material) List(java.util.List) MaterialList(com.jme3.material.MaterialList)

Example 2 with MaterialExtensionSet

use of com.jme3.scene.plugins.ogre.matext.MaterialExtensionSet in project jmonkeyengine by jMonkeyEngine.

the class MaterialLoader method load.

private MaterialList load(AssetManager assetManager, AssetKey key, InputStream in) throws IOException {
    folderName = key.getFolder();
    this.assetManager = assetManager;
    MaterialList list = null;
    List<Statement> statements = BlockLanguageParser.parse(in);
    for (Statement statement : statements) {
        if (statement.getLine().startsWith("import")) {
            MaterialExtensionSet matExts = null;
            if (key instanceof OgreMaterialKey) {
                matExts = ((OgreMaterialKey) key).getMaterialExtensionSet();
            }
            if (matExts == null) {
                throw new IOException("Must specify MaterialExtensionSet when loading\n" + "Ogre3D materials with extended materials");
            }
            list = new MaterialExtensionLoader().load(assetManager, key, matExts, statements);
            break;
        } else if (statement.getLine().startsWith("material")) {
            if (list == null) {
                list = new MaterialList();
            }
            String[] split = statement.getLine().split(" ", 2);
            matName = split[1].trim();
            if (matName.startsWith("\"") && matName.endsWith("\"")) {
                matName = matName.substring(1, matName.length() - 1);
            }
            readMaterial(statement);
            Material mat = compileMaterial();
            list.put(mat.getName(), mat);
        }
    }
    return list;
}
Also used : MaterialExtensionLoader(com.jme3.scene.plugins.ogre.matext.MaterialExtensionLoader) Statement(com.jme3.util.blockparser.Statement) MaterialList(com.jme3.material.MaterialList) OgreMaterialKey(com.jme3.scene.plugins.ogre.matext.OgreMaterialKey) Material(com.jme3.material.Material) IOException(java.io.IOException) MaterialExtensionSet(com.jme3.scene.plugins.ogre.matext.MaterialExtensionSet)

Aggregations

Material (com.jme3.material.Material)2 MaterialList (com.jme3.material.MaterialList)2 Statement (com.jme3.util.blockparser.Statement)2 MaterialExtensionLoader (com.jme3.scene.plugins.ogre.matext.MaterialExtensionLoader)1 MaterialExtensionSet (com.jme3.scene.plugins.ogre.matext.MaterialExtensionSet)1 OgreMaterialKey (com.jme3.scene.plugins.ogre.matext.OgreMaterialKey)1 IOException (java.io.IOException)1 List (java.util.List)1