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

The following examples show how to use com.jme3.material.Material#getParam() . 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: 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 2
Source File: TextureLayerSettings.java    From jmonkeybuilder with Apache License 2.0 6 votes vote down vote up
@JmeThread
private void updateTexture(@Nullable final Texture texture, @NotNull final String paramName,
                           @NotNull final Geometry geometry) {

    final Material material = geometry.getMaterial();
    final MatParam matParam = material.getParam(paramName);
    if (matParam == null && texture == null) {
        return;
    }

    if (texture == null) {
        material.clearParam(matParam.getName());
    } else {
        material.setTexture(paramName, texture);
    }
}
 
Example 3
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 4
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 5
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 6
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 7
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 8
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 9
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 10
Source File: InstancedNode.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void addToInstancedGeometry(Geometry geom) {
    Material material = geom.getMaterial();
    MatParam param = material.getParam("UseInstancing");
    if (param == null || !((Boolean)param.getValue()).booleanValue()) {
        throw new IllegalStateException("You must set the 'UseInstancing' "
                + "parameter to true on the material prior "
                + "to adding it to InstancedNode");
    }

    InstancedGeometry ig = lookUpByGeometry(geom);
    igByGeom.put(geom, ig);
    geom.associateWithGroupNode(this, 0);
    ig.addInstance(geom);
}
 
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: TextureAtlas.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private static Texture getMaterialTexture(Geometry geometry, String mapName) {
    Material mat = geometry.getMaterial();
    if (mat == null || mat.getParam(mapName) == null || !(mat.getParam(mapName) instanceof MatParamTexture)) {
        return null;
    }
    MatParamTexture param = (MatParamTexture) mat.getParam(mapName);
    Texture texture = param.getTextureValue();
    if (texture == null) {
        return null;
    }
    return texture;


}
 
Example 13
Source File: SkeletonControl.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void switchToSoftware() {
    for (Material m : materials) {
        if (m.getParam("NumberOfBones") != null) {
            m.clearParam("NumberOfBones");
        }
    }
    for (Mesh mesh : targets) {
        if (mesh.isAnimated()) {
            mesh.prepareForAnim(true);
        }
    }
}
 
Example 14
Source File: MaterialPropertyBuilder.java    From jmonkeybuilder with Apache License 2.0 2 votes vote down vote up
/**
 * Get relevant value of the material parameter.
 *
 * @param param    the material parameter.
 * @param material the material.
 * @return the relevant value.
 */
@FxThread
protected @Nullable Object getParamValue(@NotNull MatParam param, @NotNull Material material) {
    var currentParam = material.getParam(param.getName());
    return currentParam == null ? null : currentParam.getValue();
}