Ejemplo n.º 1
0
    void SetDrawFacesFromNeighbors(BlockRendererData data, MatrixView <BlockData> neighbors)
    {
        var left    = neighbors.Get(BlockFaceEx.FaceToDirInt(BlockFace.Left));
        var right   = neighbors.Get(BlockFaceEx.FaceToDirInt(BlockFace.Right));
        var up      = neighbors.Get(BlockFaceEx.FaceToDirInt(BlockFace.Up));
        var down    = neighbors.Get(BlockFaceEx.FaceToDirInt(BlockFace.Down));
        var front   = neighbors.Get(BlockFaceEx.FaceToDirInt(BlockFace.Front));
        var back    = neighbors.Get(BlockFaceEx.FaceToDirInt(BlockFace.Back));
        var current = neighbors.GetCenter();

        bool drawLeft  = !BlockTypeList.instance.Get(left.id).IsFaceFull(BlockFace.Right, left.data);
        bool drawRight = !BlockTypeList.instance.Get(right.id).IsFaceFull(BlockFace.Left, right.data);
        bool drawUp    = !BlockTypeList.instance.Get(up.id).IsFaceFull(BlockFace.Down, up.data);
        bool drawDown  = !BlockTypeList.instance.Get(down.id).IsFaceFull(BlockFace.Up, down.data);
        bool drawFront = !BlockTypeList.instance.Get(front.id).IsFaceFull(BlockFace.Back, front.data);
        bool drawBack  = !BlockTypeList.instance.Get(back.id).IsFaceFull(BlockFace.Front, back.data);

        m_data.SetFaceDraw(drawLeft, BlockFace.Left);
        m_data.SetFaceDraw(drawRight, BlockFace.Right);
        m_data.SetFaceDraw(drawUp, BlockFace.Up);
        m_data.SetFaceDraw(drawDown, BlockFace.Down);
        m_data.SetFaceDraw(drawFront, BlockFace.Front);
        m_data.SetFaceDraw(drawBack, BlockFace.Back);

        ShapeType shape    = GetShapeTypeData(current.data);
        Rotation  rotation = GetRotationData(current.data);

        if (shape == ShapeType.HalfCubic)
        {
            var leftFace  = BlockFaceEx.Rotate(BlockFace.Left, rotation);
            var rightFace = BlockFaceEx.Rotate(BlockFace.Right, rotation);

            if (m_data.GetFaceDraw(leftFace))
            {
                var leftBlock = neighbors.Get(BlockFaceEx.FaceToDirInt(leftFace));

                if (BlockTypeList.instance.Get(leftBlock.id).type == BlockType.Smoothed)
                {
                    ShapeType leftShape    = GetShapeTypeData(leftBlock.data);
                    Rotation  leftRotation = GetRotationData(leftBlock.data);

                    if (leftShape == ShapeType.HalfCubic && leftRotation == rotation)
                    {
                        m_data.SetFaceDraw(false, leftFace);
                    }

                    if (leftShape == ShapeType.Tetrahedral && leftRotation == rotation)
                    {
                        m_data.SetFaceDraw(false, leftFace);
                    }

                    if (leftShape == ShapeType.AntiTetrahedral && RotationEx.SubRotations(leftRotation, Rotation.Rot90) == rotation)
                    {
                        m_data.SetFaceDraw(false, leftFace);
                    }
                }
            }

            if (m_data.GetFaceDraw(rightFace))
            {
                var rightBlock = neighbors.Get(BlockFaceEx.FaceToDirInt(rightFace));

                if (BlockTypeList.instance.Get(rightBlock.id).type == BlockType.Smoothed)
                {
                    ShapeType rightShape    = GetShapeTypeData(rightBlock.data);
                    Rotation  rightRotation = GetRotationData(rightBlock.data);

                    if (rightShape == ShapeType.HalfCubic && rightRotation == rotation)
                    {
                        m_data.SetFaceDraw(false, rightFace);
                    }

                    if (rightShape == ShapeType.Tetrahedral && RotationEx.AddRotations(rightRotation, Rotation.Rot90) == rotation)
                    {
                        m_data.SetFaceDraw(false, rightFace);
                    }

                    if (rightShape == ShapeType.AntiTetrahedral && RotationEx.AddRotations(rightRotation, Rotation.Rot180) == rotation)
                    {
                        m_data.SetFaceDraw(false, rightFace);
                    }
                }
            }
        }

        if (shape == ShapeType.Tetrahedral)
        {
            var backFace  = BlockFaceEx.Rotate(BlockFace.Back, rotation);
            var rightFace = BlockFaceEx.Rotate(BlockFace.Right, rotation);

            if (m_data.GetFaceDraw(BlockFace.Down))
            {
                var downBlock = neighbors.Get(BlockFaceEx.FaceToDirInt(BlockFace.Down));

                if (BlockTypeList.instance.Get(downBlock.id).type == BlockType.Smoothed)
                {
                    ShapeType downShape    = GetShapeTypeData(downBlock.data);
                    Rotation  downRotation = GetRotationData(downBlock.data);

                    if (downShape == ShapeType.AntiTetrahedral && RotationEx.AddRotations(downRotation, Rotation.Rot180) == rotation)
                    {
                        m_data.SetFaceDraw(false, BlockFace.Down);
                    }

                    if (downShape == ShapeType.HorizontalHalfCubic && downRotation == rotation)
                    {
                        m_data.SetFaceDraw(false, BlockFace.Down);
                    }
                }
            }

            if (m_data.GetFaceDraw(backFace))
            {
                var backBlock = neighbors.Get(BlockFaceEx.FaceToDirInt(backFace));

                if (BlockTypeList.instance.Get(backBlock.id).type == BlockType.Smoothed)
                {
                    ShapeType backShape    = GetShapeTypeData(backBlock.data);
                    Rotation  backRotation = GetRotationData(backBlock.data);

                    if (backShape == ShapeType.HalfCubic && RotationEx.SubRotations(backRotation, Rotation.Rot90) == rotation)
                    {
                        m_data.SetFaceDraw(false, backFace);
                    }

                    if (backShape == ShapeType.Tetrahedral && RotationEx.SubRotations(backRotation, Rotation.Rot90) == rotation)
                    {
                        m_data.SetFaceDraw(false, backFace);
                    }

                    if (backShape == ShapeType.AntiTetrahedral && RotationEx.AddRotations(backRotation, Rotation.Rot180) == rotation)
                    {
                        m_data.SetFaceDraw(false, backFace);
                    }
                }
            }

            if (m_data.GetFaceDraw(rightFace))
            {
                var rightBlock = neighbors.Get(BlockFaceEx.FaceToDirInt(rightFace));

                if (BlockTypeList.instance.Get(rightBlock.id).type == BlockType.Smoothed)
                {
                    ShapeType rightShape    = GetShapeTypeData(rightBlock.data);
                    Rotation  rightRotation = GetRotationData(rightBlock.data);

                    if (rightShape == ShapeType.HalfCubic && rightRotation == rotation)
                    {
                        m_data.SetFaceDraw(false, rightFace);
                    }

                    if (rightShape == ShapeType.Tetrahedral && RotationEx.AddRotations(rightRotation, Rotation.Rot90) == rotation)
                    {
                        m_data.SetFaceDraw(false, rightFace);
                    }

                    if (rightShape == ShapeType.AntiTetrahedral && RotationEx.AddRotations(rightRotation, Rotation.Rot180) == rotation)
                    {
                        m_data.SetFaceDraw(false, rightFace);
                    }
                }
            }
        }

        if (shape == ShapeType.AntiTetrahedral)
        {
            var backFace  = BlockFaceEx.Rotate(BlockFace.Back, rotation);
            var rightFace = BlockFaceEx.Rotate(BlockFace.Right, rotation);

            if (m_data.GetFaceDraw(BlockFace.Up))
            {
                var upBlock = neighbors.Get(BlockFaceEx.FaceToDirInt(BlockFace.Up));

                if (BlockTypeList.instance.Get(upBlock.id).type == BlockType.Smoothed)
                {
                    ShapeType upShape    = GetShapeTypeData(upBlock.data);
                    Rotation  upRotation = GetRotationData(upBlock.data);

                    if (upShape == ShapeType.Tetrahedral && RotationEx.AddRotations(upRotation, Rotation.Rot180) == rotation)
                    {
                        m_data.SetFaceDraw(false, BlockFace.Up);
                    }

                    if (upShape == ShapeType.HorizontalHalfCubic && RotationEx.AddRotations(upRotation, Rotation.Rot180) == rotation)
                    {
                        m_data.SetFaceDraw(false, BlockFace.Up);
                    }
                }
            }

            if (m_data.GetFaceDraw(backFace))
            {
                var backBlock = neighbors.Get(BlockFaceEx.FaceToDirInt(backFace));

                if (BlockTypeList.instance.Get(backBlock.id).type == BlockType.Smoothed)
                {
                    ShapeType backShape    = GetShapeTypeData(backBlock.data);
                    Rotation  backRotation = GetRotationData(backBlock.data);

                    if (backShape == ShapeType.HalfCubic && RotationEx.AddRotations(backRotation, Rotation.Rot90) == rotation)
                    {
                        m_data.SetFaceDraw(false, backFace);
                    }

                    if (backShape == ShapeType.Tetrahedral && RotationEx.AddRotations(backRotation, Rotation.Rot180) == rotation)
                    {
                        m_data.SetFaceDraw(false, backFace);
                    }

                    if (backShape == ShapeType.AntiTetrahedral && RotationEx.AddRotations(backRotation, Rotation.Rot90) == rotation)
                    {
                        m_data.SetFaceDraw(false, backFace);
                    }
                }
            }

            if (m_data.GetFaceDraw(rightFace))
            {
                var rightBlock = neighbors.Get(BlockFaceEx.FaceToDirInt(rightFace));

                if (BlockTypeList.instance.Get(rightBlock.id).type == BlockType.Smoothed)
                {
                    ShapeType rightShape    = GetShapeTypeData(rightBlock.data);
                    Rotation  rightRotation = GetRotationData(rightBlock.data);

                    if (rightShape == ShapeType.HalfCubic && RotationEx.AddRotations(rightRotation, Rotation.Rot180) == rotation)
                    {
                        m_data.SetFaceDraw(false, rightFace);
                    }

                    if (rightShape == ShapeType.Tetrahedral && RotationEx.AddRotations(rightRotation, Rotation.Rot180) == rotation)
                    {
                        m_data.SetFaceDraw(false, rightFace);
                    }

                    if (rightShape == ShapeType.AntiTetrahedral && RotationEx.SubRotations(rightRotation, Rotation.Rot180) == rotation)
                    {
                        m_data.SetFaceDraw(false, rightFace);
                    }
                }
            }
        }

        if (shape == ShapeType.HorizontalHalfCubic)
        {
            if (m_data.GetFaceDraw(BlockFace.Up))
            {
                var upBlock = neighbors.Get(BlockFaceEx.FaceToDirInt(BlockFace.Up));

                if (BlockTypeList.instance.Get(upBlock.id).type == BlockType.Smoothed)
                {
                    ShapeType upShape    = GetShapeTypeData(upBlock.data);
                    Rotation  upRotation = GetRotationData(upBlock.data);

                    if (upShape == ShapeType.HorizontalHalfCubic && upRotation == rotation)
                    {
                        m_data.SetFaceDraw(false, BlockFace.Up);
                    }

                    if (upShape == ShapeType.Tetrahedral && upRotation == rotation)
                    {
                        m_data.SetFaceDraw(false, BlockFace.Up);
                    }
                }
            }

            if (m_data.GetFaceDraw(BlockFace.Down))
            {
                var downBlock = neighbors.Get(BlockFaceEx.FaceToDirInt(BlockFace.Down));

                if (BlockTypeList.instance.Get(downBlock.id).type == BlockType.Smoothed)
                {
                    ShapeType downShape    = GetShapeTypeData(downBlock.data);
                    Rotation  downRotation = GetRotationData(downBlock.data);

                    if (downShape == ShapeType.HorizontalHalfCubic && downRotation == rotation)
                    {
                        m_data.SetFaceDraw(false, BlockFace.Down);
                    }

                    if (downShape == ShapeType.AntiTetrahedral && RotationEx.AddRotations(downRotation, Rotation.Rot180) == rotation)
                    {
                        m_data.SetFaceDraw(false, BlockFace.Down);
                    }
                }
            }
        }
    }
