Positions are Required Error from Merge Mesh Optimization SceneOptimizer

When I run scene optimizer I get an error “positions are required” which is thrown when the vertexdata doesn’t have positions.

I found references on the forums here:

But it talks about an empty grid and I’m not sure if it is completely related.

And on git here:

It is marked as closed but multiple devs are still experiencing the issue post adding the check for isDisposed.

I am not sure what object is causing it in my scene but I am wondering if a simple fix would be to check in _canBeMerged if the mesh’s vertexdata has a position and return false if not. That way at least the optimization continues and just ignores that object rather than throwing an exception (and I assume stopping the optimization).

Mesh merging requires that all grids have the same kinds of geometry, must contain the kind: position, and must have the same sideOrientation. If you’re thinking about optimizing scene rendering performance, check out this article: Scene rendering performance optimization plugin based on instance object - Demos and projects - Babylon.js (babylonjs.com)

“geometry.getVerticesDataKinds()” You can get a list of geometry kind names.

I’m fairly new to Babylonjs so I’m sure there are a lot of things I can do to optimize.

However, this bug ticket is about the SceneOptimizer. The Scene Optimizer | Babylon.js Documentation

From the document above it seems as though I should just be able to call without having knowledge of grids, datakinds, etc:

“BABYLON.SceneOptimizerOptions.HighDegradationAllowed()”

My expectation would be that it would optimize what it can and ignore what it can’t. Instead, it throws an exception saying “Positions are required” and doesn’t complete any of the optimizations listed because the exception is not caught.

I would think the solution would be either to check to make sure the mesh can be merged during ‘_canBeMerged’ so in this case check to see if it has positions. Or it could at least catch the exception and move onto the next mesh (if possible) or next optimization option (if the mesh optimization needs to be aborted).

Or if I am missing something and this shouldn’t be run until the scene is setup differently so that datakinds are the same or whatever then the documentation should be updated and the error message as well.

I think it makes sense. Here’s the PR:

3 Likes