Esempio n. 1
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)); }
            }
        }
Esempio n. 2
0
        private static DrawElementsPointSearcher GetPointSearcher(DrawMode mode)
        {
            DrawElementsPointSearcher result = null;

            switch (mode)
            {
            case DrawMode.Points:
                break;

            case DrawMode.Lines:
                result = pointInLine;
                break;

            case DrawMode.LineLoop:
                result = pointInLine;
                break;

            case DrawMode.LineStrip:
                result = pointInLine;
                break;

            case DrawMode.Triangles:
                result = pointInTriangle;
                break;

            case DrawMode.TriangleStrip:
                result = pointInTriangle;
                break;

            case DrawMode.TriangleFan:
                result = pointInTriangle;
                break;

            case DrawMode.Quads:
                result = pointInQuad;
                break;

            case DrawMode.QuadStrip:
                result = pointInQuad;
                break;

            case DrawMode.Polygon:
                result = pointInPolygon;
                break;

            case DrawMode.LinesAdjacency:
                result = pointInLine;
                break;

            case DrawMode.LineStripAdjacency:
                result = pointInLine;
                break;

            case DrawMode.TrianglesAdjacency:
                result = pointInTriangle;
                break;

            case DrawMode.TriangleStripAdjacency:
                result = pointInTriangle;
                break;

            case DrawMode.Patches:
                break;

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

            return(result);
        }
Esempio n. 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="arg"></param>
        /// <param name="stageVertexId"></param>
        /// <param name="singleNodeVertexId"></param>
        /// <param name="primitiveInfo"></param>
        /// <param name="searcher"></param>
        /// <returns></returns>
        private PickedGeometry SearchPoint(PickingEventArgs arg, uint singleNodeVertexId, uint stageVertexId, RecognizedPrimitiveInfo primitiveInfo, DrawElementsPointSearcher searcher)
        {
            uint id = searcher.Search(arg, primitiveInfo, singleNodeVertexId, stageVertexId, this);

            if (id == uint.MaxValue)
            {
                return(null);
            }                                        // Scene's changed before second rendering for picking>

            uint baseId    = stageVertexId - singleNodeVertexId;
            var  vertexIds = new uint[] { (id - baseId) };

            vec3[] positions      = FillPickedGeometrysPosition(vertexIds);
            var    pickedGeometry = new PickedGeometry(GeometryType.Point, positions, vertexIds, stageVertexId, this.Node);

            return(pickedGeometry);
        }
Esempio n. 4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="arg"></param>
        /// <param name="stageVertexId"></param>
        /// <param name="lastVertexId"></param>
        /// <param name="primitiveInfo"></param>
        /// <param name="searcher"></param>
        /// <returns></returns>
        private PickedGeometry SearchPoint(PickingEventArgs arg, uint stageVertexId, uint lastVertexId, RecognizedPrimitiveInfo primitiveInfo, DrawElementsPointSearcher searcher)
        {
            var vertexIds = new uint[] { searcher.Search(arg, primitiveInfo, this), };

            vec3[] positions      = FillPickedGeometrysPosition(vertexIds);
            var    pickedGeometry = new PickedGeometry(GeometryType.Point, positions, vertexIds, stageVertexId, this.Node);

            return(pickedGeometry);
        }