Search in sources :

Example 1 with MatParamOverride

use of com.jme3.material.MatParamOverride in project jmonkeyengine by jMonkeyEngine.

the class SceneMatParamOverrideTest method testOverrides_AddRemove.

@Test
public void testOverrides_AddRemove() {
    MatParamOverride override = mpoBool("Test", true);
    Node n = new Node("Node");
    n.removeMatParamOverride(override);
    assertTrue(n.getLocalMatParamOverrides().isEmpty());
    assertTrue(n.getWorldMatParamOverrides().isEmpty());
    n.addMatParamOverride(override);
    assertSame(n.getLocalMatParamOverrides().get(0), override);
    assertTrue(n.getWorldMatParamOverrides().isEmpty());
    n.updateGeometricState();
    assertSame(n.getLocalMatParamOverrides().get(0), override);
    assertSame(n.getWorldMatParamOverrides().get(0), override);
    n.removeMatParamOverride(override);
    assertTrue(n.getLocalMatParamOverrides().isEmpty());
    assertSame(n.getWorldMatParamOverrides().get(0), override);
    n.updateGeometricState();
    assertTrue(n.getLocalMatParamOverrides().isEmpty());
    assertTrue(n.getWorldMatParamOverrides().isEmpty());
}
Also used : MatParamOverride(com.jme3.material.MatParamOverride) Test(org.junit.Test)

Example 2 with MatParamOverride

use of com.jme3.material.MatParamOverride in project jmonkeyengine by jMonkeyEngine.

the class SceneMatParamOverrideTest method testOverrides_SaveAndLoad_KeepsMPOs.

@Test
public void testOverrides_SaveAndLoad_KeepsMPOs() {
    MatParamOverride override = mpoInt("val", 5);
    Node scene = createDummyScene();
    scene.getChild("A").addMatParamOverride(override);
    AssetManager assetManager = TestUtil.createAssetManager();
    Node loadedScene = BinaryExporter.saveAndLoad(assetManager, scene);
    Node root = new Node("Root Node");
    root.attachChild(loadedScene);
    validateScene(root);
    validateScene(scene);
    assertNotSame(override, loadedScene.getChild("A").getLocalMatParamOverrides().get(0));
    assertEquals(override, loadedScene.getChild("A").getLocalMatParamOverrides().get(0));
}
Also used : AssetManager(com.jme3.asset.AssetManager) MatParamOverride(com.jme3.material.MatParamOverride) Test(org.junit.Test)

Example 3 with MatParamOverride

use of com.jme3.material.MatParamOverride in project jmonkeyengine by jMonkeyEngine.

the class SceneMatParamOverrideTest method testOverrides_Clear.

@Test
public void testOverrides_Clear() {
    MatParamOverride override = mpoBool("Test", true);
    Node n = new Node("Node");
    n.clearMatParamOverrides();
    assertTrue(n.getLocalMatParamOverrides().isEmpty());
    assertTrue(n.getWorldMatParamOverrides().isEmpty());
    n.addMatParamOverride(override);
    n.clearMatParamOverrides();
    assertTrue(n.getLocalMatParamOverrides().isEmpty());
    assertTrue(n.getWorldMatParamOverrides().isEmpty());
    n.addMatParamOverride(override);
    n.updateGeometricState();
    n.clearMatParamOverrides();
    assertTrue(n.getLocalMatParamOverrides().isEmpty());
    assertSame(n.getWorldMatParamOverrides().get(0), override);
    n.updateGeometricState();
    assertTrue(n.getLocalMatParamOverrides().isEmpty());
    assertTrue(n.getWorldMatParamOverrides().isEmpty());
    n.addMatParamOverride(override);
    n.clearMatParamOverrides();
    n.updateGeometricState();
    assertTrue(n.getLocalMatParamOverrides().isEmpty());
    assertTrue(n.getWorldMatParamOverrides().isEmpty());
}
Also used : MatParamOverride(com.jme3.material.MatParamOverride) Test(org.junit.Test)

Example 4 with MatParamOverride

use of com.jme3.material.MatParamOverride in project jmonkeyengine by jMonkeyEngine.

