Best solution to display 2D layer on top of 3D scene


I write a little Java3D program and I need to display a 2D layer on top of my 3D scene with

  • dynamic stats (FPF, memory usage, …)
  • dynamic hour (rendered as an analog watch).

I searched on the web and I think I would use a PlatformGeometry

So, I created the following structure

PlatformGeometry => TransformGroup => BranchGroup => Text2D

But I have to create/update the Text2D on every frame.

When I try to do that (add a Text2D as a Child of the BranchGroup), I get an error Group: only a BranchGroup node may be added

I get an equivalent error when I try to remove previous Text2D child from the BranchGroup.

I think I gave the needed capabilities to the BranchGroup.


I also see I can remove the BranchGroup from the TransformGroup without getting any error. But, I don’t think it’s efficient on every frame to

  • remove ‘2D stats’ BranchGroup from ‘2D stats’ TransformGroup
  • create new ‘2D stats’ BranchGroup
  • create new Text2D and add it as child to ‘2D stats’ BranchGroup
  • add new ‘2D stats’ BranchGroup to the ‘2D stats’ TransformGroup.

So, what is the best solution ?

Thanks for all.


If you just have to update the text of the Text2D, setString() should be enough.

If you have to create another Text2D, the solution I see is :

  • Detach the Text2DBranchGroup. This branchgroup should have the capability BranchGroup.ALLOW_DETACH, Group.ALLOW_CHILDREN_EXTEND and Group.ALLOW_CHILDREN_WRITE and the parent node should have the capabilities Group.ALLOW_CHILDREN_EXTEND and Group.ALLOW_CHILDREN_WRITE.
  • Remove the Text2D from the Text2DBranchGroup. No exception will be thrown I think because the Text2DBranchGroup is no longer alive.
  • Create a new Text2D and add it to the Text2DBranchGroup.
  • Attach the Text2DBranchGroup to his last parent.


Hello Antoine,

I tried what you said and it works. The Text2D is just a little bit blinking but it doesn’t matter.

Thanks / merci

But I see a strange effect.

The z offset of my Text2DBranchGroup is -2
In my scene, there is a tree at z = -50

The Text2D in the Text2DBranchGroup is displayed on top of tree trunc, ok, but the tree leafs (transparent texture) are displayed on top Text2D !

It seems there is a z-buffer bug between 3D scene and PlatformGeometry.

Maybe is it related to my clipping ?


I need these values to display near objects and very far away ones.

Any idea ?