Created
March 6, 2019 07:50
-
-
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
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
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