Java Code Examples for com.jme3.material.MatParam#getValue()

The following examples show how to use com.jme3.material.MatParam#getValue() . 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: PaintTerrainToolAction.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private Texture getAlphaTexture(Terrain terrain, int alphaLayer) {
    if (terrain == null)
        return null;
    MatParam matParam = null;
    if (alphaLayer == 0)
        matParam = terrain.getMaterial().getParam("AlphaMap");
    else if(alphaLayer == 1)
        matParam = terrain.getMaterial().getParam("AlphaMap_1");
    else if(alphaLayer == 2)
        matParam = terrain.getMaterial().getParam("AlphaMap_2");
    
    if (matParam == null || matParam.getValue() == null) {
        return null;
    }
    Texture tex = (Texture) matParam.getValue();
    return tex;
}
 
Example 2
Source File: TextureLayerSettings.java    From jmonkeybuilder with Apache License 2.0 6 votes vote down vote up
/**
 * Get a diffuse normal of the level.
 *
 * @param layer the layer.
 * @return the normal texture or null.
 */
@FromAnyThread
public @Nullable Texture getNormal(final int layer) {

    final Function<Integer, String> layerToNormalName = getLayerToNormalName();
    if (layerToNormalName == null) {
        return null;
    }

    final Terrain terrain = getTerrain();
    final Material material = terrain.getMaterial();
    final MatParam matParam = material.getParam(layerToNormalName.apply(layer));

    if (matParam == null || matParam.getValue() == null) {
        return null;
    }

    return (Texture) matParam.getValue();
}
 
Example 3
Source File: TerrainEditorController.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Get the normal map texture at the specified layer.
 * Run this on the GL thread!
 */
private Texture doGetNormalMap(int layer) {
    Terrain terrain = (Terrain) getTerrain(null);
    if (terrain == null)
        return null;
    MatParam matParam = null;
    if (layer == 0)
        matParam = terrain.getMaterial().getParam("NormalMap");
    else
        matParam = terrain.getMaterial().getParam("NormalMap_"+layer);

    if (matParam == null || matParam.getValue() == null) {
        return null;
    }
    Texture tex = (Texture) matParam.getValue();
    return tex;
}
 
Example 4
Source File: TerrainEditorController.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private Texture doGetAlphaTexture(Terrain terrain, int alphaLayer) {
    if (terrain == null)
        return null;
    MatParam matParam = null;
    if (alphaLayer == 0)
        matParam = terrain.getMaterial().getParam("AlphaMap");
    else if(alphaLayer == 1)
        matParam = terrain.getMaterial().getParam("AlphaMap_1");
    else if(alphaLayer == 2)
        matParam = terrain.getMaterial().getParam("AlphaMap_2");
    
    if (matParam == null || matParam.getValue() == null) {
        return null;
    }
    Texture tex = (Texture) matParam.getValue();
    return tex;
}
 
Example 5
Source File: TextureLayerSettings.java    From jmonkeybuilder with Apache License 2.0 6 votes vote down vote up
/**
 * Get a alpha texture of the level.
 *
 * @param layer the layer.
 * @return the alpha texture or null.
 */
@FromAnyThread
public @Nullable Texture getAlpha(final int layer) {

    final Function<Integer, String> layerToAlphaName = getLayerToAlphaName();
    if (layerToAlphaName == null) {
        return null;
    }

    final Terrain terrain = getTerrain();
    final Material material = terrain.getMaterial();
    final MatParam matParam = material.getParam(layerToAlphaName.apply(layer));

    if (matParam == null || matParam.getValue() == null) {
        return null;
    }

    return (Texture) matParam.getValue();
}
 
Example 6
Source File: TerrainEditorController.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Get the diffuse texture at the specified layer.
 * Run this on the GL thread!
 */
private Texture doGetDiffuseTexture(int layer) {
    Terrain terrain = (Terrain) getTerrain(null);
    if (terrain == null)
        return null;
    MatParam matParam = null;
    if (layer == 0)
        matParam = terrain.getMaterial().getParam("DiffuseMap");
    else
        matParam = terrain.getMaterial().getParam("DiffuseMap_"+layer);

    if (matParam == null || matParam.getValue() == null) {
        return null;
    }
    Texture tex = (Texture) matParam.getValue();

    return tex;
}
 