Ejemplo n.º 2
0
    public static void DrawThetrahedral(Vector3 pos, MeshParams <WorldVertexDefinition> meshParams, BlockRendererData blockData)
    {
        //4 triangles
        // each triangle have 3 vertex and 3 index
        var data = meshParams.Allocate(12, 12, blockData.material);

        var rot = blockData.rotation;

        int vertexIndex = 0;
        int nb          = 0;

        if (blockData.GetFaceDraw(BlockFace.Down))
        {
            var rect = blockData.GetFaceUV(BlockFace.Down);
            data.vertices[data.verticesSize + vertexIndex].pos     = new Vector3(1, 0, 0) + pos;
            data.vertices[data.verticesSize + vertexIndex].uv      = new Vector2(rect.x + rect.width, rect.y);
            data.vertices[data.verticesSize + vertexIndex + 1].pos = new Vector3(1, 0, 1) + pos;
            data.vertices[data.verticesSize + vertexIndex + 1].uv  = new Vector2(rect.x + rect.width, rect.y + rect.height);
            data.vertices[data.verticesSize + vertexIndex + 2].pos = new Vector3(0, 0, 0) + pos;
            data.vertices[data.verticesSize + vertexIndex + 2].uv  = new Vector2(rect.x, rect.y);
            vertexIndex += 3;
            nb++;
        }

        if (blockData.GetFaceDraw(BlockFaceEx.Rotate(BlockFace.Back, rot)))
        {
            var rect = blockData.GetFaceUV(BlockFace.Back);
            data.vertices[data.verticesSize + vertexIndex].pos     = new Vector3(0, 0, 0) + pos;
            data.vertices[data.verticesSize + vertexIndex].uv      = new Vector2(rect.x, rect.y);
            data.vertices[data.verticesSize + vertexIndex + 1].pos = new Vector3(1, 1, 0) + pos;
            data.vertices[data.verticesSize + vertexIndex + 1].uv  = new Vector2(rect.x + rect.width, rect.y + rect.height);
            data.vertices[data.verticesSize + vertexIndex + 2].pos = new Vector3(1, 0, 0) + pos;
            data.vertices[data.verticesSize + vertexIndex + 2].uv  = new Vector2(rect.x + rect.width, rect.y);
            vertexIndex += 3;
            nb++;
        }

        if (blockData.GetFaceDraw(BlockFaceEx.Rotate(BlockFace.Right, rot)))
        {
            var rect = blockData.GetFaceUV(BlockFace.Right);
            data.vertices[data.verticesSize + vertexIndex].pos     = new Vector3(1, 0, 0) + pos;
            data.vertices[data.verticesSize + vertexIndex].uv      = new Vector2(rect.x, rect.y);
            data.vertices[data.verticesSize + vertexIndex + 1].pos = new Vector3(1, 1, 0) + pos;
            data.vertices[data.verticesSize + vertexIndex + 1].uv  = new Vector2(rect.x, rect.y + rect.height);
            data.vertices[data.verticesSize + vertexIndex + 2].pos = new Vector3(1, 0, 1) + pos;
            data.vertices[data.verticesSize + vertexIndex + 2].uv  = new Vector2(rect.x + rect.width, rect.y);
            vertexIndex += 3;
            nb++;
        }

        //top face is drawn in all cases
        {
            var rect = blockData.GetFaceUV(BlockFace.Up);
            data.vertices[data.verticesSize + vertexIndex].pos     = new Vector3(0, 0, 0) + pos;
            data.vertices[data.verticesSize + vertexIndex].uv      = new Vector2(rect.x, rect.y);
            data.vertices[data.verticesSize + vertexIndex + 1].pos = new Vector3(1, 0, 1) + pos;
            data.vertices[data.verticesSize + vertexIndex + 1].uv  = new Vector2(rect.x + rect.width, rect.y + rect.height);
            data.vertices[data.verticesSize + vertexIndex + 2].pos = new Vector3(1, 1, 0) + pos;
            data.vertices[data.verticesSize + vertexIndex + 2].uv  = new Vector2(rect.x + rect.width, rect.y);
            vertexIndex += 3;
            nb++;
        }

        SetColor(data, data.verticesSize, vertexIndex, new Color32(255, 255, 255, 0));

        SetTrianglesIndexs(data, data.verticesSize, data.indexesSize, nb);

        RotatePos(data, data.verticesSize, vertexIndex, pos, rot);

        BakeNormals(data, data.indexesSize, nb);
        BakeTangents(data, data.indexesSize, nb);

        if (blockData.collision)
        {
            CloneCollisions(meshParams, data, vertexIndex, nb * 3);
        }

        data.verticesSize += vertexIndex;
        data.indexesSize  += nb * 3;
    }
