Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用URL在Three.js中应用纹理_Javascript_Three.js_Texture Mapping - Fatal编程技术网

Javascript 使用URL在Three.js中应用纹理

Javascript 使用URL在Three.js中应用纹理,javascript,three.js,texture-mapping,Javascript,Three.js,Texture Mapping,在Three.js中应用纹理时遇到问题。由于安全问题,我无法在Chrome中使用任何本地图像,因此我想应用一个来自web的图像。有没有一种方法可以使用URL将图像映射到Three.js网格?TextureLoader可以处理URL,只需确保您设置了crossOrigin,它不会从站点服务器加载URL。下面是一个例子: const myUrl = 'http://www.myimage.com' const textureLoader = new THREE.TextureLoader() te

在Three.js中应用纹理时遇到问题。由于安全问题,我无法在Chrome中使用任何本地图像,因此我想应用一个来自web的图像。有没有一种方法可以使用URL将图像映射到Three.js网格?

TextureLoader可以处理URL,只需确保您设置了crossOrigin,它不会从站点服务器加载URL。下面是一个例子:

const myUrl = 'http://www.myimage.com'

const textureLoader = new THREE.TextureLoader()
textureLoader.crossOrigin = "Anonymous"
const myTexture = textureLoader.load(myUrl)

myMesh.material.map(myTexture)
myMesh.material.needsUpdate = true

使用URL
TextureLoader()
为您设置
needsUpdate
标志。不要自己设定;你可以在异步加载纹理完成之前设置它。太棒了!谢谢效果很好。