Jump to content

ImportMesh by http and Access-Control-Allow-Origin


Dad72
 Share

Recommended Posts

Hello,

 

I am looking to importMesh() from my server (http://www.castorengine.com) on my local project (http://1270.0.1:122). but each time I : No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://127.0.0.1:122' is therefore not allowed access.

 

I added on every page: 

header('Access-Control-Allow-Origin: *');

I did like this:

 

By http://www.castorengine.com

function Importer(url, type) {         parent.postMessage({url:url, type:type}, '*');}
window.addEventListener('message', function(event) {	if (~event.origin.indexOf('http://www.castorengine.com')) {		var data = event.data;		layout.addObjet.importMediaStore(data.url, data.type);	}});

Why I have this error Access-Control-Allow-Origin and how to solve it.

 

with this url :  http://www.castorengine.com/boutique/MESHES/table/table.babylon

 

Thanks for help

 

Link to comment
Share on other sites

I have been in this area today too.  Looking at Tools.LoadImage(), it can set a img.crossOrigin.  You are probably calling Tools.LoadFile() sooner or later.  That is a XMLHttpRequest.  Do not know if that has something similar.

 

My usage was getting .asf & .amc files for Mocap conversion to animations.  For dev, I downloaded a 1 GB zip file, expanded it, & put html & js files in root of expansion dir.  doing a relative GET works as long as I start by double clicking html file.  I am just do it for myself, but this is not practical for sharing.

post-8492-0-08076900-1446665495.png

Link to comment
Share on other sites

I also this error just before: Cannot read property '_addPendingData' of undefined
 
and after: Uncaught Error: Error status: 0 - Unable to load http/....
 
Here is the URL that uses :  http://www.castoreng...e/table.babylon
 

BABYLON.SceneLoader.ImportMesh("", "http://www.castorengine.com/boutique/MESHES/table/", "table.babylon", scene, function (newmeshes, particleSystems, skeletons) {

This would be due to load images that turn around this error? There was not a fix that can be done to Babylon for this ?

 
post-5292-0-81483400-1446666549_thumb.jp

Link to comment
Share on other sites

We can't do nothing on the Babylon.js side. This is pure web constraints. CORS rules is part of the web. You need to setup CORS on your web server to allow specific domains (or anybody with *) to access your resources using XHR.

 

Search on the web on how to setup anonymous CORS on your webserver based on what you're currently using (Apache or IIS? PHP? etc.).

 

We've setup CORS rules on our CDN for babylonjs.com. No other choice.

 

David

Link to comment
Share on other sites

Davrous thank you. you will not have a link that would help me.
 
I try this:
<?phpheader('Access-Control-Allow-Origin: *');header('Access-Control-Allow-Methods: GET,PUT,POST,OPTIONS');header("Access-Control-Allow-Headers: X-Requested-With");?>

not work.

 

I try this: .htaccess

<IfModule mod_headers.c>    Header set Access-Control-Allow-Origin *      Header set Access-Control-Allow-Credentials true</IfModule>

I have no idea

Link to comment
Share on other sites

I guess the header must be sent by the Origin 127.0.0.1, your local webserver

The SOP (same origin policy) prevents your browser to request with xhr other domains than the one from where your  html page was downloaded (the Origin)... unless the Origin domain tells it allows its html page to request other domains than itself

Link to comment
Share on other sites

The SOP (same origin policy) prevents your browser to request with xhr other domains than the one from where your  html page was downloaded (the Origin)... unless the Origin domain tells it allows its html page to request other domains than itself

 

This is what I normally did here:

<?phpheader('Access-Control-Allow-Origin: *');header('Access-Control-Allow-Methods: GET,PUT,POST,OPTIONS');header("Access-Control-Allow-Headers: X-Requested-With");?>

This is added from the local page and the same is on the call page. But do not work.

 

Ce qui est étrange c’est que ca fonctionne si j'envoie du texte par exemple, je le reçois bien, donc mon Access-Control-Allow-Origin est ok. c’est le imporMesh qui ne fonctionne pas avec l'url reçue (que je reçois).

 

l'erreur ne viendrais pas de ici :  BABYLON.SceneLoader.ImportMesh("", "http://www.castorengine.com/boutique/MESHES/table/", "table.babylon", scene, function (newmeshes)

Link to comment
Share on other sites

Ok, it works now.

 

Solution:

 

on SSH comande:

 

apachectl -t

apachectl -k graceful

sudo service apache2 reload

a2enmod headers

 

.htaccess on the serveur call (SSH commands beings must do to avoid the error 500)

Header set Access-Control-Allow-Origin "*"Header set Access-Control-Allow-Headers "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With" Header set Access-Control-Allow-Methods "PUT, GET, POST, OPTIONS"

and page .php call

<?php$origin=isset($_SERVER['HTTP_ORIGIN'])?$_SERVER['HTTP_ORIGIN']:$_SERVER['HTTP_HOST'];header('Access-Control-Allow-Origin: '.$origin);		header('Access-Control-Allow-Methods: POST, OPTIONS, GET, PUT');header('Access-Control-Allow-Credentials: true');header('Access-Control-Allow-Headers: Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With');header('P3P: CP="NON DSP LAW CUR ADM DEV TAI PSA PSD HIS OUR DEL IND UNI PUR COM NAV INT DEM CNT STA POL HEA PRE LOC IVD SAM IVA OTC"');header('Access-Control-Max-Age: 1');?>

And finaly: Empty cache browser.

 

 

Work for FireFox and Chrome. 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...