예제 #1
0
        public NinePatch(NinePatchStyle style)
        {
            this.style = style;

            //mesh = new Mesh.Mesh(BufferUsageHint.DynamicDraw);
            mesh = new RenderStack.Mesh.Mesh();

            VertexFormat vertexFormat = new VertexFormat();

            vertexFormat.Add(new Attribute(VertexUsage.Position, VertexAttribPointerType.Float, 0, 3));
            vertexFormat.Add(new Attribute(VertexUsage.TexCoord, VertexAttribPointerType.Float, 0, 2));

            // \todo Allocate vertex buffers form from UI BufferPool and use double buffered Buffers
            // \todo Share one index buffer among all UI components that have the same index buffer
            //Buffer vertexBuffer = BufferPool.Instance.GetVertexBuffer(vertexFormat, BufferUsageHint.DynamicDraw);
            //Buffer indexBuffer = BufferPool.Instance.GetIndexBuffer(DrawElementsType.UnsignedShort, BufferUsageHint.StaticDraw);
            vertexBuffer = BufferFactory.Create(vertexFormat, BufferUsageHint.DynamicDraw);
            indexBuffer  = BufferFactory.Create(DrawElementsType.UnsignedShort, BufferUsageHint.StaticDraw);

            mesh.VertexBufferRange = vertexBuffer.CreateVertexBufferRange();
            IBufferRange indexBufferRange = mesh.FindOrCreateIndexBufferRange(
                MeshMode.PolygonFill,
                indexBuffer,
                BeginMode.Triangles
                );
            var writer = new IndexBufferWriter(indexBufferRange);

            vertexWriter = new VertexBufferWriter(mesh.VertexBufferRange);

            //  12 13 14 15
            //
            //   8  9 10 11
            //
            //   4  5  6  7
            //
            //   0  1  2  3

            writer.BeginEdit();

            writer.Quad(4, 5, 1, 0); writer.CurrentIndex += 6;
            writer.Quad(5, 6, 2, 1); writer.CurrentIndex += 6;
            writer.Quad(6, 7, 3, 2); writer.CurrentIndex += 6;

            writer.Quad(8, 9, 5, 4); writer.CurrentIndex   += 6;
            writer.Quad(9, 10, 6, 5); writer.CurrentIndex  += 6;
            writer.Quad(10, 11, 7, 6); writer.CurrentIndex += 6;

            writer.Quad(12, 13, 9, 8); writer.CurrentIndex   += 6;
            writer.Quad(13, 14, 10, 9); writer.CurrentIndex  += 6;
            writer.Quad(14, 15, 11, 10); writer.CurrentIndex += 6;

            writer.EndEdit();

            // \bug
            //indexBuffer.UpdateAll();
        }
예제 #2
0
        public void CubeFace(Vector3 A, Vector3 B, Vector3 C, Vector3 D, byte u, byte v, UInt32 col, float l)
        {
            indexWriter.Quad(
                vertexWriter.CurrentIndex, vertexWriter.CurrentIndex + 1,
                vertexWriter.CurrentIndex + 2, vertexWriter.CurrentIndex + 3
                );
            indexWriter.CurrentIndex += 6;
#if false
            byte r = 80;
            byte g = 200;
            byte b = 80;
            byte a = 255;
#else
            float r = l * (float)((col & 0xff0000) >> 16) / 255.0f;
            float g = l * (float)((col & 0xff00) >> 8) / 255.0f;
            float b = l * (float)((col & 0xff)) / 255.0f;
            float a = 1.0f;
#endif
            float u0 = (float)u * 1.0f / 16.0f;
            float v0 = (float)v * 1.0f / 16.0f;
            float u1 = (float)(u + 1) * 1.0f / 16.0f;
            float v1 = (float)(v + 1) * 1.0f / 16.0f;

            //
            vertexWriter.Set(position, D.X, D.Y, D.Z);
            vertexWriter.Set(texcoord, u0, v1);
            vertexWriter.Set(color, r, g, b, a);
            ++vertexWriter.CurrentIndex;

            vertexWriter.Set(position, C.X, C.Y, C.Z);
            vertexWriter.Set(texcoord, u1, v1);
            vertexWriter.Set(color, r, g, b, a);
            ++vertexWriter.CurrentIndex;

            vertexWriter.Set(position, B.X, B.Y, B.Z);
            vertexWriter.Set(texcoord, u1, v0);
            vertexWriter.Set(color, r, g, b, a);
            ++vertexWriter.CurrentIndex;

            vertexWriter.Set(position, A.X, A.Y, A.Z);
            vertexWriter.Set(texcoord, u0, v0);
            vertexWriter.Set(color, r, g, b, a);
            ++vertexWriter.CurrentIndex;
        }
