Here's an alternative method to achieve the same result:
function isObjectInScene(scene, object) {
let current_object = object;
while(current_object.parent !== null) {
current_object = current_object.parent;
if(current_object === scene) {
return true;
}
}
return false;
}
@Neptilo seems to be on the right path.
If an object is part of the scene, its parent or ancestor should eventually lead to the scene itself.
Therefore, by tracing the parent references upwards, you can determine if an object exists within a scene or not.
When objects are removed using scene/obj.remove(obj), their parent value becomes null.
It is likely that any other method of checking if an object is part of a scene, such as searching for objects by name or ID, would require traversing the entire scene, making it less efficient than simply following the parent chain until reaching the root.