C# 渲染由平面定义的立方体(阀映射文件格式)

C# 渲染由平面定义的立方体(阀映射文件格式),c#,3d,xna,rendering,monogame,C#,3d,Xna,Rendering,Monogame,目前我正在尝试在monogame应用程序中呈现一个立方体。 我使用的是阀映射文件格式。以下wiki页面中描述了地图格式: 导入格式很简单,一点问题都没有。 重要的部分是对平面的描述。格式如下所示: { ( x1 y1 z1) ( x2 y2 z2) ( x3 y3 z3) texture_name ... ( x1 y1 z1) ( x2 y2 z2) ( x3 y3 z3) texture_name ... ( x1 y1 z1) ( x2 y2 z2) ( x3

目前我正在尝试在monogame应用程序中呈现一个立方体。 我使用的是阀映射文件格式。以下wiki页面中描述了地图格式:

导入格式很简单,一点问题都没有。 重要的部分是对平面的描述。格式如下所示:

{
    ( x1 y1 z1) ( x2 y2 z2) ( x3 y3 z3) texture_name  ...
    ( x1 y1 z1) ( x2 y2 z2) ( x3 y3 z3) texture_name  ...
    ( x1 y1 z1) ( x2 y2 z2) ( x3 y3 z3) texture_name  ...
    ( x1 y1 z1) ( x2 y2 z2) ( x3 y3 z3) texture_name  ...
    ( x1 y1 z1) ( x2 y2 z2) ( x3 y3 z3) texture_name  ...
    ( x1 y1 z1) ( x2 y2 z2) ( x3 y3 z3) texture_name  ...
}
每条线定义一个平面。要定义一个实际平面,必须给出三个点(用x1、y1、z1、x2、y2、z2和x3、y3、z3表示)

这将定义用于设置平面在三维世界中的方向和位置的三个点。第一个标记面的左下角,第二个标记面的左上角,第三个标记面的右上角。下面是通过CSG从六个平面构建的简单笔刷的动画。第一、第二和第三个平面点由红、绿和蓝点表示

所以我加载这些平面并将它们渲染为三角形。 我的monogame应用程序中的重新渲染结果如下:

很明显,立方体中缺少了一些部分

我正在使用worldcraft hammer editor创建地图文件。所以结果应该是这样的:

{
    ( x1 y1 z1) ( x2 y2 z2) ( x3 y3 z3) texture_name  ...
    ( x1 y1 z1) ( x2 y2 z2) ( x3 y3 z3) texture_name  ...
    ( x1 y1 z1) ( x2 y2 z2) ( x3 y3 z3) texture_name  ...
    ( x1 y1 z1) ( x2 y2 z2) ( x3 y3 z3) texture_name  ...
    ( x1 y1 z1) ( x2 y2 z2) ( x3 y3 z3) texture_name  ...
    ( x1 y1 z1) ( x2 y2 z2) ( x3 y3 z3) texture_name  ...
}

顶点创建方法:

将笔刷和面转换为xna VertexPositionColor类型

    private VertexPositionColor[] CreateVertexPositions(Brush brush)
    {
        VertexPositionColor[] vertices = new VertexPositionColor[brush.Faces.Count * 3];

        int j = 0;
        for (int i = 0; i < brush.Faces.Count; i++)
        {
            Face brushFace = brush.Faces[i];
            Color color = ColorUtils.GenerateRandomColor(Color.Wheat);

            vertices[i + j + 0] = new VertexPositionColor( // bottom left of the face
                new Vector3(brushFace.V1.X, brushFace.V1.Y, brushFace.V1.Z), color
            );
            vertices[i + j + 1] = new VertexPositionColor( // top left of the face
                new Vector3(brushFace.V2.X, brushFace.V2.Y, brushFace.V2.Z), color
            );
            vertices[i + j + 2] = new VertexPositionColor( // top right of the face
                new Vector3(brushFace.V3.X, brushFace.V3.Y, brushFace.V3.Z), color
            );

            j = j + 2;
        }

        return vertices;
    }
渲染方法

public sealed class Face
{
    public Vertex3 V1 { get; set; }
    public Vertex3 V2 { get; set; }
    public Vertex3 V3 { get; set; }
    public string TextureName { get; set; }
    public Plane P1 { get; set; }
    public Plane P2 { get; set; }
    public int Rotation { get; set; }
    public float XScale { get; set; }
    public float YScale { get; set; }
}
    public override void Render(ICamera camera)
    {
        _effect.Projection = camera.Projection;
        _effect.View = camera.View;
        _effect.World = camera.World;

        RasterizerState rasterizerState = new RasterizerState();
        rasterizerState.CullMode = CullMode.None;
        rasterizerState.FillMode = FillMode.Solid;
        GraphicsDevice.RasterizerState = rasterizerState;

        foreach (EffectPass pass in _effect.CurrentTechnique.Passes)
        {
            pass.Apply();
            GraphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList, _vertices.ToArray(), 0, (_vertices.Count / 3), VertexPositionColor.VertexDeclaration);
        }
    }
我错过了一篇基本的文章。如何从给定平面创建立方体

我不是要一个完整的代码或一个完整的解决方案,而是要有人把我推向正确的方向

先谢谢你

更新

我为此制作了一个非常简单的项目,并将其上载到我的OneDrive帐户:


立方体由6个四边形(6个矩形)组成。四边形是两个三角形,不是一个。因为四边形是2个三角形,所以它有6个顶点。因此,要渲染立方体,必须处理36个顶点

构成36个顶点的所有信息都位于构成平面的18个顶点中

对于所有36个顶点,只有6个唯一的组件值。对于构成立方体的36个顶点中的任何一个,只能有2个可能的X值、2个可能的Y值和2个可能的Z值。所有36个顶点都由这6个唯一值的各种组合组成

您的任务是迭代6个平面(18个顶点)并拉出6个唯一的组件值,然后从这6个组件值中组成36个顶点。然后用36个顶点填充VertexBuffer