How to use GeometryBatchFactory correctly

I use it this way

[java]public Spatial createSpatial(){



GeometryBatchFactory fac = new GeometryBatchFactory();



Spatial sp = null;

for (int i = 0; i < Constants.patchIndDim; i++) {

for (int j = 0; j < Constants.patchIndDim; j++) {

Spatial spToAdd = GameManager.getInstance().getSpatial(Constants.desertQuad);

Vector3f pos = new Vector3f(

MathHelper.getNodePosInPatch(MathHelper.centerInd(i, Constants.patchIndDim)),

MathHelper.getNodePosInPatch(MathHelper.centerInd(heightMap[j], Constants.patchIndDim)),

MathHelper.getNodePosInPatch(MathHelper.centerInd(j, Constants.patchIndDim)));

spToAdd.setLocalTranslation(pos);



sp = fac.optimize(spToAdd);

}

}



return sp;

}[/java]



and i’m pretty sure i’m wrong

How to make one spatial from many using GeometryBatchFactory?

Just create a node, attach a bunch of stuff to it, then call optimize on it, the result is the optimized version of that node.

E.g.

[java]

Box box = new Box(1,1,1);

Geometry g1 = new Geometry("g1", box);

Geometry g2 = new Geometry("g2", box);

Geometry g3 = new Geometry("g3", box);

g1.move(-2, 0, 0);

g2.move(0, 0, 0);

g3.move(2, 0, 0);

Node boxes = new Node("boxes");

boxes.attachChild(g1);

boxes.attachChild(g2);

boxes.attachChild(g3);

boxes.setMaterial(…);

Node optimizedBoxes = GeometryBatchFactory.optimize(boxes);

rootNode.attachChild(optimizedBoxes);

[/java]

Thanks… - by the way there are some troubles in january nightly builds - some doesn’t contain engine itself (from 01.01), some contains errors (from 10.01) …

madeinsoviets said:
Thanks.. - by the way there are some troubles in january nightly builds - some doesn't contain engine itself (from 01.01), some contains errors (from 10.01) ..

That's possible, some of the recent changes caused compile errors, and if the build was made then, it would fail. Just wait for the next day for the latest build. Alternatively you can compile and build it from SVN for any date.

I have been testing GeometryBatchFactory and have come to some questions:

I noticed that optimizing my whole scene (GeometryBatchFactory.optimise(rootNode)), dramatically increases fps. I also noticed that there is much less objects and uniforms as in non-optimized scene. But when I zoom in or view only part of it, vertex and triangle count remains the same and therefore performance is not so good as with non-optimized scene, when everything drops to lower numbers… I suspect this is probably because everything is one big mesh and no vertex or triangle gets culled then… Does this mean that vertexes are being culled based on geometry bounding volume and not mesh or smth?

Also,are there any good advices on how big chunks of a scene should be optimised?

Thanks.

Its faster because theres less geometries which in turn reduces upload time of material data to the GPU.

InShadow said:
Also,are there any good advices on how big chunks of a scene should be optimised?
Thanks.

Optimize by spatial locality.