Fix uv rotation

This commit is contained in:
Teriuihi 2025-06-22 20:04:26 +02:00
parent 02c6497700
commit e00165c56f

View File

@ -213,37 +213,43 @@ export class PlayerModelService {
// Remap your custom face order to BoxGeometry face order: px, nx, py, ny, pz, nz // Remap your custom face order to BoxGeometry face order: px, nx, py, ny, pz, nz
const faceOrder = [2, 3, 0, 1, 4, 5]; // right, left, top, bottom, front, back const faceOrder = [2, 3, 0, 1, 4, 5]; // right, left, top, bottom, front, back
const textureWidth = 64; const textureWidth = 64;
const textureHeight = 64; const textureHeight = 64;
const uv = geometry.attributes['uv']; const uv = geometry.attributes['uv'];
// Per-face UV rotation (in degrees): adjust as needed (0, 90, 180, 270)
const faceUVRotations = [90, 90, 90, 90, 90, 90]; // adjust if needed
for (let i = 0; i < 6; i++) { for (let i = 0; i < 6; i++) {
const face = uvMapping[faceOrder[i]]; const face = uvMapping[faceOrder[i]];
const x1 = face.x / textureWidth; const x1 = face.x / textureWidth;
const y1 = 1 - face.y / textureHeight; const y1 = 1 - face.y / textureHeight;
const x2 = (face.x + face.w) / textureWidth; const x2 = (face.x + face.w) / textureWidth;
const y2 = 1 - (face.y + face.h) / textureHeight; const y2 = 1 - (face.y + face.h) / textureHeight;
// Each face has 4 vertices → 4 * 2 = 8 UV entries let uvs: [number, number][] = [
const uvOffset = i * 8; [x2, y1], // top-right
[x2, y2], // bottom-right
[x1, y2], // bottom-left
[x1, y1] // top-left
];
// BoxGeometry face UV layout: // Optional: rotate UVs if needed
// [ top-right, bottom-right, bottom-left, top-left ] const rot = faceUVRotations[i];
uv.array[uvOffset] = x2; if (rot === 90) uvs = [uvs[3], uvs[0], uvs[1], uvs[2]];
uv.array[uvOffset + 1] = y1; else if (rot === 180) uvs = [uvs[2], uvs[3], uvs[0], uvs[1]];
uv.array[uvOffset + 2] = x2; else if (rot === 270) uvs = [uvs[1], uvs[2], uvs[3], uvs[0]];
uv.array[uvOffset + 3] = y2;
uv.array[uvOffset + 4] = x1; const uvOffset = i * 8;
uv.array[uvOffset + 5] = y2; for (let j = 0; j < 4; j++) {
uv.array[uvOffset + 6] = x1; uv.array[uvOffset + j * 2] = uvs[j][0];
uv.array[uvOffset + 7] = y1; uv.array[uvOffset + j * 2 + 1] = uvs[j][1];
}
} }
uv.needsUpdate = true; uv.needsUpdate = true;
// Create material with the skin texture // Create material with the skin texture
const material = new THREE.MeshBasicMaterial({ const material = new THREE.MeshBasicMaterial({
map: this.skinTexture, map: this.skinTexture,