Skip to content

Instantly share code, notes, and snippets.

@DevEarley
Last active March 29, 2020 23:25
Show Gist options
  • Save DevEarley/e9f818b283d3978cdc9964b06a911d6c to your computer and use it in GitHub Desktop.
Save DevEarley/e9f818b283d3978cdc9964b06a911d6c to your computer and use it in GitHub Desktop.
Convert a 1D array into a 3D grid
function arrayTo3DGrid(xMax, yMax, zMax) {
let vertices = []
let totalVertices = xMax * yMax * zMax;
let xySquare = xMax * yMax;
for (let i = 0; i < totalVertices; i++) {
let x = i % xMax;
let z = Math.floor(i / (xySquare));
let ii = i - (z * xySquare);
let y = Math.floor(ii / xMax);
vertices.push(x, y, z);
}
return vertices;
}
function spriteTest1() {
let xMax = 100;
let yMax = 100;
let zMax = 100;
return arrayTo3DGrid(xMax, yMax, zMax)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment