What is the most direct way of clearing out all the added meshes in the highlight layer?
I rather not dispose() the layer then have to recreate it, as it seems overkill
I rather not have to somehow find all the added meshes and removeMesh on each as it seems slow.
I did not see a way in the documentation to access that mesh list (or else I would just null it.
I could just be suborn about this by not wanting to do the two options above, but is there a better way to purge the mesh list? The mesh list itself must be private as not in the documentation.
Still that is the way to go, because removing a mesh from the list is not a simple operation, it has to free some internal resources created for each mesh:
public removeMesh(mesh: Mesh) {
if (!this._meshes) {
return;
}
var meshHighlight = this._meshes[mesh.uniqueId];
if (meshHighlight) {
if (meshHighlight.observerHighlight) {
mesh.onBeforeBindObservable.remove(meshHighlight.observerHighlight);
}
if (meshHighlight.observerDefault) {
mesh.onAfterRenderObservable.remove(meshHighlight.observerDefault);
}
delete this._meshes[mesh.uniqueId];
}
this._shouldRender = false;
for (var meshHighlightToCheck in this._meshes) {
if (this._meshes[meshHighlightToCheck]) {
this._shouldRender = true;
break;
}
}
}
I guess the class could provide a removeAllMeshes function, freeing you from the need to maintain a list of the meshes in the layer. But this function would loop through the mesh list and would call removeMesh from each (well, it could do a little better because the function would not need the few last lines of removeMesh to be executed each time).