Java Code Examples for com.jme3.terrain.Terrain#getMaterial()
The following examples show how to use
com.jme3.terrain.Terrain#getMaterial() .
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 |
/** * 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 |
/** * 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: TextureLayerSettings.java From jmonkeybuilder with Apache License 2.0 | 6 votes |
/** * 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 4
Source File: TextureLayerSettings.java From jmonkeybuilder with Apache License 2.0 | 5 votes |
/** * 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 5
Source File: TextureLayerSettings.java From jmonkeybuilder with Apache License 2.0 | 5 votes |
/** * 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 6
Source File: TextureLayerSettings.java From jmonkeybuilder with Apache License 2.0 | 5 votes |
/** * 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 7
Source File: TextureLayerSettings.java From jmonkeybuilder with Apache License 2.0 | 5 votes |
/** * 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 8
Source File: TerrainGrid.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public Material getMaterial(Vector3f worldLocation) { if (worldLocation == null) return null; Vector3f tileCell = getTileCell(worldLocation); Terrain terrain = cache.get(tileCell); if (terrain == null) return null; // terrain not loaded for that cell yet! return terrain.getMaterial(worldLocation); }
Example 9
Source File: TerrainGrid.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
@Override public Material getMaterial(Vector3f worldLocation) { if (worldLocation == null) return null; Vector3f tileCell = getTileCell(worldLocation); Terrain terrain = cache.get(tileCell); if (terrain == null) return null; // terrain not loaded for that cell yet! return terrain.getMaterial(worldLocation); }