I am trying to make a scene THREE.jshaving a background image obtained from another domain.
I got tainted canvas errorit because the image did not have CORS approval, and as a result, manipulating the canvas leads to a security error.
After reading this answer , I set THREE.TextureLoader()to enable cross-start loading:
var loader = new THREE.TextureLoader();
loader.crossOrigin = '';
var texture = loader.load(
url_to_image,
function ( texture ) {
var backgroundMesh = new THREE.Mesh(
new THREE.PlaneGeometry(2, 2, 0),
new THREE.MeshBasicMaterial({
map: texture
})
);
backgroundMesh.material.depthTest = false;
backgroundMesh.material.depthWrite = false;
backgroundScene = new THREE.Scene();
backgroundCamera = new THREE.Camera();
backgroundScene.add( backgroundCamera );
backgroundScene.add( backgroundMesh );
},
function ( xhr ) {},
function ( xhr ) {}
);
However, now I get the CORS error: Access to Image at 'url_to_image' from origin 'my_domain' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'my_domain' is therefore not allowed access.
The comments of this answer seem to suggest that some domains do not give permission to use the image in a browser in WebGL, how can I find out if this is the case?
If this is not a problem with the domain from which I am extracting the image, how can I make it work?