I'm trying to code with my iPad and the Swift Playgrounds 4.0
. I tried to do Image Tracking with SwiftUI example 1 or example 2. It's possible to create a folder in the iPad App, but you can't put an Image in here... So the following code doesn't work:
func makeUIView(context: Context) -> ARView {
guard let referenceImages = ARReferenceImage.referenceImages(
inGroupNamed: "AR Resources",
bundle: nil)
else {
fatalError("Missing expected asset catalog resources.")
}
}
Here an Image from the Swift Playgrounds App
Is it possible to use reference images from the root / main like you do with the .usdz
models?
if let usdzModel = try? Entity.load(named: "drummer") {
anchor.addChild(usdzModel)
}
Here is the complete Code:
import ARKit
import SwiftUI
import RealityKit
struct RealityKitView: UIViewRepresentable {
func makeUIView(context: Context) -> ARView {
let view = ARView()
// Start AR session
let session = view.session
let config = ARWorldTrackingConfiguration()
config.planeDetection = [.horizontal]
session.run(config)
// Add coaching overlay
let coachingOverlay = ARCoachingOverlayView()
coachingOverlay.autoresizingMask = [.flexibleWidth, .flexibleHeight]
coachingOverlay.session = session
coachingOverlay.goal = .horizontalPlane
view.addSubview(coachingOverlay)
// Set debug options
#if DEBUG
view.debugOptions = [.showFeaturePoints, .showAnchorOrigins, .showAnchorGeometry]
#endif
//AnchorEntity Bild
let anchor = AnchorEntity(.image(group: "AR Resources", name: "Test"))
// Create an image anchor by specifying the group name and image name of the AR resource
let box = ModelEntity(mesh: .generateBox(size: simd_make_float3(0.1, 0.03, 0.05)))
anchor.addChild(box)
view.scene.anchors.append(anchor)
//End AnchorEntity
return view
}
func updateUIView(_ view: ARView, context: Context) {
}
}