|
|
@ -31,36 +31,65 @@ |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
package com.jme3.material.plugin; |
|
|
|
package com.jme3.material.plugin; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.jme3.asset.AssetInfo; |
|
|
|
|
|
|
|
import com.jme3.asset.AssetKey; |
|
|
|
import com.jme3.asset.AssetManager; |
|
|
|
import com.jme3.asset.AssetManager; |
|
|
|
import com.jme3.material.Material; |
|
|
|
import com.jme3.material.Material; |
|
|
|
|
|
|
|
import com.jme3.material.RenderState; |
|
|
|
import com.jme3.material.plugin.export.material.J3MExporter; |
|
|
|
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 com.jme3.system.JmeSystem; |
|
|
|
import static org.junit.Assert.*; |
|
|
|
import static org.junit.Assert.*; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.jme3.texture.Texture; |
|
|
|
|
|
|
|
import com.jme3.texture.Texture2D; |
|
|
|
import org.junit.Before; |
|
|
|
import org.junit.Before; |
|
|
|
import org.junit.Test; |
|
|
|
import org.junit.Test; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.ByteArrayInputStream; |
|
|
|
import java.io.ByteArrayOutputStream; |
|
|
|
import java.io.ByteArrayOutputStream; |
|
|
|
import java.io.IOException; |
|
|
|
import java.io.IOException; |
|
|
|
|
|
|
|
import java.io.InputStream; |
|
|
|
import java.util.Scanner; |
|
|
|
import java.util.Scanner; |
|
|
|
|
|
|
|
|
|
|
|
public class TestMaterialWrite { |
|
|
|
public class TestMaterialWrite { |
|
|
|
|
|
|
|
|
|
|
|
private AssetManager assetManager; |
|
|
|
private AssetManager assetManager; |
|
|
|
private Material mat; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Before |
|
|
|
@Before |
|
|
|
public void init() { |
|
|
|
public void init() { |
|
|
|
assetManager = JmeSystem.newAssetManager( |
|
|
|
assetManager = JmeSystem.newAssetManager( |
|
|
|
TestMaterialWrite.class.getResource("/com/jme3/asset/Desktop.cfg")); |
|
|
|
TestMaterialWrite.class.getResource("/com/jme3/asset/Desktop.cfg")); |
|
|
|
|
|
|
|
|
|
|
|
mat = assetManager.loadMaterial("/testMat.j3m"); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testWriteMat() { |
|
|
|
public void testWriteMat() throws Exception { |
|
|
|
assertNotNull(mat); |
|
|
|
|
|
|
|
ByteArrayOutputStream stream = new ByteArrayOutputStream(); |
|
|
|
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(); |
|
|
|
J3MExporter exporter = new J3MExporter(); |
|
|
|
try { |
|
|
|
try { |
|
|
@ -69,16 +98,18 @@ public class TestMaterialWrite { |
|
|
|
e.printStackTrace(); |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
String reference = convertStreamToString(TestMaterialWrite.class.getResourceAsStream("/testMat.j3m")); |
|
|
|
System.err.println(stream.toString()); |
|
|
|
// System.err.println(reference);
|
|
|
|
|
|
|
|
// 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) { |
|
|
|
assertTrue(mat.contentEquals(mat2)); |
|
|
|
Scanner s = new Scanner(is).useDelimiter("\\A"); |
|
|
|
|
|
|
|
return s.hasNext() ? s.next() : ""; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|