Drawing dynamic primitives in RealityKit

Is it possible to use RealityKit to draw dynamic primitives?
...like a thin cylinder between 2 dynamically changing location anchors for example?
Or is that still something I need to build using SceneKit?
You can create primitives programmatically in RealityKit. To create a cylinder, you can use generateBox(size:cornerRadius:) with the corner radius set to half of the box's width.
https://developer.apple.com/documentation/realitykit/meshresource/3244417-generatebox
If you want an actual cylinder the .generateBox with cornerRadius method might not be the best option, as it will give you a capsule shape.

Seeing as RealityKit doesn’t let you generate a Cylinder normally I’ve had to be a little creative when doing this; the best method I’ve found, albeit dirty, is using generateText().

The steps are:
  • Add mesh using .generateText(“.”) to a ModelEntity

  • use visualBounds method to check what dimensions it has given the cylinder

  • using the visual bounds .extents change the scale of the ModelEntity to match [1, 1, 1]

  • set the position of ModelEntity to negative .center

  • make this ModelEntity the child of another Entity (just to simplify scale and rotations)

Then you’ll have a cylinder along the Z axis with dimensions the same as the Entity. However you cannot specify the number of segments or the level of detail using generateText(), like you can with SCNCylinder.
Drawing dynamic primitives in RealityKit
 
 
Q