当我尝试使用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(我尝试将图像加载到的代码)没有显示在程序中,但是其他所有东西都可以正常工作。

另外,我尝试下载本类(class)的源代码,并且发生了同样的事情,所以我猜想它与我的浏览器(Google Chrome)有关。

最佳答案

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

07-24 20:56