Texturierung von Voxel Terrain angepasst
This commit is contained in:
@@ -238,19 +238,22 @@ public class SculptedMeshState extends BaseAppState {
|
||||
private Material buildMaterial() {
|
||||
Material mat = new Material(app.getAssetManager(), "MatDefs/BakedTerrain.j3md");
|
||||
|
||||
// DiffuseArray + DiffuseScales + AlphaMaps vom Terrain-Material übernehmen,
|
||||
// damit die gemalten Splatmap-Texturen auch ingame sichtbar sind.
|
||||
// DiffuseArray + DiffuseScales vom Terrain-Material übernehmen (selbe Textur-Slots).
|
||||
// AlphaMaps kommen aus den Voxel-spezifischen Splatmap-Arrays in MapData.
|
||||
if (terrainMaterial != null) {
|
||||
com.jme3.material.MatParam diffArr = terrainMaterial.getParam("DiffuseArray");
|
||||
if (diffArr != null) mat.setParam("DiffuseArray", diffArr.getVarType(), diffArr.getValue());
|
||||
|
||||
com.jme3.material.MatParam scales = terrainMaterial.getParam("DiffuseScales");
|
||||
if (scales != null) mat.setParam("DiffuseScales", scales.getVarType(), scales.getValue());
|
||||
|
||||
for (String key : new String[]{"AlphaMap", "AlphaMap_1", "AlphaMap_2"}) {
|
||||
com.jme3.material.MatParam p = terrainMaterial.getParam(key);
|
||||
if (p != null) mat.setTexture(key, (Texture) p.getValue());
|
||||
}
|
||||
}
|
||||
if (mapData != null) {
|
||||
com.jme3.texture.Texture2D a0 = buildVoxelAlphaMap(mapData.voxelSplatR, mapData.voxelSplatG, mapData.voxelSplatB, mapData.voxelSplatA);
|
||||
com.jme3.texture.Texture2D a1 = buildVoxelAlphaMap(mapData.voxelUpperSplatR, mapData.voxelUpperSplatG, mapData.voxelUpperSplatB, mapData.voxelUpperSplatA);
|
||||
com.jme3.texture.Texture2D a2 = buildVoxelAlphaMap(mapData.voxelThirdSplatR, mapData.voxelThirdSplatG, mapData.voxelThirdSplatB, mapData.voxelThirdSplatA);
|
||||
mat.setTexture("AlphaMap", a0);
|
||||
mat.setTexture("AlphaMap_1", a1);
|
||||
mat.setTexture("AlphaMap_2", a2);
|
||||
}
|
||||
|
||||
// Klippen-Textur: steiler Slot aus MapData für Flat/Steep-Blending
|
||||
@@ -261,4 +264,21 @@ public class SculptedMeshState extends BaseAppState {
|
||||
|
||||
return mat;
|
||||
}
|
||||
|
||||
private com.jme3.texture.Texture2D buildVoxelAlphaMap(byte[] r, byte[] g, byte[] b, byte[] a) {
|
||||
int size = MapData.SPLAT_SIZE;
|
||||
java.nio.ByteBuffer buf = com.jme3.util.BufferUtils.createByteBuffer(size * size * 4);
|
||||
for (int i = 0; i < size * size; i++) {
|
||||
buf.put(r[i]).put(g[i]).put(b[i]).put(a[i]);
|
||||
}
|
||||
buf.flip();
|
||||
com.jme3.texture.Image img = new com.jme3.texture.Image(
|
||||
com.jme3.texture.Image.Format.RGBA8, size, size, buf,
|
||||
com.jme3.texture.image.ColorSpace.Linear);
|
||||
com.jme3.texture.Texture2D tex = new com.jme3.texture.Texture2D(img);
|
||||
tex.setWrap(Texture.WrapMode.EdgeClamp);
|
||||
tex.setMinFilter(Texture.MinFilter.BilinearNoMipMaps);
|
||||
tex.setMagFilter(Texture.MagFilter.Bilinear);
|
||||
return tex;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user