[SOLVED] Attach lemur Widget Components(Buttons,labels,etc..) to Spatials Node

Hi there ,

Is there a way to attach Lemur GUI widgets(Labels or buttons ) to a spatial node rather than a guiNode ?

what i am trying to do is to attach the Water Life Guard : 100 window container to this NPC Node :slight_smile:

Code:

public void addInContainer(Node guiNode,String name,float Vx,float Vy,float Vz,float scaleX,float scaleY,float scaleZ,ColorRGBA color,String text){
        
        Container window = new Container();
        guiNode.attachChild(window);
            
    
        Label guitext=new Label(text);
                guitext.setName(name);

        guitext.setColor(color);
       
        window.setLocalScale(new Vector3f(scaleX,scaleY,scaleZ));

        window.addChild(guitext);
        window.setLocalTranslation(new Vector3f(Vx , Vy, Vz));

    }
        addInContainer(guiNode,"NPCLifeText" ,settings.getWidth()-250f, settings.getHeight(), nPc.getLocalTranslation().getZ(), 1.5f, 1.5f, 1.5f, ColorRGBA.White, "Water Guard Life : "+Mars.NPCLife);

Yes, you can attach to any Node.
You may consider adding BillboardControl to that Node as well:

        BillboardControl control=new BillboardControl();
        myNode.addControl(control);

Alsop when attaching to other Nodes, make sure you adjust the scaling of your lemur window

1 Like

As indicated above while I was typing…

Yes, a Lemur GUI element is just like any other spatial but things to consider:

  • it’s in screen space so usually HUGE for a 3D scene and needs to be scaled
  • it’s in the x,y plane and so will usually need to be rotated to face the camera using something like a billboard control

There is otherwise nothing special about it as compared to adding to the guiNode.

1 Like

@pspeed @adi.barda it works , thank you for replying.

My Code (In case one needs it):
Adding to the Node :

        addInContainer(((Node)nPC.getChild("NPCLife")),"NPCLifeText" ,0f,0f, 0f, 5f, 5f, 5f, ColorRGBA.White, "Water Guard Life : "+Mars.NPCLife);

In simpleInitApp():

 private void addNPC() {
        nPC=(Node) rootNode.getChild("NPC 1");
        CharacterControl NPC_control= new CharacterControl(new BoxCollisionShape(5f, 5f, 6f), 0.5f);
  
        NPC_control.setJumpSpeed(10f);
        nPC.addControl(NPC_control);
        ((Node)nPC.getChild("NPCLife")).addControl(new BillboardControl());
        nPC.addControl(new NPCAutoControl(player,NPC_control,cam,rootNode,physics,assetManager));
        physics.getPhysicsSpace().add(nPC);
    }

In Physics Listener :

 new CollisionerCondition(pce, "Laser Gun", "NPC 1") {
            @Override
            public void execute() {
                if(NPCLife > 0){
                        ((Label)((Node)nPC.getChild("NPCLife")).getChild("NPCLifeText")).setText("Water Guard Life : "+(--NPCLife));

                }else{
                    nPC.attachChild(effect(5f, 3f, ColorRGBA.Red, ColorRGBA.Yellow));
                    nPC.removeControl(NPCAutoControl.class);
                    physics.getPhysicsSpace().remove(nPC);
                    physics.getPhysicsSpace().remove(nPC.getControl(CharacterControl.class));
                }
            }
        };

Note(trick) : when i added the Container directly to the NPC Node , i found that the NPC rotates 180 degrees , so the viewDirection of its CharachterControl is assigned to the unit vector of camera(cam direction), i cannot actually re-modify the BillBoardControl class , So i have added another Node inside the NPC node to make it freely rotateable to the direction of camera to be visible at any point on the viewport without rotating the NPC model:

Node NPCtext=new Node("NPCLife");
NPCtext.setLocalTranslation(0f,-100f,-500f);
nPC.attachChild(NPCtext);
//then
addInContainer(((Node)nPC.getChild("NPCLife")),"NPCLifeText" ,0f,0f, 0f, 5f, 5f, 5f, ColorRGBA.White, "Water Guard Life : "+Mars.NPCLife);
1 Like