Could I load gltf data directly from online?

Hi, I knew it is easy to load the gltf data from local. However, I want to load the gltf data directly from online (such as from the Github). Is there any way to realize that?
(btw, I cloned the whole repository and used example “webgl_loader_gltf.html” code to have a try. I only change the code on line 64. Obviously, this simple change doesn’t work)
Thanks.

See what happens when you visit the URL that you used, you’ll see that it takes you to a Github HTML page, instead of delivering the asset you wanted: https://github.com/mrdoob/three.js/blob/c23b245814ac71999d8303c07434fcfd244288dd/examples/models/gltf/DamagedHelmet/glTF/DamagedHelmet.gltf

Try this one instead: https://raw.githubusercontent.com/mrdoob/three.js/dev/examples/models/gltf/DamagedHelmet/glTF/DamagedHelmet.gltf

I recommend you also read about Cross-Origin Resource Sharing (CORS). It’s a protective measure used by servers & browsers that prevents users from getting free bandwidth by denying requests from unknown domains. If your website is hosted in http://JustnZeng.com but you want to load assets from http://example.net chances are it won’t work due to the CORS policy.

2 Likes