internal override uint[] Search(RenderEventArgs arg,
                                        int x, int y,
                                        uint lastVertexId, ZeroIndexRenderer modernRenderer)
        {
            OneIndexBufferPtr indexBufferPtr = null;

            using (var buffer = new OneIndexBuffer(IndexElementType.UInt, DrawMode.Lines, BufferUsage.StaticDraw))
            {
                buffer.Create(8);
                unsafe
                {
                    var array = (uint *)buffer.Header.ToPointer();
                    array[0] = lastVertexId - 1; array[1] = lastVertexId - 0;
                    array[2] = lastVertexId - 2; array[3] = lastVertexId - 1;
                    array[4] = lastVertexId - 3; array[5] = lastVertexId - 2;
                    array[6] = lastVertexId - 0; array[7] = lastVertexId - 3;
                }

                indexBufferPtr = buffer.GetBufferPtr() as OneIndexBufferPtr;
            }

            modernRenderer.Render4InnerPicking(arg, indexBufferPtr);
            uint id = ColorCodedPicking.ReadPixel(x, arg.CanvasRect.Height - y - 1);

            indexBufferPtr.Dispose();

            if (id + 3 == lastVertexId)
            {
                return(new uint[] { id + 3, id, });
            }
            else
            {
                return(new uint[] { id - 1, id, });
            }
        }
Exemplo n.º 2
0
        public IndexBufferPtr GetIndexBufferPtr()
        {
            if (indexBufferPtr == null)
            {
                using (var buffer = new OneIndexBuffer(IndexElementType.UInt, DrawMode.TriangleStrip, BufferUsage.StaticDraw))
                {
                    buffer.Create(this.SideLength * (this.SideLength - 1) * 2);
                    unsafe
                    {
                        var pointer = (uint *)buffer.Header.ToPointer();
                        for (int k = 0; k < this.SideLength - 1; k++)
                        {
                            for (int i = 0; i < this.SideLength; i++)
                            {
                                if (k % 2 == 0)
                                {
                                    pointer[(i + k * this.SideLength) * 2 + 0] = (uint)(i + (k + 1) * this.SideLength);
                                    pointer[(i + k * this.SideLength) * 2 + 1] = (uint)(i + (k + 0) * this.SideLength);
                                }
                                else
                                {
                                    pointer[(i + k * this.SideLength) * 2 + 0] = (uint)(this.SideLength - 1 - i + (k + 0) * this.SideLength);
                                    pointer[(i + k * this.SideLength) * 2 + 1] = (uint)(this.SideLength - 1 - i + (k + 1) * this.SideLength);
                                }
                            }
                        }
                    }
                    indexBufferPtr = buffer.GetBufferPtr();
                }
            }

            return(indexBufferPtr);
        }
Exemplo n.º 3
0
        public unsafe IndexBufferPtr GetIndex()
        {
            if (this.indexBufferPtr != null)
            {
                return(this.indexBufferPtr);
            }

            int vertexCount = (faceCount * 2 + 2) * (this.pipeline.Count - 1);

            using (var buffer = new OneIndexBuffer <uint>(DrawMode.QuadStrip, BufferUsage.StaticDraw))
            {
                buffer.Create(vertexCount + (this.pipeline.Count - 1));
                var  array         = (uint *)buffer.Header.ToPointer();
                uint positionIndex = 0;
                for (int i = 0; i < buffer.Length; i++)
                {
                    if (i % (faceCount * 2 + 2 + 1) == (faceCount * 2 + 2))
                    {
                        array[i] = uint.MaxValue;//分割各个圆柱体
                    }
                    else
                    {
                        array[i] = positionIndex++;
                    }
                }

                this.indexBufferPtr = buffer.GetBufferPtr() as IndexBufferPtr;
            }

            return(this.indexBufferPtr);
        }
