XNA 4.0自定义顶点声明

本文关键字:顶点 声明 自定义 XNA | 更新日期: 2023-09-27 18:26:35

我目前正在尝试进行自定义顶点声明。

一种将位置、颜色和整数传递给Effect的方法。我在确定VertexElementUsage的哪个枚举将用于传递整数时遇到问题,以及在声明VertexElements时如何确定偏移量?

public readonly static VertexDeclaration VertexDeclaration = new VertexDeclaration
{
    new VertexElement(0, VertexElementFormat.Vector3, VertexElementUsage.Position, 0),
    new VertexElement(12, VertexElementFormat.Color, VertexElementUsage.Color, 0),
    new VertexElement(?, VertexElementFormat.Byte4, ?, 0)
};

(注意最后一个VertexElement中的?)

XNA 4.0自定义顶点声明

它将是Vector2的大小+颜色的大小。基本上是这样想的,
在一个普通数组中,只有一种类型的对象,所以知道要跳多少才能跳到下一个项
这是不同的,因为它们都有不同的尺寸
使用sizeof()很好,所以它会像:

public readonly static VertexDeclaration VertexDeclaration = new VertexDeclaration
{
    new VertexElement(0, VertexElementFormat.Vector3, VertexElementUsage.Position, 0),
    new VertexElement(sizeof(Vector3), VertexElementFormat.Color, VertexElementUsage.Color, 0),
    new VertexElement(sizeof(Vector3)+sizeof(Color), VertexElementFormat.Byte4, ?, 0)
};

或类似的。

否则,您可以找到颜色对象的大小,并将其添加到Vector3对象的大小(这将是偏移)。