Exemplo n.º 1
0
        protected override void RecognizeUShort(uint lastVertexId, IntPtr pointer, DrawElementsCmd cmd, List <RecognizedPrimitiveInfo> primitiveInfoList, uint primitiveRestartIndex)
        {
            int length = cmd.IndexBufferObject.Length;

            unsafe
            {
                var  array = (ushort *)pointer.ToPointer();
                long nearestRestartIndex = -1;
                uint i = 0;
                while (i < length && array[i] == primitiveRestartIndex)
                {
                    nearestRestartIndex = i; i++;
                }
                for (i = i + 1; i < length; i++)
                {
                    var value = array[i];
                    if (value == primitiveRestartIndex)
                    {
                        // try the loop back line.
                        nearestRestartIndex = i;
                    }
                    else if (value == lastVertexId &&
                             array[i - 1] != primitiveRestartIndex)
                    {
                        var item = new RecognizedPrimitiveInfo(i, array[i - 1], lastVertexId);
                        primitiveInfoList.Add(item);
                    }
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="arg"></param>
        /// <param name="singleNodeVertexId"></param>
        /// <param name="stageVertexId"></param>
        /// <param name="picker"></param>
        /// <returns></returns>
        internal override uint Search(PickingEventArgs arg,
                                      uint singleNodeVertexId, uint stageVertexId, DrawArraysPicker picker)
        {
            var array = new uint[]
            {
                singleNodeVertexId - 0,
                singleNodeVertexId - 2,
                singleNodeVertexId - 4
            };
            IndexBuffer buffer = array.GenIndexBuffer(BufferUsage.StaticDraw);
            var         cmd    = new DrawElementsCmd(buffer, DrawMode.Points);

            picker.Node.Render4InnerPicking(arg, cmd);
            uint id = ColorCodedPicking.ReadStageVertexId(arg.X, arg.Y);

            buffer.Dispose();

            if (stageVertexId - 0 == id || stageVertexId - 2 == id || stageVertexId - 4 == id)
            {
                return(id);
            }
            else
            {
                throw new Exception("This should not happen!");
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="arg"></param>
        /// <param name="lastVertexId"></param>
        /// <param name="picker"></param>
        /// <returns></returns>
        internal override uint Search(PickingEventArgs arg,
                                      uint lastVertexId, DrawArraysPicker picker)
        {
            IndexBuffer buffer = GLBuffer.Create(IndexBufferElementType.UInt, 4, BufferUsage.StaticDraw);

            unsafe
            {
                var array = (uint *)buffer.MapBuffer(MapBufferAccess.WriteOnly);
                array[0] = lastVertexId - 0;
                array[1] = lastVertexId - 1;
                array[2] = lastVertexId - 2;
                array[3] = lastVertexId - 3;
                buffer.UnmapBuffer();
            }
            var cmd = new DrawElementsCmd(buffer, DrawMode.Points);

            picker.Node.Render4InnerPicking(arg, IndexAccessMode.ByFrame, cmd);
            uint id = ColorCodedPicking.ReadStageVertexId(arg.X, arg.Y);

            buffer.Dispose();

            if (lastVertexId - 3 <= id && id <= lastVertexId - 0)
            {
                return(id);
            }
            else
            {
                throw new Exception("This should not happen!");
            }
        }
Exemplo n.º 4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="arg"></param>
        /// <param name="primitiveInfo"></param>
        /// <param name="picker"></param>
        /// <returns></returns>
        internal override uint Search(PickingEventArgs arg,
                                      RecognizedPrimitiveInfo primitiveInfo,
                                      DrawElementsPicker picker)
        {
            uint[] indexList = primitiveInfo.VertexIds;
            if (indexList.Length != 4)
            {
                throw new ArgumentException();
            }

            IndexBuffer buffer = indexList.GenIndexBuffer(BufferUsage.StaticDraw);
            var         cmd    = new DrawElementsCmd(buffer, DrawMode.Points);

            picker.Node.Render4InnerPicking(arg, cmd);
            uint id = ColorCodedPicking.ReadStageVertexId(arg.X, arg.Y);

            buffer.Dispose();

            if (id == indexList[0] || id == indexList[1] ||
                id == indexList[2] || id == indexList[3])
            {
                return(id);
            }
            else
            {
                throw new Exception("This should not happen!");
            }
        }
Exemplo n.º 5
0
        protected override void RecognizeUInt(uint singleNodeVertexId, DrawElementsCmd cmd, List <RecognizedPrimitiveInfo> primitiveInfoList, uint primitiveRestartIndex)
        {
            IndexBuffer indexBuffer = cmd.IndexBufferObject;
            int         length      = indexBuffer.Length;
            IntPtr      pointer     = indexBuffer.MapBuffer(MapBufferAccess.ReadOnly);

            unsafe
            {
                var  array = (uint *)pointer.ToPointer();
                long nearestRestartIndex = -1;
                uint i = 0;
                while (i < length && array[i] == primitiveRestartIndex)
                {
                    nearestRestartIndex = i; i++;
                }
                for (i = i + 3; i < length; i++)
                {
                    var value = array[i];
                    if (value == primitiveRestartIndex)
                    {
                        nearestRestartIndex = i;
                    }
                    else if (((i - 3 - nearestRestartIndex) % 4 == 0) &&
                             (value == singleNodeVertexId) &&
                             (array[i - 1] != primitiveRestartIndex) &&
                             (array[i - 2] != primitiveRestartIndex) &&
                             (array[i - 3] != primitiveRestartIndex))
                    {
                        var item = new RecognizedPrimitiveInfo(i, array[i - 3], array[i - 2], array[i - 1], singleNodeVertexId);
                        primitiveInfoList.Add(item);
                    }
                }
            }
            indexBuffer.UnmapBuffer();
        }
Exemplo n.º 6
0
        /// <summary>
        /// 在三角形图元中拾取指定位置的Point
        /// </summary>
        /// <param name="arg">渲染参数</param>
        /// <param name="flatColorVertexId">三角形图元的最后一个顶点</param>
        /// <param name="picker">目标Renderer</param>
        /// <returns></returns>
        internal override uint Search(PickingEventArgs arg, uint flatColorVertexId, DrawArraysPicker picker)
        {
            // 创建临时索引
            IndexBuffer buffer = GLBuffer.Create(IndexBufferElementType.UInt, 3, BufferUsage.StaticDraw);

            unsafe
            {
                var array = (uint *)buffer.MapBuffer(MapBufferAccess.WriteOnly);
                array[0] = flatColorVertexId - 0;
                array[1] = flatColorVertexId - 1;
                array[2] = flatColorVertexId - 2;
                buffer.UnmapBuffer();
            }
            var cmd = new DrawElementsCmd(buffer, DrawMode.Points);

            // 用临时索引渲染此三角形图元(仅渲染此三角形图元)
            picker.Node.Render4InnerPicking(arg, cmd);
            // id是拾取到的Line的Last Vertex Id
            uint id = ColorCodedPicking.ReadStageVertexId(arg.X, arg.Y);

            buffer.Dispose();

            // 对比临时索引,找到那个Line
            if (flatColorVertexId - 2 <= id && id <= flatColorVertexId - 0)
            {
                return(id);
            }
            else
            {
                throw new Exception("This should not happen!");
            }
        }
Exemplo n.º 7
0
        protected override void RecognizeByte(uint singleNodeVertexId, DrawElementsCmd cmd, List <RecognizedPrimitiveInfo> primitiveInfoList, uint primitiveRestartIndex)
        {
            IndexBuffer indexBuffer = cmd.IndexBufferObject;
            int         length      = indexBuffer.Length;
            IntPtr      pointer     = indexBuffer.MapBuffer(MapBufferAccess.ReadOnly);

            unsafe
            {
                var  array = (byte *)pointer.ToPointer();
                long nearestRestartIndex = -1;
                uint i = 0;
                while (i < length && array[i] == primitiveRestartIndex)
                {
                    nearestRestartIndex = i; i++;
                }
                for (i = i + 2; i < length; i++)
                {
                    var value = array[i];
                    if (value == primitiveRestartIndex)
                    {
                        // try the loop back line.
                        nearestRestartIndex = i;
                    }
                    else if (value == singleNodeVertexId &&
                             array[i - 1] != primitiveRestartIndex &&
                             array[nearestRestartIndex + 1] != primitiveRestartIndex &&
                             nearestRestartIndex + 2 < i)
                    {
                        var item = new RecognizedPrimitiveInfo(i, array[nearestRestartIndex + 1], array[i - 1], singleNodeVertexId);
                        primitiveInfoList.Add(item);
                    }
                }
            }
            indexBuffer.UnmapBuffer();
        }
Exemplo n.º 8
0
        /// <summary>
        /// 识别出以<paramref name="lastVertexId"/>结尾的图元。
        /// <para>识别过程中要考虑排除PrimitiveRestartIndex</para>
        /// </summary>
        /// <param name="lastVertexId"></param>
        /// <param name="pointer"></param>
        /// <param name="cmd"></param>
        /// <param name="primitiveRestartIndex"></param>
        /// <returns></returns>
        public List <RecognizedPrimitiveInfo> Recognize(
            uint lastVertexId, IntPtr pointer, DrawElementsCmd cmd, uint primitiveRestartIndex)
        {
            var lastIndexIdList = new List <RecognizedPrimitiveInfo>();

            if (lastVertexId != primitiveRestartIndex)
            {
                switch (cmd.IndexBufferObject.ElementType)
                {
                case IndexBufferElementType.UByte:
                    RecognizeByte(lastVertexId, pointer, cmd, lastIndexIdList, primitiveRestartIndex);
                    break;

                case IndexBufferElementType.UShort:
                    RecognizeUShort(lastVertexId, pointer, cmd, lastIndexIdList, primitiveRestartIndex);
                    break;

                case IndexBufferElementType.UInt:
                    RecognizeUInt(lastVertexId, pointer, cmd, lastIndexIdList, primitiveRestartIndex);
                    break;

                default:
                    throw new NotDealWithNewEnumItemException(typeof(IndexBufferElementType));
                }
            }

            return(lastIndexIdList);
        }
Exemplo n.º 9
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="arg"></param>
        /// <param name="twoPrimitivesIndexBuffer"></param>
        /// <returns></returns>
        private uint Pick(PickingEventArgs arg, DrawElementsCmd twoPrimitivesIndexBuffer)
        {
            this.Node.Render4InnerPicking(arg, ControlMode.ByFrame, twoPrimitivesIndexBuffer);

            uint pickedIndex = ColorCodedPicking.ReadStageVertexId(arg.X, arg.Y);

            return(pickedIndex);
        }
Exemplo n.º 10
0
        protected override void RecognizeUInt(uint flatColorVertexId, DrawElementsCmd cmd, List <RecognizedPrimitiveInfo> primitiveInfoList, uint primitiveRestartIndex)
        {
            IndexBuffer indexBuffer = cmd.IndexBufferObject;
            int         length      = indexBuffer.Length;
            IntPtr      pointer     = indexBuffer.MapBuffer(MapBufferAccess.ReadOnly);

            unsafe
            {
                var  array = (uint *)pointer.ToPointer();
                long nearestRestartIndex = -1;
                uint i = 0;
                while (i < length && array[i] == primitiveRestartIndex)
                {
                    nearestRestartIndex = i; i++;
                }
                for (i = i + 1; i < length; i++)
                {
                    var value = array[i];
                    if (value == primitiveRestartIndex)
                    {
                        // try the loop back line.
                        if (array[nearestRestartIndex + 1] == flatColorVertexId &&
                            array[i - 1] != primitiveRestartIndex &&
                            nearestRestartIndex + 1 < i - 1)
                        {
                            var item = new RecognizedPrimitiveInfo((uint)(nearestRestartIndex + 1), value, flatColorVertexId);
                            primitiveInfoList.Add(item);
                        }
                        nearestRestartIndex = i;
                    }
                    else if (value == flatColorVertexId &&
                             array[i - 1] != primitiveRestartIndex)
                    {
                        var item = new RecognizedPrimitiveInfo(i, array[i - 1], flatColorVertexId);
                        primitiveInfoList.Add(item);
                    }
                }
                if (array[nearestRestartIndex + 1] == flatColorVertexId &&
                    array[length - 1] != primitiveRestartIndex &&
                    nearestRestartIndex + 1 < length - 1)
                {
                    var item = new RecognizedPrimitiveInfo((uint)(nearestRestartIndex + 1), array[length - 1], flatColorVertexId);
                    primitiveInfoList.Add(item);
                }
            }
            indexBuffer.UnmapBuffer();
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="arg"></param>
        /// <param name="primitiveInfo"></param>
        /// <param name="singleNodeVertexId"></param>
        /// <param name="stageVertexId"></param>
        /// <param name="picker"></param>
        /// <returns></returns>
        internal override uint[] Search(PickingEventArgs arg,
                                        RecognizedPrimitiveInfo primitiveInfo,
                                        uint singleNodeVertexId, uint stageVertexId,
                                        DrawElementsPicker picker)
        {
            uint[] vertexIds = primitiveInfo.VertexIds;
            if (vertexIds.Length < 3)
            {
                throw new ArgumentException();
            }

            IndexBuffer buffer = vertexIds.GenIndexBuffer(BufferUsage.StaticDraw);
            var         cmd    = new DrawElementsCmd(buffer, DrawMode.LineLoop);

            picker.Node.Render4InnerPicking(arg, cmd);
            uint id = ColorCodedPicking.ReadStageVertexId(arg.X, arg.Y);

            buffer.Dispose();

            uint baseId = stageVertexId - singleNodeVertexId;

            if (id == baseId + vertexIds[0])
            {
                return(new uint[] { baseId + vertexIds[vertexIds.Length - 1], id, });
            }
            else
            {
                uint[] result = null;
                for (int i = 1; i < vertexIds.Length; i++)
                {
                    if (id == baseId + vertexIds[i])
                    {
                        result = new uint[] { baseId + vertexIds[i - 1], id, };
                        break;
                    }
                }

                if (result != null)
                {
                    return(result);
                }
                else
                {
                    throw new Exception("This should not happen!");
                }
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="arg"></param>
        /// <param name="primitiveInfo"></param>
        /// <param name="singleNodeVertexId"></param>
        /// <param name="stageVertexId"></param>
        /// <param name="picker"></param>
        /// <returns></returns>
        internal override uint[] Search(PickingEventArgs arg,
                                        RecognizedPrimitiveInfo primitiveInfo,
                                        uint singleNodeVertexId, uint stageVertexId,
                                        DrawElementsPicker picker)
        {
            uint[] verttexIds = primitiveInfo.VertexIds;
            if (verttexIds.Length != 3)
            {
                throw new ArgumentException();
            }

            //if (indexList[0] == indexList[1]) { return new uint[] { indexList[0], indexList[2], }; }
            //else if (indexList[0] == indexList[2]) { return new uint[] { indexList[0], indexList[1], }; }
            //else if (indexList[1] == indexList[2]) { return new uint[] { indexList[1], indexList[0], }; }

            var targetVertexIds = new uint[6] {
                verttexIds[0], verttexIds[1], verttexIds[1], verttexIds[2], verttexIds[2], verttexIds[0],
            };
            IndexBuffer buffer = targetVertexIds.GenIndexBuffer(BufferUsage.StaticDraw);
            var         cmd    = new DrawElementsCmd(buffer, DrawMode.Lines);

            picker.Node.Render4InnerPicking(arg, cmd);
            uint id = ColorCodedPicking.ReadStageVertexId(arg.X, arg.Y);

            buffer.Dispose();

            uint baseId = stageVertexId - singleNodeVertexId;

            if (id == baseId + verttexIds[1])
            {
                return(new uint[] { baseId + verttexIds[0], id, });
            }
            else if (id == baseId + verttexIds[2])
            {
                return(new uint[] { baseId + verttexIds[1], id, });
            }
            else if (id == baseId + verttexIds[0])
            {
                return(new uint[] { baseId + verttexIds[2], id, });
            }
            else
            {
                throw new Exception("This should not happen!");
            }
        }
Exemplo n.º 13
0
        protected override void RecognizeUShort(uint lastVertexId, IntPtr pointer, DrawElementsCmd cmd, List <RecognizedPrimitiveInfo> primitiveInfoList, uint primitiveRestartIndex)
        {
            int length = cmd.IndexBufferObject.Length;

            unsafe
            {
                var array = (ushort *)pointer.ToPointer();
                for (uint i = 0; i < length; i++)
                {
                    var value = array[i];
                    if (value == lastVertexId)
                    {
                        var item = new RecognizedPrimitiveInfo(i, value);
                        primitiveInfoList.Add(item);
                    }
                }
            }
        }
Exemplo n.º 14
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="arg"></param>
        /// <param name="primitiveInfo"></param>
        /// <param name="picker"></param>
        /// <returns></returns>
        internal override uint[] Search(PickingEventArgs arg,
                                        RecognizedPrimitiveInfo primitiveInfo,
                                        DrawElementsPicker picker)
        {
            uint[] indexList = primitiveInfo.VertexIds;
            if (indexList.Length < 3)
            {
                throw new ArgumentException();
            }

            IndexBuffer buffer = indexList.GenIndexBuffer(BufferUsage.StaticDraw);
            var         cmd    = new DrawElementsCmd(buffer, DrawMode.LineLoop);

            picker.Node.Render4InnerPicking(arg, IndexAccessMode.ByFrame, cmd);
            uint id = ColorCodedPicking.ReadStageVertexId(arg.X, arg.Y);

            buffer.Dispose();

            if (id == indexList[0])
            {
                return(new uint[] { indexList[indexList.Length - 1], id, });
            }
            else
            {
                uint[] result = null;
                for (int i = 1; i < indexList.Length; i++)
                {
                    if (id == indexList[i])
                    {
                        result = new uint[] { indexList[i - 1], indexList[i], };
                        break;
                    }
                }

                if (result != null)
                {
                    return(result);
                }
                else
                {
                    throw new Exception("This should not happen!");
                }
            }
        }
Exemplo n.º 15
0
        protected override void RecognizeUInt(uint lastVertexId, IntPtr pointer, DrawElementsCmd cmd, List <RecognizedPrimitiveInfo> primitiveInfoList)
        {
            int length = cmd.IndexBufferObject.Length;

            unsafe
            {
                var  array = (uint *)pointer.ToPointer();
                uint i     = 0;
                for (i = i + 3; i < length; i++)
                {
                    var value = array[i];
                    if (value == lastVertexId)
                    {
                        var item = new RecognizedPrimitiveInfo(i, array[i - 2], array[i - 3], array[i - 1], lastVertexId);
                        primitiveInfoList.Add(item);
                    }
                }
            }
        }
Exemplo n.º 16
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="arg"></param>
        /// <param name="lastVertexId"></param>
        /// <param name="picker"></param>
        /// <returns></returns>
        internal override uint[] Search(PickingEventArgs arg,
                                        uint lastVertexId, DrawArraysPicker picker)
        {
            IndexBuffer buffer = GLBuffer.Create(IndexBufferElementType.UInt, 8, BufferUsage.StaticDraw);

            unsafe
            {
                var array = (uint *)buffer.MapBuffer(MapBufferAccess.WriteOnly);
                array[0] = lastVertexId - 0; array[1] = lastVertexId - 2;
                array[2] = lastVertexId - 2; array[3] = lastVertexId - 3;
                array[4] = lastVertexId - 3; array[5] = lastVertexId - 1;
                array[6] = lastVertexId - 1; array[7] = lastVertexId - 0;
                buffer.UnmapBuffer();
            }
            var cmd = new DrawElementsCmd(buffer, DrawMode.Lines);

            picker.Node.Render4InnerPicking(arg, ControlMode.ByFrame, cmd);
            uint id = ColorCodedPicking.ReadStageVertexId(arg.X, arg.Y);

            buffer.Dispose();
            if (id + 2 == lastVertexId)
            {
                return(new uint[] { lastVertexId - 0, lastVertexId - 2, });
            }
            else if (id + 3 == lastVertexId)
            {
                return(new uint[] { lastVertexId - 2, lastVertexId - 3 });
            }
            else if (id + 1 == lastVertexId)
            {
                return(new uint[] { lastVertexId - 3, lastVertexId - 1, });
            }
            else if (id + 0 == lastVertexId)
            {
                return(new uint[] { lastVertexId - 1, lastVertexId - 0, });
            }
            else
            {
                throw new Exception("This should not happen!");
            }
        }
Exemplo n.º 18
0
        protected override void RecognizeUInt(uint lastVertexId, DrawElementsCmd cmd, List <RecognizedPrimitiveInfo> primitiveInfoList, uint primitiveRestartIndex)
        {
            IndexBuffer indexBuffer = cmd.IndexBufferObject;
            int         length      = indexBuffer.Length;
            IntPtr      pointer     = indexBuffer.MapBuffer(MapBufferAccess.ReadOnly);

            unsafe
            {
                var array = (uint *)pointer.ToPointer();
                for (uint i = 0; i < length; i++)
                {
                    var value = array[i];
                    if (value == lastVertexId)
                    {
                        var item = new RecognizedPrimitiveInfo(i, value);
                        primitiveInfoList.Add(item);
                    }
                }
            }
            indexBuffer.UnmapBuffer();
        }
Exemplo n.º 19
0
        protected override void RecognizeByte(uint lastVertexId, IntPtr pointer, DrawElementsCmd cmd, List <RecognizedPrimitiveInfo> primitiveInfoList)
        {
            int length = cmd.IndexBufferObject.Length;

            unsafe
            {
                var  array = (byte *)pointer.ToPointer();
                long nearestRestartIndex = -1;
                uint i = 0;
                for (i = i + 2; i < length; i++)
                {
                    var value = array[i];
                    if (value == lastVertexId &&
                        (i - nearestRestartIndex) % 3 == 0)
                    {
                        var item = new RecognizedPrimitiveInfo(i, array[i - 2], array[i - 1], lastVertexId);
                        primitiveInfoList.Add(item);
                    }
                }
            }
        }
Exemplo n.º 20
0
        protected override void RecognizeUInt(uint flatColorVertexId, DrawElementsCmd cmd, List <RecognizedPrimitiveInfo> primitiveInfoList)
        {
            IndexBuffer indexBuffer = cmd.IndexBufferObject;
            int         length      = indexBuffer.Length;
            IntPtr      pointer     = indexBuffer.MapBuffer(MapBufferAccess.ReadOnly);

            unsafe
            {
                var  array = (uint *)pointer.ToPointer();
                uint i     = 0;
                for (i = i + 1; i < length; i += 2)
                {
                    var value = array[i];
                    if (value == flatColorVertexId)
                    {
                        var item = new RecognizedPrimitiveInfo(i, array[i - 1], flatColorVertexId);
                        primitiveInfoList.Add(item);
                    }
                }
            }
            indexBuffer.UnmapBuffer();
        }
Exemplo n.º 21
0
        protected override void RecognizeByte(uint singleNodeVertexId, DrawElementsCmd cmd, List <RecognizedPrimitiveInfo> primitiveInfoList)
        {
            IndexBuffer indexBuffer = cmd.IndexBufferObject;
            int         length      = indexBuffer.Length;
            IntPtr      pointer     = indexBuffer.MapBuffer(MapBufferAccess.ReadOnly);

            unsafe
            {
                var  array = (byte *)pointer.ToPointer();
                uint i     = 0;
                for (i = i + 4; i < length; i += 6)
                {
                    var value = array[i];
                    if (value == singleNodeVertexId)
                    {
                        var item = new RecognizedPrimitiveInfo(i, array[i - 4], array[i - 2], singleNodeVertexId);
                        primitiveInfoList.Add(item);
                    }
                }
            }
            indexBuffer.UnmapBuffer();
        }
Exemplo n.º 22
0
        /// <summary>
        /// 在三角形图元中拾取指定位置的Line
        /// </summary>
        /// <param name="arg"></param>
        /// <param name="singleNodeVertexId">三角形图元的最后一个顶点</param>
        /// <param name="stageVertexId"></param>
        /// <param name="picker"></param>
        /// <returns></returns>
        internal override uint[] Search(PickingEventArgs arg,
                                        uint singleNodeVertexId, uint stageVertexId, DrawArraysPicker picker)
        {
            // 创建临时索引
            var array = new uint[]
            {
                singleNodeVertexId - 1, singleNodeVertexId - 0,
                singleNodeVertexId - 2, singleNodeVertexId - 1,
                singleNodeVertexId - 0, singleNodeVertexId - 2
            };
            IndexBuffer buffer = array.GenIndexBuffer(BufferUsage.StaticDraw);
            var         cmd    = new DrawElementsCmd(buffer, DrawMode.Lines);

            // 用临时索引渲染此三角形图元(仅渲染此三角形图元)
            picker.Node.Render4InnerPicking(arg, cmd);
            // id是拾取到的Line的Last Vertex Id
            uint id = ColorCodedPicking.ReadStageVertexId(arg.X, arg.Y);

            buffer.Dispose();

            // 对比临时索引,找到那个Line
            if (id + 2 == stageVertexId)
            {
                return(new uint[] { id + 2, id, });
            }
            else if (id + 1 == stageVertexId)
            {
                return(new uint[] { id - 1, id, });
            }
            else if (id + 0 == stageVertexId)
            {
                return(new uint[] { id - 1, id, });
            }
            else
            {
                throw new Exception("This should not happen!");
            }
        }
        /// <summary>
        /// 将共享点前移,然后重新渲染、拾取
        /// </summary>
        /// <param name="recognizedPrimitiveIndex0"></param>
        /// <param name="recognizedPrimitiveIndex1"></param>
        /// <param name="singlePrimitiveMode"></param>
        /// <param name="cmd"></param>
        /// <param name="lastIndex0"></param>
        /// <param name="lastIndex1"></param>
        private void AssembleIndexBuffer(
            RecognizedPrimitiveInfo recognizedPrimitiveIndex0,
            RecognizedPrimitiveInfo recognizedPrimitiveIndex1,
            DrawMode singlePrimitiveMode,
            out DrawElementsCmd cmd,
            out uint lastIndex0, out uint lastIndex1)
        {
            List <uint> indexArray = ArrangeIndexes(
                recognizedPrimitiveIndex0, recognizedPrimitiveIndex1,
                out lastIndex0, out lastIndex1);

            if (indexArray.Count !=
                recognizedPrimitiveIndex0.VertexIds.Length
                + 1
                + recognizedPrimitiveIndex1.VertexIds.Length)
            {
                throw new Exception(string.Format("index array[{0}] not same length with [recognized primitive1 index length{1}] + [1] + recognized primitive2 index length[{2}]", indexArray.Count, recognizedPrimitiveIndex0.VertexIds.Length, recognizedPrimitiveIndex1.VertexIds.Length));
            }

            IndexBuffer buffer = indexArray.ToArray().GenIndexBuffer(BufferUsage.StaticDraw);

            cmd = new DrawElementsCmd(buffer, singlePrimitiveMode, uint.MaxValue);// uint.MaxValue in glPrimitiveRestartIndex();

            //oneIndexBuffer = Buffer.Create(IndexElementType.UInt,
            //    recognizedPrimitiveIndex0.VertexIds.Length
            //    + 1
            //    + recognizedPrimitiveIndex1.VertexIds.Length,
            //    singlePrimitiveMode, BufferUsage.StaticDraw);
            //unsafe
            //{
            //    var array = (uint*)oneIndexBuffer.MapBuffer(MapBufferAccess.WriteOnly);
            //    for (int i = 0; i < indexArray.Count; i++)
            //    {
            //        array[i] = indexArray[i];
            //    }
            //    oneIndexBuffer.UnmapBuffer();
            //}
        }
Exemplo n.º 24
0
        protected override void RecognizeUShort(uint lastVertexId, DrawElementsCmd cmd, List <RecognizedPrimitiveInfo> primitiveInfoList)
        {
            IndexBuffer indexBuffer = cmd.IndexBufferObject;
            int         length      = indexBuffer.Length;
            IntPtr      pointer     = indexBuffer.MapBuffer(MapBufferAccess.ReadOnly);

            unsafe
            {
                var  array = (ushort *)pointer.ToPointer();
                uint i     = 0;
                for (i = i + 3; i < length; i++)
                {
                    var value = array[i];
                    if (value == lastVertexId &&
                        (i - 3) % 4 == 0)
                    {
                        var item = new RecognizedPrimitiveInfo(i, array[i - 3], array[i - 2], array[i - 1], lastVertexId);
                        primitiveInfoList.Add(item);
                    }
                }
            }
            indexBuffer.UnmapBuffer();
        }
Exemplo n.º 25
0
        protected override void RecognizeByte(uint lastVertexId, IntPtr pointer, DrawElementsCmd cmd, List <RecognizedPrimitiveInfo> primitiveInfoList)
        {
            int length = cmd.IndexBufferObject.Length;

            unsafe
            {
                var array = (byte *)pointer.ToPointer();
                for (uint i = 1; i < length; i++)
                {
                    var value = array[i];
                    if (value == lastVertexId)
                    {
                        var item = new RecognizedPrimitiveInfo(i, array[i - 1], lastVertexId);
                        primitiveInfoList.Add(item);
                    }
                }
                if (array[0] == lastVertexId &&
                    length > 1)
                {
                    var item = new RecognizedPrimitiveInfo(0, array[length - 1], lastVertexId);
                    primitiveInfoList.Add(item);
                }
            }
        }
Exemplo n.º 26
0
        protected override void RecognizeByte(uint lastVertexId, DrawElementsCmd cmd, List <RecognizedPrimitiveInfo> primitiveInfoList)
        {
            IndexBuffer indexBuffer = cmd.IndexBufferObject;
            int         length      = indexBuffer.Length;
            IntPtr      pointer     = indexBuffer.MapBuffer(MapBufferAccess.ReadOnly);

            unsafe
            {
                var array = (byte *)pointer.ToPointer();
                //long nearestRestartIndex = -1;
                uint i = 0;
                for (i = i + 2; i < length; i += 3)
                {
                    var value = array[i];
                    if (value == lastVertexId)
                    //&& (i - nearestRestartIndex) % 3 == 0)
                    {
                        var item = new RecognizedPrimitiveInfo(i, array[i - 2], array[i - 1], lastVertexId);
                        primitiveInfoList.Add(item);
                    }
                }
            }
            indexBuffer.UnmapBuffer();
        }
Exemplo n.º 27
0
 public OneIndexBufferController(DrawElementsCmd drawCmd)
 {
     this.drawCmd = drawCmd;
 }
Exemplo n.º 28
0
 /// <summary>
 /// Get picked geometry from a <see cref="PickableNode"/> with <see cref="DrawArraysCmd"/> as index buffer.
 /// </summary>
 /// <param name="node"></param>
 /// <param name="positionBuffer"></param>
 /// <param name="drawCommand"></param>
 public DrawElementsPicker(PickableNode node, VertexBuffer positionBuffer, DrawElementsCmd drawCommand)
     : base(node, positionBuffer)
 {
     this.DrawCommand = drawCommand;
 }
Exemplo n.º 29
0
 protected abstract void RecognizeByte(uint lastVertexId, DrawElementsCmd cmd, List <RecognizedPrimitiveInfo> primitiveInfoList, uint primitiveRestartIndex);
Exemplo n.º 30
0
 protected abstract void RecognizeUShort(uint lastVertexId, DrawElementsCmd cmd, List <RecognizedPrimitiveInfo> primitiveInfoList);