我正在将一个大型 XNA 项目移植到 Unity 项目中。我没有编写 XNA 项目,也没有任何背景。移植进行得很顺利,直到我遇到了一个用来绘制几何图形的部分。它看起来像下面这样:
using (VertexDeclaration vertexdecl =
new VertexDeclaration(GraphicsDevice,
VertexPositionNormalTexture.
VertexElements))
{
GraphicsDevice.VertexDeclaration = vertexdecl;
GraphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList, verticesArray, 0, 2);
}
verticesArray它试图绘制的变量在VertexPositionNormalTexture结构中表示并初始化如下:
VertexPositionNormalTexture[] verticesArray;
private void InitGeometry()
{
verticesArray = new VertexPositionNormalTexture[6];
verticesArray[0] = new VertexPositionNormalTexture( new Vector3(-20,0,0),
-Vector3.UnitZ,
new Vector2(0,0));
verticesArray[1] = new VertexPositionNormalTexture( new Vector3(20,10,0),
-Vector3.UnitZ,
new Vector2(13,12));
verticesArray[2] = new VertexPositionNormalTexture( new Vector3(-5, 20, 0),
-Vector3.UnitZ,
new Vector2(0, 1));
verticesArray[3] = verticesArray[0];
verticesArray[4] = new VertexPositionNormalTexture( new Vector3(5, 0, 0),
-Vector3.UnitZ,
new Vector2(3, 0));
verticesArray[5] = verticesArray[1];
}
我能够从源头重新创建VertexPositionNormalTexture,但现在很难像上面使用的那样绘制它GraphicsDevice.DrawUserPrimitives。
我找到的最接近的 Unity 函数是Graphics.DrawMesh,但它只能绘制Mesh传递给它。此外,即使我设法转换 VertexPositionNormalTexture为Mesh,Unity 的Graphics.DrawMesh函数也没有PrimitiveType.TriangleList枚举或类似的东西。
也许我错过了,但 Unity 中是否有类似的功能来绘制VertexPositionNormalTexture struct?