Can I render an object ontop of everything, but under gui?


Because of the size of my guns in my game I need to render them on like a diffrent layer.

So that first I render the 3d stuff. Then on top of that, I render the gun. Just like sky.jm3d tho the opposite way.

Then I render the gui on top of that.

So that when I walk into a wall the gun wont appear to go through.

I know this has been asked before, but the solution does no longer work for me.

I must have a resonable view fustrum and still have my guns not going through walls.

So is there a way to achive this? Maybe modding that sky.jm3d file?

change the following booleans of the material DepthTest, DepthWrite.

DepthTest = false i think.

Nice. I set depthTest to false, and it works!

The gun is renderd before everything else.

Problem is that its renders wrong.

Since it does not care about depth, then it will render the pipe on top of the handle making a very, Very, ugly gun :stuck_out_tongue:

You solved that problem too?

Put this somewhere:

[java]cam.setFrustumPerspective(40, (float)cam.getWidth() / cam.getHeight(), .1f, 1000);[/java]

and change the .1f to whatever suits you. It doesn’t change your FOV like changing the near plane alone does.

Addez said:
I must have a resonable view fustrum and still have my guns not going through walls.

Oops just kidding.
  1. does the gun have multiple nodes inside it ? maybe if its a single node it wont have a problem ?
  2. any screenshot ?

Thanks kidney, but that is the exact thing that I used to do :stuck_out_tongue:

I had that exact line in my mainclass before :stuck_out_tongue:

Scaling it would be possible, but sad. It would be more fun to have the possebility to work with layers…

With multiple nodes, then I think i say no.

Its one mesh loaded once from assetmanager. But the mesh is splited up and animated with diffrent bones in blender.

As for screenshot:

I made and textured that DB shotgun, tell me what you think of it too :wink:

Addez said:
I made and textured that DB shotgun, tell me what you think of it too ;)

Hehe. The colors looks painted by hand, it's just a diffuse map ok?

Lawls :stuck_out_tongue:

I know, but its good to be me :smiley:

Also, the texture used was not really commercial so I will create my own when I get the foundation of the game going :slight_smile:

Can you try it with the gun being “single”, not splitted up in blender. can you merge its parts in blender ?

It looks the shotgun’s geometries aren’t been rendered in correct order.

Ah yea they are merged. ctrl+j so its only one mesh.

recalculate the face normals outside in blender by selecting all verticies (ctrl+a) and ctrl+alt+t ( i think :stuck_out_tongue_winking_eye: ).

Already did that :confused:

Tho It did change a bit when I recalculated again.

But still some parts are too messed up…

If you have triangles overlapping then it will be very difficult to get this to work merely with depth buffer trickery.

If the player can really walk in such a way that they can stick their gun through a wall then you may have to do this with a viewport. You can add a new main viewport and then it will be rendered under the GUI layer but on top of your scene. You have to manage your own root node for the viewport, though. The one that you will attach your gun, too. It won’t be quite as convenient as the normal scene.

…however, the nice thing is that the camera for that viewport won’t move when the other one does… so you won’t have to do anything special to keep the gun in view.

I do this with a custom AppState in Mythruna for object editor. If you get really stuck figuring it out then I might be able to post my OverlayAppState code.

  1. so from what i understood from pspeed if you remove the overlapping vertices, propably with Boolean.Subtract / pressing delete button on vertices it will be solved.

  2. if your gun doesnt move then use an image instead.
1 Like

Yes, if you can somehow arrange your geometry so that no triangles overlap then you might get away with it. As long as you never turn the gun… in which case then use an image.

Or, you can just setup a custom viewport and do whatever complicated geometry you want, turn it, shake it, rotate it, whatever. With the added benefit of not having to move your gun to some position relative to the main camera.

A viewport app state would be something like this… I’m having to clean some things out I depend on in my own code but hopefully it’s close:


public class ViewPortState extends AbstractAppState {

private Camera cam;

private ViewPort view;

private Node root;

public ViewPortState() {


public Node getRoot() {

return root;


public Camera getCamera() {

return cam;



protected void initialize( Application app )


root = new Node( “Viewport Root” );


Camera originalCam = app.getCamera();

cam = new Camera(originalCam.getWidth(), originalCam.getHeight());

view = app.getRenderManager().createMainView( getName() + " ViewPort", cam);


view.setClearFlags(false, true, false);

view.attachScene( root );

// You can leave this out or change it if you have different lighting needs

DirectionalLight light = new DirectionalLight();

light.setDirection( new Vector3f( 1, 0.2f, -1.5f ).normalizeLocal() );






public void render(RenderManager rm) {




public void update( float tpf ) {




I’ve left out the setEnabled() because I have a base class that makes that nicer in my own code and I think it is obvious.

Once added, from anywhere in your app that you can access the state manager then you can easily look-up this class and get the root node. It’s self-managing once attached.


That is EXACLY what I want to do :smiley:

But Im a bit stuck at an error:

java.lang.IllegalStateException: Scene graph is not properly updated for rendering.
Make sure scene graph state was not changed after
rootNode.updateGeometricState() call.
Problem spatial name: Root

To make another viewport I did this:
[java]Camera cam_n = MainClass.getCam().clone();
cam_n.setLocation(new Vector3f(0,0,0));
cam_n.setRotation(new Quaternion());

ViewPort view_n = MainClass.getRender().createMainView("View of camera #n", cam_n);


I feel like Im missing to register the new view port or something. Didnt find any instructions in wiki on how to do this so
Im hoping you know the answer? :/

Did you use my app state?

You have to maintain the state of your own root node when you have your own viewport. And that app state will take care of it for you.

Somewhere in your app setup, call getStateManager().attach( new ViewPortState() );

Then you can use getStateManager().getState( ViewPortState.class ).getRootNode() to get its root node.

And app state is the easiest way to do the junk required on update() and render() for an ViewPort.