não é possível carregar a textura com Babylon.js no Chrome
-
20-12-2019 - |
Pergunta
Quando tento adicionar uma imagem em 3d de uma esfera usando Babylon.js, eu recebo o erro Uncaught SecurityError: Failed to execute 'texImage2D' on 'WebGLRenderingContext': Tainted canvases may not be loaded.
Isto é como eu já escrevi o meu código.Eu segui o tutorial aqui e tudo tem funcionado perfeitamente até eu tentar alterar as 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
(o que eu tentei carregar a imagem) não aparecer no programa, mas tudo o resto funciona bem.
Além disso, eu tentei baixar o código-fonte para a aula e aconteceu a mesma coisa, então eu estou supondo que é algo a ver com o meu navegador (Google Chrome).
Solução
Você tem que usar seus arquivos em um servidor web e não localmente para garantir que não haja problemas de segurança
Outras dicas
Você pode carregar ativos apenas se o seu aplicativo executado no local ou global do servidor.Se não, solicitação http não pode ser concluída.