How to render 3d models properly in GUI (aspect2d/render2d/pixel2d)

from panda3d.core import *
from direct.showbase.ShowBase import ShowBase

base = ShowBase()

model = base.loader.loadModel("panda")
model.reparentTo(base.aspect2d)
model.setPosHprScale(0,0,-0.7, -30,30,0, 0.15,0.15,0.15)

base.run()

Result:

I have a program where I need 3d gizmos for manipulating the camera view, very similar to most 3d modelling programs.
I could attach it to the camera and set it to be rendered in front of everything else in the render scene graph, but the catch is these widgets need to be rendered orthographically, while the camera view can either be ortho or perspective.
I guess a custom DIsplayRegion can be set up, but that seems more work than needed here.
So I just tried to parent the widget geometry to aspect2d instead. Seems to work, except culling is not right.
Is there a solution to this, short of using custom display regions?

Panda disables z-buffering by default on render2d, because models in render2d are not usually self-overlapping.

To re-enable it on a specific model:

model.setDepthTest(True)
model.setDepthWrite(True)

Is this mentioned anywhere in the manual? It really should be. Sure, my use case is not common, but 3d elements in UI not so.

1 Like

I could have sworn it was, but I can’t find it from a quick search. I’ve made a note to add it here.

2 Likes