diff --git a/frontend/src/app/particles/services/player-model.service.ts b/frontend/src/app/particles/services/player-model.service.ts index d34188f..8e4ee88 100644 --- a/frontend/src/app/particles/services/player-model.service.ts +++ b/frontend/src/app/particles/services/player-model.service.ts @@ -213,37 +213,43 @@ export class PlayerModelService { // 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 textureWidth = 64; const textureHeight = 64; - 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++) { const face = uvMapping[faceOrder[i]]; - const x1 = face.x / textureWidth; const y1 = 1 - face.y / textureHeight; const x2 = (face.x + face.w) / textureWidth; const y2 = 1 - (face.y + face.h) / textureHeight; - // Each face has 4 vertices → 4 * 2 = 8 UV entries - const uvOffset = i * 8; + let uvs: [number, number][] = [ + [x2, y1], // top-right + [x2, y2], // bottom-right + [x1, y2], // bottom-left + [x1, y1] // top-left + ]; - // BoxGeometry face UV layout: - // [ top-right, bottom-right, bottom-left, top-left ] - uv.array[uvOffset] = x2; - uv.array[uvOffset + 1] = y1; - uv.array[uvOffset + 2] = x2; - uv.array[uvOffset + 3] = y2; - uv.array[uvOffset + 4] = x1; - uv.array[uvOffset + 5] = y2; - uv.array[uvOffset + 6] = x1; - uv.array[uvOffset + 7] = y1; + // Optional: rotate UVs if needed + const rot = faceUVRotations[i]; + if (rot === 90) uvs = [uvs[3], uvs[0], uvs[1], uvs[2]]; + else if (rot === 180) uvs = [uvs[2], uvs[3], uvs[0], uvs[1]]; + else if (rot === 270) uvs = [uvs[1], uvs[2], uvs[3], uvs[0]]; + + const uvOffset = i * 8; + for (let j = 0; j < 4; j++) { + uv.array[uvOffset + j * 2] = uvs[j][0]; + uv.array[uvOffset + j * 2 + 1] = uvs[j][1]; + } } uv.needsUpdate = true; + // Create material with the skin texture const material = new THREE.MeshBasicMaterial({ map: this.skinTexture,