Ejemplo n.º 1
0
        /// <summary>
        /// 遍历以<paramref name="flatColorVertexId"/>为最后一个顶点的图元,
        /// 瞄准每个图元的索引(例如1个三角形有3个索引)中的最后一个索引,
        /// 将此索引在<see cref="IndexBuffer"/>中的索引(位置)收集起来。
        /// </summary>
        /// <param name="arg"></param>
        /// <param name="flatColorVertexId"></param>
        /// <returns></returns>
        private List <RecognizedPrimitiveInfo> GetPossiblePrimitives(PickingEventArgs arg, uint flatColorVertexId)
        {
            var                 drawCmd    = this.DrawCommand;
            DrawMode            mode       = drawCmd.CurrentMode;
            PrimitiveRecognizer recognizer = PrimitiveRecognizerFactory.Create(
                (arg.GeometryType.Contains(GeometryType.Point) &&
                 mode.ToGeometryType() == GeometryType.Line) ?
                DrawMode.Points : mode);

            List <RecognizedPrimitiveInfo> primitiveInfoList = recognizer.Recognize(flatColorVertexId, drawCmd);

            return(primitiveInfoList);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 遍历以<paramref name="lastVertexId"/>为最后一个顶点的图元,
        /// 瞄准每个图元的索引(例如1个三角形有3个索引)中的最后一个索引,
        /// 将此索引在<see cref="IndexBuffer"/>中的索引(位置)收集起来。
        /// </summary>
        /// <param name="arg"></param>
        /// <param name="lastVertexId"></param>
        /// <returns></returns>
        private List <RecognizedPrimitiveInfo> GetLastIndexIdList(PickingEventArgs arg, uint lastVertexId)
        {
            var                 drawCmd    = this.DrawCommand;
            DrawMode            mode       = drawCmd.Mode;
            PrimitiveRecognizer recognizer = PrimitiveRecognizerFactory.Create(
                (arg.GeometryType.Contains(GeometryType.Point) &&
                 mode.ToGeometryType() == GeometryType.Line) ?
                DrawMode.Points : mode);

            PrimitiveRestartState glState = GetPrimitiveRestartState();

            List <RecognizedPrimitiveInfo> primitiveInfoList = null;

            if (glState == null)
            {
                primitiveInfoList = recognizer.Recognize(lastVertexId, drawCmd);
            }
            else
            {
                primitiveInfoList = recognizer.Recognize(lastVertexId, drawCmd, glState.RestartIndex);
            }

            return(primitiveInfoList);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="arg"></param>
        /// <param name="stageVertexId"></param>
        /// <param name="x">mouse position(Left Down is (0, 0)).</param>
        /// <param name="y">mouse position(Left Down is (0, 0)).</param>
        /// <returns></returns>
        public override PickedGeometry GetPickedGeometry(RenderEventArgs arg, uint stageVertexId,
                                                         int x, int y)
        {
            uint lastVertexId;

            if (!this.GetLastVertexIdOfPickedGeometry(stageVertexId, out lastVertexId))
            {
                return(null);
            }

            PickingGeometryType geometryType = arg.PickingGeometryType;

            if (geometryType == PickingGeometryType.Point)
            {
                DrawMode            mode       = this.indexBuffer.Mode;
                PickingGeometryType typeOfMode = mode.ToGeometryType();
                if (typeOfMode == PickingGeometryType.Point)
                {
                    return(PickWhateverItIs(arg, stageVertexId, lastVertexId, mode, typeOfMode));
                }
                else if (typeOfMode == PickingGeometryType.Line)
                {
                    if (this.OnPrimitiveTest(lastVertexId, mode))
                    {
                        return(PickPoint(arg, stageVertexId, lastVertexId));
                    }
                    else
                    {
                        return(null);
                    }
                }
                else
                {
                    ZeroIndexPointSearcher searcher = GetPointSearcher(mode);
                    if (searcher != null)// point is from triangle, quad or polygon
                    {
                        return(SearchPoint(arg, stageVertexId, x, y, lastVertexId, searcher));
                    }
                    else
                    {
                        throw new Exception(string.Format("Lack of searcher for [{0}]", mode));
                    }
                }
            }
            else if (geometryType == PickingGeometryType.Line)
            {
                DrawMode            mode       = this.indexBuffer.Mode;
                PickingGeometryType typeOfMode = mode.ToGeometryType();
                if (geometryType == typeOfMode)
                {
                    return(PickWhateverItIs(arg, stageVertexId, lastVertexId, mode, typeOfMode));
                }
                else
                {
                    ZeroIndexLineSearcher searcher = GetLineSearcher(mode);
                    if (searcher != null)// line is from triangle, quad or polygon
                    {
                        return(SearchLine(arg, stageVertexId, x, y, lastVertexId, searcher));
                    }
                    else if (mode == DrawMode.Points)// want a line when rendering GL_POINTS
                    {
                        return(null);
                    }
                    else
                    {
                        throw new Exception(string.Format("Lack of searcher for [{0}]", mode));
                    }
                }
            }
            else
            {
                DrawMode            mode       = this.indexBuffer.Mode;
                PickingGeometryType typeOfMode = mode.ToGeometryType();
                if (typeOfMode == geometryType)// I want what it is
                {
                    return(PickWhateverItIs(arg, stageVertexId, lastVertexId, mode, typeOfMode));
                }
                else
                {
                    return(null);
                }
                //{ throw new Exception(string.Format("Lack of searcher for [{0}]", mode)); }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="arg"></param>
        /// <param name="stageVertexId">The last vertex's id that constructs the picked primitive.
        /// <para>This id is in scene's all <see cref="IPickable"/>s' order.</para></param>
        /// <param name="baseId">Index of first vertex of the buffer that The geometry belongs to.
        /// <para>This id is in scene's all <see cref="IPickable"/>s' order.</para></param>
        /// <returns></returns>
        public override PickedGeometry GetPickedGeometry(PickingEventArgs arg, uint stageVertexId, uint baseId)
        {
            if (stageVertexId < baseId)
            {
                return(null);
            }
            uint singleNodeVertexId = stageVertexId - baseId;

            if (this.PositionBuffer.Length <= singleNodeVertexId)
            {
                return(null);
            }

            PickableNode node = this.Node;

            // Find primitiveInfo
            RecognizedPrimitiveInfo primitiveInfo = this.GetPrimitiveInfoOfPickedGeometry(arg, singleNodeVertexId, baseId);

            if (primitiveInfo == null)
            {
                Debug.WriteLine(string.Format(
                                    "Got singleNodeVertexId[{0}] but no primitiveInfo! Params are [{1}] [{2}]",
                                    singleNodeVertexId, arg, stageVertexId));
                { return(null); }
            }

            PickingGeometryTypes geometryType = arg.GeometryType;
            DrawMode             drawMode     = this.DrawCommand.CurrentMode;
            GeometryType         typeOfMode   = drawMode.ToGeometryType();

            if ((geometryType & PickingGeometryTypes.Point) == PickingGeometryTypes.Point)
            {
                // 获取pickedGeometry
                if (typeOfMode == GeometryType.Point)
                {
                    return(PickWhateverItIs(arg, stageVertexId, primitiveInfo, typeOfMode));
                }
                else
                {
                    DrawElementsPointSearcher searcher = GetPointSearcher(drawMode);
                    if (searcher != null)// line is from triangle, quad or polygon
                    {
                        return(SearchPoint(arg, singleNodeVertexId, stageVertexId, primitiveInfo, searcher));
                    }
                    else
                    {
                        throw new Exception(string.Format("Lack of searcher for [{0}]", drawMode));
                    }
                }
            }
            else if ((geometryType & PickingGeometryTypes.Line) == PickingGeometryTypes.Line)
            {
                // 获取pickedGeometry
                if (typeOfMode == GeometryType.Point) // want a line when rendering GL_POINTS
                {
                    return(null);
                }
                if (typeOfMode == GeometryType.Line)
                {
                    return(PickWhateverItIs(arg, stageVertexId, primitiveInfo, typeOfMode));
                }
                else
                {
                    DrawElementsLineSearcher searcher = GetLineSearcher(drawMode);
                    if (searcher != null)// line is from triangle, quad or polygon
                    {
                        return(SearchLine(arg, singleNodeVertexId, stageVertexId, primitiveInfo, searcher));
                    }
                    else
                    {
                        throw new Exception(string.Format("Lack of searcher for [{0}]", drawMode));
                    }
                }
            }
            else
            {
                if (geometryType.Contains(typeOfMode)) // I want what it is
                {
                    return(PickWhateverItIs(arg, stageVertexId, primitiveInfo, typeOfMode));
                }
                else
                {
                    return(null);
                }
                //{ throw new Exception(string.Format("Lack of searcher for [{0}]", mode)); }
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="arg"></param>
        /// <param name="stageVertexId">The last vertex's id that constructs the picked primitive.
        /// <para>This id is in scene's all <see cref="IPickable"/>s' order.</para></param>
        /// <param name="baseId">Index of first vertex of the buffer that The geometry belongs to.
        /// <para>This id is in scene's all <see cref="IPickable"/>s' order.</para></param>
        /// <returns></returns>
        public override PickedGeometry GetPickedGeometry(PickingEventArgs arg, uint stageVertexId, uint baseId)
        {
            if (stageVertexId < baseId)
            {
                return(null);
            }
            uint singleNodeVertexId = stageVertexId - baseId;

            if (this.PositionBuffer.Length <= singleNodeVertexId)
            {
                return(null);
            }

            PickingGeometryTypes pickingType = arg.GeometryType;

            if ((pickingType & PickingGeometryTypes.Point) == PickingGeometryTypes.Point)
            {
                DrawMode     mode       = this.DrawCommand.CurrentMode;
                GeometryType typeOfMode = mode.ToGeometryType();
                if (typeOfMode == GeometryType.Point)
                {
                    return(PickWhateverItIs(arg, stageVertexId, singleNodeVertexId, mode, typeOfMode));
                }
                else if (typeOfMode == GeometryType.Line)
                {
                    if (this.OnPrimitiveTest(singleNodeVertexId, mode))
                    {
                        return(PickPoint(arg, stageVertexId, singleNodeVertexId));
                    }
                    else
                    {
                        return(null);
                    }
                }
                else
                {
                    DrawArraysPointSearcher searcher = GetPointSearcher(mode);
                    if (searcher != null)// point is from triangle, quad or polygon
                    {
                        return(SearchPoint(arg, stageVertexId, singleNodeVertexId, searcher));
                    }
                    else
                    {
                        throw new Exception(string.Format("Lack of searcher for [{0}]", mode));
                    }
                }
            }
            else if ((pickingType & PickingGeometryTypes.Line) == PickingGeometryTypes.Line)
            {
                DrawMode     mode       = this.DrawCommand.CurrentMode;
                GeometryType typeOfMode = mode.ToGeometryType();
                if (pickingType.Contains(typeOfMode))
                {
                    return(PickWhateverItIs(arg, stageVertexId, singleNodeVertexId, mode, typeOfMode));
                }
                else
                {
                    DrawArraysLineSearcher searcher = GetLineSearcher(mode);
                    if (searcher != null)// line is from triangle, quad or polygon
                    {
                        return(SearchLine(arg, stageVertexId, singleNodeVertexId, searcher));
                    }
                    else if (mode == DrawMode.Points)// want a line when rendering GL_POINTS
                    {
                        return(null);
                    }
                    else
                    {
                        throw new Exception(string.Format("Lack of searcher for [{0}]", mode));
                    }
                }
            }
            else
            {
                DrawMode     mode       = this.DrawCommand.CurrentMode;
                GeometryType typeOfMode = mode.ToGeometryType();
                if (pickingType.Contains(typeOfMode)) // I want what it is
                {
                    return(PickWhateverItIs(arg, stageVertexId, singleNodeVertexId, mode, typeOfMode));
                }
                else
                {
                    return(null);
                }
                //{ throw new Exception(string.Format("Lack of searcher for [{0}]", mode)); }
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="arg"></param>
        /// <param name="stageVertexId"></param>
        /// <returns></returns>
        public override PickedGeometry GetPickedGeometry(PickingEventArgs arg, uint stageVertexId)
        {
            PickableNode node = this.Renderer;

            uint lastVertexId;

            if (!node.GetLastVertexIdOfPickedGeometry(stageVertexId, out lastVertexId))
            {
                return(null);
            }

            // 找到 lastIndexId
            RecognizedPrimitiveInfo lastIndexId = this.GetLastIndexIdOfPickedGeometry(
                arg, lastVertexId);

            if (lastIndexId == null)
            {
                Debug.WriteLine(string.Format(
                                    "Got lastVertexId[{0}] but no lastIndexId! Params are [{1}] [{2}]",
                                    lastVertexId, arg, stageVertexId));
                { return(null); }
            }

            PickingGeometryTypes geometryType = arg.GeometryType;
            DrawMode             drawMode     = node.PickingRenderUnit.VertexArrayObject.IndexBuffer.Mode;
            GeometryType         typeOfMode   = drawMode.ToGeometryType();

            if ((geometryType & PickingGeometryTypes.Point) == PickingGeometryTypes.Point)
            {
                // 获取pickedGeometry
                if (typeOfMode == GeometryType.Point)
                {
                    return(PickWhateverItIs(arg, stageVertexId, lastIndexId, typeOfMode));
                }
                else if (typeOfMode == GeometryType.Line)
                {
                    if (this.OnPrimitiveTest(lastVertexId, drawMode))
                    {
                        return(PickPoint(arg, stageVertexId, lastVertexId));
                    }
                    else
                    {
                        return(null);
                    }
                }
                else
                {
                    OneIndexPointSearcher searcher = GetPointSearcher(drawMode);
                    if (searcher != null)// line is from triangle, quad or polygon
                    {
                        return(SearchPoint(arg, stageVertexId, lastVertexId, lastIndexId, searcher));
                    }
                    else
                    {
                        throw new Exception(string.Format("Lack of searcher for [{0}]", drawMode));
                    }
                }
            }
            else if ((geometryType & PickingGeometryTypes.Line) == PickingGeometryTypes.Line)
            {
                // 获取pickedGeometry
                if (typeOfMode == GeometryType.Point) // want a line when rendering GL_POINTS
                {
                    return(null);
                }
                if (typeOfMode == GeometryType.Line)
                {
                    return(PickWhateverItIs(arg, stageVertexId, lastIndexId, typeOfMode));
                }
                else
                {
                    OneIndexLineSearcher searcher = GetLineSearcher(drawMode);
                    if (searcher != null)// line is from triangle, quad or polygon
                    {
                        return(SearchLine(arg, stageVertexId, lastIndexId, searcher));
                    }
                    else
                    {
                        throw new Exception(string.Format("Lack of searcher for [{0}]", drawMode));
                    }
                }
            }
            else
            {
                if (geometryType.Contains(typeOfMode)) // I want what it is
                {
                    return(PickWhateverItIs(arg, stageVertexId, lastIndexId, typeOfMode));
                }
                else
                {
                    return(null);
                }
                //{ throw new Exception(string.Format("Lack of searcher for [{0}]", mode)); }
            }
        }
Ejemplo n.º 7
0
        public override PickedGeometry Pick(RenderEventArgs arg, uint stageVertexId,
                                            int x, int y)
        {
            uint lastVertexId;

            if (!this.GetLastVertexIdOfPickedGeometry(stageVertexId, out lastVertexId))
            {
                return(null);
            }

            // 找到 lastIndexId
            RecognizedPrimitiveIndex lastIndexId = this.GetLastIndexIdOfPickedGeometry(
                arg, lastVertexId, x, y);

            if (lastIndexId == null)
            {
                Debug.WriteLine(
                    "Got lastVertexId[{0}] but no lastIndexId! Params are [{1}] [{2}] [{3}] [{4}]",
                    lastVertexId, arg, stageVertexId, x, y);
                { return(null); }
            }

            GeometryType geometryType = arg.PickingGeometryType;
            DrawMode     mode         = this.indexBufferPtr.Mode;
            GeometryType typeOfMode   = mode.ToGeometryType();

            if (geometryType == GeometryType.Point)
            {
                // 获取pickedGeometry
                if (typeOfMode == GeometryType.Point)
                {
                    return(PickWhateverItIs(stageVertexId, lastIndexId, typeOfMode));
                }
                else if (typeOfMode == GeometryType.Line)
                {
                    if (this.OnPrimitiveTest(lastVertexId, mode))
                    {
                        return(PickPoint(stageVertexId, lastVertexId));
                    }
                    else
                    {
                        return(null);
                    }
                }
                else
                {
                    OneIndexPointSearcher searcher = GetPointSearcher(mode);
                    if (searcher != null)// line is from triangle, quad or polygon
                    {
                        return(SearchPoint(arg, stageVertexId, x, y, lastVertexId, lastIndexId, searcher));
                    }
                    else
                    {
                        throw new Exception(string.Format("Lack of searcher for [{0}]", mode));
                    }
                }
            }
            else if (geometryType == GeometryType.Line)
            {
                // 获取pickedGeometry
                if (geometryType == typeOfMode)
                {
                    return(PickWhateverItIs(stageVertexId, lastIndexId, typeOfMode));
                }
                else
                {
                    OneIndexLineSearcher searcher = GetLineSearcher(mode);
                    if (searcher != null)// line is from triangle, quad or polygon
                    {
                        return(SearchLine(arg, stageVertexId, x, y, lastVertexId, lastIndexId, searcher));
                    }
                    else if (mode == DrawMode.Points)// want a line when rendering GL_POINTS
                    {
                        return(null);
                    }
                    else
                    {
                        throw new Exception(string.Format("Lack of searcher for [{0}]", mode));
                    }
                }
            }
            else
            {
                if (typeOfMode == geometryType)// I want what it is
                {
                    return(PickWhateverItIs(stageVertexId, lastIndexId, typeOfMode));
                }
                else
                {
                    return(null);
                }
                //{ throw new Exception(string.Format("Lack of searcher for [{0}]", mode)); }
            }
        }