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