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?