简体   繁体   中英

Does STLLoader accepts a web URL and display the file?

I want to render or load a.stl file from the web ( https://cdn.thingiverse.com/assets/99/39/31/f9/33/90_Degree_-_4_Segments.stl ) with the help of STLLoader. I am doing this stuff in Angular.

var loader=new STLLoader();

Can I place the web url link in the loader.load? The web url link is taken as an input from the user.

   loader.load('https://cdn.thingiverse.com/assets/99/39/31/f9/33/90_Degree_-_4_Segments.stl',geometry =>{
     var material = new MeshPhongMaterial( { color: this.col });
     var mesh = new Mesh( geometry, material );
     this.scene.add(mesh);

   })

Could anyone suggest any way to make this work?

You can't load this asset from the given URL because of the CORS policy. Meaning the backend does not add the Access-Control-Allow-Origin header to the HTTP response. Hence, it's not possible to load it with an AJAX request.

You have to ensure to serve the asset in a way so Access-Control-Allow-Origin header is set.

BTW: Here is a live example that demonstrates the error (open the browser console to see the message): https://jsfiddle.net/em8upjdz/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM