Render in front [Solved]

I’m making my interactive portfolio in panda3d and I have a 3d model viewer in it. I want to make it so the model always gets rendered in front so that spinning the model won’t make it clip into the ground. I tried the way of doing it in the manual which is the following:

model.setBin("fixed", 40)

It works in that it renders the model on top but now parts of the model show through.

I think I understand why this is happening but I still don’t know how to get the effect that I want. Is there a better way of making models render in front other than the one in the manual?

Two ideas:

  • Call flattenStrong on the model.
  • or, make sure the background is in the background bin instead of setting the car to the foreground bin.

The problem is that your model involves self-occluding pieces, so you will require the depth buffer to properly render your model. (Calling flattenStrong() won’t change this property of the model.) However, your model is simple enough that you might get away with back-to-front sorting instead of depth buffer.

cbMgr = CullBinManager.getGlobalPtr()
cbMgr.addBin('btf', cbMgr.BTBackToFront, 45)
model.setBin('btf', 0)

If that doesn’t work, you might be able to go the other route, which pro-rsoft hints at: change the state of your background instead of your model. This will work only if your background doesn’t involve self-occluding pieces:

background.setBin('background', 0)

If your background has self-occluding pieces but is otherwise simple, you might try back-to-front sorting there:

cbMgr = CullBinManager.getGlobalPtr()
cbMgr.addBin('back_btf', cbMgr.BTBackToFront, 0)
background.setBin('back_btf', 0)

Finally, if both your background and your model are too complex to play games like this, then you can solve this problem with DisplayRegions. You’ll need to create another DisplayRegion to render your model, and set it to clear the depth buffer.


Thanks David, the DisplayRegion method worked, I’m afraid my models are a bit too complex to simply mess with the bins. I’ll update the manual with this information.

renderMask = BitMask32(2)
pieceMask = BitMask32(1)

# Set up the main display region of the piece
pieceRegion =
# Set up the piece camera, and parent it to the main camera
camera = Camera('pieceCam')
pieceCamera = NodePath(camera)
# Set a mask for the camera so it will selectively render the model
# Hide render from being seen by the new camera
# Hide the model from the main camera
# Show the model in the new camera