Hello, I’m trying to develop a mug customizer but when I add the texture with the method below, it duplicates the texture and adds it to half the normal mug and to the other half in mirror mode, if someone could help me, it would be perfect
function updateTextureFromCanvas(mesh) {
const texture = new THREE.CanvasTexture(canvas.value.lowerCanvasEl);
mesh.material.map = texture;
mesh.material.needsUpdate = true;
mesh.geometry.computeBoundingBox();
console.log(mesh.geometry)
let box = mesh.geometry.boundingBox;
let size = new THREE.Vector3();
box.getSize(size);
let pa = mesh.geometry.attributes.position.array;
let uva = mesh.geometry.attributes.uv.array;
let v = new THREE.Vector3();
for (let i = 0, j = 0; i < pa.length; i += 3, j += 2) {
v.set(pa[i], pa[i + 1], pa[i + 2]);
v.sub(box.min);
v.multiplyScalar(1 / size.x);
uva[j] = v.x;
uva[j + 1] = v.y;
}
mesh.geometry.attributes.uv.needsUpdate = true;
}