Point and line sizes for meshes

Hello,

I’m actually developing an application that has to deal with points clouds and line sets. In order to render the two components, i’m using underlying meshes as follows:

Points cloud:

	      Material mat = new Material(application.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
      mat.setBoolean("VertexColor", true);
      mat.getAdditionalRenderState().setBlendMode(BlendMode.Off);
      mat.getAdditionalRenderState().setFaceCullMode(FaceCullMode.Off);
      
      Mesh m = new Mesh();
      m.setMode(Mode.Points);
      m.setBuffer(VertexBuffer.Type.Position, 3, coords);
      m.setBuffer(VertexBuffer.Type.Color, 4, colors);
      m.setBuffer(VertexBuffer.Type.Size, 1, sizes);
      m.setStatic();
      m.updateBound();
      
      geometry = new Geometry("Point Cloud", m);
      geometry.setShadowMode(ShadowMode.Off);
      geometry.setQueueBucket(Bucket.Opaque);
      geometry.setMaterial(mat);
      geometry.updateModelBound();

Line set:

Mesh line = new Mesh();
	      line.setMode(Mesh.Mode.Lines);

	      // Line from 0,0,0 to 0,1,0
	      line.setBuffer(Type.Position, 3, new float[]{ (float)pos.getX(), (float)pos.getY(), (float)pos.getZ(), (float)orus3dTrajectoryPreviousPos.getX(), (float)orus3dTrajectoryPreviousPos.getY(), (float)orus3dTrajectoryPreviousPos.getZ()});
	      line.setBuffer(Type.Index, 2, new short[]{ 0, 1 });
	      line.updateBound();

Material trajectoryMat = new Material(viewer.getJMEApplication().getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");

	      trajectoryMat.getAdditionalRenderState().setWireframe(true);
	      trajectoryMat.getAdditionalRenderState().setLineWidth(3.0f);

      com.jme3.scene.Geometry lineGeom = new com.jme3.scene.Geometry();

      lineGeom.setMesh(line);
      lineGeom.setMaterial(trajectoryMat);

My two concerns are about the size on points an lines. I would like to dynamically set the point size and the line width oh the displayed meshes. However, the methods related to points size and line width are deprecated within the JMonkey documentation.

For the point size, it is recommended to use shaders properties to deal with the point size I also tried another solution that was to set GL11 values as follows:

      if (GL11.glIsEnabled(GL32.GL_PROGRAM_POINT_SIZE)) {
      GL11.glDisable(GL32.GL_PROGRAM_POINT_SIZE);
  }
  GL11.glPointSize(getPointDisplaySize());

This method work for the first call to GL11 bu throws an access violation exception if i try to run it another time.
According to the mesh line width, the previous code (related to mesh line) does just do nothing (the mesh lines are always 1 pixel width.)

Can someone tell me how to handle dynamic points size and line width for meshes ?

Thanks a lot,

Julien

2 Likes

That should work. Not sure why it isn’t working for you.

2 Likes

I dynamically set point size and line width in the Material, like so:

pointMaterial.setFloat("PointSize", size);
lineMaterial.getAdditionalRenderState().setLineWidth(effectiveLineWidth);

I always use my own material (not Unshaded.j3md) but I’ve forgotten why.

Also, be aware that there’s an open issue regarding point sizes: issue 878

1 Like

Did you solve the issue you were having?

I also need to set line width on a Line mesh but it does not work for me too.

my code:

private Geometry createLine(Vector3f start, Vector3f end) {
        Material mat = GuiGlobals.getInstance().createMaterial(ColorRGBA.Red, false).getMaterial();
        mat.getAdditionalRenderState().setWireframe(true);
        mat.getAdditionalRenderState().setLineWidth(5);
        Geometry line = new Geometry("line", new Line(start, end));
        line.setMaterial(mat);
        return line;
    }

tried with both Unshaded and Lighting material.

1 Like

Hmm, to get sure if it is not a problem with Line mesh I also tried it with a Box mesh and yet not working. Previously this was working for me.

What version do you use? 3.3 right?

Line width work fine for me. I already use it for editor terrain paint circle (made from lines with some bigger width and i seen difference) and for sphere wireframe it work for me too.

maybe because i use LWJGL3 and you might use 2?

however i did not try change it dynamically…

Ah… just remembered why it does not work :man_facepalming:

it’s because of

settings.setRenderer(AppSettings.LWJGL_OPENGL3);

OpenGL 3 core profile only supports line widths of 1 (do not know why), I am sure I had read it somewhere before.

2 Likes

OK, works fine !! with

settings.setRenderer(AppSettings.LWJGL_OPENGL45);

Hello,

I’ve tried this code:

Material mat = new Material(viewer.getJMEApplication().getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
mat.getAdditionalRenderState().setWireframe(true);
mat.getAdditionalRenderState().setLineWidth(5);
Geometry lineGeom = new Geometry("line", new Line(start, end));
lineGeom.setMaterial(mat);

With various LWJGL renderer and here are the results:

LWJGL_OPENGL2: Line width can be modified
LWJGL_OPENGL3: Line width cannot be modified
LWJGL_OPENGL33: Line width cannot be modified
LWJGL_OPENGL4: Line width cannot be modified
LWJGL_OPENGL44: Line width cannot be modified
LWJGL_OPENGL45: Line width cannot be modified

I’m using jme3-lwjgl3 for the LWJGL rendering (the jme3-lwjgl jar is not in my classpath)

played a little arround this.

im using jme3-lwjgl3 jar, and

settings.setRenderer(AppSettings.LWJGL_OPENGL45)

then Line width cant be modified.
and log line is:

  • OpenGL Version: 4.5.13476 Core Profile Forward-Compatible Context 22.19.171.1024

//settings.setRenderer(AppSettings.LWJGL_OPENGL45)

then Line width can be modified.

in log line there is:

  • OpenGL Version: 4.5.13476 Compatibility Profile Context 22.19.171.1024

the only difference in log line i see is:

Compatibility Profile Context

vs

Core Profile Forward-Compatible Context

im not sure about difference and if this is the reason, but if openGL version is the same, then why in first it dont work and in second it work?

can someone explain difference here.

btw. @seinturier you said before AppSettings.LWJGL_OPENGL45 works for you, what did you changed? just PointSize vs LineWidth right?

can you try like me then just remove settings.setRenderer() line and look.

See here:

apparently, Line width has been @deprecated for some time. “forward-compatibility” basically means “only stuff that is guaranteed to still work next version,” whereas “compatibility” means “Stuff that worked as of 3.0, but was removed from 3.1”