How can I add a 3D geometry to a Lemur GUI?

Hello,

I am trying to create a minecraft-like inventory system using Lemur. To do this, I have geometries that represent inventory items added to a SpringGridLayout.

Here is my code:

@Override
protected void setupGui(){
    container = new Container(new SpringGridLayout(Axis.X, Axis.Y));

    container.addChild(new Label("Inventory"), 0, 0);

    Material mat = new Material(getApp().getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
    mat.setColor("Color", ColorRGBA.Green);

    for(int x=0;x<8;x++){
        for(int y=1;y<=4;y++){
            Geometry geometry = new Geometry("inventory-" + x + "," + y, new Box(1, 1, 1));
            geometry.setMaterial(mat);
            geometry.setLocalScale(16);
            geometry.rotate(new Quaternion().fromAngleAxis(toRadians(-25), Vector3f.UNIT_X));
            geometry.rotate(new Quaternion().fromAngleAxis(toRadians(-45), Vector3f.UNIT_Y));

            Node node = new Node(); //a similar error that requests a node occurs when the inventory item is attached directly
            node.attachChild(geometry);

            container.addChild(node, x, y);
        }
    }

    container.setLocalTranslation(getApp().getCamera().getWidth() / 2 - container.getSize().length() / 2, getApp().getCamera().getHeight() / 2 - container.getSize().getY() / 2, 0f);
    getApp().getGuiNode().attachChild(container);
}

private float toRadians(float degrees){
    return (degrees / 180) * FastMath.PI;
}

When I run it I get the following error:

java.lang.IllegalArgumentException: Child is not GUI element.
    at com.simsilica.lemur.component.SpringGridLayout.addChild(SpringGridLayout.java:326)
    at com.simsilica.lemur.component.SpringGridLayout.addChild(SpringGridLayout.java:392)
    at com.simsilica.lemur.Container.addChild(Container.java:112)
    at src.john01dav.lemurlearning.InventoryGuiAppState.setupGui(InventoryGuiAppState.java:40)
    at src.john01dav.lemurlearning.GuiAppState.initialize(GuiAppState.java:15)
    at com.jme3.app.state.AppStateManager.initializePending(AppStateManager.java:251)
    at com.jme3.app.state.AppStateManager.update(AppStateManager.java:281)
    at com.jme3.app.SimpleApplication.update(SimpleApplication.java:236)
    at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:151)
    at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:193)
    at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:232)
    at java.lang.Thread.run(Thread.java:745)

The only reason I would use Lemur over Nifty (or even just somehow embedding Swing) is because of it’s inherent ability to use 3D objects as described in other threads.

In order to be managed by a layout, as addChild() would do, the child has to be what Lemur considers a “GUI element”. But that’s not as onerous as it sounds.

Any JME Spatial can be a “GUI element” simply by adding a GuiControl to it. You will need to set a preferred size on the GuiControl. After that things should “just work”.

On my to-do list is to write something like IconComponent but for spatials instead of images. This would let one pop a 3D object into any regular GUI element’s component layers (like Button, Label, etc.).

5 Likes

@pspeed I have to say … I have 3 technologies on my gui right now … tonegodgui, javafx, and lemur. After the coding I have been doing this past week I have just decided to scrap tonegodgui cause lemur KICKS IT’S ASS!!

1 Like

Thanks! :slight_smile:

1 Like

I also think about replacing tonegodGUI on lemur in my game, which use the mix javafx + tonegoGUI :slight_smile:

3 Likes

The great thing about lemur is that components don’t need to be attached to a Screen like in tonegodgui … another great feature is in my space game all the ship models have a GUIControl on them so cloning them and dropping them into Information windows while they spin in a preview pane is literally one line of code. Having a unified mouse/animation event handler for the gui and the game assets is another cool feature … I can go on and on.

3 Likes

Whee… it’s neat to see someone praise specific features I built in for exactly the reasons I built them. :slight_smile: Thanks, again.

3 Likes

By the way your network code has been running in production for over a week now … no glitches, no crashes :slight_smile:

1 Like

At some point you’re going to need a room guys…

Did you try the InputMapper? That’s gonna burst your bubble :wink:

And he means that in a good way. Not in a “you will be disappointed” way.

oh … it can mean that?
I meant “it’s gonna blow your mind”
Is that ok ? :slight_smile:

Yes, that’s better.

“Burst your bubble” at least in english means that “you were all excited and something disappointed you”. Like being happy because someone handed you a balloon but then it pops.

1 Like

I would rather just use Lemur and drop a mouse listener on my spatial thank you very much :stuck_out_tongue:

InputMapper is part of Lemur. It allows you to map keys, mouse input, joystick buttons, etc. to listeners in a nice way. It supports key combos and such.

2 Likes