Simplify UV mapping logic and remove unnecessary face rotation handling
This commit is contained in:
parent
e00165c56f
commit
39f20796ce
|
|
@ -211,15 +211,12 @@ export class PlayerModelService {
|
||||||
): THREE.Mesh {
|
): THREE.Mesh {
|
||||||
const geometry = new THREE.BoxGeometry(width, height, depth);
|
const geometry = new THREE.BoxGeometry(width, height, depth);
|
||||||
|
|
||||||
// Remap your custom face order to BoxGeometry face order: px, nx, py, ny, pz, nz
|
// Remap the 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;
|
||||||
|
|
@ -228,18 +225,12 @@ export class PlayerModelService {
|
||||||
const y2 = 1 - (face.y + face.h) / textureHeight;
|
const y2 = 1 - (face.y + face.h) / textureHeight;
|
||||||
|
|
||||||
let uvs: [number, number][] = [
|
let uvs: [number, number][] = [
|
||||||
|
[x1, y1], // top-left
|
||||||
[x2, y1], // top-right
|
[x2, y1], // top-right
|
||||||
[x2, y2], // bottom-right
|
|
||||||
[x1, y2], // bottom-left
|
[x1, y2], // bottom-left
|
||||||
[x1, y1] // top-left
|
[x2, y2] // bottom-right
|
||||||
];
|
];
|
||||||
|
|
||||||
// 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;
|
const uvOffset = i * 8;
|
||||||
for (let j = 0; j < 4; j++) {
|
for (let j = 0; j < 4; j++) {
|
||||||
uv.array[uvOffset + j * 2] = uvs[j][0];
|
uv.array[uvOffset + j * 2] = uvs[j][0];
|
||||||
|
|
@ -249,31 +240,14 @@ export class PlayerModelService {
|
||||||
|
|
||||||
uv.needsUpdate = true;
|
uv.needsUpdate = true;
|
||||||
|
|
||||||
|
|
||||||
// Create material with the skin texture
|
|
||||||
const material = new THREE.MeshBasicMaterial({
|
const material = new THREE.MeshBasicMaterial({
|
||||||
map: this.skinTexture,
|
map: this.skinTexture,
|
||||||
transparent: true,
|
transparent: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Create mesh and set position
|
|
||||||
const mesh = new THREE.Mesh(geometry, material);
|
const mesh = new THREE.Mesh(geometry, material);
|
||||||
const wireframeMaterial = new THREE.MeshBasicMaterial({
|
|
||||||
wireframe: true,
|
|
||||||
color: 0xff0000
|
|
||||||
});
|
|
||||||
const wireframe = new THREE.Mesh(geometry, wireframeMaterial);
|
|
||||||
mesh.add(wireframe);
|
|
||||||
|
|
||||||
mesh.position.set(position.x, position.y, position.z);
|
mesh.position.set(position.x, position.y, position.z);
|
||||||
|
|
||||||
return mesh;
|
return mesh;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the player model
|
|
||||||
*/
|
|
||||||
getPlayerModel(): THREE.Group {
|
|
||||||
return this.playerModel;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user