Search code examples
meshbabylonjs

Delete a Mesh selected with a button in BabylonJs


This my code in the Default.Html Page:

<button id="Remove_mesh" class="group">Remove</button>

And this my JS:

var pickResult = scene.pick(offsetX, offsetY);
if (pickResult.pickedMesh) {
 if ($('Remove_mesh').click(function(){}))
 {
    pickResult.dispose();
 }

This didn't work


Solution

  • You should use: pickResult.pickedMesh.dispose()

    $('Remove_mesh').on("click", function () {
        pickResult.pickedMesh.dispose();
    });
    

    More info: http://doc.babylonjs.com/page.php?p=24938