Exemplo n.º 1
0
        public void FillRect(int width, int height, ref MeshInfo info)
        {
            Assert.IsNotNull(info.Vertices);
            Assert.IsNotNull(info.UVs);
            Assert.IsNotNull(info.Indices);

            Assert.AreEqual(info.Vertices.Length, 4);
            Assert.AreEqual(info.UVs.Length, 4);
            Assert.AreEqual(info.Indices.Length, 6);

            float halfWidth  = width / 2;
            float halfHeight = height / 2;

            info.Vertices[0] = new Vector3(-halfWidth, 0, halfHeight);
            info.Vertices[1] = new Vector3(halfWidth, 0, halfHeight);
            info.Vertices[2] = new Vector3(-halfWidth, 0, -halfHeight);
            info.Vertices[3] = new Vector3(halfWidth, 0, -halfHeight);

            info.UVs[0] = new Vector2(0, 0);
            info.UVs[1] = new Vector2(1, 0);
            info.UVs[2] = new Vector2(0, 1);
            info.UVs[3] = new Vector2(1, 1);

            info.Indices[0] = 0;
            info.Indices[1] = 1;
            info.Indices[2] = 3;

            info.Indices[3] = 3;
            info.Indices[4] = 2;
            info.Indices[5] = 0;
        }
Exemplo n.º 2
0
        public void FillRing(float innerRadius, float outerRadius, int angle, ref MeshInfo info)
        {
            Assert.IsNotNull(info.Vertices);
            Assert.IsNotNull(info.UVs);
            Assert.IsNotNull(info.Indices);

            const int detailAngle = 10;
            var initialAngle = -angle / 2;
            var seg = (angle / detailAngle);
            int numVerts = 2 + (2 * seg);
            int numIndices = 6 * seg;

            Assert.AreEqual(info.Vertices.Length, numVerts);
            Assert.AreEqual(info.UVs.Length, numVerts);
            Assert.AreEqual(info.Indices.Length, numIndices);

            float totalRadius = innerRadius + outerRadius;

            for (int i = 0; i <= seg; ++i)
            {
                var v = Quaternion.AngleAxis(initialAngle + (detailAngle * i), Vector3.up) * Vector3.forward;
                int index = i * 2;
                info.Vertices[index + 0] = v * innerRadius;
                info.Vertices[index + 1] = v * totalRadius;

                float normedHorizontal = (info.Vertices[index].x + 1.0f) * 0.5f;
                float normedVertical = (info.Vertices[index].x + 1.0f) * 0.5f;
                info.UVs[index + 0] = new Vector2(normedHorizontal, normedVertical);
                info.UVs[index + 1] = new Vector2(normedHorizontal, normedVertical);
            }

            for (int i = 0; i < seg; ++i)
            {
                int index = i * 6;
                int vi = i * 2;
                info.Indices[index + 0] = vi + 0;
                info.Indices[index + 1] = vi + 1;
                info.Indices[index + 2] = vi + 2;

                info.Indices[index + 3] = vi + 2;
                info.Indices[index + 4] = vi + 1;
                info.Indices[index + 5] = vi + 3;
            }
        }
Exemplo n.º 3
0
        public MeshInfo FillRing(float innerRadius, float outerRadius, int angle)
        {
            var info = new MeshInfo();
            const int detailAngle = 10;
            var initialAngle = -angle / 2;
            var seg = (angle / detailAngle);
            int numVerts = 2 + (2 * seg);
            int numIndices = 6 * seg;
            info.Vertices = new Vector3[numVerts];
            info.UVs = new Vector2[numVerts];
            info.Indices = new int[numIndices];

            float totalRadius = innerRadius + outerRadius;

            for (int i = 0; i <= seg; ++i)
            {
                var v = Quaternion.AngleAxis(initialAngle + (detailAngle * i), Vector3.up) * Vector3.forward;
                int index = i * 2;
                info.Vertices[index + 0] = v * innerRadius;
                info.Vertices[index + 1] = v * totalRadius;

                float normedHorizontal = (info.Vertices[index].x + 1.0f) * 0.5f;
                float normedVertical = (info.Vertices[index].x + 1.0f) * 0.5f;
                info.UVs[index + 0] = new Vector2(normedHorizontal, normedVertical);
                info.UVs[index + 1] = new Vector2(normedHorizontal, normedVertical);
            }

            for (int i = 0; i < seg; ++i)
            {
                int index = i * 6;
                int vi = i * 2;
                info.Indices[index + 0] = vi + 0;
                info.Indices[index + 1] = vi + 1;
                info.Indices[index + 2] = vi + 2;

                info.Indices[index + 3] = vi + 2;
                info.Indices[index + 4] = vi + 1;
                info.Indices[index + 5] = vi + 3;
            }
            return info;
        }
