【发布时间】:2018-02-24 01:07:20
【问题描述】:
我正在尝试加载纹理,但无论我做什么,我都会收到此错误:
Access to Image at '<file-path>/IMG/1.jpg' from origin 'null' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.
这是我用来加载图像的代码:
var loader = new THREE.TextureLoader();
loader.crossOrigin = "";
var url = "IMG/1.jpg";
var materials = [
new THREE.MeshLambertMaterial({
map: loader.load(url)
}),
new THREE.MeshLambertMaterial({
map: loader.load(url)
}),
new THREE.MeshLambertMaterial({
map: loader.load(url)
}),
new THREE.MeshLambertMaterial({
map: loader.load(url)
}),
new THREE.MeshLambertMaterial({
map: loader.load(url)
}),
new THREE.MeshLambertMaterial({
map: loader.load(url)
}),
];
【问题讨论】:
-
什么是
<file-path>?这是来自同一个域吗? -
是文件的路径,我在这里省略了它,但我检查了错误消息中的链接,文件肯定在那里 -
路径是什么意思?你的 path 以什么开头?
-
@SunnySoni 这是一个学校作业,我们必须使用 three.js 在 webgl 中制作一个场景。要求之一是我们使用纹理映射,并且我们需要使用本地图像,因为我们必须在某个时候提交它
-
为什么不使用相对 URL,在适当的上下文中不使用
file:///D:/?
标签: javascript three.js textures