Example 7
Source File: TextureLayerSettings.java    From jmonkeybuilder with Apache License 2.0 6 votes vote down vote up
/**
 * Get a diffuse texture of the level.
 *
 * @param layer the layer.
 * @return the diffuse texture or null.
 */
@FromAnyThread
public @Nullable Texture getDiffuse(final int layer) {

    final Function<Integer, String> layerToDiffuseName = getLayerToDiffuseName();
    if (layerToDiffuseName == null) {
        return null;
    }

    final Terrain terrain = getTerrain();
    final Material material = terrain.getMaterial();
    final MatParam matParam = material.getParam(layerToDiffuseName.apply(layer));

    if (matParam == null || matParam.getValue() == null) {
        return null;
    }

    return (Texture) matParam.getValue();
}
 
Example 8
Source File: J3MOutputCapsule.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private String formatMatParam(MatParam param){
    VarType type = param.getVarType();
    Object val = param.getValue();
    switch (type) {
        case Boolean:
        case Float:
        case Int:
            return val.toString();
        case Vector2:
            Vector2f v2 = (Vector2f) val;
            return v2.getX() + " " + v2.getY();
        case Vector3:
            Vector3f v3 = (Vector3f) val;
            return v3.getX() + " " + v3.getY() + " " + v3.getZ();
        case Vector4:
            // can be either ColorRGBA, Vector4f or Quaternion
            if (val instanceof Vector4f) {
                Vector4f v4 = (Vector4f) val;
                return v4.getX() + " " + v4.getY() + " "
                        + v4.getZ() + " " + v4.getW();
            } else if (val instanceof ColorRGBA) {
                ColorRGBA color = (ColorRGBA) val;
                return color.getRed() + " " + color.getGreen() + " "
                        + color.getBlue() + " " + color.getAlpha();
            } else if (val instanceof Quaternion) {
                Quaternion quat = (Quaternion) val;
                return quat.getX() + " " + quat.getY() + " "
                        + quat.getZ() + " " + quat.getW();
            } else {
                throw new UnsupportedOperationException("Unexpected Vector4 type: " + val);
            }

        default:
            return null; // parameter type not supported in J3M
    }
}
 
Example 9
Source File: TerrainEditorController.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private boolean doIsTriPlanarEnabled() {
    Terrain terrain = (Terrain) getTerrain(null);
    if (terrain == null)
        return false;
    MatParam param = terrain.getMaterial().getParam("useTriPlanarMapping");
    if (param != null)
        return (Boolean)param.getValue();

    return false;
}
 
Example 10
Source File: TerrainEditorController.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private Float doGetTextureScale(int layer) {
    Terrain terrain = (Terrain) getTerrain(null);
    if (terrain == null)
        return 1f;
    MatParam matParam = null;
    matParam = terrain.getMaterial().getParam("DiffuseMap_"+layer+"_scale");
    return (Float) matParam.getValue();
}
 
Example 11
Source File: BitmapText.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private ColorRGBA getColor( Material mat, String name ) {
    MatParam mp = mat.getParam(name);
    if( mp == null ) {
        return null;
    }
    return (ColorRGBA)mp.getValue();
}
 
Example 12
Source File: GuiGlobals.java    From Lemur with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private Texture getTexture( Material mat, String name ) {
    MatParam mp = mat.getParam(name);
    if( mp == null ) {
        return null;
    }
    return (Texture)mp.getValue();
}
 
Example 13
Source File: TextureLayerSettings.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
/**
 * Set a new texture scale to a level.
 *
 * @param scale the texture scale.
 * @param layer the layer.
 */
