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

查看:30
本文介绍了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.

我的问题是,为什么当文件在服务器上而不是在我的电脑上时它可以工作?所有文件都已复制,因此不会出现丢失文件的问题.我也试过绝对路径,但仍然没有结果.我是否必须更改计算机上的某些设置?我正在使用 Chrome 32.0.1700.76 m(撰写本文时的最新版本)在 Windows 7 上尝试此操作,并且我正在使用 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.

运行本地服务器.

有关更多信息,请参阅three.js wiki 文章如何在本地运行事物.

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

three.js r.112

three.js r.112

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

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