How can I create a custom mesh in RealityKit?

I am trying to create a path representation on a Plane in RealityKit. To do that, I tried to create a custom mesh and create a ModelEntity with that mesh, but the MeshResource type only provides static methods to generate simple shapes. Is there a way to do that?

Replies

Bump - also have this same question.

Thirded - being able to walk the verts/faces of a mesh would be 😎

  • Have you been able to achieve that verts/faces traversal? It would help me a lot!

Add a Comment

Looks like custom meshes don't exist as of beta 4.


That said (until API support is added), you could leverage the fact that SceneKit can export USDZs as a hack / temporary solution.
I wouldn't recommend doing this because it would potentially involve running both RealityKit and SceneKit code in parallel, which would be very CPU/GPU intensive. Especially if you want to repeatedly modify your mesh / geometry at runtime (lots of IO to read/write files).


I haven't tried it, so it might not even work; Here's how you could do it:


1. Spin up a SCNScene and build your custom geometry. See: https://medium.com/@zxlee618/custom-geometry-in-scenekit-f91464297fd1

2. Write the SCNScene to a temporary USDZ file. See Working with USD Slide 51 and SCNScene write method docs

3. Load the ModelEntity via URL https://developer.apple.com/documentation/realitykit/modelentity/stored_entities

Best

I can confirm this works just fine. It's much less than ideal though and I wouldn't recommend it for any use case where you want to use change the geometry in realtime (for example, drawing a spline based on touch interaction)!.

  • ? David, that is precisely how you build mesh, while, drawing with a finger. How else could it be done ???

Add a Comment

I’m glad to see many others are wanting this!


Hopefully this will be added in iOS 13.1 or the likes; creating a mesh with SceneKit, exporting as a USDZ and then importing to RealityKit is IMO against the reason RealityKit was made (to be a highly optimised renderer for AR).


I’m also hoping at least some shader modifiers are added before too long.

I agree that for AR you should be able to create procedural geometry and graphics. I'm surprised that this isn't supported.

Is it possible to create and modify procedural meshes yet?

Unfortunately this still isn't possible. Please file a report with https://feedbackassistant.apple.com and we'll take these reports into consideration when deciding on new features.

With the WWDC21 software updates, I noticed that RealityKit now has some additional methods on MeshResource:

(and async oriented variations of these methods)

The generate method is used in the example code BuildingAnImmersiveExperienceWithRealityKit

which looks like it is now possible to provide the indices, normals, etc to build up a mesh procedurally. These methods don't have any documentation on them, so I'm not 100% certain about the details, but the Swift generated headers for it have some relevant notes that make it appear like these might the the "RealityKit" way to procedurally create meshes.

Am I inferring correctly that these methods enable procedural generation with this year's release, or are these methods more focused elsewhere?

@heckj yes, you are correct, the new APIs allow you to create custom/procedural meshes. Please see the RealityKit WWDC21 session videos for more information.

  • I am able to generate custom mesh in realitykit at runtime but not able to release the memory causing memory leak issue. Has anyone faced similar issue? Are you aware of how to tackle this issue?

  • @silentKiller can you create a brand new forums post about this issue? It'll be easier for us to have a discussion there.

Add a Comment