Loading a ModelEntity with a MDLMesh

I have a .stl file on disk that is being correctly loaded as a MDLAsset by MDLAsset.init(url:), and the MDLMesh is extracted from there seamlessly.

The problem is that I cannot create a ModelEntity using said mesh. All constructors for it only take MeshResource as a argument, and I can't seem to convert MDLMesh to a MeshResource - which doesn't make much sense.

Unfortunately I cannot use Entity.loadModel because it either panics with a bad memory access or loads my models incorrectly (the Z dimension is lost, so it's like the model is just a plane).

Any pointers on this?
I was hunting for something akin to this path myself, and haven't found any public accessors for RealityKit's entities to be loaded other than the loadModel, which in the examples are specific to USD formats. I suspect that in order to load your model in RealityKit, you'll first need to explicitly transform your STL-sourced model into USDZ, write it to a file or buffer, and then load it from there with loadModel or it's neighboring methods.

The problem is that I cannot create a ModelEntity using said mesh. All constructors for it only take MeshResource as a argument, and I can't seem to convert MDLMesh to a MeshResource

There is no way to construct a MeshResource from vertices, faces, or other mesh types (like MDLMesh). The only way to get a MeshResource is to either load the mesh from a supported file type (As noted in the generated interface for Entity, "Supported file formats are USD (.usd, .usda, .usdc, .usdz) and Reality File (.reality)."), or to use one of the "generate" methods for certain geometry primitives (like box, plane, and text).

I recommend that you file an enhancement request for this feature using Feedback Assistant.

Thanks!

Loading a ModelEntity with a MDLMesh
 
 
Q