来自硬盘的纹理未在three.js中加载 - 显示黑色 [英] Texture from hard disk not loading in three.js - showing black
问题描述
我在尝试从本地计算机加载图像时遇到问题.如果我在互联网上提供一个 jpeg 文件的链接,它可以正常工作,但如果我用本地机器的路径替换 - 纹理是黑色的.
I encountered problem on trying to load images from the local machine. If I give a link in internet to a jpeg file it works okay, but if I replace with path from my local machine - the texture is black.
var texture = THREE.ImageUtils.loadTexture( 'http://ewgl.erbix.com/js/nodes2/textures/sun.jpg', {}, function(){ renderer.render(scene, camera); } );
paintMaterial = new THREE.MeshBasicMaterial({map: texture})
所以,而不是 'http://ewgl.erbix.com/js/node2/textures/sun.jpg' 如果我从我的机器加载相同的图像,它会显示黑色.我发现在 https://github.com/mrdoob/three.js/讨论了同样的问题问题/432 ,但仍然无法从我的机器加载纹理.
So instead of 'http://ewgl.erbix.com/js/nodes2/textures/sun.jpg' if I load the same image from my machine it shows black. I found the same issue discussed at https://github.com/mrdoob/three.js/issues/432 , but still not able to load textures from my machine.
我也尝试将 chrome 作为 chrome --allow-file-access-from-files 运行,然后打开链接 file:///C:/Users/Anubha/Desktop/pencil/pencil.html,但是paint3.jpg甚至与js和html在同一个文件夹中显示为黑色.
I also tried running chrome as chrome --allow-file-access-from-files, and then opening the link file:///C:/Users/Anubha/Desktop/pencil/pencil.html, but the paint3.jpg even being in the same folder as the js and html showed black.
var texture = THREE.ImageUtils.loadTexture( 'paint3.jpg', {}, function(){ renderer.render(scene, camera); } );
paintMaterial = new THREE.MeshBasicMaterial({color: 0x3D59AB, map: texture, specular: 0x555555, shininess: 20})
推荐答案
此页面 解释了如何加载本地纹理.
This page explains how to load local textures.
这篇关于来自硬盘的纹理未在three.js中加载 - 显示黑色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!