| 887 | } |
| 888 | |
| 889 | MArray* MeshBase::DownloadIndexBuffer(bool forceGpu, MTypeObject* resultType, bool use16Bit) |
| 890 | { |
| 891 | ScopeLock lock(GetModelBase()->Locker); |
| 892 | |
| 893 | // Get index buffer data from the mesh (CPU or GPU) |
| 894 | MeshAccessor accessor; |
| 895 | MeshBufferType bufferTypes[1] = { MeshBufferType::Index }; |
| 896 | if (accessor.LoadMesh(this, forceGpu, ToSpan(bufferTypes, 1))) |
| 897 | return nullptr; |
| 898 | auto indexStream = accessor.Index(); |
| 899 | if (!indexStream.IsValid()) |
| 900 | return nullptr; |
| 901 | auto indexData = indexStream.GetData(); |
| 902 | auto indexCount = indexStream.GetCount(); |
| 903 | auto indexStride = indexStream.GetStride(); |
| 904 | |
| 905 | // Convert into managed array |
| 906 | MArray* result = MCore::Array::New(MCore::Type::GetClass(INTERNAL_TYPE_OBJECT_GET(resultType)), indexCount); |
| 907 | void* managedArrayPtr = MCore::Array::GetAddress(result); |
| 908 | if (use16Bit) |
| 909 | { |
| 910 | if (indexStride == sizeof(uint16)) |
| 911 | { |
| 912 | Platform::MemoryCopy(managedArrayPtr, indexData.Get(), indexData.Length()); |
| 913 | } |
| 914 | else |
| 915 | { |
| 916 | auto dst = (uint16*)managedArrayPtr; |
| 917 | auto src = (const uint32*)indexData.Get(); |
| 918 | for (int32 i = 0; i < indexCount; i++) |
| 919 | dst[i] = src[i]; |
| 920 | } |
| 921 | } |
| 922 | else |
| 923 | { |
| 924 | if (indexStride == sizeof(uint16)) |
| 925 | { |
| 926 | auto dst = (uint32*)managedArrayPtr; |
| 927 | auto src = (const uint16*)indexData.Get(); |
| 928 | for (int32 i = 0; i < indexCount; i++) |
| 929 | dst[i] = src[i]; |
| 930 | } |
| 931 | else |
| 932 | { |
| 933 | Platform::MemoryCopy(managedArrayPtr, indexData.Get(), indexData.Length()); |
| 934 | } |
| 935 | } |
| 936 | |
| 937 | return result; |
| 938 | } |
| 939 | |
| 940 | bool MeshBase::DownloadData(int32 count, MeshBufferType* types, BytesContainer& buffer0, BytesContainer& buffer1, BytesContainer& buffer2, BytesContainer& buffer3, GPUVertexLayout*& layout0, GPUVertexLayout*& layout1, GPUVertexLayout*& layout2, GPUVertexLayout*& layout3, bool forceGpu) const |
| 941 | { |
no test coverage detected