예제 #3
0
        public void LowPrint(
            VertexBufferWriter vertexWriter,
            IndexBufferWriter indexWriter,
            float x,
            float y,
            float z,
            string text
            )
        {
            if (string.IsNullOrEmpty(text) == true)
            {
                return;
            }
            y += common.Base;
            FontChar fontChar = null;

            for (int i = 0; i < text.Length; ++i)
            {
                char c = text[i];

                fontChar = chars[c];
                if (fontChar == null)
                {
                    continue;
                }

                float a  = fontChar.XAdvance;
                float w  = fontChar.Width;
                float h  = fontChar.Height;
                float ox = fontChar.XOffset;
                float oy = fontChar.YOffset;

                indexWriter.Quad(
                    vertexWriter.CurrentIndex,
                    vertexWriter.CurrentIndex + 1,
                    vertexWriter.CurrentIndex + 2,
                    vertexWriter.CurrentIndex + 3
                    );
                indexWriter.CurrentIndex += 6;
                vertexWriter.Set(position, x + ox, y - oy, z);
                vertexWriter.Set(texCoord, fontChar.U, fontChar.V);
                vertexWriter.Set(color, 1.0f, 1.0f, 1.0f);
                ++vertexWriter.CurrentIndex;
                Bounds.Extend(x + ox, y - oy);

                vertexWriter.Set(position, x + w + ox, y - oy, z);
                vertexWriter.Set(texCoord, fontChar.U2, fontChar.V);
                vertexWriter.Set(color, 1.0f, 1.0f, 1.0f);
                ++vertexWriter.CurrentIndex;
                Bounds.Extend(x + w + ox, y - oy);

                vertexWriter.Set(position, x + w + ox, y - h - oy, z);
                vertexWriter.Set(texCoord, fontChar.U2, fontChar.V2);
                vertexWriter.Set(color, 1.0f, 1.0f, 1.0f);
                ++vertexWriter.CurrentIndex;
                Bounds.Extend(x + w + ox, y - h - oy);

                vertexWriter.Set(position, x + ox, y - h - oy, z);
                vertexWriter.Set(texCoord, fontChar.U, fontChar.V2);
                vertexWriter.Set(color, 1.0f, 1.0f, 1.0f);
                ++vertexWriter.CurrentIndex;
                Bounds.Extend(x + ox, y - h - oy);

                x += a;

                if (
                    (i + 1 < text.Length - 1) &&
                    (fontChar.Kernings != null)
                    )
                {
                    char next = text[i + 1];

                    FontKerning compare = new FontKerning((short)next);

                    int index = fontChar.Kernings.BinarySearch(compare);

                    if (index >= 0)
                    {
                        short amount = fontChar.Kernings[index].Amount;
                        x += (float)(amount);
                    }
                }
            }
        }
