Image three.js(canvas/webGL)的跨域图像,代理?

Image three.js(canvas/webGL)的跨域图像,代理?,image,proxy,cross-domain,three.js,webgl,Image,Proxy,Cross Domain,Three.js,Webgl,我意识到这可能是不可能的。。。我一直在四处搜寻,尝试各种各样的东西,但都没有用,但我认为在放弃之前,这可能值得一个帖子 我正在组装一个使用three.js(webGL)的应用程序,我想让用户可以选择输入web上任何图像的URL,并使用该URL在web应用程序中对3D对象进行纹理处理。如果不是整个跨域安全问题,这将不会有问题 我知道CORS认可的图像应该有一些解决办法,虽然我不完全理解这一点,但我的印象是,这必须设置在主机端(我的用户需要能够从web上的任何位置提取图像并将其用作纹理)>>我尝试过

我意识到这可能是不可能的。。。我一直在四处搜寻,尝试各种各样的东西,但都没有用,但我认为在放弃之前,这可能值得一个帖子

我正在组装一个使用three.js(webGL)的应用程序,我想让用户可以选择输入web上任何图像的URL,并使用该URL在web应用程序中对3D对象进行纹理处理。如果不是整个跨域安全问题,这将不会有问题

我知道CORS认可的图像应该有一些解决办法,虽然我不完全理解这一点,但我的印象是,这必须设置在主机端(我的用户需要能够从web上的任何位置提取图像并将其用作纹理)>>我尝试过这个:……但没有成功(可能是因为我对“CORS批准”的构成有误解)

我想也许做一些php代理可能会有用?我试过:…但似乎也没有任何运气。(它可能不是为处理图像而编写的…我遇到了MIME类型的错误…当我进行一些黑客攻击时,我设法消除了错误…但仍然没有运气)


…希望有人能帮上忙!

EUREKA!!!像loox一样的代理是最好的选择, 这就成功了:)


我发现,对于three.js,在使用three.ImageUtils.loadTexture函数时,WebGL+CORS对我不起作用

不过,这段代码确实对我有用(注意:corsproxy.com与Nick回答中的PHP做的相同)


您可以从其他服务器下载映像,然后使用它。
<?php
// PHP Proxy
// Responds to both HTTP GET and POST requests
//
// Author: Abdul Qabiz
// March 31st, 2006
//

// Get the url of to be proxied
// Is it a POST or a GET?
$url = ($_POST['url']) ? $_POST['url'] : $_GET['url'];
$headers = ($_POST['headers']) ? $_POST['headers'] : $_GET['headers'];
$mimeType =($_POST['mimeType']) ? $_POST['mimeType'] : $_GET['mimeType'];


//Start the Curl session
$session = curl_init($url);

// If it's a POST, put the POST data in the body
if ($_POST['url']) {
    $postvars = '';
    while ($element = current($_POST)) {
        $postvars .= key($_POST).'='.$element.'&';
        next($_POST);
    }
    curl_setopt ($session, CURLOPT_POST, true);
    curl_setopt ($session, CURLOPT_POSTFIELDS, $postvars);
}

// Don't return HTTP headers. Do return the contents of the call
curl_setopt($session, CURLOPT_HEADER, ($headers == "true") ? true : false);

curl_setopt($session, CURLOPT_FOLLOWLOCATION, true); 
//curl_setopt($ch, CURLOPT_TIMEOUT, 4); 
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);

// Make the call
$response = curl_exec($session);

if ($mimeType != "")
{
    // The web service returns XML. Set the Content-Type appropriately
    header("Content-Type: ".$mimeType);
}

echo $response;

curl_close($session);

?>
var url = 'http://www.corsproxy.com/yourdomain/yourfolder/yourimage.png';    
var image = document.createElement('img');
image.crossOrigin = '';
image.src = url;
var texture = new THREE.Texture(image);
texture.needsUpdate = true;
material.map = texture;