在 libgdx Mesh, Color, Texture 教程中,Mesh 表示一个简单的三角形,每个顶点的颜色和纹理信息由以下方法创建:
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
构造函数中,整数参数是什么?该文档说它是编码信息所需的“组件数量”。
我将其读取为每个条目使用的“顶点”数组(浮点数组)中的条目数。因此,对于第一个VertexAttribute
是 3,这是有道理的(x、y 和 z 各一个)。但是,ColorPacked 属性有 4,但是由于颜色数据被编码为单个浮点数,这不应该是 1 吗?最后添加纹理坐标(得到 2,与每个顶点所需的两个浮点 u,v 坐标相匹配)。
VertexAttribute 构造函数的javadoc说这个参数是:
numComponents - the number of components of this attribute, must be between 1 and 4.
请注意一个较旧的问题, VertexAttribute() 中的第三个参数用于 libgdx 中是什么?, 涵盖了这个构造函数的第三个参数,所以我们只需要一个 SO 问题来涵盖第一个。:)