Beispiel #1
0
        public void ShouldGetARightMeshAfterAppendingATextMesh()
        {
            var style = GUIStyle.Default;

            var state         = GUIState.Normal;
            var fontFamily    = style.Get <string>(GUIStyleName.FontFamily, state);
            var fontSize      = style.Get <double>(GUIStyleName.FontSize, state);
            var fontStretch   = (FontStretch)style.Get <int>(GUIStyleName.FontStretch, state);
            var fontStyle     = (FontStyle)style.Get <int>(GUIStyleName.FontStyle, state);
            var fontWeight    = (FontWeight)style.Get <int>(GUIStyleName.FontWeight, state);
            var textAlignment = (TextAlignment)style.Get <int>(GUIStyleName.TextAlignment, state);

            var rect        = new Rect(0, 0, 200, 200);
            var textContext = Application.platformContext.CreateTextContext(
                "ij = I::oO(0xB81l);",
                fontFamily, (int)fontSize, fontStretch, fontStyle, fontWeight,
                (int)Math.Ceiling(rect.Size.Width), (int)Math.Ceiling(rect.Size.Height),
                textAlignment);

            var textMesh = new TextMesh();

            textMesh.Build(Point.Zero, style, textContext);

            var anotherTextContext = Application.platformContext.CreateTextContext(
                "auto-sized",
                fontFamily, (int)fontSize, fontStretch, fontStyle, fontWeight,
                200, 200,
                textAlignment);

            var anotherTextMesh = new TextMesh();

            anotherTextMesh.Build(new Point(50, 100), style, anotherTextContext);

            DrawList drawList            = new DrawList();
            var      expectedVertexCount = 0;
            var      expectedIndexCount  = 0;

            drawList.AddRectFilled(Point.Zero, new Point(200, 100), Color.Metal);
            expectedVertexCount += 4;
            expectedIndexCount  += 6;
            Assert.Equal(drawList.DrawBuffer.VertexBuffer.Count, expectedVertexCount);
            Assert.Equal(drawList.DrawBuffer.IndexBuffer.Count, expectedIndexCount);

            drawList.Append(textMesh, Vector.Zero);
            expectedVertexCount += textMesh.VertexBuffer.Count;
            expectedIndexCount  += textMesh.IndexBuffer.Count;
            Assert.Equal(drawList.DrawBuffer.VertexBuffer.Count, expectedVertexCount);
            Assert.Equal(drawList.DrawBuffer.IndexBuffer.Count, expectedIndexCount);

            drawList.AddRectFilled(new Point(0, 110), new Point(200, 150), Color.Metal);
            expectedVertexCount += 4;
            expectedIndexCount  += 6;
            Assert.Equal(drawList.DrawBuffer.VertexBuffer.Count, expectedVertexCount);
            Assert.Equal(drawList.DrawBuffer.IndexBuffer.Count, expectedIndexCount);

            drawList.AddRectFilled(new Point(0, 160), new Point(200, 200), Color.Metal);
            expectedVertexCount += 4;
            expectedIndexCount  += 6;
            Assert.Equal(drawList.DrawBuffer.VertexBuffer.Count, expectedVertexCount);
            Assert.Equal(drawList.DrawBuffer.IndexBuffer.Count, expectedIndexCount);

            drawList.Append(anotherTextMesh, Vector.Zero);
            expectedVertexCount += anotherTextMesh.VertexBuffer.Count;
            expectedIndexCount  += anotherTextMesh.IndexBuffer.Count;
            Assert.Equal(drawList.DrawBuffer.VertexBuffer.Count, expectedVertexCount);
            Assert.Equal(drawList.DrawBuffer.IndexBuffer.Count, expectedIndexCount);

            var objFilePath = "D:\\TextRenderingTest_ShouldGetARightMeshAfterAppendingATextMesh.obj";

            Utility.SaveToObjFile(objFilePath, drawList.DrawBuffer.VertexBuffer, drawList.DrawBuffer.IndexBuffer);
            Process.Start(ModelViewerPath, objFilePath);
        }