Created
July 8, 2018 17:54
-
-
Save kenjiSpecial/e991ec1dfb7b9331ccb22e0dd2ccfcf6 to your computer and use it in GitHub Desktop.
セグメントなしのシンプルな直方体・立方体の頂点、法線を返す関数
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 createBoxArrary(width, height, depth) { | |
| let x = -width / 2; | |
| let y = -height / 2; | |
| let z = -depth / 2; | |
| let fbl = { | |
| x: x, | |
| y: y, | |
| z: z + depth | |
| }; | |
| let fbr = { | |
| x: x + width, | |
| y: y, | |
| z: z + depth | |
| }; | |
| let ftl = { | |
| x: x, | |
| y: y + height, | |
| z: z + depth | |
| }; | |
| let ftr = { | |
| x: x + width, | |
| y: y + height, | |
| z: z + depth | |
| }; | |
| let bbl = { | |
| x: x, | |
| y: y, | |
| z: z | |
| }; | |
| let bbr = { | |
| x: x + width, | |
| y: y, | |
| z: z | |
| }; | |
| let btl = { | |
| x: x, | |
| y: y + height, | |
| z: z | |
| }; | |
| let btr = { | |
| x: x + width, | |
| y: y + height, | |
| z: z | |
| }; | |
| let positions = new Float32Array([ | |
| //front | |
| fbl.x, | |
| fbl.y, | |
| fbl.z, | |
| fbr.x, | |
| fbr.y, | |
| fbr.z, | |
| ftl.x, | |
| ftl.y, | |
| ftl.z, | |
| ftl.x, | |
| ftl.y, | |
| ftl.z, | |
| fbr.x, | |
| fbr.y, | |
| fbr.z, | |
| ftr.x, | |
| ftr.y, | |
| ftr.z, | |
| //right | |
| fbr.x, | |
| fbr.y, | |
| fbr.z, | |
| bbr.x, | |
| bbr.y, | |
| bbr.z, | |
| ftr.x, | |
| ftr.y, | |
| ftr.z, | |
| ftr.x, | |
| ftr.y, | |
| ftr.z, | |
| bbr.x, | |
| bbr.y, | |
| bbr.z, | |
| btr.x, | |
| btr.y, | |
| btr.z, | |
| //back | |
| fbr.x, | |
| bbr.y, | |
| bbr.z, | |
| bbl.x, | |
| bbl.y, | |
| bbl.z, | |
| btr.x, | |
| btr.y, | |
| btr.z, | |
| btr.x, | |
| btr.y, | |
| btr.z, | |
| bbl.x, | |
| bbl.y, | |
| bbl.z, | |
| btl.x, | |
| btl.y, | |
| btl.z, | |
| //left | |
| bbl.x, | |
| bbl.y, | |
| bbl.z, | |
| fbl.x, | |
| fbl.y, | |
| fbl.z, | |
| btl.x, | |
| btl.y, | |
| btl.z, | |
| btl.x, | |
| btl.y, | |
| btl.z, | |
| fbl.x, | |
| fbl.y, | |
| fbl.z, | |
| ftl.x, | |
| ftl.y, | |
| ftl.z, | |
| //top | |
| ftl.x, | |
| ftl.y, | |
| ftl.z, | |
| ftr.x, | |
| ftr.y, | |
| ftr.z, | |
| btl.x, | |
| btl.y, | |
| btl.z, | |
| btl.x, | |
| btl.y, | |
| btl.z, | |
| ftr.x, | |
| ftr.y, | |
| ftr.z, | |
| btr.x, | |
| btr.y, | |
| btr.z, | |
| //bottom | |
| bbl.x, | |
| bbl.y, | |
| bbl.z, | |
| bbr.x, | |
| bbr.y, | |
| bbr.z, | |
| fbl.x, | |
| fbl.y, | |
| fbl.z, | |
| fbl.x, | |
| fbl.y, | |
| fbl.z, | |
| bbr.x, | |
| bbr.y, | |
| bbr.z, | |
| fbr.x, | |
| fbr.y, | |
| fbr.z | |
| ]); | |
| let normals = new Float32Array(positions.length); | |
| let i, count; | |
| let ni; | |
| for (i = 0, count = positions.length / 3; i < count; i++) { | |
| ni = i * 3; | |
| normals[ni] = parseInt(i / 6, 10) === 1 ? 1 : parseInt(i / 6, 10) === 3 ? -1 : 0; | |
| normals[ni + 1] = parseInt(i / 6, 10) === 4 ? 1 : parseInt(i / 6, 10) === 5 ? -1 : 0; | |
| normals[ni + 2] = parseInt(i / 6, 10) === 0 ? 1 : parseInt(i / 6, 10) === 2 ? -1 : 0; | |
| } | |
| return { | |
| positions: positions, | |
| normals: normals | |
| }; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment