Skip to content

Instantly share code, notes, and snippets.

@jbilcke
Created October 6, 2011 10:51
Show Gist options
  • Save jbilcke/1267122 to your computer and use it in GitHub Desktop.
Save jbilcke/1267122 to your computer and use it in GitHub Desktop.
Download a texture using JQuery and YQL - please have a look at it before copypasting it inside your code (remember, YQL has quotas (1000queries/h for anonymous queries), and I'm not a Three.JS expert so I'm not sure about memory leaks, too)
// Use this function like the standard THREE.ImageUtils.loadTexture
THREE.ImageUtils.loadTextureWithYQL = function ( path, mapping, callback ) {
var image = new Image(), texture = new THREE.Texture( image, mapping );
var me = this;
image.onload = function () { };
image.crossOrigin = '';
image.src = path;
var query = 'select * from data.uri where url="'+path+'"';
var yql = 'http://query.yahooapis.com/v1/public/yql?q=' + encodeURIComponent(query) + '&format=json&diagnostics=false&callback=?';
$.getJSON(yql, function(data)
{
var dataUri = data.query.results.url;
var canvas = document.createElement('canvas');;
var ctx = canvas.getContext('2d');
image = new Image();
image.onload = function(){
ctx.drawImage(image,0,0);
texture.image = image;
texture.needsUpdate = true;
if ( callback ) callback( me );
};
image.src = dataUri;
});
return texture;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment