Fix: Texture stretching in large rooms

- Used texture cloning for floor tiles to ensure independent repeat settings for each room.
- Calculated texture repetition based on room dimensions relative to the base 4x4 tile size, preventing distortion in non-square rooms.
This commit is contained in:
2025-12-23 13:13:37 +01:00
parent 12fb18b1de
commit 3c599093cf

View File

@@ -790,13 +790,21 @@ async function renderRoom(room) {
entities: []
};
// Renderizar tile
// Renderizar tile
const tileDef = ASSETS.tiles[room.tile.type];
const tileTex = await loadTexture(tileDef.src);
const baseTex = await loadTexture(tileDef.src);
const tileTex = baseTex.clone(); // CLONAR para no afectar a otras salas
tileTex.needsUpdate = true; // Asegurar que Three.js sepa que es nueva
tileTex.wrapS = THREE.RepeatWrapping;
tileTex.wrapT = THREE.RepeatWrapping;
// Ajustar repetición según tamaño real de la sala para evitar estiramiento
tileTex.repeat.set(tileDef.width / 4, tileDef.height / 4);
// Lógica de repetición: La textura base es de 4x4 celdas.
// Si la sala es 8x4, repetimos 2 en X, 1 en Y.
const repeatX = tileDef.width / 4;
const repeatY = tileDef.height / 4;
tileTex.repeat.set(repeatX, repeatY);
const worldWidth = tileDef.width * CONFIG.CELL_SIZE;
const worldHeight = tileDef.height * CONFIG.CELL_SIZE;