Error when applying convertToFlatShadedMesh to terrain


I notice this error when I tried to call convertToFlatShadedMesh() on a ground mesh generated by MeshBuilder.CreateGroundFromHeightMap. The error can be reproduced in the following PG by uncommenting line 31.

This is because the CreateGroundFromHeightMap function is asynchronous as it needs to load the image first,

Just move your code in the callback offered as a parameter of the function (options.onReady)