Exemplo n.º 4
0
        public IndexBufferPtr GetIndexBufferPtr()
        {
            if (this.indexBufferPtr == null)
            {
                int uCount = GetUCount(interval);
                int vCount = GetVCount(interval);
                using (var buffer = new OneIndexBuffer(IndexElementType.UInt, DrawMode.LineStrip, BufferUsage.StaticDraw))
                {
                    int count = (uCount + 1) * vCount + (vCount + 1 + 1) * uCount;
                    buffer.Create(count);
                    int index = 0;
                    unsafe
                    {
                        var array = (uint *)buffer.Header.ToPointer();
                        // vertical lines.
                        for (int i = 0; i < vCount; i++)
                        {
                            for (int j = 0; j < uCount; j++)
                            {
                                array[index++] = (uint)(i + j * vCount);
                            }
                            array[index++] = uint.MaxValue;// primitive restart index.
                        }
                        // horizontal lines.
                        for (int i = 0; i < uCount; i++)
                        {
                            for (int j = 0; j < vCount; j++)
                            {
                                array[index++] = (uint)(j + i * vCount);
                            }
                            array[index++] = (uint)(0 + i * vCount);
                            array[index++] = uint.MaxValue;// primitive restart index.
                        }
                    }

                    this.indexBufferPtr = buffer.GetBufferPtr();
                }
                //using (var buffer = new ZeroIndexBuffer(
                //    DrawMode.Points, 0, uCount * vCount))
                //{
                //    indexBufferPtr = buffer.GetBufferPtr();
                //}
            }

            return(this.indexBufferPtr);
        }
Exemplo n.º 5
0
        public IndexBufferPtr GetIndexBufferPtr()
        {
            if (indexBufferPtr == null)
            {
                using (var buffer = new OneIndexBuffer(IndexElementType.UInt, DrawMode.Triangles, BufferUsage.StaticDraw))
                {
                    buffer.Create(3 * 3);
                    unsafe
                    {
                        var array = (uint *)buffer.Header.ToPointer();
                        array[0] = 0; array[1] = 1; array[2] = 3;
                        array[3] = 0; array[4] = 3; array[5] = 2;
                        array[6] = 1; array[7] = 3; array[8] = 2;
                    }

                    indexBufferPtr = buffer.GetBufferPtr();
                }
            }

            return(indexBufferPtr);
        }
Exemplo n.º 6
0
        public IndexBufferPtr GetIndexBufferPtr()
        {
            if (indexBufferPtr == null)
            {
                using (var buffer = new OneIndexBuffer(IndexElementType.UInt, DrawMode.Triangles, BufferUsage.StaticDraw))
                {
                    buffer.Create(xy_indices.Length);
                    unsafe
                    {
                        var array = (uint *)buffer.Header.ToPointer();
                        for (int i = 0; i < xy_indices.Length; i++)
                        {
                            array[i] = xy_indices[i];
                        }
                    }
                    indexBufferPtr = buffer.GetBufferPtr();
                }
            }

            return(indexBufferPtr);
        }
Exemplo n.º 7
0
        public override IndexBufferPtr GetIndexBufferPtr()
        {
            if (this.indexBufferPtr == null)
            {
                using (var buffer = new OneIndexBuffer(IndexElementType.UInt, DrawMode.QuadStrip, BufferUsage.StaticDraw))
                {
                    int dimSize = this.DataSource.DimenSize;
                    buffer.Create(dimSize * 2 * (Marshal.SizeOf(typeof(HalfHexahedronIndex)) / sizeof(uint)));
                    unsafe
                    {
                        var array = (HalfHexahedronIndex *)buffer.Header.ToPointer();
                        for (int gridIndex = 0; gridIndex < dimSize; gridIndex++)
                        {
                            array[gridIndex * 2].dot0         = (uint)(8 * gridIndex + 6);
                            array[gridIndex * 2].dot1         = (uint)(8 * gridIndex + 2);
                            array[gridIndex * 2].dot2         = (uint)(8 * gridIndex + 7);
                            array[gridIndex * 2].dot3         = (uint)(8 * gridIndex + 3);
                            array[gridIndex * 2].dot4         = (uint)(8 * gridIndex + 4);
                            array[gridIndex * 2].dot5         = (uint)(8 * gridIndex + 0);
                            array[gridIndex * 2].dot6         = (uint)(8 * gridIndex + 5);
                            array[gridIndex * 2].dot7         = (uint)(8 * gridIndex + 1);
                            array[gridIndex * 2].restartIndex = uint.MaxValue;

                            array[gridIndex * 2 + 1].dot0         = (uint)(8 * gridIndex + 3);
                            array[gridIndex * 2 + 1].dot1         = (uint)(8 * gridIndex + 0);
                            array[gridIndex * 2 + 1].dot2         = (uint)(8 * gridIndex + 2);
                            array[gridIndex * 2 + 1].dot3         = (uint)(8 * gridIndex + 1);
                            array[gridIndex * 2 + 1].dot4         = (uint)(8 * gridIndex + 6);
                            array[gridIndex * 2 + 1].dot5         = (uint)(8 * gridIndex + 5);
                            array[gridIndex * 2 + 1].dot6         = (uint)(8 * gridIndex + 7);
                            array[gridIndex * 2 + 1].dot7         = (uint)(8 * gridIndex + 4);
                            array[gridIndex * 2 + 1].restartIndex = uint.MaxValue;
                        }
                    }
                    this.indexBufferPtr = buffer.GetBufferPtr();
                }
            }

            return(this.indexBufferPtr);
        }
