Displaying a Model on top of everything

Here’s what’s happening:

And here is what I want

I’m drawing the gun in front of the camera, so when walls are too close, it gets cut by the wall (as would be expected). How do I force it to be drawn on top of everything?

I’ve tried turning off the depthWrite, but since the model overlaps itself, the gun isn’t drawn correctly
This is the same with nodePath.setAttrib(DepthTestAttrib.make(RenderAttrib.MNone))and MAlways and MNotEqual

Is there a way to maintain the depth buffer order of the model (so it’s drawn right) and move that to the top?

Why don’t you render the as 2d…it’s easier

If I reparent it to render2d, it doesn’t get drawn correctly.

I have the same problem. I solved it partially by reparenting to aspect2d as suggested, but it doesn’t look like it should.

I guess it can be solved by the bin order…
Maybe you should look at:

in C++ it looks like

nodePath.set_bin(“foreground”, 0);

I think python is:

nodePath.setBin(“foreground”, 0)

see if that helps

I added my nodePath to the “fixed” bin, as suggested in the manual page in the link, and it worked. Thank you!

As expected, altering the bin causes problems

So I looked into the display regions and copy pasta’d what they had.

    # --- Create the display region for the weapons
        dr2 = base.win.makeDisplayRegion(0, 1, 0, 1)

        render2 = NodePath('render2')
        cam2 = render2.attachNewNode(Camera('cam2'))
    # --- Load Weapon Model
        self.weapon = loader.loadModel("mp5")

If I just run the sample code by itself, everything works great. When I try to incorporate the code into my modules, I get an error creating the camera:

line 239, in createDisplayRegion
cam2 = render2.attachNewNode(Camera(‘cam2’))
TypeError: init() takes exactly 3 arguments (2 given)

I don’t understand why this error happens. The APIs for the camera class even describe creating a camera by passing a string…

At least in c++ you need to pass a Lens as the second parameter.
Dunno if it’s overhidden in the python layer, but by the error message I could guess it’s not (overhidden).

So you probably should try to pass a Lens in camera construction…

I looked in my own code and I use base.makeCamera(buffer).
You might try:


I don’t know if you can substitute a display region in place of a texture buffer, but I think they inherit from the same class so it might work.

You guys sure replay fast.
The problem I was having with the creating a Camera was my fault. I had named my camera class ‘Camera’ so when I thought I was making a Camera node, I was actually making an object of my custom class.

Here’s the code that works for me, in case someone else sees this thread:

        dr2 = base.win.makeDisplayRegion(0, 1, 0, 1)

        render2 = NodePath('render2')
        tempGunCam = Camera('cam2')
        self.gunCam = render2.attachNewNode(tempGunCam)
        self.weaponCamLens = tempGunCam.getLens()

        self.weapon = loader.loadModel("mp5")

The only problem now is that the gun’s position is fixed (it doesn’t need to follow the player since it’s drawn on its own display region that sits on top of render), so the lighting never changes on it. Maybe I’ll fake this by adding the lighting to render2, and then moving the camera and the gun in the same way that I was moving it before. How taxing would it be to draw every light in both display regions? Does anyone have a better solution?