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());
}
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));
}
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());
}
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();
}
}
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;
}
Aggregations