[SOLVED]How to switch geometry's mesh by setMesh?

I make a custom lod. But display state not change after setMesh.Do you know why?

@Override
public void setLodLevel(int lodLevel) {
	if (lodMeshs.length > lodLevel && lodMeshs[lodLevel] != getMesh() && lodMeshs[lodLevel] != null) {
		System.out.println("PTSGeometry.setLodLevel()..." + lodLevel);
		setMesh(lodMeshs[lodLevel]);
		updateModelBound();
		updateGeometricState();
	}
}

You were more on the right track here to have LOD for point cloud.
Have several meshes and switch them.
Why it doesn’t work, is another story. First you don’t need the updateGeometricState().
How do you build your mesh?

i just new mesh.

private Mesh[] getLodMeshs(int vCount, float[] vertex, float[] colors) {
	Mesh[] meshs = new Mesh[4];
	Mesh m0 = new Mesh();
	m0.setMode(Mode.Points);
	m0.setBuffer(Type.Position, 3, BufferUtils.createFloatBuffer(vertex));
	m0.setBuffer(Type.Color, 4, BufferUtils.createFloatBuffer(colors));
	m0.setStatic();
	m0.updateBound();
	meshs[0] = m0;

	meshs[1] = getReductedMesh(0.6f, vCount, vertex, colors);
	meshs[2] = getReductedMesh(0.9f, vCount, vertex, colors);

	Mesh m3 = new Mesh();
	m3.setMode(Mode.Points);
	meshs[3] = m3;

	return meshs;
}

private Mesh getReductedMesh(float reduction, int vCount, float[] vertex, float[] colors) {
	int reductionLevel1 = (int) (vCount * reduction);
	float[] vertexLevel1 = new float[reductionLevel1 * 3];
	float[] colorLevel1 = new float[reductionLevel1 * 4];
	int j;
	for (int i = 0; i < reductionLevel1; i++) {
		j = (int) (i / 0.5f);
		if (j * 3 >= vertex.length) {
			continue;
		}
		vertexLevel1[i * 3] = vertex[j * 3];
		vertexLevel1[i * 3 + 1] = vertex[j * 3 + 1];
		vertexLevel1[i * 3 + 2] = vertex[j * 3 + 2];
		colorLevel1[i * 4] = colors[j * 4];
		colorLevel1[i * 4 + 1] = colors[j * 4 + 1];
		colorLevel1[i * 4 + 2] = colors[j * 4 + 2];
		colorLevel1[i * 4 + 3] = colors[j * 4 + 3];
	}

	Mesh lodMesh = new Mesh();
	lodMesh.setMode(Mode.Points);
	lodMesh.setBuffer(Type.Position, 3, BufferUtils.createFloatBuffer(vertexLevel1));
	lodMesh.setBuffer(Type.Color, 4, BufferUtils.createFloatBuffer(colorLevel1));
	lodMesh.setStatic();
	lodMesh.updateBound();

	return lodMesh;
}

And I save meshs in my geometry.

public class PTSGeometry extends Geometry {

private Mesh[] lodMeshs;

public PTSGeometry(String name) {
	super(name);
}

@Override
public void setLodLevel(int lodLevel) {
	if (lodMeshs.length > lodLevel && lodMeshs[lodLevel] != getMesh() && lodMeshs[lodLevel] != null) {
		System.out.println("PTSGeometry.setLodLevel()..." + lodLevel);
		setMesh(lodMeshs[lodLevel]);
		updateModelBound();
		updateGeometricState();
	}
}

@Override
public void read(JmeImporter im) throws IOException {
	super.read(im);
}

@Override
public void write(JmeExporter ex) throws IOException {
	super.write(ex);
}

public Mesh[] getLodMeshs() {
	return lodMeshs;
}

public void setLodMeshs(Mesh[] lodMeshs) {
	this.lodMeshs = lodMeshs;
}

}

The mesh didn’t really change.

If the mesh changes then what’s displayed will change… unless the mesh is really showing the same thing or you have another geometry in the same place with the same mesh or something. Too many things we can’t see.

But if you try a simple test case with a single geometry and multiple meshes you will see that swapping them will change the display.

Which method to swapping them?

Geometry.setMesh()

…the only way to change the mesh of a geometry.

But now my problem is that geometry no change effective after swap the mesh.:sob:

No. Your problem is something else.

Repeating myself only once: put together a simple test case with ONE GEOMETRY and TWO MESHES. Try it. Post the WHOLE CLASS here. Your problem is something else not in the code you’ve shown… as I already said.

There is a 0.00001% chance that you’ve found a bug in JME… in which case we’d need such a test case anyway.

Thank you very much, I got your message.

Yes, you are right, it changed normally.

public class TestSwitchMesh extends SimpleApplication implements ActionListener {

	public static void main(String[] args) {
		new TestSwitchMesh().start();
	}

	private Mesh mesh2;
	private Mesh mesh1;
	private Geometry geometry;

	@Override
	public void simpleInitApp() {
		// unshaded material
		Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
		mat.setBoolean("VertexColor", true);

		// create a geometry
		geometry = new Geometry();
		geometry.setShadowMode(ShadowMode.Off);
		geometry.setQueueBucket(Bucket.Opaque);
		geometry.setMaterial(mat);

		mesh1 = new Mesh();
		mesh1.setMode(Mode.Points);
		mesh1.setBuffer(Type.Position, 3, BufferUtils.createFloatBuffer(0, 0, 0));
		mesh1.setBuffer(Type.Color, 4, BufferUtils.createFloatBuffer(1, 0, 0, 0));
		mesh1.setBuffer(Type.Size, 1, BufferUtils.createFloatBuffer(10));
		mesh1.setStatic();
		mesh1.updateBound();

		mesh2 = new Mesh();
		mesh2.setMode(Mode.Points);
		mesh2.setBuffer(Type.Position, 3, BufferUtils.createFloatBuffer(-1, 0, 0, 1, 0, 0));
		mesh2.setBuffer(Type.Color, 4, BufferUtils.createFloatBuffer(0, 1, 0, 0, 1, 1, 0, 0));
		mesh2.setBuffer(Type.Size, 1, BufferUtils.createFloatBuffer(10, 10));
		mesh2.setStatic();
		mesh2.updateBound();

		geometry.setMesh(mesh1);

		rootNode.attachChild(geometry);

		// input
		inputManager.addMapping("1", new KeyTrigger(KeyInput.KEY_1));
		inputManager.addMapping("2", new KeyTrigger(KeyInput.KEY_2));
		inputManager.addListener(this, "1", "2");
	}

	@Override
	public void onAction(String name, boolean isPressed, float tpf) {
		if (isPressed) {
			if ("1".equals(name)) {
				geometry.setMesh(mesh1);
			} else if ("2".equals(name)) {
				geometry.setMesh(mesh2);
			}
		}
	}

}