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)
model.setDepthTest(False)
model.setDepthWrite(False)

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)
model.setDepthTest(False)

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)
background.setDepthWrite(False)

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)
background.setDepthWrite(False)

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.

David

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 = base.win.makeDisplayRegion()
# Set up the piece camera, and parent it to the main camera
camera = Camera('pieceCam')
camera.setLens(base.camLens)
pieceCamera = NodePath(camera)
pieceCamera.reparentTo(base.camera)
pieceRegion.setCamera(pieceCamera)
# Set a mask for the camera so it will selectively render the model
camera.setCameraMask(pieceMask)
# Hide render from being seen by the new camera
render.hide(pieceMask)
# Hide the model from the main camera
model.hide(self.renderMask)
# Show the model in the new camera
model.showThrough(self.pieceMask)