How to use UVs in ShapeBufferGeometry?

The part, that you need, is here:

var box = new THREE.Box3().setFromObject(mesh);
var size = new THREE.Vector3();
box.getSize(size);
var vec3 = new THREE.Vector3(); // temp vector
var attPos = mesh.geometry.attributes.position;
var attUv = mesh.geometry.attributes.uv;
for (let i = 0; i < attPos.count; i++){
	vec3.fromBufferAttribute(attPos, i);
	attUv.setXY(i,
  	(vec3.x - box.min.x) / size.x,
    (vec3.y - box.min.y) / size.y
  );
}
1 Like