Search code examples
swiftxcodeswiftuiscenekitrealitykit

RealityKit's equivalent of SceneKit's SCNShape


On SceneKit, using SCNShape we can create SCN geometry from SwiftUI 2D shapes/beziers: https://developer.apple.com/documentation/scenekit/scnshape

Is there an equivalent in RealityKit? Could we use the generate(from:) for that? https://developer.apple.com/documentation/realitykit/meshresource/3768520-generate


Solution

  • In RealityKit 2.0 you can generate a mesh using MeshDescriptor. There is no support for two-dimensional path at the moment, like it's implemented in SceneKit.

    var descriptor = MeshDescriptor(name: "anything")
    descriptor.primitives = .triangles(indices)
    let mesh: MeshResource = try! .generate(from: [descriptor])