the class Spatial method oldClone.

/**
     *  The old clone() method that did not use the new Cloner utility.
     */
public Spatial oldClone(boolean cloneMaterial) {
    try {
        Spatial clone = (Spatial) super.clone();
        if (worldBound != null) {
            clone.worldBound = worldBound.clone();
        }
        clone.worldLights = worldLights.clone();
        clone.localLights = localLights.clone();
        // Set the new owner of the light lists
        clone.localLights.setOwner(clone);
        clone.worldLights.setOwner(clone);
        clone.worldOverrides = new SafeArrayList<>(MatParamOverride.class);
        clone.localOverrides = new SafeArrayList<>(MatParamOverride.class);
        for (MatParamOverride override : localOverrides) {
            clone.localOverrides.add((MatParamOverride) override.clone());
        }
        // No need to force cloned to update.
        // This node already has the refresh flags
        // set below so it will have to update anyway.
        clone.worldTransform = worldTransform.clone();
        clone.localTransform = localTransform.clone();
        if (clone instanceof Node) {
            Node node = (Node) this;
            Node nodeClone = (Node) clone;
            nodeClone.children = new SafeArrayList<Spatial>(Spatial.class);
            for (Spatial child : node.children) {
                Spatial childClone = child.clone(cloneMaterial);
                childClone.parent = nodeClone;
                nodeClone.children.add(childClone);
            }
        }
        clone.parent = null;
        clone.setBoundRefresh();
        clone.setTransformRefresh();
        clone.setLightListRefresh();
        clone.setMatParamOverrideRefresh();
        clone.controls = new SafeArrayList<Control>(Control.class);
        for (int i = 0; i < controls.size(); i++) {
            Control newControl = controls.get(i).cloneForSpatial(clone);
            newControl.setSpatial(clone);
            clone.controls.add(newControl);
        }
        if (userData != null) {
            clone.userData = (HashMap<String, Savable>) userData.clone();
        }
        return clone;
    } catch (CloneNotSupportedException ex) {
        throw new AssertionError();
    }
}
Also used : Control(com.jme3.scene.control.Control) MatParamOverride(com.jme3.material.MatParamOverride)

Example 5 with MatParamOverride

use of com.jme3.material.MatParamOverride in project jmonkeyengine by jMonkeyEngine.

the class Material method applyOverrides.

private int applyOverrides(Renderer renderer, Shader shader, SafeArrayList<MatParamOverride> overrides, int unit) {
    for (MatParamOverride override : overrides.getArray()) {
        VarType type = override.getVarType();
        MatParam paramDef = def.getMaterialParam(override.getName());
        if (paramDef == null || paramDef.getVarType() != type || !override.isEnabled()) {
            continue;
        }
        Uniform uniform = shader.getUniform(override.getPrefixedName());
        if (override.getValue() != null) {
            if (type.isTextureType()) {
                renderer.setTexture(unit, (Texture) override.getValue());
                uniform.setValue(VarType.Int, unit);
                unit++;
            } else {
                uniform.setValue(type, override.getValue());
            }
        } else {
            uniform.clearValue();
        }
    }
    return unit;
}
Also used : Uniform(com.jme3.shader.Uniform) VarType(com.jme3.shader.VarType)

Aggregations

MatParamOverride (com.jme3.material.MatParamOverride)6 Test (org.junit.Test)3 AssetManager (com.jme3.asset.AssetManager)2 Uniform (com.jme3.shader.Uniform)2 VarType (com.jme3.shader.VarType)2 TechniqueDefLogic (com.jme3.material.logic.TechniqueDefLogic)1 Caps (com.jme3.renderer.Caps)1 Renderer (com.jme3.renderer.Renderer)1 Bucket (com.jme3.renderer.queue.RenderQueue.Bucket)1 ShadowMode (com.jme3.renderer.queue.RenderQueue.ShadowMode)1 Control (com.jme3.scene.control.Control)1 Shader (com.jme3.shader.Shader)1 SafeArrayList (com.jme3.util.SafeArrayList)1 HashSet (java.util.HashSet)1