Search in sources :

Example 16 with Technique

use of com.jme3.material.Technique in project jmonkeyengine by jMonkeyEngine.

the class J3MLoader method loadFromRoot.

private void loadFromRoot(List<Statement> roots) throws IOException {
    if (roots.size() == 2) {
        Statement exception = roots.get(0);
        String line = exception.getLine();
        if (line.startsWith("Exception")) {
            throw new AssetLoadException(line.substring("Exception ".length()));
        } else {
            throw new IOException("In multiroot material, expected first statement to be 'Exception'");
        }
    } else if (roots.size() != 1) {
        throw new IOException("Too many roots in J3M/J3MD file");
    }
    boolean extending = false;
    Statement materialStat = roots.get(0);
    String materialName = materialStat.getLine();
    if (materialName.startsWith("MaterialDef")) {
        materialName = materialName.substring("MaterialDef ".length()).trim();
        extending = false;
    } else if (materialName.startsWith("Material")) {
        materialName = materialName.substring("Material ".length()).trim();
        extending = true;
    } else {
        throw new IOException("Specified file is not a Material file");
    }
    String[] split = materialName.split(":", 2);
    if (materialName.equals("")) {
        throw new MatParseException("Material name cannot be empty", materialStat);
    }
    if (split.length == 2) {
        if (!extending) {
            throw new MatParseException("Must use 'Material' when extending.", materialStat);
        }
        String extendedMat = split[1].trim();
        MaterialDef def = (MaterialDef) assetManager.loadAsset(new AssetKey(extendedMat));
        if (def == null) {
            throw new MatParseException("Extended material " + extendedMat + " cannot be found.", materialStat);
        }
        material = new Material(def);
        material.setKey(key);
        material.setName(split[0].trim());
    //            material.setAssetName(fileName);
    } else if (split.length == 1) {
        if (extending) {
            throw new MatParseException("Expected ':', got '{'", materialStat);
        }
        materialDef = new MaterialDef(assetManager, materialName);
        // NOTE: pass file name for defs so they can be loaded later
        materialDef.setAssetName(key.getName());
    } else {
        throw new MatParseException("Cannot use colon in material name/path", materialStat);
    }
    for (Statement statement : materialStat.getContents()) {
        split = statement.getLine().split("[ \\{]");
        String statType = split[0];
        if (extending) {
            if (statType.equals("MaterialParameters")) {
                readExtendingMaterialParams(statement.getContents());
            } else if (statType.equals("AdditionalRenderState")) {
                readAdditionalRenderState(statement.getContents());
            } else if (statType.equals("Transparent")) {
                readTransparentStatement(statement.getLine());
            }
        } else {
            if (statType.equals("Technique")) {
                readTechnique(statement);
            } else if (statType.equals("MaterialParameters")) {
                readMaterialParams(statement.getContents());
            } else {
                throw new MatParseException("Expected material statement, got '" + statType + "'", statement);
            }
        }
    }
}
Also used : Statement(com.jme3.util.blockparser.Statement) IOException(java.io.IOException)

Example 17 with Technique

use of com.jme3.material.Technique in project jmonkeyengine by jMonkeyEngine.

the class TestShaderNodes method simpleInitApp.

@Override
public void simpleInitApp() {
    flyCam.setMoveSpeed(20);
    Logger.getLogger("com.jme3").setLevel(Level.WARNING);
    Box boxshape1 = new Box(1f, 1f, 1f);
    Geometry cube_tex = new Geometry("A Textured Box", boxshape1);
    Texture tex = assetManager.loadTexture("Interface/Logo/Monkey.jpg");
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/UnshadedNodes.j3md");
    mat.selectTechnique(TechniqueDef.DEFAULT_TECHNIQUE_NAME, renderManager);
    Technique t = mat.getActiveTechnique();
    //        for (Shader.ShaderSource shaderSource : t.getShader().getSources()) {
    //            System.out.println(shaderSource.getSource());
    //        }
    mat.setColor("Color", ColorRGBA.Yellow);
    mat.setTexture("ColorMap", tex);
    cube_tex.setMaterial(mat);
    rootNode.attachChild(cube_tex);
}
Also used : Geometry(com.jme3.scene.Geometry) Box(com.jme3.scene.shape.Box) Material(com.jme3.material.Material) Technique(com.jme3.material.Technique) Texture(com.jme3.texture.Texture)

Aggregations

Caps (com.jme3.renderer.Caps)4 Material (com.jme3.material.Material)3 Camera (com.jme3.renderer.Camera)3 Technique (com.jme3.material.Technique)2 Renderer (com.jme3.renderer.Renderer)2 Shader (com.jme3.shader.Shader)2 ShaderType (com.jme3.shader.Shader.ShaderType)2 Texture (com.jme3.texture.Texture)2 Statement (com.jme3.util.blockparser.Statement)2 IOException (java.io.IOException)2 LightList (com.jme3.light.LightList)1 MaterialDef (com.jme3.material.MaterialDef)1 RenderState (com.jme3.material.RenderState)1 ShaderGenerationInfo (com.jme3.material.ShaderGenerationInfo)1 StaticPassLightingLogic (com.jme3.material.logic.StaticPassLightingLogic)1 TechniqueDefLogic (com.jme3.material.logic.TechniqueDefLogic)1 GeometryList (com.jme3.renderer.queue.GeometryList)1 Geometry (com.jme3.scene.Geometry)1 Box (com.jme3.scene.shape.Box)1 DefineList (com.jme3.shader.DefineList)1