From 3c599093cf845b9d12b8e16fac67643e32881fd2 Mon Sep 17 00:00:00 2001 From: marti Date: Tue, 23 Dec 2025 13:13:37 +0100 Subject: [PATCH] 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. --- src/main.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/main.js b/src/main.js index c21e8d6..bdb0c78 100644 --- a/src/main.js +++ b/src/main.js @@ -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;