Skip to content

Instantly share code, notes, and snippets.

@ikeryou
Created September 8, 2016 00:28
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 ikeryou/a85cf03f70bb832164c7ad51f58f12a6 to your computer and use it in GitHub Desktop.
Save ikeryou/a85cf03f70bb832164c7ad51f58f12a6 to your computer and use it in GitHub Desktop.
three.js BufferGeometryのサイズ設定
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