Texture on dynamically created object

I wrote a short code to fix this thing:

var box = new THREE.Box3().setFromObject(mesh);
var size = new THREE.Vector3();
box.getSize(size)
mesh.geometry.faceVertexUvs[0].forEach(fvUvs => {
  fvUvs.forEach(fvUv => {
    fvUv.x = (fvUv.x - box.min.x) / size.x;
    fvUv.y = 1 - (fvUv.y - box.min.y) / size.y;
  });
});

https://jsfiddle.net/prisoner849/k0vg5ore/
I’m not sure though, how correct that approach is, but, at least, it works :slight_smile:

2 Likes