DirectEntry parented to Render

Is it possible to attach a DirectEntry object to something other than aspect2d? I’m constructing the DirectEntry using

retitle = DirectEntry(text="", scale=0.5,
                              initialText="test", numLines=1, focus=1, text_fg=(0.5, 0, 0, 1),
                              frameColor=(1, 1, 1, 0.1), width=5, parent=base.render)

But then nothing shows on screen. If I change ‘parent’ to base.render2d, I can see the DirectEntry box, but not type into it. If I use base.aspect2d, I can see and enter text into it. However, I don’t want the DirectEntry in 2D space. The idea is that a cube in 3D space has a DirectEntry field next to it so that you can rename the box, and that rename field will move with the box.

I’m only a day into this project, so I don’t have much more code to share. I’m already stuck just trying to get a DirectEntry to work on 3D space. Would appreciate any advice you can give!

I see two problems at the moment, offhand:

First, when you construct your DirectEntry, you don’t seem to be setting a position, meaning that it presumably ends up at (0, 0, 0). This is fine under “aspect2d” or “render2d”–but not under “render”, or a least, not under the default conditions of render.

You see, the default 3D camera is also located at (0, 0, 0), and thus, presuming that it’s not moved, anything placed there is too close to it to be seen.

Your DirectEntry might thus become visible if you move it along the y-axis by some distance; how far I’m not sure offhand, as I don’t know the default size of a DirectEntry in world-units.

The other problem is that, as you’ve found, I believe that DirectGUI objects only by default work properly when parented below aspect2d.

A quick search turned up this old post–I don’t know whether it’s still accurate, but it may be, and it offers some information that might aid you in getting your DirectEntry to work:

Now, I wouldn’t be surprised if the default MouseWatcher is fine in your case, as you’re not creating a new window.

However, it may be that what you’re lacking is a “PGTop” node.

Conversely, a little more searching turned up the neat trick described and shown in this thread:

Thanks, @ Thaumaturge! That second link is exactly what I needed. It’s quite an advanced technique. I’m glad I asked because I was probably not going to figure that out on my own.

1 Like