Java Code Examples for com.jme3.material.Material#setName()

The following examples show how to use com.jme3.material.Material#setName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MaterialExtensionLoader.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private Material readExtendingMaterial(Statement statement) throws IOException{
    String[] split = statement.getLine().split(" ", 2);
    String[] subsplit = split[1].split(":");
    matName = subsplit[0].trim();
    String extendedMat = subsplit[1].trim();

    matExt = matExts.getMaterialExtension(extendedMat);
    if (matExt == null){
        logger.log(Level.WARNING, "Cannot find MaterialExtension for: {0}. Ignoring material.", extendedMat);
        matExt = null;
        return null;
    }

    material = new Material(assetManager, matExt.getJmeMatDefName());
    material.setName(matName);
    for (Statement extMatStat : statement.getContents()){
        readExtendingMaterialStatement(extMatStat);
    }
    return material;
}
 
Example 2
Source File: OpaqueComparatorTest.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Test
public void testSortByTexture() {
    Material texture1Mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    Material texture2Mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    Material texture3Mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    
    Texture tex1 = createTexture("A");
    tex1.getImage().setId(1);
    
    Texture tex2 = createTexture("B");
    tex2.getImage().setId(2);
    
    Texture tex3 = createTexture("C");
    tex3.getImage().setId(3);
    
    texture1Mat.setName("TexA");
    texture1Mat.setTexture("ColorMap", tex1);
    
    texture2Mat.setName("TexB");
    texture2Mat.setTexture("ColorMap", tex2);
    
    texture3Mat.setName("TexC");
    texture3Mat.setTexture("ColorMap", tex3);
    
    testSort(texture1Mat, texture2Mat, texture3Mat);
}
 
Example 3
Source File: FbxMaterial.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private Material createMaterial() {
	Material m = new Material(scene.assetManager, "Common/MatDefs/Light/Lighting.j3md");
	m.setName(name);
	ambientColor.multLocal(ambientFactor);
	diffuseColor.multLocal(diffuseFactor);
	specularColor.multLocal(specularFactor);
	m.setColor("Ambient", new ColorRGBA(ambientColor.x, ambientColor.y, ambientColor.z, 1));
	m.setColor("Diffuse", new ColorRGBA(diffuseColor.x, diffuseColor.y, diffuseColor.z, 1));
	m.setColor("Specular", new ColorRGBA(specularColor.x, specularColor.y, specularColor.z, 1));
	m.setFloat("Shininess", shininessExponent);
	m.setBoolean("UseMaterialColors", true);
	m.setFloat("AlphaDiscardThreshold", 0.5f); // TODO replace with right way in JME to set "Aplha Test"
	m.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
	return m;
}
 
Example 4
Source File: OpaqueComparatorTest.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testSortByMaterialDef() {
    Material lightingMat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
    Material particleMat = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md");
    Material unshadedMat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    Material skyMat      = new Material(assetManager, "Common/MatDefs/Misc/Sky.j3md");
    
    lightingMat.setName("MatLight");
    particleMat.setName("MatParticle");
    unshadedMat.setName("MatUnshaded");
    skyMat.setName("MatSky");
    testSort(skyMat, lightingMat, particleMat, unshadedMat);
}
 
Example 5
Source File: OpaqueComparatorTest.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testSortByTechnique() {
    Material lightingMatDefault = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
    Material lightingPreShadow = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
    Material lightingPostShadow = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
    Material lightingMatPreNormalPass = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
    Material lightingMatGBuf = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
    Material lightingMatGlow = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
    
    lightingMatDefault.setName("TechDefault");
    lightingMatDefault.selectTechnique(TechniqueDef.DEFAULT_TECHNIQUE_NAME, renderManager);
    
    lightingPostShadow.setName("TechPostShad");
    lightingPostShadow.selectTechnique("PostShadow", renderManager);
    
    lightingPreShadow.setName("TechPreShad");
    lightingPreShadow.selectTechnique("PreShadow", renderManager);
    
    lightingMatPreNormalPass.setName("TechNorm");
    lightingMatPreNormalPass.selectTechnique("PreNormalPass", renderManager);
    
    lightingMatGlow.setName("TechGlow");
    lightingMatGlow.selectTechnique("Glow", renderManager);
    
    testSort(lightingMatGlow, lightingPreShadow, lightingMatPreNormalPass,
            lightingMatDefault, lightingPostShadow);
}
 
