Hi,
I am trying to create some generic mesh using boxGeometry, where the dimensions will be given as an input. It would use a texture (that I just downloaded from polyHaven for now…)
Although, whatever I try it gets stretched at least on one side:
What I have tried
const repeatTextures = (textures, width, height) => {
textures.forEach((t) => {
// t.repeat.set(2, 2);
t.wrapS = THREE.RepeatWrapping;
t.WrapT = THREE.RepeatWrapping;
t.needsUpdate = true;
});
};
export function genericMesh(props) {
const { position, width = 1000, height = 1000, depth = 100 } = props;
const [colorMap, aoMap, dispMap, normMap, roughMap] = useTexture([
"./asset/metal/green_metal_rust_diff_1k.jpg",
"./asset/metal/green_metal_rust_ao_1k.jpg",
"./asset/metal/green_metal_rust_disp_1k.png",
"./asset/metal/green_metal_rust_nor_gl_1k.jpg",
"./asset/metal/green_metal_rust_rough_1k.jpg",
]);
repeatTextures(
[colorMap, aoMap, dispMap, normMap, roughMap],
width,
height
);
const material = useMemo(() => {
return new THREE.MeshPhysicalMaterial({
side: THREE.DoubleSide,
map: colorMap,
aoMap,
displacementMap: dispMap,
normalMap: normMap,
roughnessMap: roughMap,
});
}, [colorMap, aoMap, dispMap, normMap, roughMap]);
return (
<group>
<mesh position={[0, 500, 0]} material={material}>
<boxGeometry args={[width, height, depth]}></boxGeometry>
</mesh>
</group>
);
}
Adding back the repeat texture it gets even worse
Can someone point out what did I misunderstood or I am doing wrong?
Many thanks,
Mat