Skip to content

Instantly share code, notes, and snippets.

@JoostKiens
Created January 17, 2019 08:47
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 JoostKiens/ca8d03613382c453e3551d6adf733407 to your computer and use it in GitHub Desktop.
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)
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