/// <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.Points); picker.Node.Render4InnerPicking(arg, cmd); uint id = ColorCodedPicking.ReadStageVertexId(arg.X, arg.Y); buffer.Dispose(); if (id != uint.MaxValue) { return(id); } 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[] 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(); uint baseId = stageVertexId - singleNodeVertexId; if (id == baseId + indexList[0] || id == baseId + indexList[1] || id == baseId + indexList[2] || id == baseId + indexList[3]) { return(id); } else if (id == uint.MaxValue) // Scene's changed before second rendering for picking> { return(id); } 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[] 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!"); } }
/// <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!"); } } }
/// <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(); } var targetIndexList = new uint[8] { indexList[0], indexList[1], indexList[1], indexList[2], indexList[2], indexList[3], indexList[3], indexList[0], }; IndexBuffer buffer = targetIndexList.GenIndexBuffer(BufferUsage.StaticDraw); var cmd = new DrawElementsCmd(buffer, DrawMode.Lines); picker.Node.Render4InnerPicking(arg, IndexAccessMode.ByFrame, cmd); uint id = ColorCodedPicking.ReadStageVertexId(arg.X, arg.Y); buffer.Dispose(); if (id == indexList[1]) { return(new uint[] { indexList[0], indexList[1], }); } else if (id == indexList[2]) { return(new uint[] { indexList[1], indexList[2], }); } else if (id == indexList[3]) { return(new uint[] { indexList[2], indexList[3], }); } else if (id == indexList[0]) { return(new uint[] { indexList[2], indexList[0], }); } else { throw new Exception("This should not happen!"); } }