Exemplo n.º 8
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public IndexBufferPtr GetIndexBufferPtr()
        {
            if (indexBufferPtr == null)
            {
                using (var buffer = new OneIndexBuffer(IndexElementType.UByte, DrawMode.Triangles, BufferUsage.StaticDraw))
                {
                    buffer.Create(TetrahedronModel.index.Length);
                    unsafe
                    {
                        var array = (byte *)buffer.Header.ToPointer();
                        for (int i = 0; i < TetrahedronModel.index.Length; i++)
                        {
                            array[i] = TetrahedronModel.index[i];
                        }
                    }

                    indexBufferPtr = buffer.GetBufferPtr();
                }
            }

            return(indexBufferPtr);
        }
Exemplo n.º 9
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public IndexBufferPtr GetIndexBufferPtr()
        {
            if (indexBufferPtr == null)
            {
                using (var buffer = new OneIndexBuffer(IndexElementType.UShort, DrawMode.Triangles, BufferUsage.StaticDraw))
                {
                    ushort[] faces = model.GetFaces();
                    buffer.Create(faces.Length);
                    unsafe
                    {
                        var array = (ushort *)buffer.Header.ToPointer();
                        for (int i = 0; i < faces.Length; i++)
                        {
                            array[i] = (ushort)(faces[i] - 1);
                        }
                    }

                    indexBufferPtr = buffer.GetBufferPtr();
                }
            }

            return(indexBufferPtr);
        }
Exemplo n.º 10
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public IndexBufferPtr GetIndexBufferPtr()
        {
            if (indexBufferPtr == null)
            {
                if (model.positions.Length < byte.MaxValue)
                {
                    using (var buffer = new OneIndexBuffer(IndexElementType.UByte, DrawMode.TriangleStrip, BufferUsage.StaticDraw))
                    {
                        buffer.Create(model.indexes.Length);
                        unsafe
                        {
                            var indexArray = (byte *)buffer.Header.ToPointer();
                            for (int i = 0; i < model.indexes.Length; i++)
                            {
                                if (model.indexes[i] == uint.MaxValue)
                                {
                                    indexArray[i] = byte.MaxValue;
                                }
                                else
                                {
                                    indexArray[i] = (byte)model.indexes[i];
                                }
                            }
                        }

                        indexBufferPtr = buffer.GetBufferPtr();
                    }
                }
                else if (model.positions.Length < ushort.MaxValue)
                {
                    using (var buffer = new OneIndexBuffer(IndexElementType.UShort, DrawMode.TriangleStrip, BufferUsage.StaticDraw))
                    {
                        buffer.Create(model.indexes.Length);
                        unsafe
                        {
                            var indexArray = (ushort *)buffer.Header.ToPointer();
                            for (int i = 0; i < model.indexes.Length; i++)
                            {
                                if (model.indexes[i] == uint.MaxValue)
                                {
                                    indexArray[i] = ushort.MaxValue;
                                }
                                else
                                {
                                    indexArray[i] = (ushort)model.indexes[i];
                                }
                            }
                        }

                        indexBufferPtr = buffer.GetBufferPtr();
                    }
                }
                else
                {
                    using (var buffer = new OneIndexBuffer(IndexElementType.UInt, DrawMode.TriangleStrip, BufferUsage.StaticDraw))
                    {
                        buffer.Create(model.indexes.Length);
                        unsafe
                        {
                            var indexArray = (uint *)buffer.Header.ToPointer();
                            for (int i = 0; i < model.indexes.Length; i++)
                            {
                                indexArray[i] = model.indexes[i];
                            }
                        }

                        indexBufferPtr = buffer.GetBufferPtr();
                    }
                }
            }

            return(indexBufferPtr);
        }