Search in sources :

Example 1 with J3MLoader

use of com.jme3.material.plugins.J3MLoader in project jmonkeyengine by jMonkeyEngine.

the class TestMaterialWrite method testWriteMat.

@Test
public void testWriteMat() throws Exception {
    Material mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
    mat.setBoolean("UseMaterialColors", true);
    mat.setColor("Diffuse", ColorRGBA.White);
    mat.setColor("Ambient", ColorRGBA.DarkGray);
    mat.setFloat("AlphaDiscardThreshold", 0.5f);
    mat.setFloat("Shininess", 2.5f);
    Texture tex = assetManager.loadTexture("Common/Textures/MissingTexture.png");
    tex.setMagFilter(Texture.MagFilter.Nearest);
    tex.setMinFilter(Texture.MinFilter.BilinearNoMipMaps);
    tex.setWrap(Texture.WrapAxis.S, Texture.WrapMode.Repeat);
    tex.setWrap(Texture.WrapAxis.T, Texture.WrapMode.MirroredRepeat);
    mat.setTexture("DiffuseMap", tex);
    mat.getAdditionalRenderState().setDepthWrite(false);
    mat.getAdditionalRenderState().setDepthTest(false);
    mat.getAdditionalRenderState().setLineWidth(5);
    mat.getAdditionalRenderState().setBlendMode(RenderState.BlendMode.Alpha);
    final ByteArrayOutputStream stream = new ByteArrayOutputStream();
    J3MExporter exporter = new J3MExporter();
    try {
        exporter.save(mat, stream);
    } catch (IOException e) {
        e.printStackTrace();
    }
    System.err.println(stream.toString());
    J3MLoader loader = new J3MLoader();
    AssetInfo info = new AssetInfo(assetManager, new AssetKey("test")) {

        @Override
        public InputStream openStream() {
            return new ByteArrayInputStream(stream.toByteArray());
        }
    };
    Material mat2 = (Material) loader.load(info);
    assertTrue(mat.contentEquals(mat2));
}
Also used : AssetKey(com.jme3.asset.AssetKey) ByteArrayInputStream(java.io.ByteArrayInputStream) Material(com.jme3.material.Material) J3MExporter(com.jme3.material.plugin.export.material.J3MExporter) J3MLoader(com.jme3.material.plugins.J3MLoader) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) AssetInfo(com.jme3.asset.AssetInfo) Texture(com.jme3.texture.Texture) Test(org.junit.Test)

Example 2 with J3MLoader

use of com.jme3.material.plugins.J3MLoader in project jmonkeyengine by jMonkeyEngine.

the class TestMaterialDefWrite method testWriteMat.

@Test
public void testWriteMat() throws Exception {
    Material mat = new Material(assetManager, "example.j3md");
    final ByteArrayOutputStream stream = new ByteArrayOutputStream();
    J3mdExporter exporter = new J3mdExporter();
    try {
        exporter.save(mat.getMaterialDef(), stream);
    } catch (IOException e) {
        e.printStackTrace();
    }
    //   System.err.println(stream.toString());
    J3MLoader loader = new J3MLoader();
    AssetInfo info = new AssetInfo(assetManager, new AssetKey("test")) {

        @Override
        public InputStream openStream() {
            return new ByteArrayInputStream(stream.toByteArray());
        }
    };
    MaterialDef matDef = (MaterialDef) loader.load(info);
    MaterialDef ref = mat.getMaterialDef();
    for (MatParam refParam : ref.getMaterialParams()) {
        MatParam matParam = matDef.getMaterialParam(refParam.getName());
        assertTrue(refParam != null);
        assertEquals(refParam, matParam);
    }
    for (String key : ref.getTechniqueDefsNames()) {
        List<TechniqueDef> refDefs = ref.getTechniqueDefs(key);
        List<TechniqueDef> defs = matDef.getTechniqueDefs(key);
        assertNotNull(defs);
        assertTrue(refDefs.size() == defs.size());
        for (int i = 0; i < refDefs.size(); i++) {
            assertEqualTechniqueDefs(refDefs.get(i), defs.get(i));
        }
    }
}
Also used : J3MLoader(com.jme3.material.plugins.J3MLoader) J3mdExporter(com.jme3.material.plugin.export.materialdef.J3mdExporter)

Aggregations

J3MLoader (com.jme3.material.plugins.J3MLoader)2 AssetInfo (com.jme3.asset.AssetInfo)1 AssetKey (com.jme3.asset.AssetKey)1 Material (com.jme3.material.Material)1 J3MExporter (com.jme3.material.plugin.export.material.J3MExporter)1 J3mdExporter (com.jme3.material.plugin.export.materialdef.J3mdExporter)1 Texture (com.jme3.texture.Texture)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 Test (org.junit.Test)1