Example 6
Source File: OpaqueComparatorTest.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test(expected = AssertionError.class)
public void testNoSortByParam() {
    Material sameMat1 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    Material sameMat2 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    
    sameMat1.setName("MatRed");
    sameMat1.setColor("Color", ColorRGBA.Red);
    
    sameMat2.setName("MatBlue");
    sameMat2.setColor("Color", ColorRGBA.Blue);
    
    testSort(sameMat1, sameMat2);
}
 
Example 7
Source File: OpaqueComparatorTest.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testSortByShaderDefines() {
    Material lightingMat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
    Material lightingMatVColor = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
    Material lightingMatVLight = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
    Material lightingMatTC = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
    Material lightingMatVColorLight = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
    Material lightingMatTCVColorLight = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
    
    lightingMat.setName("DefNone");
    
    lightingMatVColor.setName("DefVC");
    lightingMatVColor.setBoolean("UseVertexColor", true);
    
    lightingMatVLight.setName("DefVL");
    lightingMatVLight.setBoolean("VertexLighting", true);
    
    lightingMatTC.setName("DefTC");
    lightingMatTC.setBoolean("SeparateTexCoord", true);
    
    lightingMatVColorLight.setName("DefVCVL");
    lightingMatVColorLight.setBoolean("UseVertexColor", true);
    lightingMatVColorLight.setBoolean("VertexLighting", true);
    
    lightingMatTCVColorLight.setName("DefVCVLTC");
    lightingMatTCVColorLight.setBoolean("UseVertexColor", true);
    lightingMatTCVColorLight.setBoolean("VertexLighting", true);
    lightingMatTCVColorLight.setBoolean("SeparateTexCoord", true);
    
    testSort(lightingMat, lightingMatVColor, lightingMatVLight,
             lightingMatVColorLight, lightingMatTC, lightingMatTCVColorLight);
}
 
Example 8
Source File: TestMaterialCompare.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public static void main(String[] args) {
    AssetManager assetManager = JmeSystem.newAssetManager(
            TestMaterialCompare.class.getResource("/com/jme3/asset/Desktop.cfg"));
    
    // Cloned materials
    Material mat1 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat1.setName("mat1");
    mat1.setColor("Color", ColorRGBA.Blue);

    Material mat2 = mat1.clone();
    mat2.setName("mat2");
    testEquality(mat1, mat2, true);

    // Cloned material with different render states
    Material mat3 = mat1.clone();
    mat3.setName("mat3");
    mat3.getAdditionalRenderState().setBlendMode(BlendMode.ModulateX2);
    testEquality(mat1, mat3, false);

    // Two separately loaded materials
    Material mat4 = assetManager.loadMaterial("Models/Sign Post/Sign Post.j3m");
    mat4.setName("mat4");
    Material mat5 = assetManager.loadMaterial("Models/Sign Post/Sign Post.j3m");
    mat5.setName("mat5");
    testEquality(mat4, mat5, true);
    
    // Comparing same textures
    TextureKey originalKey = (TextureKey) mat4.getTextureParam("DiffuseMap").getTextureValue().getKey();
    TextureKey tex1key = new TextureKey("Models/Sign Post/Sign Post.jpg", false);
    tex1key.setGenerateMips(true);
    
    // Texture keys from the original and the loaded texture
    // must be identical, otherwise the resultant textures not identical
    // and thus materials are not identical!
    if (!originalKey.equals(tex1key)){
        System.out.println("TEXTURE KEYS ARE NOT EQUAL");
    }
    
    Texture tex1 = assetManager.loadTexture(tex1key);
    mat4.setTexture("DiffuseMap", tex1);
    testEquality(mat4, mat5, true);
    
    // Change some stuff on the texture and compare, materials no longer equal
    tex1.setWrap(Texture.WrapMode.MirroredRepeat);
    testEquality(mat4, mat5, false);
    
    // Comparing different textures
    Texture tex2 = assetManager.loadTexture("Interface/Logo/Monkey.jpg");
    mat4.setTexture("DiffuseMap", tex2);
    testEquality(mat4, mat5, false);

    // Two materials created the same way
    Material mat6 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat6.setName("mat6");
    mat6.setColor("Color", ColorRGBA.Blue);
    testEquality(mat1, mat6, true);

    // Changing a material param
    mat6.setColor("Color", ColorRGBA.Green);
    testEquality(mat1, mat6, false);
}
 
