Last active
March 29, 2020 23:25
-
-
Save DevEarley/e9f818b283d3978cdc9964b06a911d6c to your computer and use it in GitHub Desktop.
Convert a 1D array into a 3D grid
This file contains hidden or 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
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