Search code examples
iosscenekitaugmented-realityrealitykit

Apple RealityKit: How to draw a polygon plane using ModelEntity?


I used to use some SceneKit APIs such as

SCNGeometrySource(vertices: vertices)

SCNGeometryElement(data: indexData,
                   primitiveType: .polygon,
                   primitiveCount: 1,
                   bytesPerIndex: MemoryLayout<Int32>.size)

or

SCNShape(path: bezierPath, extrusionDepth: 0.0003)

to implement drawing a polygon in the scene.

Nowadays I am trying to rewrite the implementation via RealityKit. But I have only found some basic mesh APIs such as

generatePlane(width: Float, height: Float, cornerRadius: Float = 0) -> MeshResource
generatePlane(width: Float, depth: Float, cornerRadius: Float = 0) -> MeshResource
generateBox(size: Float, cornerRadius: Float = 0) -> MeshResource
generateSphere(radius: Float) -> MeshResource
...

I was hoping for something closer to SceneKit's convenience.


Solution

  • RealityKit does not have APIs to create custom geometry at run time.


    Edit: RealityKit 2 introduced support for dynamic meshes. See Explore advanced rendering with RealityKit 2 from WWDC21.