No information anywhere about optimizeIndicesAsync function. how to use it?

Hi i found a function which updates indices of a mesh inside babylon engine. Looks like it affects performance.

optimizeIndicesAsync();

looks like it was introduced here Questions about onPointerObservable - #11 by Deltakosh

There is no information about this function anywhere (docs, forum). This article also don’t have info about it Babylon.js docs

Can i use it at all? or it’s only for internal babylon purposes and babylon call it himself?

Should i use it if i can? Should i use it on each mesh which is loaded?

If I use it on mesh does it clones/instances will have already optimized indices? Or i need to optimized them too?

Thanks!

It is totally ok to use it. By default we do not add processing to meshes so you will need to call it if you need to have the faces with common indices close in the index buffer

My question would be: why do you need it?

i’m trying to optimize my scene to have highest possible fps.

When i’m finding some new feature which in theory can help to increase fps i’m trying to add it and see is fps is better than it was.

when i was implementing some other feature and reading forum i found that topic with that function. i tried it in my scene and it’s not clear if it helped with fps or not. the only thing i’m sure that loading time is much higher:) because i’m calling it for each instance (as test)

My scene have ~40 of meshes with high faces. each of them has ~20-50 instances

Oh I see. This one is not optimize for perf so you can skip it. It is meant to optimize for geometry processing

when this function should be used then?

It is used mostly for NGE so preserve faces continuity when working with geometry

in theory can it help to improve loading time of scene? for example if i will call this function for some huge face number meshes

You should preprocess the models / geometry before loading if you want to speed up loading times. Processing on load, is just going to prolong that.

1 Like

Nope it will actually slow it down due to the processing time

What you might be looking for is “simplification”, which means to reduce faces of the mesh while keeping rendering result “similar” as before.
To start with, gltfpack tool from the meshoptimizer repo is a good choice, with a widely used and optimized simplification algorithm. Or you can call meshoptimizer api for lower-level control.

glTF-Transform has a js api, making it more friendly to js/ts devs, but it has not integrated latest features of meshoptimizer.

If you are looking for a solution fully in babylon.js, it has a “simplify” function, but the underlying algorithm might not be as optimized as meshoptimizer.

Or here is a quick demo of using meshoptimizer simplify in babylon.js, but it’s far from complete.