Text Texture?

I recently began to use JMonkey and I wanted to know if it is possible to use Text as if it were a texture.

The thing is, I'm making a virtual keyboard, with Boxes being the keys. Can I use the Text class to apply a letter to one side of the Box, so it follows it's movements, like a texture?

Thanks!

Wouldnt it be easier to just load an actual character set image as real texture and set UV coords to the right character?

Hmmm… yeah, it probably would be better… so I have another question:

Using the Box class, can I apply a texture to only one side of the box? If so, how is that done?

Or should I manually build a box using squares?

this question comes up frequently, and i think building your own box made out of 6 quads is the easiest method.

Nope. The easiest solution is com.jme.scene.shape.MultiFaceBox

It takes a texture 1 unit wide and 8 units heigh, or 8 stacked up squares. The first 6 squares are mapped to the sides of the Box. Everything else is exactly as in Box.

Landei said:

Nope. The easiest solution is com.jme.scene.shape.MultiFaceBox
It takes a texture 1 unit wide and 8 units heigh, or 8 stacked up squares. The first 6 squares are mapped to the sides of the Box. Everything else is exactly as in Box.


Landei, that seems very useful, but I can't find this MultiFaceBox. It doesn't appear to be in com.jme.scene.shape ... why could that be?
Chocobo_Master said:

Landei, that seems very useful, but I can't find this MultiFaceBox. It doesn't appear to be in com.jme.scene.shape ... why could that be?


Wierd - its there for me. When I look at the CVS history of the class, it has only 1 entry:
21.09.2007 - move to using clones instead of what should be immutable static values.

Anyways - perhaps you have an older version of jME? get the version from CVS or just the latest jar.
Landei said:

Nope. The easiest solution is com.jme.scene.shape.MultiFaceBox


ah yes there is that new thing :)

Chocobo_Master, here is it:



package com.jme.scene.shape;

import java.nio.FloatBuffer;

import com.jme.math.Vector3f;

public class MultiFaceBox extends Box {

    private static final long serialVersionUID = 1L;

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

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

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

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

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