Draw line

i need show hp above monster
got the idea to draw a line
found this code

import com.jme3.app.SimpleApplication;
import com.jme3.asset.AssetManager;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.renderer.RenderManager;
import com.jme3.scene.Geometry;
import com.jme3.scene.Mesh;
import com.jme3.scene.Node;
import com.jme3.scene.VertexBuffer;
import com.jme3.scene.shape.Box;
import com.jme3.util.BufferUtils;

public class Main extends SimpleApplication {

    public static void main(String[] args) {
        Main app = new Main();

    public void simpleInitApp() {
        Vector3f[] lineVerticies=new Vector3f[5];
        lineVerticies[0]=new Vector3f(2,0,0);
        lineVerticies[1]=new Vector3f(-1,0,1);
        lineVerticies[2]=new Vector3f(0,1,1);
        lineVerticies[3]=new Vector3f(1,1,1);
        lineVerticies[4]=new Vector3f(1,4,0);

    public void plotLine(Vector3f[] lineVerticies, ColorRGBA lineColor){
        Mesh m = new Mesh();

        m.setBuffer(VertexBuffer.Type.Position, 3, BufferUtils.createFloatBuffer(lineVerticies));
        short[] indexes=new short[2*lineVerticies.length]; //Indexes are in pairs, from a vertex and to a vertex
        for(short i=0;i<lineVerticies.length-1;i++){
        m.setBuffer(VertexBuffer.Type.Index, 2, indexes);

        Geometry geo=new Geometry("line",m);
        Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
        mat.setColor("Color", lineColor);
    public void simpleUpdate(float tpf) {
        //TODO: add update code

    public void simpleRender(RenderManager rm) {
        //TODO: add render code

but how to make the line thick?

maybe there is some other way to do it?

i would not do Mode.Lines as it had some issues in some LWJGL or OpenGL versions as i remember.

There are some ways like:

  • Make Quad rotated always to camera in 3d space
  • Use Lemur GUI and add its elements into 3d View
  • Use ANY GUI and find 2d screen position of 3d object, and just place hp bar in that position in 2d space
  • maybe some more ideas, but its just some of ideas quickly.

how to make a line with a lemur and place a monster on top of the monster?

That’s not really a line, though… it’s like a progress bar, right?


You probably mean a box.

You can use a Quad class which creates a 2D rectangle and fill it with red color to represent the health percentage. You can attach the quad to a Node object and make it follow your monster’s location.

And if a box like a health bar is what you mean then this would probably work:

More info on getting started with Lemur here:

Latest version is: 1.16.0

1 Like