three.js加载图片时,出现Failed to execute 'texImage2D' on 'WebGLRenderingContext .Tainted canvases may not be loaded.的错误
跨域安全问题。
解决办法:
1 如果你用的是纹理题图:如:
var loader = new THREE.TextureLoader();
加上:
loader.setCrossOrigin( 'Anonymous');
即可。(THREE.ImageUtils.loadTexture也可用这个方法)
2 如果你是直接用img的,如:
var img = new image(); 加上 img.crossOrigin =“anonymous” 即可
3 如果你被THREE.WebGLRenderer: image is not power of two 这样的warning所困扰,在你的建立mesh后加上:mesh.material.map.minFilter = THREE.LinearFilter; 即可。如
var mesh = new THREE.Mesh( geometry, material );
mesh.material.map.minFilter = THREE.LinearFilter;