Fixed size text

How should I go about inserting a fixed size text object which tracks to another object in the scene. By this I mean the text node isn't a child of the object node. If the object node gets farther away the text should stay the same size but move with the projection of the object on the screen. I was told this capability is present in java3d using Rasters. Is there a similar such thing in Java Monkey? I looked at the Test3DFlatText demo and it helped but it isn't exactly what I'm looking for in this case.



Thanks for any help you can provide!

I'd assume you could do this by rendering the text in the ORTHO queue even if it's attached to the Objects node.



I'm sure there have been several posts about this sort of thing before so a search will bring up something (not sure what to search for maybe ORTHO + Text)



I'm also sure some one will come along and be more helpful  :slight_smile:

If you put it in the ortho queue then it will use translation as a position on the screen- you need to convert your model's position into screen coordinates using Camera.getScreenCoordinates().

Thanks for the advice, but I'm still having trouble.



Forgive me if this doesn't make much sense. I'm new to java monkey and 3d engines.



but here is the code that I tried and does not work.


       
        Font3D font2 = new Font3D(new Font("Arial", Font.PLAIN, 24), 0.001f, true, true, true);
        Text3D text2 = font2.createText("BillboardNode 1, 2, 3", 50.0f, 0);
        text2.setLocalScale(new Vector3f(0.250f, 0.250f, 0.01f));
        text2.setLocalTranslation(new Vector3f(0,-1.0f,0));
     
        billboard = new BillboardNode("Billboard");
        billboard.setAlignment(BillboardNode.SCREEN_ALIGNED);
    
        Node n1 = new Node();
        n1.attachChild(text2);
        billboard.attachChild(n1);

        n1.setRenderQueueMode(Renderer.QUEUE_ORTHO);
        n1.setCullMode(Spatial.CULL_NEVER);
        n1.getLocalTranslation().set(cam.getScreenCoordinates(n1.getWorldTranslation()));
        n1.updateRenderState();
       
        node.attachChild(billboard);



I'm also curious about a screen aligned billboard node when not in ortho mode.
The text stays directed at the screen but it is all scrunched together at certain
angles. I tried calling rotateBillboard(cam) but it didn't have any effect.

I would be very thankful for any help you can provide.

Don't use billboarded node or anything like that, just regular 2D text, and render it in ortho mode. In your update method, take the world coordinates from the object you're attaching to, and convert to screen coordinates, then apply them as a translation to the text.

Thanks everyone for the help! I was able to get the text to display with fixed size and to track to a sphere that I was animating with a spatial transformer. Here's the code I ended up using.



    protected void simpleInitGame() {       

        ...

        Font2D font2D = new Font2D();

        text2D = font2D.createText("simpleText", 10, 0);
        text2D.setRenderQueueMode(Renderer.QUEUE_ORTHO);
        text2D.setLocalTranslation(100,100,100);
        node.attachChild(text2D);
       
    }

   
    protected void simpleUpdate() {
        if( transformer.getCurTime() > 8-.001) {
            transformer.setCurTime(0);
        }               
        Vector3f v1 = sphere.getWorldTranslation();
        Vector3f v2 = cam.getScreenCoordinates(v1);
        text2D.setLocalTranslation(v2);
     }



Hoorah for  :) endings!