I'm using RealityKit and SwiftUI to place 3DText on iOS but I can't get the text to anchor to a position. I stripped the project down to the bare essentials below and it still doesn't work. The box will anchor and stay in one place as I walk around but the text will follow above my device wherever I move. This is driving me crazy because the box works totally as expected but the text just does not. I have tried so many different iterations of the code below to no avail. I was wondering if anyone else was having this problem or if it was just me, potentially a bug? Is there something else I should try?
import SwiftUI
import RealityKit
struct ContentView : View {
var body: some View {
return ARViewContainer().edgesIgnoringSafeArea(.all)
}
}
struct ARViewContainer: UIViewRepresentable {
func makeUIView(context: Context) -> ARView {
let arView = ARView(frame: .zero)
let anchor = AnchorEntity()
anchor.position = simd_make_float3(0, -0.5, -1)
let textEntity = ModelEntity(mesh: .generateText("Hello there", extrusionDepth: 0.4, font: .boldSystemFont(ofSize: 8), containerFrame: .zero, alignment: .center, lineBreakMode: .byWordWrapping))
let boxEntity = ModelEntity(mesh: .generateBox(size: 0.2))
anchor.addChild(textEntity)
anchor.addChild(boxEntity)
arView.scene.anchors.append(anchor)
return arView
}
func updateUIView(_ uiView: ARView, context: Context) {}
}