I'm using RealityKit and Model I/O to scan a 3D model and then UV unwrap it. I have created an MDLMesh from ARMeshGeometry following https://stackoverflow.com/questions/61063571/arkit-3-5-how-to-export-obj-from-new-ipad-pro-with-lidar.
It seems that MDLMesh has a method addUnwrappedTextureCoordinates() - https://developer.apple.com/documentation/modelio/mdlmesh/1644690-addunwrappedtexturecoordinates which should be what I needed. My usage was mesh.addUnwrappedTextureCoordinates(forAttributeNamed: MDLVertexAttributeTextureCoordinate).
Most of the times it gave a runtime error saying
libc++abi.dylib: terminating with uncaught exception of type std::outofrange: unorderedmap::at: key not found
terminating with uncaught exception of type std::outofrange: unorderedmap::at: key not found But it did work twice, although I didn't change anything in my code. The exported OBJ has correctly unwrapped UV texture coordinates.
Since there is so little information about this method online, I'd appreciate it if anyone had similar issues or knows how to make this work. Thanks!