无法在Chrome上使用Babylon.js加载纹理

时间:2014-06-02 17:31:57

标签: javascript google-chrome textures assets babylonjs

当我尝试使用Babylon.js将图像添加到3d球体时,我收到错误Uncaught SecurityError: Failed to execute 'texImage2D' on 'WebGLRenderingContext': Tainted canvases may not be loaded.

这就是我编写代码的方式。我已经按照教程here进行了操作,所有内容都完美无缺,直到我尝试更改纹理。

//Creation of spheres
var sphere1 = BABYLON.Mesh.CreateSphere("Sphere1", 10.0, 6.0, scene);
var sphere2 = BABYLON.Mesh.CreateSphere("Sphere2", 2.0, 7.0, scene);
var sphere3 = BABYLON.Mesh.CreateSphere("Sphere3", 10.0, 8.0, scene);

//Positioning the meshes
sphere1.position.x = 10;
sphere3.position.x = -10;

//Textures
var sphere1texture = new BABYLON.StandardMaterial("sphere1texture", scene);
var sphere2texture = new BABYLON.StandardMaterial("sphere2texture", scene);
var sphere3texture = new BABYLON.StandardMaterial("sphere3texture", scene);
sphere1texture.alpha = 0.75
sphere2texture.diffuseTexture = new BABYLON.Texture("./texture1.jpg", scene); 

sphere2(我试图加载图片的那个)没有出现在程序中,但其他一切都运行良好。

另外,我尝试下载课程的源代码并且发生了同样的事情,因此我猜测它与我的浏览器(Google Chrome)有关。

2 个答案:

答案 0 :(得分:5)

您必须在网络服务器上使用您的文件,而不是在本地使用以确保没有安全问题

答案 1 :(得分:1)

仅当您的应用在本地或全局服务器上运行时,才能加载资源。如果没有,http请求无法完成。