Remove object from three js scene by selecting it

Hello :),

My three js scene contains many OBJ models, some of which are preloaded with the scene, some of which are added to the scene via button click.

A user of my application may add an object but then decide to remove it. I am trying to figure out how to this but need guidance.

Ideally I would do this my holding shift and clicking the object to delete, or by adding the object to a group with shift + select and then deleting with a keyboard press (similar to the grouping here: three.js examples).

I would imagine the first way is easier to implement as I had a lot of trouble trying to group the OBJ models this way previously (I think due to their associated MTL files preventing their material being of type Lambert).

Thank you for your support :+1:

But is the question about making a choice or how to implement either of these options :thinking: ?

To remove objects you can use remove method of the parent (ie. selectedModel.parent.remove(selectedModel)).
To make groups of selected objects you can simply use an array - materials aren’t involved in any way, unless you’d also like to highlight selected objects.

1 Like

Marking this as the solution as it worked, for anyone looking at this “selectedModel” is equivalent to “object” in function onClick( event ) in the official example I shared.

and thanks :heart: