title: Cross Domain Problems when loading OBJ/MTL Files with textures in THREE.JS
body: <p>I have an OBJ file generated dynamically by a server on a separate domain. It has some materials and texture JPG files.</p>
  
  <p>I load this OBJ file with a simple php proxy (fileProxy.php):</p>
  
  <pre><code>&lt;?php
   header('Access-Control-Allow-Origin: *');
   header("Access-Control-Allow-Credentials: true"); 
   header('Access-Control-Allow-Headers: X-Requested-With');
   header('Access-Control-Allow-Headers: Content-Type');
   header('Access-Control-Allow-Methods: POST, GET, OPTIONS, DELETE, PUT'); // http://stackoverflow.com/a/7605119/578667
   header('Access-Control-Max-Age: 86400');
  
  //Check if this is an image. if So print coorect header.
  if (strpos($_REQUEST['fileToProxy'],'jpg') !== false) {
  
       header('Content-Type: image/jpeg');
  
  }
  
  
  $proxyFile = (isset($_REQUEST['fileToProxy'])? $_REQUEST['fileToProxy'] : null);
  
  if ( isset($proxyFile)){
    // the files sent to us aren't properly url encoded
    $proxyFile = str_replace(' ', '+', $proxyFile);
  
    $content = file_get_contents($proxyFile);
  
    print($content);
  }
  else {
    echo "ERROR: no file to proxy";
  }
  
  
  
  ?&gt;
  </code></pre>
  
  <p>Loading the OBJ files works like a charm</p>
  
  <p>BUT, i cant load the JPG textures embeded in the MTL file. Single colored shaders all work fine, but loading images i get errors.</p>
  
  <p>I get the following error in chrome:</p>
  
  <p><strong>Uncaught SecurityError: Failed to execute 'texImage2D' on 'WebGLRenderingContext': the cross-origin image at <a href="http://ec2-54-201-204-177.us-west-2.compute.amazonaws.com/fileProxy.php?fil" rel="nofollow">http://ec2-54-201-204-177.us-west-2.compute.amazonaws.com/fileProxy.php?fil</a>…est-2.compute.amazonaws.com/3DModels/435639/DonutFullBread.jpg&amp;timtest=115 may not be loaded.</strong> </p>
  
  <p>The address of the texture file is fed correctly into my proxy:
  <a href="http://ec2-54-201-204-177.us-west-2.compute.amazonaws.com/fileProxy.php?fileToProxy=http://ec2-54-201-204-177.us-west-2.compute.amazonaws.com/3DModels/435639/DonutFullBread.jpg&amp;timtest=115" rel="nofollow">http://ec2-54-201-204-177.us-west-2.compute.amazonaws.com/fileProxy.php?fileToProxy=http://ec2-54-201-204-177.us-west-2.compute.amazonaws.com/3DModels/435639/DonutFullBread.jpg&amp;timtest=115</a></p>
  
  <p>Now after checking my Network monitor, i realise that the Jpg Image is successfully downloaded and the correct CORS headers are all in place. But webgl/three.js still spits out the errors and does not display my model.</p>
  
  <p>SO this seems like a WEBGL bug. But i get security erros in all browsers.
  I have tested this on my localhost and on my server. Same problem.</p>
  
  <p>Any solutions?</p>
  
  <p><em>UPDATE</em>
  Here's how i load the OBJ/MTL files with three.js:
  (Only cross domain textures fail)</p>
  
  <pre><code>var loader = new THREE.OBJMTLLoader( manager);
  
  ///////////////////LOAD MDOEL////////////////////
   loader.load( 'http://ec2-54-201-204-177.us-west-2.compute.amazonaws.com/fileProxy.php?fileToProxy=' + obj.file, 'http://ec2-54-201-204-177.us-west-2.compute.amazonaws.com/fileProxy.php?fileToProxy=' + obj.material, function ( object ) {                                              
  //if loaded, do some stuff here.                                                   
  }
  loadedmodel.add(object);
  </code></pre>
  
  <p>That's all I do really. The Materials and textures are phrased correctly by the loader.
  I dont have to set any materials up.</p>