Search in sources :

Example 1 with J3MExporter

use of com.jme3.material.plugin.export.material.J3MExporter 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 J3MExporter

use of com.jme3.material.plugin.export.material.J3MExporter in project jmonkeyengine by jMonkeyEngine.

the class J3MExporter method save.

@Override
public void save(Savable object, OutputStream f) throws IOException {
    if (!(object instanceof Material)) {
        throw new IllegalArgumentException("J3MExporter can only save com.jme3.material.Material class");
    }
    OutputStreamWriter out = new OutputStreamWriter(f, Charset.forName("UTF-8"));
    rootCapsule.clear();
    object.write(this);
    rootCapsule.writeToStream(out);
    out.flush();
}
Also used : Material(com.jme3.material.Material) OutputStreamWriter(java.io.OutputStreamWriter)

Aggregations

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