I am porting a large XNA project into Unity project. I did not write XNA project and don't have any background with it. The porting was going smoothly until I came across a part that's used to draw a geometry. It looks something like below:
using (VertexDeclaration vertexdecl =
new VertexDeclaration(GraphicsDevice,
VertexPositionNormalTexture.
VertexElements))
{
GraphicsDevice.VertexDeclaration = vertexdecl;
GraphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList, verticesArray, 0, 2);
}
The verticesArray
variable it is trying to draw is represented in the VertexPositionNormalTexture
structure and initialized as below:
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];
}
I was able to re-create VertexPositionNormalTexture
from the source but now struggling to draw it like GraphicsDevice.DrawUserPrimitives
as used above.
The closest Unity function I found is Graphics.DrawMesh
but it can only draw Mesh
passed into it. Also, even if I manage to convert VertexPositionNormalTexture
to Mesh
, Unity's Graphics.DrawMesh
function does not have the PrimitiveType.TriangleList
enum or anything similar.
Maybe I missed it but is there a similar function in Unity to draw the VertexPositionNormalTexture
struct
?