Ejemplo n.º 3
0
    public static void DrawCubic(Vector3 pos, MeshParams <WorldVertexDefinition> meshParams, BlockRendererData blockData)
    {
        var data = meshParams.Allocate(24, 36, blockData.material);

        int vertexIndex = 0;
        int nb          = 0;

        if (blockData.GetFaceDraw(BlockFace.Left))
        {
            var rect = blockData.GetFaceUV(BlockFaceEx.Rotate(BlockFace.Left, blockData.rotation));
            data.vertices[data.verticesSize + vertexIndex].pos     = new Vector3(0, 0, 0) + pos;
            data.vertices[data.verticesSize + vertexIndex].uv      = new Vector2(rect.x + rect.width, rect.y);
            data.vertices[data.verticesSize + vertexIndex + 1].pos = new Vector3(0, 0, 1) + pos;
            data.vertices[data.verticesSize + vertexIndex + 1].uv  = new Vector2(rect.x, rect.y);
            data.vertices[data.verticesSize + vertexIndex + 2].pos = new Vector3(0, 1, 1) + pos;
            data.vertices[data.verticesSize + vertexIndex + 2].uv  = new Vector2(rect.x, rect.y + rect.height);
            data.vertices[data.verticesSize + vertexIndex + 3].pos = new Vector3(0, 1, 0) + pos;
            data.vertices[data.verticesSize + vertexIndex + 3].uv  = new Vector2(rect.x + rect.width, rect.y + rect.height);
            vertexIndex += 4;
            nb++;
        }

        if (blockData.GetFaceDraw(BlockFace.Up))
        {
            var rect = blockData.GetFaceUV(BlockFace.Up);
            data.vertices[data.verticesSize + vertexIndex].pos     = new Vector3(0, 1, 0) + pos;
            data.vertices[data.verticesSize + vertexIndex].uv      = new Vector2(rect.x, rect.y);
            data.vertices[data.verticesSize + vertexIndex + 1].pos = new Vector3(0, 1, 1) + pos;
            data.vertices[data.verticesSize + vertexIndex + 1].uv  = new Vector2(rect.x, rect.y + rect.height);
            data.vertices[data.verticesSize + vertexIndex + 2].pos = new Vector3(1, 1, 1) + pos;
            data.vertices[data.verticesSize + vertexIndex + 2].uv  = new Vector2(rect.x + rect.width, rect.y + rect.height);
            data.vertices[data.verticesSize + vertexIndex + 3].pos = new Vector3(1, 1, 0) + pos;
            data.vertices[data.verticesSize + vertexIndex + 3].uv  = new Vector2(rect.x + rect.width, rect.y);
            RotateUV(data, data.verticesSize + vertexIndex, 4, (int)blockData.rotation);
            vertexIndex += 4;
            nb++;
        }

        if (blockData.GetFaceDraw(BlockFace.Front))
        {
            var rect = blockData.GetFaceUV(BlockFaceEx.Rotate(BlockFace.Front, blockData.rotation));
            data.vertices[data.verticesSize + vertexIndex].pos     = new Vector3(0, 0, 1) + pos;
            data.vertices[data.verticesSize + vertexIndex].uv      = new Vector2(rect.x + rect.width, rect.y);
            data.vertices[data.verticesSize + vertexIndex + 1].pos = new Vector3(1, 0, 1) + pos;
            data.vertices[data.verticesSize + vertexIndex + 1].uv  = new Vector2(rect.x, rect.y);
            data.vertices[data.verticesSize + vertexIndex + 2].pos = new Vector3(1, 1, 1) + pos;
            data.vertices[data.verticesSize + vertexIndex + 2].uv  = new Vector2(rect.x, rect.y + rect.height);
            data.vertices[data.verticesSize + vertexIndex + 3].pos = new Vector3(0, 1, 1) + pos;
            data.vertices[data.verticesSize + vertexIndex + 3].uv  = new Vector2(rect.x + rect.width, rect.y + rect.height);
            vertexIndex += 4;
            nb++;
        }

        if (blockData.GetFaceDraw(BlockFace.Down))
        {
            var rect = blockData.GetFaceUV(BlockFace.Down);
            data.vertices[data.verticesSize + vertexIndex].pos     = new Vector3(1, 0, 0) + pos;
            data.vertices[data.verticesSize + vertexIndex].uv      = new Vector2(rect.x + rect.width, rect.y);
            data.vertices[data.verticesSize + vertexIndex + 1].pos = new Vector3(1, 0, 1) + pos;
            data.vertices[data.verticesSize + vertexIndex + 1].uv  = new Vector2(rect.x + rect.width, rect.y + rect.height);
            data.vertices[data.verticesSize + vertexIndex + 2].pos = new Vector3(0, 0, 1) + pos;
            data.vertices[data.verticesSize + vertexIndex + 2].uv  = new Vector2(rect.x, rect.y + rect.height);
            data.vertices[data.verticesSize + vertexIndex + 3].pos = new Vector3(0, 0, 0) + pos;
            data.vertices[data.verticesSize + vertexIndex + 3].uv  = new Vector2(rect.x, rect.y);
            RotateUV(data, data.verticesSize + vertexIndex, 4, (int)blockData.rotation);
            vertexIndex += 4;
            nb++;
        }

        if (blockData.GetFaceDraw(BlockFace.Right))
        {
            var rect = blockData.GetFaceUV(BlockFaceEx.Rotate(BlockFace.Right, blockData.rotation));
            data.vertices[data.verticesSize + vertexIndex].pos     = new Vector3(1, 1, 0) + pos;
            data.vertices[data.verticesSize + vertexIndex].uv      = new Vector2(rect.x, rect.y + rect.height);
            data.vertices[data.verticesSize + vertexIndex + 1].pos = new Vector3(1, 1, 1) + pos;
            data.vertices[data.verticesSize + vertexIndex + 1].uv  = new Vector2(rect.x + rect.width, rect.y + rect.height);
            data.vertices[data.verticesSize + vertexIndex + 2].pos = new Vector3(1, 0, 1) + pos;
            data.vertices[data.verticesSize + vertexIndex + 2].uv  = new Vector2(rect.x + rect.width, rect.y);
            data.vertices[data.verticesSize + vertexIndex + 3].pos = new Vector3(1, 0, 0) + pos;
            data.vertices[data.verticesSize + vertexIndex + 3].uv  = new Vector2(rect.x, rect.y);
            vertexIndex += 4;
            nb++;
        }

        if (blockData.GetFaceDraw(BlockFace.Back))
        {
            var rect = blockData.GetFaceUV(BlockFaceEx.Rotate(BlockFace.Back, blockData.rotation));
            data.vertices[data.verticesSize + vertexIndex].pos     = new Vector3(0, 1, 0) + pos;
            data.vertices[data.verticesSize + vertexIndex].uv      = new Vector2(rect.x, rect.y + rect.height);
            data.vertices[data.verticesSize + vertexIndex + 1].pos = new Vector3(1, 1, 0) + pos;
            data.vertices[data.verticesSize + vertexIndex + 1].uv  = new Vector2(rect.x + rect.width, rect.y + rect.height);
            data.vertices[data.verticesSize + vertexIndex + 2].pos = new Vector3(1, 0, 0) + pos;
            data.vertices[data.verticesSize + vertexIndex + 2].uv  = new Vector2(rect.x + rect.width, rect.y);
            data.vertices[data.verticesSize + vertexIndex + 3].pos = new Vector3(0, 0, 0) + pos;
            data.vertices[data.verticesSize + vertexIndex + 3].uv  = new Vector2(rect.x, rect.y);
            vertexIndex += 4;
            nb++;
        }

        SetColor(data, data.verticesSize, vertexIndex, new Color32(255, 255, 255, 0));

        SetQuadsIndexs(data, data.verticesSize, data.indexesSize, nb);

        BakeNormals(data, data.indexesSize, nb * 2);
        BakeTangents(data, data.indexesSize, nb * 2);

        if (blockData.collision)
        {
            CloneCollisions(meshParams, data, vertexIndex, nb * 6);
        }

        data.verticesSize += vertexIndex;
        data.indexesSize  += nb * 6;
    }
