Created
January 17, 2019 08:47
-
-
Save JoostKiens/ca8d03613382c453e3551d6adf733407 to your computer and use it in GitHub Desktop.
Create a 3D grid in uvw coordinates for THREE.js (pure function, no loops)
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
const createUVWGrid = ([cx, cy, cz]) => { | |
return times(cx).map(x => times(cy).map((y) => times(cz).map(z => | |
new THREE.Vector3( | |
cx <= 1 ? 0.5 : x / (cx - 1), | |
cy <= 1 ? 0.5 : y / (cy - 1), | |
cz <= 1 ? 0.5 : z / (cz - 1) | |
) | |
))).flat(2) | |
} | |
const times = (n) => Array.from(new Array(n)).map((_, i) => i) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment