From 33dc9a54be863b11dd3ba2edb8646c4b4b85720f Mon Sep 17 00:00:00 2001 From: yyc12345 Date: Fri, 1 Nov 2024 11:13:05 +0800 Subject: [PATCH] feat: finish BMapSharp - basically finish BMapSharp bindings however done test does not cover all scenarios. --- .../BMapSharp/BMapSharp/BMapWrapper.cs | 37 ++++++++++++++++--- 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/BMapBindings/BMapSharp/BMapSharp/BMapWrapper.cs b/BMapBindings/BMapSharp/BMapSharp/BMapWrapper.cs index 54a478d..2fe9e89 100644 --- a/BMapBindings/BMapSharp/BMapSharp/BMapWrapper.cs +++ b/BMapBindings/BMapSharp/BMapSharp/BMapWrapper.cs @@ -61,6 +61,10 @@ namespace BMapSharp.BMapWrapper { => StructAssigner(pstruct, count, iem); internal static void ShortAssigner(IntPtr pstruct, uint count, IEnumerable iem) => StructAssigner(pstruct, count, iem); + internal static void CKIDAssigner(IntPtr pstruct, uint count, IEnumerable iem) + => StructAssigner(pstruct, count, iem); + internal static void CKDWORDAssigner(IntPtr pstruct, uint count, IEnumerable iem) + => StructAssigner(pstruct, count, iem); private static IEnumerable StructIterator(IntPtr pstruct, uint count) { var stride = Marshal.SizeOf(); @@ -79,6 +83,10 @@ namespace BMapSharp.BMapWrapper { => StructIterator(pstruct, count); internal static IEnumerable ShortIterator(IntPtr pstruct, uint count) => StructIterator(pstruct, count); + internal static IEnumerable CKIDIterator(IntPtr pstruct, uint count) + => StructIterator(pstruct, count); + internal static IEnumerable CKDWORDIterator(IntPtr pstruct, uint count) + => StructIterator(pstruct, count); #endregion @@ -548,12 +556,29 @@ namespace BMapSharp.BMapWrapper { Utils.VxVector2Assigner(out_mem, count, iem); } - // public void PrepareMtlSlot(uint count, IEnumerable iem) { - // // Prepare count first - // BMapException.ThrowIfFailed(BMap.BMMeshTrans_PrepareMtlSlotCount(getPointer(), count)); - // // Then put data - // BMapException.ThrowIfFailed(BMap.BMMeshTrans_PrepareMtlSlot(getPointer(), out IntPtr out_mem)); - // } + public void PrepareMtlSlot(uint count, IEnumerable iem) { + // Prepare count first + BMapException.ThrowIfFailed(BMap.BMMeshTrans_PrepareMtlSlotCount(getPointer(), count)); + // Then put data + BMapException.ThrowIfFailed(BMap.BMMeshTrans_PrepareMtlSlot(getPointer(), out IntPtr out_mem)); + var cast_iem = iem.Select((mtl) => mtl is null ? Utils.INVALID_CKID : mtl.getCKID()); + Utils.CKIDAssigner(out_mem, count, cast_iem); + } + + public void PrepareFace(uint count, IEnumerable vec_idx, IEnumerable nml_idx, IEnumerable uv_idx, IEnumerable mtl_idx) { + // Prepare count first + BMapException.ThrowIfFailed(BMap.BMMeshTrans_PrepareFaceCount(getPointer(), count)); + // Get data address + BMapException.ThrowIfFailed(BMap.BMMeshTrans_PrepareFaceVertexIndices(getPointer(), out IntPtr raw_vec_idx)); + BMapException.ThrowIfFailed(BMap.BMMeshTrans_PrepareFaceNormalIndices(getPointer(), out IntPtr raw_nml_idx)); + BMapException.ThrowIfFailed(BMap.BMMeshTrans_PrepareFaceUVIndices(getPointer(), out IntPtr raw_uv_idx)); + BMapException.ThrowIfFailed(BMap.BMMeshTrans_PrepareFaceMtlSlot(getPointer(), out IntPtr raw_mtl_idx)); + // Assign data + Utils.CKFaceIndicesAssigner(raw_vec_idx, count, vec_idx); + Utils.CKFaceIndicesAssigner(raw_nml_idx, count, nml_idx); + Utils.CKFaceIndicesAssigner(raw_uv_idx, count, uv_idx); + Utils.CKDWORDAssigner(raw_mtl_idx, count, mtl_idx); + } }