JME3 bitmap text in 3D

Hi folks,



I'm trying to make 3d bitmap text quads as labels for objects that sit in the XY plane.  I noticed that by default BitmapText objects live in Screen Coordinates, and I noticed that was happening due to the queue bucket call in their constructor.



I stumbled across this post:



http://www.jmonkeyengine.com/forum/index.php?topic=12277.0



Which was somebody with my exact problem in JME2.  I did the same kind of solution (switch the queue to the transparent one and resize accordingly) but it doesn't seem to be working at all.  Here's what I've got so far:


        labelText = new BitmapText(constants.labelFont);
        labelText.setQueueBucket(Bucket.Transparent);
        labelText.setSize(20);  //suitably big, no?
        labelText.getLocalRotation().fromAngleAxis(FastMath.PI/2f, Vector3f.UNIT_X);  //tried rotating 90 degrees just in case it was sitting perpendicular to my fixed plane
        labelText.setLocalTranslation(0, 0, 1f);
        labelText.setLocalScale(100);  //tried making really damn big to no avail
        labelText.setText("TEST");
       
        anchor.attachChild(labelText);



Any thoughts what I could be doing wrong?  I've been at this for about an hour and a half and I'm starting to lose my mind! I really need these quads to live in the XY plane with world coordinates because the "anchor" Node for each label is getting translated like crazy and I don't want to have to have another loop translating the labels' positions from world coordinates.

Thanks in advance!

It seems it happens due to the Gui shader automatically constricting it to the XY plane.





I got it to work by disabling this feature, as you can see in the screenshot:







I committed the change and added a new test: jme3test.gui.TestBitmapText3D

Beautiful work, Momoko_Fan…thanks for the fix!

One last question…is there an easy way to center the resulting Geom?  It's anchored by default at the top left corner.  I've got vertical centering working but the horizontal doesn't seem to be working.



Here's what I've got right now:



        labelText = new BitmapText(constants.labelFont, false);
        labelText.setBox(new Rectangle(0, 0, 6, 3));
        labelText.setQueueBucket(Bucket.Transparent);
        labelText.setSize(constants.labelSize);
        labelText.setColor(constants.labelColor);
        labelText.setText(this.nodeId+"");
        System.out.println(labelText.getLineWidth());
        System.out.println(labelText.getLineHeight());
        labelText.setLocalTranslation(0f, labelText.getLineHeight()/2f, constants.labelHeight);



Right now getLineHeight() returns 9.882353 (a perfect vertical center in world coords) but getLineWidth() returns 0.0.  Is this a bug or am I using the API wrong?

Amazing coincidence!

I just encountered this exact problem today and found this post doing a Google search.

Weird…



/bs

You can call updateLogicalState on the text to update the line width. Although ideally you wouldn't have to do that. I'll fix this at some point.

By the way, BitmapText.getLineWidth() won't return the correct value until updateLogicalState has been called at least once, since that's where the actual text geometry is assembled (by calling assemble()).



/bs

I love this forum. :slight_smile:

Momoko_Fan said:

You can call updateLogicalState on the text to update the line width. Although ideally you wouldn't have to do that. I'll fix this at some point.


Wow, you're fast.. I should have refreshed the topic page before posting again.