Bloxel 0.2.0 with better performance


To handle scenes with many elements you have to „merge“ identical objects (Geometry’s) … I did it for bloxel 0.2.0 and the performance is now much better … here are two brand new screenshots :

 

JMonkey contains a class for that :  jme3tools.optimize.GeometryBatchFactory. This forum entry shows me the way : http://jmonkeyengine.org/groups/general/forum/topic/how-to-useoptimize-pvs-or-octree

FYI: our main application loop contains a „updateTerrain“ method:

// near elements ... player can add/remove such elements ...
final TerrainElementsResult result = terrainManager.getTerrainElements(thePlayerPosition, theWalkDirection);
final Set<TerrainElement> currentElements = Sets.newLinkedHashSet(currentTerrainElements);
final Set<TerrainElement> elementsToAdd = Sets.difference(new HashSet(result.getNearElements()), currentElements);
final Set<TerrainElement> elementsToRemove = Sets.difference(currentTe, new HashSet(result.getNearElements()));
// ... add new elements to scene, physics, cache etc ...
// ... remove old elements from scene, physics, cache etc ...

// far elements
final Iterator<TerrainElement> iterator = result.getFarElements().iterator();
final List<Geometry> geos = Lists.newArrayList();
while (iterator.hasNext()) {
  final TerrainElement te = iterator.next();
  Bloxel bloxel = bloxelCache.getFromCache(te.getCenter());
  if (bloxel == null) {
    bloxel = bloxelFactory.create(te.getBloxelType());
    bloxel.setLocalTranslation(te.getCenter());
  }
  geos.add(bloxel);
}
final List<Geometry> makeBatches = GeometryBatchFactory.makeBatches(geos);
bloxelsFarNode.detachAllChildren();
final Material material = new Material(assetManager, "Common/MatDefs/Misc/WireColor.j3md");
material.setColor("Color", ColorRGBA.White);
for (final Geometry geometry : makeBatches) {
  // for debugging
  // geometry.setMaterial(material);
  bloxelsFarNode.attachChild(geometry);
}
System.out.println("update far terrain time: " + (System.currentTimeMillis() - start));

Good night😉