Better test for material loading, also ensured that the J3MExporter writes UTF-8 files
This commit is contained in:
parent
3245c9ac89
commit
e0ffff3af0
@ -16,6 +16,7 @@ import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
/**
|
||||
* Saves a Material to a j3m file with proper formatting.
|
||||
@ -49,7 +50,7 @@ public class J3MExporter implements JmeExporter {
|
||||
throw new IllegalArgumentException("J3MExporter can only save com.jme3.material.Material class");
|
||||
}
|
||||
|
||||
OutputStreamWriter out = new OutputStreamWriter(f);
|
||||
OutputStreamWriter out = new OutputStreamWriter(f, Charset.forName("UTF-8"));
|
||||
|
||||
rootCapsule.clear();
|
||||
object.write(this);
|
||||
|
@ -31,36 +31,65 @@
|
||||
*/
|
||||
package com.jme3.material.plugin;
|
||||
|
||||
import com.jme3.asset.AssetInfo;
|
||||
import com.jme3.asset.AssetKey;
|
||||
import com.jme3.asset.AssetManager;
|
||||
import com.jme3.material.Material;
|
||||
import com.jme3.material.RenderState;
|
||||
import com.jme3.material.plugin.export.material.J3MExporter;
|
||||
import com.jme3.material.plugins.J3MLoader;
|
||||
import com.jme3.math.ColorRGBA;
|
||||
import com.jme3.system.JmeSystem;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import com.jme3.texture.Texture;
|
||||
import com.jme3.texture.Texture2D;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class TestMaterialWrite {
|
||||
|
||||
private AssetManager assetManager;
|
||||
private Material mat;
|
||||
|
||||
@Before
|
||||
public void init() {
|
||||
assetManager = JmeSystem.newAssetManager(
|
||||
TestMaterialWrite.class.getResource("/com/jme3/asset/Desktop.cfg"));
|
||||
|
||||
mat = assetManager.loadMaterial("/testMat.j3m");
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testWriteMat() {
|
||||
assertNotNull(mat);
|
||||
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||
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().setBlendMode(RenderState.BlendMode.Alpha);
|
||||
|
||||
final ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||
|
||||
J3MExporter exporter = new J3MExporter();
|
||||
try {
|
||||
@ -69,16 +98,18 @@ public class TestMaterialWrite {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
String reference = convertStreamToString(TestMaterialWrite.class.getResourceAsStream("/testMat.j3m"));
|
||||
// System.err.println(reference);
|
||||
// System.err.println(stream.toString());
|
||||
System.err.println(stream.toString());
|
||||
|
||||
// assertEquals(reference.replaceAll("[\\s\\r\\n]",""), stream.toString().replaceAll("[\\s\\r\\n]",""));
|
||||
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);
|
||||
|
||||
private String convertStreamToString(java.io.InputStream is) {
|
||||
Scanner s = new Scanner(is).useDelimiter("\\A");
|
||||
return s.hasNext() ? s.next() : "";
|
||||
assertTrue(mat.contentEquals(mat2));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,15 +0,0 @@
|
||||
Material test : Common/MatDefs/Light/Lighting.j3md {
|
||||
|
||||
MaterialParameters {
|
||||
Diffuse : 1.0 1.0 1.0 1.0
|
||||
UseMaterialColors : true
|
||||
ParallaxHeight : 0.05
|
||||
Ambient : 1.0 1.0 1.0 1.0
|
||||
DiffuseMap : Flip WrapRepeat_S WrapRepeat_T MinNearestNoMipMaps MagNearest "Textures/ColoredTex/Monkey.png"
|
||||
Specular : 0.01375 0.01375 0.01375 1.0
|
||||
Shininess : 50.0
|
||||
}
|
||||
|
||||
AdditionalRenderState {
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user