Created
September 8, 2016 00:28
-
-
Save ikeryou/a85cf03f70bb832164c7ad51f58f12a6 to your computer and use it in GitHub Desktop.
three.js BufferGeometryのサイズ設定
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
geo = new THREE.BufferGeometry(); | |
geo.setIndex(new THREE.BufferAttribute(new Uint16Array(3 * 2), 1)); | |
geo.addAttribute('position', new THREE.BufferAttribute(new Float32Array(3 * 4), 3)); | |
geo.addAttribute('uv', new THREE.BufferAttribute(new Float32Array(2 * 4), 2)); | |
// サイズ | |
w = 1000; | |
h = 1000; | |
// 頂点インデックス | |
index = geo.index.array; | |
index[0] = 0; | |
index[1] = 1; | |
index[2] = 2; | |
index[3] = 0; | |
index[4] = 2; | |
index[5] = 3; | |
// UV座標 | |
uv = geo.attributes.uv.array; | |
uv[0] = 0; | |
uv[1] = 0; | |
uv[2] = 1; | |
uv[3] = 0; | |
uv[4] = 1; | |
uv[5] = 1; | |
uv[6] = 0; | |
uv[7] = 1; | |
// 頂点位置 | |
pos = geo.attributes.position.array; | |
pos[0] = -w * 0.5; | |
pos[1] = -h * 0.5; | |
pos[2] = 0; | |
pos[3] = w * 0.5; | |
pos[4] = -h * 0.5; | |
pos[5] = 0; | |
pos[6] = w * 0.5; | |
pos[7] = h * 0.5; | |
pos[8] = 0; | |
pos[9] = -w * 0.5; | |
pos[10] = h * 0.5; | |
pos[11] = 0; | |
// 動的に変えるときは忘れずに | |
geo.attributes.position.needsUpdate = true; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment