javascripthtmlthree.jswebxr

How to restart webxr session with all objects(only models) removed from the scene


currently when webxr session restarts 2 X previous objects are shown on the screen , I want to show clear screen just as if session restart , currently I write this:

 for( var i = scene.children.length - 1; i >= 0; i--) { 
                     scene.remove(scene.children[i]); 
                    }

This removes everything and ar functionality is lost , so how to remove only models added in webxr ( they can be of gltf or obj format) , I write this inside webxr sessionend listener


Solution

  • I needed to check the object type if it was group I deleted it ,

    for( var i = scene.children.length - 1; i >= 0; i--) { 
                         if(scene.children[i].type === "Group"){
                         scene.remove(scene.children[i]); 
                              }
                        }