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

The following examples show how to use com.jme3.material.Material#clone() . 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: GeometryTreeNode.java    From jmonkeybuilder with Apache License 2.0 6 votes vote down vote up
@Override
public void accept(@NotNull final ChangeConsumer changeConsumer, @NotNull final Object object,
                   final boolean isCopy) {

    final Geometry geometry = getElement();

    if (object instanceof Material) {

        final Material material = (Material) object;

        if (isCopy) {

            final Material clone = material.clone();
            final PropertyOperation<ChangeConsumer, Geometry, Material> operation =
                    new PropertyOperation<>(geometry, "Material", clone, geometry.getMaterial());
            operation.setApplyHandler(Geometry::setMaterial);

            changeConsumer.execute(operation);
        }
    }

    super.accept(changeConsumer, object, isCopy);
}
 
Example 2
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 3
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);
}
 
Example 4
Source File: MaterialKey.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public Object createClonedInstance(Object asset){
    Material mat = (Material) asset;
    return mat.clone();
}