Class MatParamOverride

java.lang.Object
com.jme3.material.MatParam
com.jme3.material.MatParamOverride
All Implemented Interfaces:
Savable, Cloneable

public final class MatParamOverride extends MatParam
MatParamOverride is a mechanism by which material parameters can be overridden on the scene graph.

A scene branch which has a MatParamOverride applied to it will cause all material parameters with the same name and type to have their value replaced with the value set on the MatParamOverride. If those parameters are mapped to a define, then the define will be overridden as well using the same rules as the ones used for regular material parameters.

MatParamOverrides are applied to a Spatial via the Spatial.addMatParamOverride(com.jme3.material.MatParamOverride) method. They are propagated to child Spatials via Spatial.updateGeometricState() similar to how lights are propagated.

Example:

 

 Geometry box = new Geometry("Box", new Box(1,1,1));
 Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
 mat.setColor("Color", ColorRGBA.Blue);
 box.setMaterial(mat);
 rootNode.attachChild(box);

 // ... later ...
 MatParamOverride override = new MatParamOverride(Type.Vector4, "Color", ColorRGBA.Red);
 rootNode.addMatParamOverride(override);

 // After adding the override to the root node, the box becomes red.
 
 
See Also:
  • Constructor Details

    • MatParamOverride

      protected MatParamOverride()
      Serialization only. Do not use.
    • MatParamOverride

      public MatParamOverride(VarType type, String name, Object value)
      Create a new MatParamOverride. Overrides are created enabled by default.
      Parameters:
      type - The type of parameter.
      name - The name of the parameter.
      value - The value to set the material parameter to.
  • Method Details

    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class MatParam
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class MatParam
    • isEnabled

      public boolean isEnabled()
      Determine if the MatParamOverride is enabled or disabled.
      Returns:
      true if enabled, false if disabled.
      See Also:
    • setEnabled

      public void setEnabled(boolean enabled)
      Enable or disable this MatParamOverride. When disabled, the override will continue to propagate through the scene graph like before, but it will have no effect on materials. Overrides are enabled by default.
      Parameters:
      enabled - Whether to enable or disable this override.
    • write

      public void write(JmeExporter ex) throws IOException
      Specified by:
      write in interface Savable
      Overrides:
      write in class MatParam
      Throws:
      IOException
    • read

      public void read(JmeImporter im) throws IOException
      Specified by:
      read in interface Savable
      Overrides:
      read in class MatParam
      Throws:
      IOException