public IntPtr this[Guid id] { // 'size' should be the size of the data pointed to by 'data' get { // Request the size of the available private data var size = 0U; View3d_TexturePrivateDataGet(m_handle, id, ref size, IntPtr.Zero); if (size == 0) { return(IntPtr.Zero); } // Create a buffer and read the private data var buffer = new byte[size]; using var buf = Marshal_.Pin(buffer, GCHandleType.Pinned); View3d_TexturePrivateDataGet(m_handle, id, ref size, buf.Pointer); if (size == 8) { return(new IntPtr(BitConverter.ToInt64(buffer, 0))); } if (size == 4) { return(new IntPtr(BitConverter.ToInt32(buffer, 0))); } throw new Exception("Private data is not a pointer type"); } set { View3d_TexturePrivateDataIFSet(m_handle, id, value); } }
public byte[] this[Guid id] { // 'size' should be the size of the data pointed to by 'data' get { // Request the size of the available private data var size = 0U; View3d_TexturePrivateDataGet(m_handle, id, ref size, IntPtr.Zero); if (size == 0) { return(Array.Empty <byte>()); } // Create a buffer and read the private data var buffer = new byte[size]; using var buf = Marshal_.Pin(buffer, GCHandleType.Pinned); View3d_TexturePrivateDataGet(m_handle, id, ref size, buf.Pointer); return(buffer); } set { using var buf = Marshal_.Pin(value, GCHandleType.Pinned); View3d_TexturePrivateDataSet(m_handle, id, (uint)(value?.Length ?? 0), buf.Pointer); } }
public DummyWindow(string?diag_name = null) { var atom = EnsureWndClassRegistered(HInstance); using var pin = Marshal_.Pin(this, GCHandleType.Normal); Handle = Win32.CreateWindow(0, atom, diag_name ?? string.Empty, 0, 0, 0, 1, 1, Win32.HWND_MESSAGE, IntPtr.Zero, HInstance, pin.Pointer); if (Handle == IntPtr.Zero) { throw new Win32Exception(); } }
public Object(string name, uint colour, byte[] p3d_data, Guid?context_id) { Owned = true; var ctx = context_id ?? Guid.NewGuid(); using var pin = Marshal_.Pin(p3d_data, GCHandleType.Pinned); Handle = View3D_ObjectCreateP3DStream(name, colour, p3d_data.Length, pin.Pointer, ref ctx); if (Handle == HObject.Zero) { throw new Exception($"Failed to create object from p3d model data stream"); } }
/// <summary>Create from buffer</summary> public Object(string name, uint colour, int vcount, int icount, int ncount, Vertex[] verts, ushort[] indices, Nugget[] nuggets, Guid?context_id) { Owned = true; var ctx = context_id ?? Guid.NewGuid(); // Serialise the verts/indices to a memory buffer using var vbuf = Marshal_.Pin(verts, GCHandleType.Pinned); using var ibuf = Marshal_.Pin(indices, GCHandleType.Pinned); using var nbuf = Marshal_.ArrayToPtr(EHeap.HGlobal, nuggets); Handle = View3D_ObjectCreate(name, colour, vcount, icount, ncount, vbuf.Pointer, ibuf.Pointer, nbuf.Value.Ptr, ref ctx); if (Handle == HObject.Zero) { throw new System.Exception($"Failed to create object '{name}' from provided buffers"); } }
public HitTestResult HitTest(HitTestRay ray, float snap_distance, EHitTestFlags flags, IEnumerable <Object> objects) { var rays = new HitTestRay[1] { ray }; var hits = new HitTestResult[1]; var insts = objects.Select(x => x.Handle).ToArray(); using var rays_buf = Marshal_.Pin(rays, GCHandleType.Pinned); using var hits_buf = Marshal_.Pin(hits, GCHandleType.Pinned); using var insts_buf = Marshal_.Pin(insts, GCHandleType.Pinned); View3D_WindowHitTestObjects(Handle, rays_buf.Pointer, hits_buf.Pointer, 1, snap_distance, flags, insts, insts.Length); return(hits[0]); }
public HitTestResult HitTest(HitTestRay ray, float snap_distance, EHitTestFlags flags, Guid[] guids, int include_count, int exclude_count) { Debug.Assert(include_count + exclude_count == guids.Length); var rays = new HitTestRay[1] { ray }; var hits = new HitTestResult[1]; using var rays_buf = Marshal_.Pin(rays, GCHandleType.Pinned); using var hits_buf = Marshal_.Pin(hits, GCHandleType.Pinned); using var guids_buf = Marshal_.Pin(guids, GCHandleType.Pinned); View3D_WindowHitTestByCtx(Handle, rays_buf.Pointer, hits_buf.Pointer, 1, snap_distance, flags, guids_buf.Pointer, include_count, exclude_count); return(hits[0]); }