Hi guys .I hope you are well.
I am creating a 3d configurator for clothes like T-shirts.
I have Problem in adding different images correctly on each meshes.
I used DecalGeometry but for curve layers(meshes) I have problem in image projection. (In some meshes by the reason of way of projection I see bad stretch image o n layer. )
this is three.js result:(look at sleeves too)
By default decalgeometry and load texture on it is upon mesh .In substance painater software we have Image projection too like this picture:(In three js decal type of projection is like planer projection in substance painter But the correct form is uv projection , I need to do uv projection in three.js decalGeometry)
this is planar projection in substance painter that is like three.js default decalGeometry:
And this is uv projection image on substance painter that I need in three.js decalGeometry :
And this is my code:
async function imageTextureManager(file, normalTextureURL, id) {
const textureLoader = new THREE.TextureLoader();
const texture = await textureLoader.loadAsync(file);
texture.encoding = THREE.sRGBEncoding;
const normalTexture = await textureLoader.loadAsync(normalTextureURL);
normalTexture.wrapS = THREE.RepeatWrapping;
normalTexture.wrapT = THREE.RepeatWrapping;
normalTexture.repeat.set(5, 5);
const decalMaterial = new THREE.MeshStandardMaterial(
{
side: THREE.DoubleSide,
normalMap: normalTexture,
normalScale: new THREE.Vector2(0.3, 0.3),
map: texture,
transparent: true,
depthTest: true,
depthWrite: false,
polygonOffset: true,
polygonOffsetUnits: 1,
polygonOffsetFactor: -4,
});
decalMaterial.map.encoding = THREE.sRGBEncoding;
decalMaterial.needsUpdate = true;
**addNewDecal**(decalMaterial, file, normalTextureURL, id)
tick()
}
async function **addNewDecal**(decalMaterial, imageFile, normalTextureURL, id) {
const newMesh = activeMeshRef.current
newMesh.geometry.computeBoundingBox();
var boundingBox = newMesh.geometry.boundingBox;
var position = new THREE.Vector3();
position.subVectors(boundingBox.max, boundingBox.min);
position.multiplyScalar(0.5);
position.add(boundingBox.min);
position.applyMatrix4(newMesh.matrixWorld);
const meshSize = getMeshSize(newMesh);
let rot = new THREE.Euler(0, 0, 0)
if (position.z < 0) {
console.log('position is on back')
rot = new THREE.Euler(0, degToRad(180), 0)
}
let newDecal = new DecalGeometry(activeMeshRef.current, position, rot, meshSize);
newDecal.name = id
selectedDecalID.current = id
const decalMesh = new THREE.Mesh(newDecal, decalMaterial);
decalMesh.name = id
scene.current.add(decalMesh);
}