/// <summary> /// /// </summary> /// <param name="arg"></param> /// <param name="lastVertexId"></param> /// <param name="picker"></param> /// <returns></returns> internal override uint Search(PickingEventArgs arg, uint lastVertexId, ZeroIndexPicker picker) { OneIndexBuffer buffer = GLBuffer.Create(IndexBufferElementType.UInt, 4, DrawMode.Points, 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(); } picker.Renderer.Render4InnerPicking(arg, buffer); 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!"); } }
/// <summary> /// 在三角形图元中拾取指定位置的Point /// </summary> /// <param name="arg">渲染参数</param> /// <param name="x">mouse position(Left Down is (0, 0)).</param> /// <param name="y">mouse position(Left Down is (0, 0)).</param> /// <param name="lastVertexId">三角形图元的最后一个顶点</param> /// <param name="modernRenderer">目标Renderer</param> /// <returns></returns> internal override uint Search(RenderEventArgs arg, int x, int y, uint lastVertexId, ZeroIndexRenderer modernRenderer) { // 创建临时索引 OneIndexBuffer buffer = Buffer.Create(IndexBufferElementType.UInt, 3, DrawMode.Points, BufferUsage.StaticDraw); unsafe { var array = (uint *)buffer.MapBuffer(MapBufferAccess.WriteOnly); array[0] = lastVertexId - 0; array[1] = lastVertexId - 1; array[2] = lastVertexId - 2; buffer.UnmapBuffer(); } // 用临时索引渲染此三角形图元(仅渲染此三角形图元) modernRenderer.Render4InnerPicking(arg, buffer); // id是拾取到的Line的Last Vertex Id uint id = ColorCodedPicking.ReadStageVertexId(x, y); buffer.Dispose(); // 对比临时索引,找到那个Line if (lastVertexId - 2 <= id && id <= lastVertexId - 0) { return(id); } else { throw new Exception("This should not happen!"); } }
public IndexBuffer GetIndexBuffer() { if (this.indexBuffer == null) { int polygon = (this.mesh.faces[0] is ObjVNFTriangle) ? 3 : 4; DrawMode mode = (this.mesh.faces[0] is ObjVNFTriangle) ? DrawMode.Triangles : DrawMode.Quads; OneIndexBuffer indexBuffer = OneIndexBuffer.Create(IndexBufferElementType.UInt, polygon * this.mesh.faces.Length, mode, BufferUsage.StaticDraw); unsafe { var array = (uint *)indexBuffer.MapBuffer(MapBufferAccess.WriteOnly); int index = 0; foreach (var face in this.mesh.faces) { foreach (var vertexIndex in face.VertexIndexes()) { array[index++] = vertexIndex; } } indexBuffer.UnmapBuffer(); } this.indexBuffer = indexBuffer; } return(this.indexBuffer); }
/// <summary> /// /// </summary> /// <param name="arg"></param> /// <param name="x">mouse position(Left Down is (0, 0)).</param> /// <param name="y">mouse position(Left Down is (0, 0)).</param> /// <param name="lastVertexId"></param> /// <param name="modernRenderer"></param> /// <returns></returns> internal override uint Search(RenderEventArgs arg, int x, int y, uint lastVertexId, ZeroIndexRenderer modernRenderer) { OneIndexBuffer buffer = GLBuffer.Create(IndexBufferElementType.UInt, 3, DrawMode.Points, BufferUsage.StaticDraw); unsafe { var array = (uint *)buffer.MapBuffer(MapBufferAccess.WriteOnly); array[0] = 0; array[1] = lastVertexId - 1; array[2] = lastVertexId - 0; buffer.UnmapBuffer(); } modernRenderer.Render4InnerPicking(arg, buffer); uint id = ColorCodedPicking.ReadStageVertexId(x, y); buffer.Dispose(); if (0 == id || lastVertexId - 1 == id || lastVertexId - 0 == 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, ZeroIndexPicker picker) { OneIndexBuffer buffer = GLBuffer.Create(IndexBufferElementType.UInt, 6, DrawMode.Lines, BufferUsage.StaticDraw); unsafe { var array = (uint *)buffer.MapBuffer(MapBufferAccess.WriteOnly); array[0] = 0; array[1] = lastVertexId - 1; array[2] = lastVertexId - 1; array[3] = lastVertexId - 0; array[4] = lastVertexId - 0; array[5] = 0; buffer.UnmapBuffer(); } picker.Renderer.Render4InnerPicking(arg, buffer); uint id = ColorCodedPicking.ReadStageVertexId(arg.X, arg.Y); buffer.Dispose(); if (id + 1 == lastVertexId) { return(new uint[] { 0, lastVertexId - 1, }); } else if (id == lastVertexId) { return(new uint[] { lastVertexId - 1, lastVertexId - 0, }); } else if (id == 0) { return(new uint[] { lastVertexId - 0, 0, }); } else { throw new Exception("This should not happen!"); } }
/// <summary> /// /// </summary> /// <returns></returns> public IndexBuffer GetIndexBuffer() { if (this.indexBuffer == null) { int length = TetrahedronModel.index.Length; OneIndexBuffer buffer = GLBuffer.Create(IndexBufferElementType.UByte, length, DrawMode.Triangles, BufferUsage.StaticDraw); unsafe { IntPtr pointer = buffer.MapBuffer(MapBufferAccess.WriteOnly); var array = (byte *)pointer; for (int i = 0; i < TetrahedronModel.index.Length; i++) { array[i] = TetrahedronModel.index[i]; } buffer.UnmapBuffer(); } this.indexBuffer = buffer; } return(this.indexBuffer); }
/// <summary> /// /// </summary> /// <param name="arg"></param> /// <param name="x">mouse position(Left Down is (0, 0)).</param> /// <param name="y">mouse position(Left Down is (0, 0)).</param> /// <param name="lastVertexId"></param> /// <param name="modernRenderer"></param> /// <returns></returns> internal override uint[] Search(RenderEventArgs arg, int x, int y, uint lastVertexId, ZeroIndexRenderer modernRenderer) { OneIndexBuffer buffer = Buffer.Create(IndexBufferElementType.UInt, 8, DrawMode.Lines, 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(); } modernRenderer.Render4InnerPicking(arg, buffer); uint id = ColorCodedPicking.ReadStageVertexId(x, 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!"); } }
/// <summary> /// /// </summary> /// <returns></returns> public IndexBuffer GetIndexBuffer() { if (indexBuffer == null) { ushort[] faces = model.GetFaces(); int length = faces.Length; OneIndexBuffer buffer = GLBuffer.Create(IndexBufferElementType.UShort, length, DrawMode.Triangles, BufferUsage.StaticDraw); unsafe { IntPtr pointer = buffer.MapBuffer(MapBufferAccess.WriteOnly); var array = (ushort *)pointer; for (int i = 0; i < faces.Length; i++) { array[i] = (ushort)(faces[i] - 1); } buffer.UnmapBuffer(); } this.indexBuffer = buffer; } return(indexBuffer); }
public IndexBuffer GetIndexBuffer() { if (this.indexBuffer == null) { int uCount = GetUCount(interval); int vCount = GetVCount(interval); int length = (uCount + 1) * vCount + (vCount + 1 + 1) * uCount; OneIndexBuffer buffer = CSharpGL.GLBuffer.Create(IndexBufferElementType.UInt, length, DrawMode.LineStrip, BufferUsage.StaticDraw); unsafe { IntPtr pointer = buffer.MapBuffer(MapBufferAccess.WriteOnly); var array = (uint *)pointer; int index = 0; // vertical lines. for (int i = 0; i < vCount; i++) { for (int j = 0; j < uCount; j++) { array[index++] = (uint)(i + j * vCount); } array[index++] = uint.MaxValue;// primitive restart index. } // horizontal lines. for (int i = 0; i < uCount; i++) { for (int j = 0; j < vCount; j++) { array[index++] = (uint)(j + i * vCount); } array[index++] = (uint)(0 + i * vCount); array[index++] = uint.MaxValue;// primitive restart index. } buffer.UnmapBuffer(); } this.indexBuffer = buffer; } return(this.indexBuffer); }
public IndexBuffer GetIndexBuffer() { if (this.indexBuffer == null) { Face[] faces = Teapot.faceData; int length = faces.Length * 3; OneIndexBuffer buffer = GLBuffer.Create(IndexBufferElementType.UShort, length, DrawMode.Triangles, BufferUsage.StaticDraw); unsafe { IntPtr pointer = buffer.MapBuffer(MapBufferAccess.WriteOnly); var array = (ushort *)pointer; for (int i = 0; i < faces.Length; i++) { array[i * 3 + 0] = (ushort)(faces[i].vertexId1 - 1); array[i * 3 + 1] = (ushort)(faces[i].vertexId2 - 1); array[i * 3 + 2] = (ushort)(faces[i].vertexId3 - 1); } buffer.UnmapBuffer(); } this.indexBuffer = buffer; } return(this.indexBuffer); }
/// <summary> /// /// </summary> /// <returns></returns> public IndexBuffer GetIndexBuffer() { if (this.indexBuffer == null) { int length = model.indexes.Length; if (model.positions.Length < byte.MaxValue) { OneIndexBuffer buffer = GLBuffer.Create(IndexBufferElementType.UByte, length, DrawMode.TriangleStrip, BufferUsage.StaticDraw); unsafe { IntPtr pointer = buffer.MapBuffer(MapBufferAccess.WriteOnly); var array = (byte *)pointer; for (int i = 0; i < model.indexes.Length; i++) { if (model.indexes[i] == uint.MaxValue) { array[i] = byte.MaxValue; } else { array[i] = (byte)model.indexes[i]; } } buffer.UnmapBuffer(); } this.indexBuffer = buffer; } else if (model.positions.Length < ushort.MaxValue) { OneIndexBuffer buffer = GLBuffer.Create(IndexBufferElementType.UShort, length, DrawMode.TriangleStrip, BufferUsage.StaticDraw); unsafe { IntPtr pointer = buffer.MapBuffer(MapBufferAccess.WriteOnly); var array = (ushort *)pointer; for (int i = 0; i < model.indexes.Length; i++) { if (model.indexes[i] == uint.MaxValue) { array[i] = ushort.MaxValue; } else { array[i] = (ushort)model.indexes[i]; } } buffer.UnmapBuffer(); } this.indexBuffer = buffer; } else { OneIndexBuffer buffer = GLBuffer.Create(IndexBufferElementType.UInt, length, DrawMode.TriangleStrip, BufferUsage.StaticDraw); unsafe { IntPtr pointer = buffer.MapBuffer(MapBufferAccess.WriteOnly); var array = (uint *)pointer; for (int i = 0; i < model.indexes.Length; i++) { array[i] = model.indexes[i]; } buffer.UnmapBuffer(); } this.indexBuffer = buffer; } } return(indexBuffer); }