THREE.js - 无法在本地加载纹理 [英] THREE.js - Can't load texture locally

查看:554
本文介绍了THREE.js - 无法在本地加载纹理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个本地文件,我尝试加载这样的纹理:

I have a local file in which I try to load texture like this:

var texture = THREE.ImageUtils.loadTexture( 'image.jpg' );
var cubeGeo = new THREE.CubeGeometry( 50, 50, 50 );
var cubeMat = new THREE.MeshBasicMaterial( { map: texture } );
var cube = new THREE.Mesh( cubeGeo, cubeMat );
scene.add( cube );

图像未显示(立方体为黑色)。
当我将整个文件夹移动到服务器并从那里加载时,会显示图像。

The image doesn't show (the cube is black). When I move the whole folder to a server, and load it from there, the image is displayed.

我的问题是,为什么它在文件在服务器上,而不是在我的计算机上?所有文件都已复制,因此丢失文件不是问题。我也试过绝对路径,但仍然没有结果。我是否必须更改计算机上的某些设置?
我在Windows 7上尝试使用Chrome 32.0.1700.76 m(编写本文时的最新版本),我正在使用THREE.js r64。没有使用其他库。

My question is, why does it work when the files are on a server and not when they are on my computer? All files have been copied so it is not a problem with missing files. I also tried with absolute path but still no result. Do I have to change some settings on my computer? I am trying this on Windows 7 with Chrome 32.0.1700.76 m (latest version at the time of writing this) and I am using THREE.js r64. No other libraries are used.

推荐答案

您的问题是出于安全限制。

Your problem is due to security restrictions.

对于Chrome,您可以使用命令行标志 - allow-file-access-from-files 运行浏览器。

In the case of Chrome, you can run the browser with the command-line flag --allow-file-access-from-files.

或者,您可以运行本地服务器。

Alternatively, you can run a local server.

有关更多选项,请参阅three.js wiki文章如何在当地经营物品

For more options, see the three.js wiki article How to Run Things Locally.

three.js r.65

three.js r.65

这篇关于THREE.js - 无法在本地加载纹理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