[SOLVED] Displaying BitmapText in 3D

Hello,

I am having trouble displaying BitmapText in 3D. If I attach it to guiNode, it displays without any issues. If I attach it to rootNode, I can’t see it. I tried attaching both BitmapText and a Geometry to the same Node, to make sure I’m displaying both at the same coordinates. I can see the Geometry, but not the text.

Here is the example code:

BitmapText bitmapText = new BitmapText(bitmapFont);
        bitmapText.setSize(bitmapFont.getPreferredSize());
        bitmapText.setColor(ColorRGBA.Blue);
        bitmapText.setText("Text");
        Curve triangle = new Curve(new Spline(Spline.SplineType.Linear, new Vector3f[]{ new Vector3f(-1f, 2f, -0.1f), new Vector3f(1f, 2f, 0.1f), new Vector3f(0f, 0f, -0.1f) }, 0f, false), 0);
        triangle.setMode(Mesh.Mode.TriangleFan);
        Material material = new Material(assetManager,"Common/MatDefs/Misc/Unshaded.j3md");
        material.setColor("Color", ColorRGBA.fromRGBA255(255, 64, 128, 128));
        Geometry triangleGeometry = new Geometry("Triangle", triangle);
        triangleGeometry.setMaterial(material);
        Node node = new Node("TextNodeTest");
        node.attachChild(triangleGeometry);
        node.attachChild(bitmapText);
        node = (Node) adjustToCamera(node, location).move(location).move(0f, 20f, 0f);
        parentNode.attachChild(node);
    private Spatial adjustToCamera(Spatial spatial, Vector3f location) {
        float distance = camera.getLocation().distance(location);
        spatial.setLocalScale(distance/70.f);
        spatial.setLocalRotation(camera.getRotation());
        return spatial;
    }

I’ve tried different text sizes and rotating the text node itself before attaching to common node, but I still can’t see the text. What am I doing wrong?

1 Like

There really isn’t anything special about bitmap text geometry except that it’s SUPER LARGE in the 3D world, very flat, and one sided.

All of these things can combine to make it hard to spot.

But note that at the size you have it set, it’s probably like 24 meters high. For reference, the standard blue box is only 2 meters high.

Try bitmapTest.setLocalScale(0.01f)… and see if you can find it then.

4 Likes

Thanks! I got it working. I had to scale it by 0.1f, but even then it was not visible, until I figured out that it’s rotated the wrong way and facing away from the camera - and it’s not visible from the back. Rotating the BitmapText solved the issue.

3 Likes