Ejemplo n.º 4
0
    public static void DrawHorizontalHalfCubic(Vector3 pos, MeshParams <WorldVertexDefinition> meshParams, BlockRendererData blockData)
    {
        //3 square and 2 triangles
        // each square have 4 vertex and 6 index
        // each triangle have 3 vertex and 3 index
        var data = meshParams.Allocate(18, 24, blockData.material);

        var rot = blockData.rotation;

        int vertexIndex = 0;
        int nbSquare    = 0;
        int nbTriangle  = 0;

        if (blockData.GetFaceDraw(BlockFaceEx.Rotate(BlockFace.Right, rot)))
        {
            var rect = blockData.GetFaceUV(BlockFace.Right);
            data.vertices[data.verticesSize + vertexIndex].pos     = new Vector3(1, 1, 0) + pos;
            data.vertices[data.verticesSize + vertexIndex].uv      = new Vector2(rect.x, rect.y + rect.height);
            data.vertices[data.verticesSize + vertexIndex + 1].pos = new Vector3(1, 1, 1) + pos;
            data.vertices[data.verticesSize + vertexIndex + 1].uv  = new Vector2(rect.x + rect.width, rect.y + rect.height);
            data.vertices[data.verticesSize + vertexIndex + 2].pos = new Vector3(1, 0, 1) + pos;
            data.vertices[data.verticesSize + vertexIndex + 2].uv  = new Vector2(rect.x + rect.width, rect.y);
            data.vertices[data.verticesSize + vertexIndex + 3].pos = new Vector3(1, 0, 0) + pos;
            data.vertices[data.verticesSize + vertexIndex + 3].uv  = new Vector2(rect.x, rect.y);
            vertexIndex += 4;
            nbSquare++;
        }

        if (blockData.GetFaceDraw(BlockFaceEx.Rotate(BlockFace.Back, rot)))
        {
            var rect = blockData.GetFaceUV(BlockFace.Back);
            data.vertices[data.verticesSize + vertexIndex].pos     = new Vector3(0, 1, 0) + pos;
            data.vertices[data.verticesSize + vertexIndex].uv      = new Vector2(rect.x, rect.y + rect.height);
            data.vertices[data.verticesSize + vertexIndex + 1].pos = new Vector3(1, 1, 0) + pos;
            data.vertices[data.verticesSize + vertexIndex + 1].uv  = new Vector2(rect.x + rect.width, rect.y + rect.height);
            data.vertices[data.verticesSize + vertexIndex + 2].pos = new Vector3(1, 0, 0) + pos;
            data.vertices[data.verticesSize + vertexIndex + 2].uv  = new Vector2(rect.x + rect.width, rect.y);
            data.vertices[data.verticesSize + vertexIndex + 3].pos = new Vector3(0, 0, 0) + pos;
            data.vertices[data.verticesSize + vertexIndex + 3].uv  = new Vector2(rect.x, rect.y);
            vertexIndex += 4;
            nbSquare++;
        }

        //diagonal face is drawn in all cases
        {
            var rect = blockData.GetFaceUV(BlockFace.Front);
            data.vertices[data.verticesSize + vertexIndex].pos     = new Vector3(0, 1, 0) + pos;
            data.vertices[data.verticesSize + vertexIndex].uv      = new Vector2(rect.x, rect.y + rect.height);
            data.vertices[data.verticesSize + vertexIndex + 1].pos = new Vector3(0, 0, 0) + pos;
            data.vertices[data.verticesSize + vertexIndex + 1].uv  = new Vector2(rect.x, rect.y);
            data.vertices[data.verticesSize + vertexIndex + 2].pos = new Vector3(1, 0, 1) + pos;
            data.vertices[data.verticesSize + vertexIndex + 2].uv  = new Vector2(rect.x + rect.width, rect.y);
            data.vertices[data.verticesSize + vertexIndex + 3].pos = new Vector3(1, 1, 1) + pos;
            data.vertices[data.verticesSize + vertexIndex + 3].uv  = new Vector2(rect.x + rect.width, rect.y + rect.height);
            vertexIndex += 4;
            nbSquare++;
        }

        if (blockData.GetFaceDraw(BlockFace.Down))
        {
            var rect = blockData.GetFaceUV(BlockFace.Down);
            data.vertices[data.verticesSize + vertexIndex].pos     = new Vector3(1, 0, 0) + pos;
            data.vertices[data.verticesSize + vertexIndex].uv      = new Vector2(rect.x + rect.width, rect.y);
            data.vertices[data.verticesSize + vertexIndex + 1].pos = new Vector3(1, 0, 1) + pos;
            data.vertices[data.verticesSize + vertexIndex + 1].uv  = new Vector2(rect.x + rect.width, rect.y + rect.height);
            data.vertices[data.verticesSize + vertexIndex + 2].pos = new Vector3(0, 0, 0) + pos;
            data.vertices[data.verticesSize + vertexIndex + 2].uv  = new Vector2(rect.x, rect.y);
            vertexIndex += 3;
            nbTriangle++;
        }

        if (blockData.GetFaceDraw(BlockFace.Up))
        {
            var rect = blockData.GetFaceUV(BlockFace.Up);
            data.vertices[data.verticesSize + vertexIndex].pos     = new Vector3(1, 1, 0) + pos;
            data.vertices[data.verticesSize + vertexIndex].uv      = new Vector2(rect.x + rect.width, rect.y);
            data.vertices[data.verticesSize + vertexIndex + 1].pos = new Vector3(0, 1, 0) + pos;
            data.vertices[data.verticesSize + vertexIndex + 1].uv  = new Vector2(rect.x, rect.y);
            data.vertices[data.verticesSize + vertexIndex + 2].pos = new Vector3(1, 1, 1) + pos;
            data.vertices[data.verticesSize + vertexIndex + 2].uv  = new Vector2(rect.x + rect.width, rect.y + rect.height);
            vertexIndex += 3;
            nbTriangle++;
        }

        SetColor(data, data.verticesSize, vertexIndex, new Color32(255, 255, 255, 0));

        SetQuadsIndexs(data, data.verticesSize, data.indexesSize, nbSquare);
        SetTrianglesIndexs(data, data.verticesSize + 4 * nbSquare, data.indexesSize + 6 * nbSquare, nbTriangle);

        RotatePos(data, data.verticesSize, vertexIndex, pos, rot);

        BakeNormals(data, data.indexesSize, nbSquare * 2 + nbTriangle);
        BakeTangents(data, data.indexesSize, nbSquare * 2 + nbTriangle);

        if (blockData.collision)
        {
            CloneCollisions(meshParams, data, vertexIndex, nbSquare * 6 + nbTriangle * 3);
        }

        data.verticesSize += vertexIndex;
        data.indexesSize  += nbSquare * 6 + nbTriangle * 3;
    }