Spatials in Nifty Gui


I have recently considered switching to the Lemur GUI but I decided not to do so as I already knew Nifty and there didn’t seem to be any features that I really needed at the time. If, however, the best solution to this issue is to switch GUI libraries, then please say so.

Right now, my game has a simple hotbar with three-dimensional objects attached to the guinode (without the help of Nifty) representing the items in the inventory that can be switched through via keys on the keyboard. I would like to implement a full-fledged inventory system via a gui library of some sort. As such, I need some way to add spatials to a nifty gui in such a way that I can allow the user to interact with them using the mouse. Is this possible with Nifty? If so, how? If not, then is Lemur the best option? If not, then what?

Thank you.

For Nifty, there are only three ways to include a JME spatial in a nifty screen:
-render it behind nifty
-render it in front of nifty
-render it to a texture and somehow get the image into nifty

Do note: if you do choose to use something like Lemur, you don’t need to abandon Nifty. You could use Lemur for just that parts that it makes sense. It’s not a big library and it’s separated into separate modules internally to be useful for lots of things (3d scene picking, input mapping, etc.) even if you don’t use the whole library. Though in this case you’d probably be using quite a bit of it.

Setting up a grid of spatials in Lemur wouldn’t be overly difficult. There is one missing component that I haven’t written yet that would make it really pretty easy. But it’s not overly difficult to write, either. (I’d explain but it wouldn’t make sense until you understood more about the Lemur architecture… so it will wait. :slight_smile: )

I guess it’s up to you whether it would be easier just to line up a JME Spatial layer and a Nifty GUI layer rather than learning a whole new UI. Or you could start that way and switch the JME Spatial layer to something Lemur-managed if you get frustrated.

For general scene picking, there is really nothing better than Lemur in my opinion. So you might choose to use it just for that. (It let’s you add mouse listeners to any spatial, basically, and then the picking is done for you.)

Does Nifty include a method to get the guinode coordinates of an on-screen item? If not, then what is the recommended way to render it behind or in front of nifty? Also, is there a built-in way to check what guinode spatial a user clicked on? I know there is picking for the regular 3D rootnode.

Not sure as I haven’t used nifty in 5 years or more. But the coordinate systems should be the same.

The guiNode is rendered behind by default, I think. You’d create another post view port if you wanted to render on top.

Picking in 2D is the same as 3D except for how you construct your ray. It’s much easier in 2D.

Lemur would let you avoid all of that, though. If you don’t want to initialize lemur itself and just want to use the picking support, just attach the MouseAppState. Then for any Spatial you want to receive mouse events for…

MouseEventControl.addMouseListeners(spatial, new DefaultMouseListener() {
    protected void click( MouseButtonEvent event, Spatial target, Spatial capture ) {
        System.out.println("I've been clicked:" + target);

It supports more than click, that’s just the example.


…the “Direct Usage” section has exactly what you’d want.

Edit: note that if you do create your own viewport then you will need to let Lemur’s MouseAppState know about it.