I am creating a t-shirt configurator and I use decal geometry to show images on each mesh.
But for sleeves, it appears twice like a mirror
this is my code:
const decalMaterial = new THREE.MeshStandardMaterial(
{
normalMap: normalTexture,
normalScale: new THREE.Vector2(1.5, 1.5),
map: texture,
transparent: true,
depthTest: true,
depthWrite: false,
polygonOffset: true,
polygonOffsetUnits: 1,
polygonOffsetFactor: -4,
});
decalMaterial.map.encoding = THREE.sRGBEncoding;
decalMaterial.needsUpdate = true;
const newMesh = activeMeshRef.current
newMesh.geometry.computeBoundingBox();
var boundingBox = newMesh.geometry.boundingBox;
position.subVectors(boundingBox.max, boundingBox.min);
position.multiplyScalar(0.5);
position.add(boundingBox.min);
position.applyMatrix4(newMesh.matrixWorld);
meshSize = getMeshSize(newMesh);
scale = new THREE.Vector3(width, height, Number(meshSize.z.toFixed(4)))
ratio = Number((width / height).toFixed(4))
position.x = +position.x.toFixed(4)
position.y = +position.y.toFixed(4)
position.z = +position.z.toFixed(4)
meshSize.x = +meshSize.x.toFixed(4)
meshSize.y = +meshSize.y.toFixed(4)
meshSize.z = +meshSize.z.toFixed(4)
if (position.z < 0) {
rot = new THREE.Euler(0, degToRad(180), 0)
}
}
let newDecal = new DecalGeometry(activeMeshRef.current, position, rot, scale);
const decalMesh = new THREE.Mesh(newDecal, decalMaterial1);
scene.current.add(decalMesh);
Result:
It is ok in frontside and …
but in sleeves:
and this is my model. Does geometry or uv have any problem? Does decalgeometry work upon UV?
M.glb (694.6 KB)