This may seem like a very trivial problem but I can't find a solution to this. I've added an object to the scene using OBJLoader as seen below. How can I remove it from the scene? I've tried using code to clear scene.children, but this doesn't remove my "flower.obj"
const mloader = new THREE.OBJLoader();
mloader.load
(
'models/flower.obj', function(object)
{
object.scale.x=1
object.translateZ(2);
scene.add(object);
}
);
You need to save a reference to the loaded object so you can subsequently call scene.remove() when you're ready to get rid of it.
var flower;
const mloader = new THREE.OBJLoader();
mloader.load('models/flower.obj',
function(object) {
flower = object;
flower.scale.x=1
flower.translateZ(2);
scene.add(flower);
}
);
function removeFlower() {
scene.remove(flower);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With