/// <summary> /// /// </summary> /// <param name="arg"></param> /// <param name="stageVertexId"></param> /// <param name="primitiveInfo"></param> /// <param name="searcher"></param> /// <returns></returns> private PickedGeometry SearchLine(PickingEventArgs arg, uint singleNodeVertexId, uint stageVertexId, RecognizedPrimitiveInfo primitiveInfo, DrawElementsLineSearcher searcher) { var vertexIds = searcher.Search(arg, primitiveInfo, singleNodeVertexId, stageVertexId, this); vec3[] positions = FillPickedGeometrysPosition(vertexIds); var pickedGeometry = new PickedGeometry(GeometryType.Line, positions, vertexIds, stageVertexId, this.Node); return(pickedGeometry); }
/// <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)); } } }
private static DrawElementsLineSearcher GetLineSearcher(DrawMode mode) { DrawElementsLineSearcher result = null; switch (mode) { case DrawMode.Points: break; case DrawMode.Lines: break; case DrawMode.LineLoop: break; case DrawMode.LineStrip: break; case DrawMode.Triangles: result = lineInTriangle; break; case DrawMode.TriangleStrip: result = lineInTriangle; break; case DrawMode.TriangleFan: result = lineInTriangle; break; case DrawMode.Quads: result = lineInQuad; break; case DrawMode.QuadStrip: result = lineInQuad; break; case DrawMode.Polygon: result = lineInPolygon; break; case DrawMode.LinesAdjacency: break; case DrawMode.LineStripAdjacency: break; case DrawMode.TrianglesAdjacency: result = lineInTriangle; break; case DrawMode.TriangleStripAdjacency: result = lineInTriangle; break; case DrawMode.Patches: break; default: throw new NotDealWithNewEnumItemException(typeof(DrawMode)); } return(result); }