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));
}
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();
}
Aggregations