Skip to content

Instantly share code, notes, and snippets.

@cabbibo
Created September 23, 2020 18:21
Show Gist options
  • Save cabbibo/b9d6a7a916941eb09f8e1933c751aaf2 to your computer and use it in GitHub Desktop.
Save cabbibo/b9d6a7a916941eb09f8e1933c751aaf2 to your computer and use it in GitHub Desktop.
Glacier.prototype.Get3DPosition = function(x,y){
// if(!offset){ offset = 0}
// offset = 0;
var x2 = Math.floor(x * this.imageData.width);
var y2 = Math.floor(y * this.imageData.height);
var color = getPixel( this.imageData, x2,y2);
var h = color.r;
h = Math.pow( h , .8);
var v = new T.Vector3( x - .5, y - .5 , h);
v.z *= this.offset ;
v.z += .03;
return v;
}
function getImageData( image ) {
var canvas = document.createElement( 'canvas' );
canvas.width = image.width;
canvas.height = image.height;
var context = canvas.getContext( '2d' );
context.drawImage( image, 0, 0 );
return context.getImageData( 0, 0, image.width, image.height );
}
function getPixel( imagedata, x, y ) {
var position = ( x + imagedata.width * y ) * 4, data = imagedata.data;
var color = new T.Color(
data[ position + 0]/256,
data[ position + 1]/256,
data[position + 2 ]/256
);
return color;// { r: data[ position ], g: data[ position + 1 ], b: data[ position + 2 ], a: data[ position + 3 ] };
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment