Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check whether an Object is Present in the scene or not in THREE.js?

I want to add and remove objects to my scene in clicks.

Simply I use scene.add(object) and scene.remove(object).

Is there any way to check whether the object is present in the scene?

like image 684
ArUn Avatar asked Nov 18 '15 09:11

ArUn


2 Answers

When adding your object to scene, add name to that object like

object.name = 'object_name';

Then you can check if your object exist in scene by

scene.getObjectByName('object_name');

If it return any object it means object exist in scene.

like image 185
Siraj ul Haq Avatar answered Oct 21 '22 11:10

Siraj ul Haq


Probably more efficient: object.parent === scene

like image 37
Neptilo Avatar answered Oct 21 '22 09:10

Neptilo