Put OnscreenText on 3D scene

I am trying to put some text on the 3D scene graph using:

self.m = loader.loadModel(‘data/streets/access.bam’)

        self.m.reparentTo(np.attachNewNode('streetAccess-'+str(streetId)))
        self.m.setPos(pos)
        self.m.setHpr(hpr)
        self.streetId = streetId
        
        self.t = OnscreenText(scale=3, text=self.GetStreetName(),fg=(1,1,1,1), decal=True)

        self.t.setTextureOff()
    
        #self.t.setBillboardAxis()
        
        self._d = self.m.attachNewNode('text')
        self._d.setPos(-20, 0, 15)
        self._d.setH(90)
        self.t.setDepthTest(True)
        self.t.setDepthWrite(True)
        self.t.setDepthOffset(10000)
    
        self.t.reparentTo(self._d) 

It works but the text is inside the street access (self.m) like this:


| I
| T
| S
| H
| E
| R

E

And it’s supposed to be:


H|
E|
R|

E

However, setX, setY and setZ for self.t nor for self._d can seem to put it in the right place :imp:

Since the OnscreenText class is really designed for 2-D text placement, you’ll probably be better off with the lower-level TextNode class instead, which is less likely to get in your way. (OnscreenText is just a thin wrapper around TextNode, with additional interfaces that make it more convenient for some 2-D operations, but which don’t help you for 3-D text.)

I think your particular problem is one of alignment. You want to set the text alignment property to TextNode.ARight and set its position to the right side of the box.

David