Hi
For my terrain, I am using a modified version of JME Box mesh (I removed the top and bottom faces) to use it as a block wall and added a Quad on the top as a block surface.
I am using terrain material with useTriPlanarMapping = true
on both block surface and wall.
My issue is with the block wall texture mapping,
the texture is displayed correctly on the front and back side of the box
but incorrect at right and left side:
my custom box mesh code:
public class BlockWall extends AbstractBox{
private static final short[] GEOMETRY_INDICES_DATA = {
2, 1, 0, 3, 2, 0, // back
6, 5, 4, 7, 6, 4, // right
10, 9, 8, 11, 10, 8, // front
14, 13, 12, 15, 14, 12, // left
//18, 17, 16, 19, 18, 16, // top
//22, 21, 20, 23, 22, 20 // bottom
};
private static final float[] GEOMETRY_NORMALS_DATA = {
0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, // back
1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, // right
0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, // front
-1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, // left
//0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, // top
//0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0 // bottom
};
private static final float[] GEOMETRY_TEXTURE_DATA = {
1, 0, 0, 0, 0, 1, 1, 1, // back
1, 0, 0, 0, 0, 1, 1, 1, // right
1, 0, 0, 0, 0, 1, 1, 1, // front
1, 0, 0, 0, 0, 1, 1, 1, // left
//1, 0, 0, 0, 0, 1, 1, 1, // top
//1, 0, 0, 0, 0, 1, 1, 1 // bottom
};
/**
* Creates a new box.
* <p>
* The box has a center of 0,0,0 and extends in the out from the center by
* the given amount in <em>each</em> direction. So, for example, a box
* with extent of 0.5 would be the unit cube.
*
* @param x the size of the box along the x axis, in both directions.
* @param y the size of the box along the y axis, in both directions.
* @param z the size of the box along the z axis, in both directions.
*/
public BlockWall(float x, float y, float z) {
super();
updateGeometry(Vector3f.ZERO, x, y, z);
}
/**
* Constructor instantiates a new <code>Box</code> object.
* <p>
* The minimum and maximum point are provided, these two points define the
* shape and size of the box but not it's orientation or position. You should
* use the {@link com.jme3.scene.Spatial#setLocalTranslation(com.jme3.math.Vector3f) }
* and {@link com.jme3.scene.Spatial#setLocalRotation(com.jme3.math.Quaternion) }
* methods to define those properties.
*
* @param min the minimum point that defines the box.
* @param max the maximum point that defines the box.
*/
public BlockWall(Vector3f min, Vector3f max) {
super();
updateGeometry(min, max);
}
/**
* Empty constructor for serialization only. Do not use.
*/
public BlockWall(){
super();
}
/**
* Creates a clone of this box.
* <p>
* The cloned box will have '_clone' appended to its name, but all other
* properties will be the same as this box.
*/
@Override
public BlockWall clone() {
return new BlockWall(xExtent, yExtent, zExtent);
}
protected void doUpdateGeometryIndices() {
if (getBuffer(Type.Index) == null){
setBuffer(Type.Index, 3, BufferUtils.createShortBuffer(GEOMETRY_INDICES_DATA));
}
}
protected void doUpdateGeometryNormals() {
if (getBuffer(Type.Normal) == null){
setBuffer(Type.Normal, 3, BufferUtils.createFloatBuffer(GEOMETRY_NORMALS_DATA));
}
}
protected void doUpdateGeometryTextures() {
if (getBuffer(Type.TexCoord) == null){
setBuffer(Type.TexCoord, 2, BufferUtils.createFloatBuffer(GEOMETRY_TEXTURE_DATA));
}
}
protected void doUpdateGeometryVertices() {
FloatBuffer fpb = BufferUtils.createVector3Buffer(24);
Vector3f[] v = computeVertices();
fpb.put(new float[] {
v[0].x, v[0].y, v[0].z, v[1].x, v[1].y, v[1].z, v[2].x, v[2].y, v[2].z, v[3].x, v[3].y, v[3].z, // back
v[1].x, v[1].y, v[1].z, v[4].x, v[4].y, v[4].z, v[6].x, v[6].y, v[6].z, v[2].x, v[2].y, v[2].z, // right
v[4].x, v[4].y, v[4].z, v[5].x, v[5].y, v[5].z, v[7].x, v[7].y, v[7].z, v[6].x, v[6].y, v[6].z, // front
v[5].x, v[5].y, v[5].z, v[0].x, v[0].y, v[0].z, v[3].x, v[3].y, v[3].z, v[7].x, v[7].y, v[7].z, // left
v[2].x, v[2].y, v[2].z, v[6].x, v[6].y, v[6].z, v[7].x, v[7].y, v[7].z, v[3].x, v[3].y, v[3].z, // top
v[0].x, v[0].y, v[0].z, v[5].x, v[5].y, v[5].z, v[4].x, v[4].y, v[4].z, v[1].x, v[1].y, v[1].z // bottom
});
setBuffer(Type.Position, 3, fpb);
updateBound();
}
}
itâs exactly the same as JME Box, I just commented top and bottom.
I guess it can be fixed with some reordering in indexes/position/uv, but I do not have enough knowledge to fix it myself.
Will appreciate if someone can help me to fix this?
Just in case I am using this material for my terrain
https://github.com/yaRnMcDonuts/AfflictedPbrTerrainConverter/blob/master/PBRTerrain/assets/MatDefs/shaders/AfflictedPBRTerrain_33.j3md