Skip to content

Instantly share code, notes, and snippets.

@akjava
Created March 6, 2019 07:50
Show Gist options
  • Save akjava/f9492b19dd57393f9f6c85dbd542f659 to your computer and use it in GitHub Desktop.
Save akjava/f9492b19dd57393f9f6c85dbd542f659 to your computer and use it in GitHub Desktop.
convert TileMap Image(4x3 Old equirectangular format) to cube texture map on three.js
function tileMapToCubeTextureImages(image){//image must be loaded
var positions=[
[2,1],//right
[0,1],//left
[1,0],//up
[1,2],//down
[1,1],//front
[3,1],//back
]
var images=[];
var cubicSize=image.width/4;
for(var i=0;i<6;i++){
var canvas = document.createElement('canvas');
canvas.width=cubicSize;
canvas.height=cubicSize;
var ctx=canvas.getContext('2d');
var x=positions[i][0];
var y=positions[i][1];
canvas.getContext('2d').drawImage(image,-cubicSize*x, -cubicSize*y);
var urlImage= document.createElement('img');
urlImage.src=canvas.toDataURL();
images.push(urlImage);
}
return images;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment