3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Babylon jsで独自attributeを設定するメモ

Posted at

Babylon jsでカスタムattributeを設定するやり方がドキュメントで詳しく載ってなかったのでメモ。

まずShaderMaterialを作るときに、attributesに設定したい値の名前を入れる。
ここで設定した名前がshader上でのattribute名に。

new ShaderMaterial("material", scene,
  {
    fragmentElement: document.getElementById('frag'),
    vertexElement: document.getElementById('vert')
  },
  {
    attributes: ['velocity']
  }

fragment,vertexのあたりはてきとーに自分の環境に合わせる。

このmaterialをつけるmeshにattributeデータを設定

mesh.setVerticesData, 'velocity', velocities, true, 3

引数は順番に

  • attribute名
  • データ(Array)
  • 変更可能かどうか(true/false)
  • 個々のデータ長(Vector3だと3、Vector2だと2、みたいな感じ)

これでvelocitiesにずらっと値を入れとけば、vertex shader上でindicesに対応したデータがとれるはず。

3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?