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

1 Like

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