Exemplo n.º 4
0
        public void FillCircle(int angle, ref MeshInfo info)
        {
            Assert.IsNotNull(info.Vertices);
            Assert.IsNotNull(info.UVs);
            Assert.IsNotNull(info.Indices);

            var initialAngle = -angle / 2;
            var seg          = (angle / 10);
            int numVerts     = seg + 2;
            int numIndices   = 3 * seg;

            Assert.AreEqual(info.Vertices.Length, numVerts);
            Assert.AreEqual(info.UVs.Length, numVerts);
            Assert.AreEqual(info.Indices.Length, numIndices);

            info.Vertices[0] = Vector3.zero;
            info.UVs[0]      = new Vector2(0.5f, 0.5f);

            float detailAngle = 10;

            for (int i = 1; i < numVerts; ++i)
            {
                info.Vertices[i] = Quaternion.AngleAxis(initialAngle + (detailAngle * (i - 1)), Vector3.up) * Vector3.forward;

                float normedHorizontal = (info.Vertices[i].x + 1.0f) * 0.5f;
                float normedVertical   = (info.Vertices[i].x + 1.0f) * 0.5f;
                info.UVs[i] = new Vector2(normedHorizontal, normedVertical);
            }

            for (int i = 0; i < seg; ++i)
            {
                int index = i * 3;
                info.Indices[index + 0] = 0;
                info.Indices[index + 1] = i + 1;
                info.Indices[index + 2] = i + 2;
            }
        }
Exemplo n.º 5
0
        public MeshInfo FillCircle(int angle)
        {
            var info = new MeshInfo();

            var initialAngle = -angle / 2;
            var seg          = (angle / 10);
            int numVerts     = seg + 2;
            int numIndices   = 3 * seg;

            info.Vertices = new Vector3[numVerts];
            info.UVs      = new Vector2[numVerts];
            info.Indices  = new int[numIndices];

            info.Vertices[0] = Vector3.zero;
            info.UVs[0]      = new Vector2(0.5f, 0.5f);

            float detailAngle = 10;

            for (int i = 1; i < numVerts; ++i)
            {
                info.Vertices[i] = Quaternion.AngleAxis(initialAngle + (detailAngle * (i - 1)), Vector3.up) * Vector3.forward;

                float normedHorizontal = (info.Vertices[i].x + 1.0f) * 0.5f;
                float normedVertical   = (info.Vertices[i].x + 1.0f) * 0.5f;
                info.UVs[i] = new Vector2(normedHorizontal, normedVertical);
            }

            for (int i = 0; i < seg; ++i)
            {
                int index = i * 3;
                info.Indices[index + 0] = 0;
                info.Indices[index + 1] = i + 1;
                info.Indices[index + 2] = i + 2;
            }
            return(info);
        }
