Pregunta

Cuando intento agregar una imagen a una esfera 3D usando babylon.js, obtengo el error Uncaught SecurityError: Failed to execute 'texImage2D' on 'WebGLRenderingContext': Tainted canvases may not be loaded.

Así es como he escrito mi código.He seguido el tutorial aquí y todo ha trabajado prefectivamente hasta que lo intentopara cambiar las texturas.

//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 (el que intenté cargar la imagen a) no se presenta en el programa, pero todo lo demás funciona bien.

También intenté descargar el código fuente de la lección y lo mismo sucedió, así que supongo que es algo que ver con mi navegador (Google Chrome).

¿Fue útil?

Solución

Tienes que usar sus archivos en un servidor web y no localmente para asegurarse de que no haya problemas de seguridad

Otros consejos

Puede cargar activos solo si su aplicación se ha ejecutado en el servidor local o global.Si no, la solicitud http no se puede completar.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top