var createScene = function () {
var scene = new BABYLON.Scene(engine);
var camera = new BABYLON.FreeCamera("camera1", new BABYLON.Vector3(0, 0, -5), scene);
camera.setTarget(BABYLON.Vector3.Zero());
camera.attachControl(canvas, true);
new BABYLON.HemisphericLight("light", new BABYLON.Vector3(0, 1, -1), scene);
/**
* Is there any way to load an image from cross origin
* where Access-Control-Allow-Origin is not set by the server ?
*/
const src = 'https://vhaonline.usc.edu/vhaimages/stills/617269.jpeg';
//const src = 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSArIeRcpcwIHj6R1zzYhEyJNPHHiBCXpN_vfjiloDdh9f9Svb8RUFGiJycz-kttSQpCeU&usqp=CAU';
BABYLON.Tools.CorsBehavior = 'anonymous';
BABYLON.Tools.SetCorsBehavior( src,canvas );
const mat = new BABYLON.StandardMaterial('billboard-material', scene);
mat.diffuseTexture = new BABYLON.Texture(
src,
scene
);
const billboard = BABYLON.MeshBuilder.CreatePlane('billboard-mesh', {}, scene);
billboard.material = mat;
return scene;
};
Not in modern browser as it is a security constraint to prevent unallowed cross origin accesses.
You could nevertheless disable cors on your browsers if really required but it would not work for other users.
1 Like
Ah that makes sense, thanks,
There are hacky ways around cors. One method is to use PHP and spoof the server to think it’s a local request.
I posted a GitHub about it at some point and a forum post. I’ll see if I can’t dig that up for you.
That was years ago now though and I don’t know if stuff has changed, but I’m assuming it works still.
@Pryme8
Thanks for the input … I think I do not want to do a work-around i will just do the proper thing which is to get the server response corrected.
Well I mean, the definition of respond correctly is loose when you talk internet .
It’s prolly worth a look, you basically do a cors bypass php page that routs an ajax request and returns the results as Json/html/binary what have you then just parse it. Some assets on a html page might not come through but anything like images videos etc are totally accessable even if they don’t want you to have them.