Exemplo n.º 6
0
        public int FillTrackVUCI2(NF.Collections.Generic.LinkedList <LineInfo> lines, int maxLineCount, Color colorStart, Color colorEnd, ref MeshInfo meshInfo)
        {
            Assert.IsNotNull(meshInfo.Vertices);
            Assert.IsNotNull(meshInfo.UVs);
            Assert.IsNotNull(meshInfo.Colors);
            Assert.IsNotNull(meshInfo.Indices);

            int line = Math.Min(lines.Count, maxLineCount);

            if (line < 2)
            {
                return(line);
            }
            Assert.AreEqual(meshInfo.Vertices.Length, line * 2);
            Assert.AreEqual(meshInfo.UVs.Length, line * 2);
            Assert.AreEqual(meshInfo.Colors.Length, line * 2);
            Assert.AreEqual(meshInfo.Indices.Length, (line - 1) * 6);

            float addPerc     = 1f / line;
            float acc         = 0;
            int   recordIndex = 0;

            for (var node = lines.GetHeadNode(); node != null; node = node.Next)
            {
                var record = node.Item;
                if (recordIndex >= line)
                {
                    break;
                }
                Vector3 p0 = record.BasePosition;
                Vector3 p2 = record.TipPosition;

                // p0                    p2
                // |---------------------|
                int index = (recordIndex * 2);
                meshInfo.Vertices[index + 0] = p0;
                meshInfo.Vertices[index + 1] = p2;

                meshInfo.UVs[index + 0] = new Vector2(0, acc);
                meshInfo.UVs[index + 1] = new Vector2(1, acc);

                Color c = Color.Lerp(colorStart, colorEnd, acc);
                meshInfo.Colors[index + 0] = c;
                meshInfo.Colors[index + 1] = c;

                acc += addPerc;
                recordIndex++;
            }

            for (int i = 0; i < line - 1; ++i)
            {
                int ci = i * 2;
                int ni = ci + 2;

                int index = i * 6;

                // c0                    c1
                // 2---------------------|
                // |          |          |
                // 0---------------------1
                // n0                    n1
                meshInfo.Indices[index + 0] = ni + 0;
                meshInfo.Indices[index + 1] = ni + 1;
                meshInfo.Indices[index + 2] = ci + 0;

                // c0                    c1
                // 5---------------------4
                // |          |          |
                // |---------------------3
                // n0                    n1
                meshInfo.Indices[index + 3] = ni + 1;
                meshInfo.Indices[index + 4] = ci + 1;
                meshInfo.Indices[index + 5] = ci + 0;
            }
            return(line);
        }
Exemplo n.º 7
0
        public int FillSplineVUCI2(Spliner spliner, Color colorStart, Color colorEnd, ref MeshInfo meshInfo)
        {
            Assert.IsNotNull(meshInfo.Vertices);
            Assert.IsNotNull(meshInfo.UVs);
            Assert.IsNotNull(meshInfo.Colors);
            Assert.IsNotNull(meshInfo.Indices);

            int line = spliner.GetLineCount();

            Assert.AreEqual(meshInfo.Vertices.Length, line * 2);
            Assert.AreEqual(meshInfo.UVs.Length, line * 2);
            Assert.AreEqual(meshInfo.Colors.Length, line * 2);
            Assert.AreEqual(meshInfo.Indices.Length, (line - 1) * 6);

            float addPerc = 1f / line;
            float acc     = 0;

            for (int i = 0; i < line; ++i)
            {
                (Vector3 p1, Vector3 up) = spliner.Interpolate(acc);
                Vector3 width = (up * 0.5f);
                Vector3 p0    = p1 - width;
                Vector3 p2    = p1 + width;

                // p0                    p2
                // |---------------------|
                int index = (i * 2);
                meshInfo.Vertices[index + 0] = p0;
                meshInfo.Vertices[index + 1] = p2;

                meshInfo.UVs[index + 0] = new Vector2(0, acc);
                meshInfo.UVs[index + 1] = new Vector2(1, acc);

                Color c = Color.Lerp(colorStart, colorEnd, acc);
                meshInfo.Colors[index + 0] = c;
                meshInfo.Colors[index + 1] = c;

                acc += addPerc;
            }

            for (int i = 0; i < line - 1; ++i)
            {
                int ci = i * 2;
                int ni = ci + 2;

                int index = i * 6;

                // c0                    c1
                // 2---------------------|
                // |          |          |
                // 0---------------------1
                // n0                    n1
                meshInfo.Indices[index + 0] = ni + 0;
                meshInfo.Indices[index + 1] = ni + 1;
                meshInfo.Indices[index + 2] = ci + 0;

                // c0                    c1
                // 5---------------------4
                // |          |          |
                // |---------------------3
                // n0                    n1
                meshInfo.Indices[index + 3] = ni + 1;
                meshInfo.Indices[index + 4] = ci + 1;
                meshInfo.Indices[index + 5] = ci + 0;
            }
            return(line);
        }