Example 9
Source File: OpaqueComparatorTest.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Test
public void testSortByAll() {
    Material matBase1 = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
    Material matBase2 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    
    Texture texBase = createTexture("BASE");
    texBase.getImage().setId(1);
    Texture tex1 = createTexture("1");
    tex1.getImage().setId(2);
    Texture tex2 = createTexture("2");
    tex2.getImage().setId(3);
    
    matBase1.setName("BASE");
    matBase1.selectTechnique(TechniqueDef.DEFAULT_TECHNIQUE_NAME, renderManager);
    matBase1.setBoolean("UseVertexColor", true);
    matBase1.setTexture("DiffuseMap", texBase);
    
    Material mat1100 = matBase1.clone();
    mat1100.setName("1100");
    mat1100.selectTechnique("PreShadow", renderManager);
    
    Material mat1101 = matBase1.clone();
    mat1101.setName("1101");
    mat1101.selectTechnique("PreShadow", renderManager);
    mat1101.setTexture("DiffuseMap", tex1);
    
    Material mat1102 = matBase1.clone();
    mat1102.setName("1102");
    mat1102.selectTechnique("PreShadow", renderManager);
    mat1102.setTexture("DiffuseMap", tex2);
    
    Material mat1110 = matBase1.clone();
    mat1110.setName("1110");
    mat1110.selectTechnique("PreShadow", renderManager);
    mat1110.setFloat("AlphaDiscardThreshold", 2f);
    
    Material mat1120 = matBase1.clone();
    mat1120.setName("1120");
    mat1120.selectTechnique("PreShadow", renderManager);
    mat1120.setBoolean("UseInstancing", true);
    
    Material mat1121 = matBase1.clone();
    mat1121.setName("1121");
    mat1121.selectTechnique("PreShadow", renderManager);
    mat1121.setBoolean("UseInstancing", true);
    mat1121.setTexture("DiffuseMap", tex1);
    
    Material mat1122 = matBase1.clone();
    mat1122.setName("1122");
    mat1122.selectTechnique("PreShadow", renderManager);
    mat1122.setBoolean("UseInstancing", true);
    mat1122.setTexture("DiffuseMap", tex2);
    
    Material mat1140 = matBase1.clone();
    mat1140.setName("1140");
    mat1140.selectTechnique("PreShadow", renderManager);
    mat1140.setFloat("AlphaDiscardThreshold", 2f);
    mat1140.setBoolean("UseInstancing", true);
    
    Material mat1200 = matBase1.clone();
    mat1200.setName("1200");
    mat1200.selectTechnique("PostShadow", renderManager);
    
    Material mat1210 = matBase1.clone();
    mat1210.setName("1210");
    mat1210.selectTechnique("PostShadow", renderManager);
    mat1210.setFloat("AlphaDiscardThreshold", 2f);
    
    Material mat1220 = matBase1.clone();
    mat1220.setName("1220");
    mat1220.selectTechnique("PostShadow", renderManager);
    mat1220.setBoolean("UseInstancing", true);
    
    Material mat2000 = matBase2.clone();
    mat2000.setName("2000");
    
    testSort(mat1100, mat1101, mat1102, mat1110, 
             mat1120, mat1121, mat1122, mat1140, 
             mat1200, mat1210, mat1220, mat2000);
}