Question about MaterialCache/GeometryBatch

Wel i have the following problem:



I want to batch mutiple groundvegetation models together.

I currently only use one model, and assume, sine it is unanimated, that after batching X objects of them, I would have 1/x the amount of Geometries than without batching.

However it seems that the merging does not do anything at all if I do it as following:

Code:
private void loadGrassHigh() { final Node unoptimized = new Node(); this.random = new Random((long) (vegetationSubTile.density + vegetationSubTile.subx + vegetationSubTile.suby * vegetationSubTile.subtilesize + gtilex + gtiley * grassTileSize));
	for (int x = 0; x < grassTileSize - grassTileSize / grassdensity; x += grassTileSize / grassdensity) {
		for (int y = 0; y < grassTileSize - grassTileSize / grassdensity; y += grassTileSize / grassdensity) {
			final float rx = random.nextFloat() * grassTileSize / grassdensity;
			final float ry = random.nextFloat() * grassTileSize / grassdensity;
			final Vector3f treepos = new Vector3f(x + rx, vegetationSubTile.getHeight(this.gtilex * this.grassTileSize + x + rx, this.gtiley * this.grassTileSize + y + ry), y + ry);

			final Spatial tree = ModelLoader.loadNow(440814);
			unoptimized.attachChild(tree);
			unoptimized.setLocalScale(1f);
			tree.setLocalTranslation(treepos);
		}
	}
	final Spatial grassbatch = GeometryBatchFactory.optimize(unoptimized);
	this.attachChild(unoptimized);
}</div>

Do i make any mistake? Or oversee something?

The model is a j3o file, if that matters at all.

The models are batched by material, you need to ensure the material used is the same. Load the model once and then call clone(false) on it which ensures the material isn’t cloned with it.

Ah that worked, I tried it with clone() but not with clone(false) so far, 4x framerate now :wink: