Skip to content

Commit 7745241

Browse files
authored
Add files via upload
1 parent fc1c7af commit 7745241

1 file changed

Lines changed: 65 additions & 0 deletions

File tree

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package com.jme3.material;
2+
3+
import com.jme3.asset.AssetManager;
4+
import com.jme3.asset.DesktopAssetManager;
5+
import com.jme3.export.binary.BinaryExporter;
6+
import com.jme3.texture.Texture;
7+
import org.junit.Assert;
8+
import org.junit.Test;
9+
10+
import java.util.Arrays;
11+
import java.util.List;
12+
13+
/**
14+
* @author capdevon
15+
*/
16+
public class MaterialCompareTest {
17+
18+
@Test
19+
public void testMaterialCloneAndSave() {
20+
21+
AssetManager assetManager = new DesktopAssetManager(true);
22+
23+
List<String> matDefs = Arrays.asList(Materials.UNSHADED, Materials.LIGHTING, Materials.PBR);
24+
25+
Texture tex = assetManager.loadTexture("Common/Textures/MissingMaterial.png");
26+
tex.setWrap(Texture.WrapMode.Repeat);
27+
28+
int index = 0;
29+
for (String matDef : matDefs) {
30+
Material mat = new Material(assetManager, matDef);
31+
32+
String name = index == 0 ? "ColorMap" : index == 1 ? "DiffuseMap" : "BaseColorMap";
33+
mat.setTexture(name, tex);
34+
35+
Material clone = mat.clone();
36+
Assert.assertTrue(mat.contentEquals(clone));
37+
Assert.assertEquals(mat.contentHashCode(), clone.contentHashCode());
38+
test(mat, clone);
39+
40+
Material copy = BinaryExporter.saveAndLoad(assetManager, mat);
41+
Assert.assertTrue(mat.contentEquals(copy));
42+
Assert.assertEquals(mat.contentHashCode(), copy.contentHashCode());
43+
test(mat, copy);
44+
45+
index++;
46+
}
47+
}
48+
49+
private void test(Material mat, Material copy) {
50+
for (MatParam def : mat.getMaterialDef().getMaterialParams()) {
51+
MatParam param = mat.getParam(def.getName());
52+
53+
if (param != null) {
54+
MatParam mCopy = copy.getParam(def.getName());
55+
Assert.assertEquals(param, mCopy);
56+
Assert.assertEquals(param.hashCode(), mCopy.hashCode());
57+
58+
} else {
59+
MatParam mCopy = copy.getMaterialDef().getMaterialParam(def.getName());
60+
Assert.assertEquals(def, mCopy);
61+
Assert.assertEquals(def.hashCode(), mCopy.hashCode());
62+
}
63+
}
64+
}
65+
}

0 commit comments

Comments
 (0)