http://html5snippet.net/post/14
/** * * Hack to load cross domain models, generated by obj_to_threejs converter from here * https://github.com/mrdoob/three.js/blob/master/utils/exporters/convert_obj_three.py * without changing generated models's code... * ...generates js files are supposed to run inside a worker, but workers dont support * cross domain scripts (yet??) :'( ... * * Usage is EXACTLY the same as THREE.JSONLoader * */ THREE.CrossDomainJSONLoader = function ( showStatus ) { THREE.JSONLoader.call( this, showStatus ); }; THREE.CrossDomainJSONLoader.prototype = new THREE.JSONLoader(); THREE.CrossDomainJSONLoader.prototype.constructor = THREE.CrossDomainJSONLoader; THREE.CrossDomainJSONLoader.prototype.supr = THREE.JSONLoader.prototype; THREE.CrossDomainJSONLoader.prototype.load = function ( parameters ) { var scope = this, url = parameters.model, callback = parameters.callback, texture_path = parameters.texture_path ? parameters.texture_path : this.extractUrlbase( url ); this.onLoadStart(); function _eval(src) { postMessage = function(model){}; close = function(){}; eval(src); return model; } var req = new XMLHttpRequest(); req.open('GET', url, true); req.withCredentials = true; req.onreadystatechange = function (aEvt) { if (req.readyState == 4) { if(req.status == 200) { var tmp = _eval(req.responseText); scope.createModel(tmp, callback, texture_path); scope.onLoadComplete(); } else console.log("ERROR loading model"); } }; req.send(null); };
<?php header('Access-Control-Allow-Credentials: true'); header('Access-Control-Allow-Methods: GET'); header('Access-Control-Allow-Origin: http://echo.html5snippet.net'); if (isset($_GET['file'])) { switch($_GET['file']) { case 'texture.jpg': header('Content-Type: image/jpg'); die (file_get_contents("texture.jpg")); break; case 'model.js': die (file_get_contents("model.js")); break; } }