예제 #4
0
 //   b-----c
 //   |\    |
 //   |  \  |
 //   |    \|
 //   a-----d
 public void Quad(Vector3 bottomLeft, Vector3 topRight, Vector4 rgba)
 {
     indexWriter.Quad(
         vertexWriter.CurrentIndex,
         vertexWriter.CurrentIndex + 1,
         vertexWriter.CurrentIndex + 2,
         vertexWriter.CurrentIndex + 3
         );
     indexWriter.CurrentIndex += 6;
     vertexWriter.Set(color, rgba.X, rgba.Y, rgba.Z, rgba.W);
     vertexWriter.Set(texcoord, 0.0f, 0.0f);
     vertexWriter.Set(position, bottomLeft.X, bottomLeft.Y, bottomLeft.Z);   ++vertexWriter.CurrentIndex;
     vertexWriter.Set(color, rgba.X, rgba.Y, rgba.Z, rgba.W);
     vertexWriter.Set(texcoord, 0.0f, 1.0f);
     vertexWriter.Set(position, bottomLeft.X, topRight.Y, bottomLeft.Z);   ++vertexWriter.CurrentIndex;
     vertexWriter.Set(color, rgba.X, rgba.Y, rgba.Z, rgba.W);
     vertexWriter.Set(texcoord, 1.0f, 1.0f);
     vertexWriter.Set(position, topRight.X, topRight.Y, bottomLeft.Z);   ++vertexWriter.CurrentIndex;
     vertexWriter.Set(color, rgba.X, rgba.Y, rgba.Z, rgba.W);
     vertexWriter.Set(texcoord, 1.0f, 0.0f);
     vertexWriter.Set(position, topRight.X, bottomLeft.Y, bottomLeft.Z);   ++vertexWriter.CurrentIndex;
 }
예제 #5
0
        public virtual void UpdateTubeMesh()
        {
            var vertexFormat = TubeMesh.VertexBufferRange.VertexFormat;

            tubePosition = vertexFormat.FindAttribute(VertexUsage.Position, 0);
            tubeNormal   = vertexFormat.FindAttribute(VertexUsage.Normal, 0);
            tubeTangent  = vertexFormat.FindAttribute(VertexUsage.Tangent, 0);
            tubeColor    = vertexFormat.FindAttribute(VertexUsage.Color, 0);
            tubeT        = vertexFormat.FindAttribute(VertexUsage.Color, 1);
            tubeId       = vertexFormat.FindAttribute(VertexUsage.Id, 0);

            tubeVertexWriter.BeginEdit();
            tubeIndexWriter.BeginEdit();

            //  \todo hack fixme
            ((GenericCurve)(curve)).UpdateNURBS();

            //  Compute initial N
            Vector3 pos     = curve.PositionAt(0.0f);
            Vector3 posNext = curve.PositionAt(1.0f / 512.0f);
            Vector3 d1      = posNext - pos;
            Vector3 T       = Vector3.Normalize(d1);
            Vector3 N       = d1.MinAxis;
            Vector3 B       = Vector3.Normalize(Vector3.Cross(T, N));

            LastN = Vector3.Normalize(Vector3.Cross(B, T));

            UpdateTubeMeshWithAdaptiveSubdivision();

            for (int stack = 1; stack < TubeStackCount - 2; ++stack)
            {
                int nextStack = stack + 1;
                for (int slice = 0; slice < tubeSliceCount; ++slice)
                {
                    int nextSlice = (slice + 1) % tubeSliceCount;
                    tubeIndexWriter.Quad(
                        (uint)(stack * tubeSliceCount + nextSlice),
                        (uint)(stack * tubeSliceCount + slice),
                        (uint)(nextStack * tubeSliceCount + slice),
                        (uint)(nextStack * tubeSliceCount + nextSlice)
                        );
                    tubeIndexWriter.CurrentIndex += 6;
                }
            }
            for (int slice = 0; slice < tubeSliceCount; ++slice)
            {
                int nextSlice1 = (slice + 1) % tubeSliceCount;
                tubeIndexWriter.Triangle(
                    (uint)(0 * tubeSliceCount),
                    (uint)(0 * tubeSliceCount + slice),
                    (uint)(0 * tubeSliceCount + nextSlice1)
                    );
                tubeIndexWriter.CurrentIndex += 3;
            }
            for (int slice = 0; slice < tubeSliceCount; ++slice)
            {
                int nextSlice1 = (slice + 1) % tubeSliceCount;
                tubeIndexWriter.Triangle(
                    (uint)((TubeStackCount - 1) * tubeSliceCount + nextSlice1),
                    (uint)((TubeStackCount - 1) * tubeSliceCount + slice),
                    (uint)((TubeStackCount - 1) * tubeSliceCount)
                    );
                tubeIndexWriter.CurrentIndex += 3;
            }
            tubeVertexWriter.EndEdit();
            tubeIndexWriter.EndEdit();
        }