CesiumGS / cesium-unreal

Bringing the 3D geospatial ecosystem to Unreal Engine
https://cesium.com/platform/cesium-for-unreal/
Apache License 2.0
943 stars 296 forks source link

Eliminate an unnecessary copy operation while creating Unreal meshes from tiles #1516

Open kring opened 1 month ago

kring commented 1 month ago

CesiumGltfComponent.cpp copies the glTF vertex data into a TArray<FStaticMeshBuildVertex>, which represents the mesh as an array of structures. Then, it calls Init on various Unreal "vertex buffer" classes to copy that data into Unreal's structure of arrays form.

This is pointless. We can just copy the glTF data into the FPositionVertexBuffer, FColorVertexBuffer, and FStaticMeshVertexBuffer instances directly and save some heap allocations and a pass over the vertex data. The only slightly tricky thing about this is that we need to determine the total number of texture coordinates required before we can start populating any of them. Previously, we could count and copy simultaneously. So this will require a slight reorganization of the code.

kring commented 1 month ago

I was originally going to do this as part of #1515, but decided against it in order to avoid merge conflicts. @azrogers is currently making significant changes to this same code as part of the Unreal side of CesiumGS/cesium-native#926.