Hide scene if file does not exist

Hi is there a way to hide the whole loader and the scene if there is not any file in my case STL file. In my use sometimes i have stl files and sometimes just an photo and i already solve the problem for the photo if there isn`t any photos only loads the stl loader but i need to make the same thing for the stl loader.

this is what i used for hiding the picture:
img.onerror = function () {
this.style.display = “none”;
}
I tried on the scene of the loader and on the loader where the path is but no luck.

Thanks

Not sure I fully understand your use but you can of course stop rendering and hide/remove the renderer’s canvas no asset has to be rendered. Hiding the canvas can be done like so:

renderer.domElement.style.display = 'none';
1 Like

Hi N.J,

sounds like you want to show either the image or the canvas, if the stl file exists, right? If so, i would go for just checking the file existance first (see https://stackoverflow.com/a/3646923) and putting the threejs scen in the success path.

1 Like

Hi

Thanks worked like charm with ajax solution and using the display = none in the error section solved my problem thank you so much

Thanks this solved my problem using also ajax from Sebastian_Bauer link. Now the code looks something like this :
$.ajax({
url:“the url of the file location”,
type:‘HEAD’,
error: function()
{
webGLRenderer.domElement.style.display = ‘none’;

},
});