MultiFaceBox mesh for bloxel


News from bloxel …

Last days I spend a couple of hours creating a box mesh for our game bloxel which have different textures for each side … like this one …

… without success … until now *g*

First of all jmonkey rocks … but the multi texture support is not easy to use/understand for a rookie like me.

Here the thinks I checked out:

  • http://jmonkeyengine.org/groups/general-2/forum/topic/box-with-multiple-textures/
    • the idea here was to create a box in a editor, and generate mapping coordinates for it, then  import it into JME with the ogre xml importer
    • paddy (bloxel team member) tried this approach with blender, the result was an .obj file with two geometries inside a) the grass geo on top and b) the dirt geos on the other sides
    • long story short end … this doesn’t work very well
  • then I tried the jme3 sky material
    • this material use a TextureCubeMap (multiple images for cube sides)
    • not working for me … sky material is only for sky-boxes I guess
  • then I want use shaders (glsl) to get the different textures on the box
    • but my knowledge about glsl is near zero *gg* … so I tried to find shader-code with google … no success
  • then I found the jme2 class MultiFaceBox
    • ported to jme3 was quite simple
    • play a little bit with the right texture
    • and voilà … here we are

public class MultiFaceBox extends Box {

  public MultiFaceBox() {
    super();
    remap();
  }

  public MultiFaceBox(final Vector3f center, final float xExtent, final float yExtent, final float zExtent) {
    super(center, xExtent, yExtent, zExtent);
    remap();
  }

  public MultiFaceBox(final Vector3f min, final Vector3f max) {
    super(min, max);
    remap();
  }

  private void remap() {
    final FloatBuffer fb = getFloatBuffer(Type.TexCoord);
    fb.rewind();
    for (int i = 0; i < 6; i++) {
      final float top = i / 8f;
      final float bottom = (i + 1) / 8f;
      final float[] tex = new float[] { 1, bottom, 0, bottom, 0, top, 1, top };
      fb.put(tex);
    }
  }
}

This works for me … now I can remove the unused two empty areas in the texture …