RCProjectStrategy

public struct RCProjectStrategy<CardItem> : AnnotationLoadingStrategy, SceneLoadable where CardItem : CardItemModel, CardItem.ID : LosslessStringConvertible
extension RCProjectStrategy: AsyncAnnotationLoadingStrategy where CardItem: Codable

A loading strategy that uses the RealityComposer app. After creating the Reality Composer scene, the entities in the scene correlate to a real world location relative to the image or object anchor. This strategy wraps the anchors that represents these locations with the CardItemModels that they correspond to in a ScreenAnnotation struct for a single source of truth. Loading the data into the ARAnnotationViewModel should be done in the onAppear method.

If an Object Anchor is used the anchorImage and physicalWidth can be set to nil and are ignored

Usage

let cardItems = [ExampleCardItem(id: 0, title_: "Hello"), ExampleCardItem(id: 1, title_: "World")]
guard let anchorImage = UIImage(named: "qrImage") else { return }
let strategy = RealityComposerStrategy(cardContents: cardItems, anchorImage: anchorImage, rcFile: "ExampleRC", rcScene: "ExampleScene")
arModel.load(loadingStrategy: strategy)
  • An array of CardItem : CardItemModel which represent what will be displayed in the default CardView

    Declaration

    Swift

    public var cardContents: [CardItem]
  • Image to be converted to ARReferenceImage and added to ARConfiguration for discovery, can be nil if detecting an object Anchor

    Declaration

    Swift

    public var anchorImage: UIImage?
  • The width of the image in meters

    Declaration

    Swift

    public var physicalWidth: CGFloat?
  • Name of the Reality Composer File without the extension. Note: .rcproject file, not a .reality file

    Declaration

    Swift

    public var rcFile: String
  • Name given to the scene in the Reality Composer app.

    Declaration

    Swift

    public var rcScene: String
  • Constructor for loading annotations using an Image as an anchor with a Reality Composer scene

    Declaration

    Swift

    public init(cardContents: [CardItem], anchorImage: UIImage? = nil, physicalWidth: CGFloat? = nil, rcFile: String, rcScene: String, bundle: Bundle = Bundle.main)

    Parameters

    cardContents

    An array of CardItem : CardItemModel which represent what will be displayed in the default CardView

    anchorImage

    Image to be converted to ARReferenceImage and added to ARConfiguration for discovery, can be nil if detecting an object Anchor

    physicalWidth

    The width of the image in meters

    rcFile

    Name of the Reality Composer File without the extension. Note: .rcproject file, not a .reality file

    rcScene

    Name given to the scene in the Reality Composer app.

    bundle

    bundle containing the Reality Composer File. If not supplied then Bundle.main is used

  • Constructor for loading annotations using Data from a JSON Array JSON key/value: “id”: String, “title_”: String, “subtitle_”: String?, “detailImage_”: Data?, // base64 encoding of Image “actionText_”: String?, “icon_”: String? // systemName of SFSymbol

    Example: [ { “id”: “WasherFluid”, “title_”: “Recommended Washer Fluid”, “subtitle_”: “Rain X”, “detailImage_”: null, “actionText_”: null, “icon_”: null }, { “id”: “Coolant”, “title_”: “Genuine Coolant”, “subtitle_”: “Price: 20.99”, “detailImage_”: “iVBORw0KGgoAAAANSUhE…”, “actionText_”: “Order”, “icon_”: “cart.fill” } ]

    Declaration

    Swift

    public init(jsonData: Data, anchorImage: UIImage, physicalWidth: CGFloat? = nil, rcFile: String, rcScene: String, bundle: Bundle = Bundle.main) throws where CardItem == CodableCardItem
  • Loads the Reality Composer Scene and extracts the Entities pairing them with the data that corresponds to their ID into a list of ScreenAnnotation

    Declaration

    Swift

    public func load(with manager: ARManager) throws -> (annotations: [ScreenAnnotation<CardItem>], guideImage: UIImage?)

Available where CardItem: Codable