I´ve been trying to make an sphere with three.js with an image texture but without a server, whether this a local image or an https image online it gives this error:
Access to image at 'file:///C:/Users//.....//sun.jpg' from origin 'null' has been blocked by
CORS policy: Cross origin requests are only supported for protocol schemes: http, data, isolated-app, chrome-extension, chrome, https, chrome-untrusted. GET file:///C:/Users/...../sun.jpg net::ERR_FAILED
And here is the code I'm using:
const geometry = new THREE.SphereGeometry(5, 32, 32);
const cargador = new THREE.TextureLoader().load("sun.jpg");
const cargaTextura = new THREE.MeshBasicMaterial({
map: cargador
});
const sphere = new THREE.Mesh(geometry, material);
scene.add(sphere);
Browsers restrict loading files from the local file system.
You have several options:
You can serve the image using a web server like express, nginx...
Use a cloud storage bucket and access it via URI
You can convert the image to base64 or something and display it directly by doing
new THREE.TextureLoader().load(yourBase64string)