libgdxメッシュ、色、テクスチャ チュートリアルでは、各頂点の色とテクスチャ情報を持つ単純な三角形を表すメッシュが次のように作成されます。
mesh = new Mesh(true, 3, 3,
new VertexAttribute(Usage.Position, 3, "a_position"),
new VertexAttribute(Usage.ColorPacked, 4, "a_color"),
new VertexAttribute(Usage.TextureCoordinates, 2, "a_texCoords"));
コンストラクターのVertexAttribute
整数引数は何ですか? ドキュメントには、情報をエンコードするために必要な「コンポーネントの数」と書かれています。
I read that as the number of entries in the 'vertex' array (an array of floats) that each entry uses. So, for the first VertexAttribute
that is 3, which makes sense (one each for x, for y, and for z). However, the ColorPacked attribute has 4 but but since the color data gets encoded into a single float, shouldn't this be 1? Finally the texture coordinates are added (that gets 2, which matches the two float u,v coordinates needed for each vertex).
The javadoc for the VertexAttribute constructor says this parameter is:
numComponents - the number of components of this attribute, must be between 1 and 4.
Note an older question, Whats the 3rd argument in VertexAttribute() used for in libgdx?, covers the 3rd argument to this constructor, so we just need one more SO question to cover the first. :)