Created
April 26, 2020 02:01
-
-
Save AlainBarrios/7ad1f87a6913e384bac45ce104f77516 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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