I wanted to create a 3D model of the moon with a 2D map. But when I am giving the texture as image tiles based on the zoom level, there is significant distortion of the square tiles at the poles. Is there any way to mathematically warp and stitch the tiles to prevent distortion? I tried Decals, but no method works till now.
I have added the observed distortion and the code I have currently used to give the texture
const [zoom, x, y] = tileKey.split('/').map(Number);
const tilesPerRow = Math.pow(2, zoom);
const uOffset = x / tilesPerRow;
const vOffset = y / tilesPerRow;
const uvScale = 1 / tilesPerRow;
const geometry = new THREE.SphereGeometry(
2,
64,
64,
uOffset * Math.PI * 2,
uvScale * Math.PI * 2,
vOffset * Math.PI,
uvScale * Math.PI
);
// Create a group to hold both base and overlay meshes
const group = new THREE.Group();
// Base material - always created
const baseMaterial = new THREE.MeshPhongMaterial({
map: baseTexture,
combine: THREE.MultiplyOperation,
shininess: 30
});
const baseMesh = new THREE.Mesh(geometry, baseMaterial);
group.add(baseMesh);
const baseTexture = await loadTexture(`/images/images/${tileKey}.jpg`)
.catch(() => {
// Create fallback texture for base layer
const canvas = document.createElement('canvas');
canvas.width = canvas.height = 256;
const ctx = canvas.getContext('2d');
ctx.fillStyle = '#444444';
ctx.fillRect(0, 0, 256, 256);
return new THREE.CanvasTexture(canvas);
});