0

I'm having a problem loading MTL files on Chrome with Three.js. It works fine on Safari but I'm getting a cross origin request error in Chrome. I don't know how to fix this issue for local files. It does work fine if I publish this to an http website on Chrome.

var mtlLoader = new THREE.MTLLoader();
mtlLoader.setPath('assets/');
mtlLoader.setBaseUrl('assets/');
mtlLoader.load('file.mtl', function(materials) {
     ...
});

three.js:18280 XMLHttpRequest cannot load file:///.../assets/file.mtl. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.

Berry Blue
  • 15,330
  • 18
  • 62
  • 113

1 Answers1

0

This isn't really a THREEjs question but i'll answer it here anyway:

This isn't really safe or permissible to allow a website to request files from the local file system.

What if the website requested an index of file:///C:/Users/Installation/Pictures/ on a windows system and then just started loading all of the contents to the server.

This is really unsafe because it could allow malicious agents to strip files from your computer just by you visiting. As a result, websites are only allowed to request files from outside the local file system.

You should use Mamp or the built in server emulation in Brackets. I use Mamp because it also makes it easy to test on mobile quickly and it is much faster than working with an FTP.

OtterFamily
  • 803
  • 4
  • 10