Digging hole in the ground

I tried to dig a hole to a ground by using CSG.
BabylonJS gives me an error: “Line 16 : 2458624 - Cannot read property ‘length’ of undefined”.

It says line 16, but I know the problem is on line 77:
var bCSG = CSG.FromMesh(ground);

Playground here: https://www.babylonjs-playground.com/#YB006J#241

Can anybody help?


This problem I solved by typing: ground.subMeshes = [];
But instead of hole in the ground I’ve got a ball which looks like ground: https://www.babylonjs-playground.com/#YB006J#240

I had done a function like that.
Click on the ground :


With another ground

1 Like

Thank you, dad!
Your solution works.
I also implemented it to my example: https://www.babylonjs-playground.com/#YB006J#243

1 Like

If you want to make it work with CSG, you need to wait that the ground is built before doing CSG:


Note that it will take some time before displaying something, because converting the ground to CSG + CSG subtraction is slow.

Also, after the CSG operation, the ground is no more a GroundMesh, it is a regular mesh, so functions like getHeightAtCoordinates don’t work (hence the error message in the console).

1 Like