Text as a 3d object

Is there a way to create Text nodes (or something similar) that allows text to be drawn in a perspective view like any other Spatial, or is it restricted to ortho mode? I’ve been trying to draw a model’s skeleton with each joint labelled with its name.



I worked around it myself by changing LWJGLRenderer and LWJGLFont so that Text is drawn normally if it’s not in the ortho queue - go to http://www.chaosdeathfish.com/jme/textpatch.jar for the code.

There is no need to do any of that. Its quite simple really. What you need to do is set the local translation of the text you want to display to the ScreenCoordiantes of the model/joint you want to display.



Vector3f textPosition = display.getRenderer().getScreenCoordinates(joint1.getWorldTranslation);
if (textPosition.z > 1) {
  text.setLocalTranslation(textPosition);
}



I can't remember if the z needs to be less than 1 or more than...otherwise, the spatial is behind the camera.

I think thats what you want...But distance isn't taken into account (and for the better, so that you can read the text!).

Hope that helps,
DP

The only problem I can see with that is that you have to update the screen coordinates whenever the camera moves. And I like the text shrinking, it helps see the perspective of the skeleton (which is difficult when you’re just using lines :slight_smile: )



I thought my fix might also be useful for (e.g.) interactive textual displays in the 3d world - a computer monitor whose display changes, for instance.



Thanks for the reply though :slight_smile:


The only problem I can see with that is that you have to update the screen coordinates whenever the camera moves. And I like the text shrinking, it helps see the perspective of the skeleton (which is difficult when you're just using lines)


Well, thats true, you do need to update that everytime the camera moves. Just simply attach a controller to the text spatial that does that...its no biggie.

About the distance thing, Im sure you can scale the text according to the distance the object is away from the camera, its also better, because you can then cap the text so you can still read it from a distance. Thats how most games do it nowadays, e.g. Metal Gear Solid with pickups, TrankMania with names of players.

DP :)

You should be able to use stuff that uses text as textures (like UIText does, I think) to do what you want. But I havn’t tested this yet.