Skip to content

Instantly share code, notes, and snippets.

@AlainBarrios
Created April 26, 2020 02:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlainBarrios/7ad1f87a6913e384bac45ce104f77516 to your computer and use it in GitHub Desktop.
Save AlainBarrios/7ad1f87a6913e384bac45ce104f77516 to your computer and use it in GitHub Desktop.
/* this.bufferGeometry.setAttribute(
"uv",
new THREE.BufferAttribute(uvArray, 2)
);
*/
createUV(mesh) {
const box = new THREE.Box3().setFromObject(mesh);
const size = new THREE.Vector3();
box.getSize(size);
const vec3 = new THREE.Vector3();
const { position, uv } = this.bufferGeometry.attributes;
for (let i = 0; i < position.count; i++) {
vec3.fromBufferAttribute(position, i);
const x = (vec3.x - box.min.x) / size.x;
const y = (vec3.y - box.min.y) / size.y;
uv.setXYZ(i, x, y);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment