Created
October 6, 2011 10:51
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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