@FromAnyThread
public void setTextureScale(final float scale, final int layer) {

    final Function<Integer, String> layerToScaleName = getLayerToScaleName();
    if (layerToScaleName == null) {
        return;
    }

    final Terrain terrain = getTerrain();
    final Material material = terrain.getMaterial();
    final String paramName = layerToScaleName.apply(layer);
    final MatParam matParam = material.getParam(paramName);
    final Float current = matParam == null ? null : (Float) matParam.getValue();

    final PropertyOperation<ChangeConsumer, Node, Float> operation =
            new PropertyOperation<>(getTerrainNode(), TERRAIN_PARAM, scale, current);

    operation.setApplyHandler((node, newScale) -> {
        NodeUtils.visitGeometry(getTerrainNode(), geometry -> {

            final Material geometryMaterial = geometry.getMaterial();
            final MatParam param = geometryMaterial.getParam(paramName);

            if (param == null && (newScale == null || newScale == -1F)) {
                return;
            }

            if (newScale == null || newScale == -1F) {
                geometryMaterial.clearParam(paramName);
            } else {
                geometryMaterial.setFloat(paramName, newScale);
            }
        });
    });

    final ModelChangeConsumer changeConsumer = paintingComponent.getChangeConsumer();
    changeConsumer.execute(operation);
}
 
Example 14
Source File: TextureLayerSettings.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
/**
 * Get a texture scale of the level.
 *
 * @param layer the layer.
 * @return the texture scale or -1.
 */
@FromAnyThread
public float getTextureScale(final int layer) {

    final Function<Integer, String> layerToScaleName = getLayerToScaleName();
    if (layerToScaleName == null) {
        return -1F;
    }

    final Terrain terrain = getTerrain();
    final Material material = terrain.getMaterial();
    final MatParam matParam = material.getParam(layerToScaleName.apply(layer));
    return matParam == null ? -1F : (float) matParam.getValue();
}
 
Example 15
Source File: TextureLayerSettings.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
/**
 * Set a new normal texture to a level.
 *
 * @param texture the normal texture.
 * @param layer   the layer.
 */
@FromAnyThread
public void setNormal(@Nullable final Texture texture, final int layer) {

    final Function<Integer, String> layerToNormalName = getLayerToNormalName();
    if (layerToNormalName == null) {
        return;
    }

    final Terrain terrain = getTerrain();
    final Material material = terrain.getMaterial();
    final String paramName = layerToNormalName.apply(layer);
    final MatParam matParam = material.getParam(paramName);
    final Texture current = matParam == null ? null : (Texture) matParam.getValue();

    if (texture != null) {
        texture.setWrap(Texture.WrapMode.Repeat);
    }

    final PropertyOperation<ChangeConsumer, Node, Texture> operation =
            new PropertyOperation<>(getTerrainNode(), TERRAIN_PARAM, texture, current);

    operation.setApplyHandler((node, newTexture) ->
            NodeUtils.visitGeometry(node, geometry -> updateTexture(newTexture, paramName, geometry)));

    final ModelChangeConsumer changeConsumer = paintingComponent.getChangeConsumer();
    changeConsumer.execute(operation);
}
 
Example 16
Source File: TextureLayerSettings.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
/**
 * Set a new diffuse texture to a level.
 *
 * @param texture the new texture.
 * @param layer   the layer.
 */
@FromAnyThread
public void setDiffuse(@Nullable final Texture texture, final int layer) {

    final Function<Integer, String> layerToDiffuseName = getLayerToDiffuseName();
    if (layerToDiffuseName == null) {
        return;
    }

    final Terrain terrain = getTerrain();
    final Material material = terrain.getMaterial();
    final String paramName = layerToDiffuseName.apply(layer);
    final MatParam matParam = material.getParam(paramName);
    final Texture current = matParam == null ? null : (Texture) matParam.getValue();

    if (texture != null) {
        texture.setWrap(Texture.WrapMode.Repeat);
    }

    final PropertyOperation<ChangeConsumer, Node, Texture> operation =
            new PropertyOperation<>(getTerrainNode(), TERRAIN_PARAM, texture, current);

    operation.setApplyHandler((node, newTexture) ->
            NodeUtils.visitGeometry(node, geometry -> updateTexture(newTexture, paramName, geometry)));

    final ModelChangeConsumer changeConsumer = paintingComponent.getChangeConsumer();
    changeConsumer.execute(operation);
}
 
Example 17
Source File: MaterialProperty.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public MaterialProperty(MatParam param) {
    this.type = param.getVarType().name();
    this.name = param.getName();
    Object obj = param.getValue();
    this.value = param.getValueAsString();
}