How to draw a 2d overlay on a 3d Java scene?

I have a scene written in Java 3d where the user’s viewing position is set to some coordinate using the following code:

ViewingPlatform vp = simpleUniverse.getViewingPlatform(); TransformGroup steerTG = vp.getViewPlatformTransform(); Transform3D t3d = new Transform3D(); steerTG.getTransform(t3d); t3d.lookAt( new Point3d(-5, 10, 25), new Point3d(0, 0, 0), new Vector3d(0, 1, 0)); t3d.invert(); steerTG.setTransform(t3d); 

Now I need to put an inscription on top of the scene, which is always visible, for example, some text. I tried the following, but to no avail:

 PlatformGeometry pg = new PlatformGeometry(); Text2D text = new Text2D("Text to display", Cell.BLACK, "Verdana", 18, 1); pg.addChild(text); simpleUniverse.getViewingPlatform().setPlatformGeometry(pg); 

When I run the above code, I don’t see any text at all. Can anybody help?

+6
java 3d opengl java-3d
source share
1 answer

The problem is that you are displaying the text directly on top of the camera inside the clipping plane. You need something like this to translate -1 along the z axis.

  PlatformGeometry pg = new PlatformGeometry(); TransformGroup objScale = new TransformGroup(); Transform3D t3d = new Transform3D(); t3d.setTranslation(new Vector3f(0f, 0f, -1f)); objScale.setTransform(t3d); Text2D text = new Text2D("Text to display", Cell.BLACK, "Verdana", 18, 1); objScale.addChild(text); pg.addChild(objScale); simpleUniverse.getViewingPlatform().setPlatformGeometry(pg); 

Hope this helps.

+4
source share

All Articles