Model I/O addUnwrappedTextureCoordinates() terminating with uncaught exception

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() 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::out
ofrange: 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!





Attaching environment information:
  • macOS Catalina 10.15.7 (MacBook Pro 16-inch 2019)

  • XCode 12.3

  • iPadOS 14.2 (iPad Pro 11-inch 2nd gen)

Model I/O addUnwrappedTextureCoordinates() terminating with uncaught exception
 
 
Q