简体   繁体   中英

Delete an object from scene in three.js

How to delete an object from scene in three.js? I want to delete a cube after certain key press.But I could not delete a particular cube but able to clear the whole scene

You can remove the mesh object from the scene in the following manner.

var cubeMesh = new THREE.Mesh(geometry, material);

scene.add(cubeMesh);
//...

someDeleteFunction() {
    scene.remove(cubeMesh);
    cubeMesh.geometry.dispose();
    cubeMesh.material.dispose();
    cubeMesh = undefined; //clear any reference for it to be able to garbage collected
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM