I would like to make text change size as I move towards/away from the image anchor I created.
as I move towards the image, the text gets smaller
as I move away from the image, the gets bigger
My current function to create the text is below:
func addTitleToAnchor(text:String, color:SimpleMaterial.Color, isMetallic:Bool, anchor: AnchorEntity, height: Float) {
let mesh = MeshResource.generateText(
text,
extrusionDepth: 0.02,
font: .init(descriptor: .init(name: "Helvetica", size: 1), size: 1),
containerFrame: .zero,
alignment: .center,
lineBreakMode: .byWordWrapping)
let material = SimpleMaterial(color: color, isMetallic: isMetallic)
let entity = ModelEntity(mesh: mesh, materials: [material])
entity.name = "title"
entity.setScale(SIMD3<Float>(0.015 ,0.015,0.015), relativeTo: anchor)
anchor.addChild(entity)
entity.setPosition(SIMD3<Float>(-0.05, 0.03, -height), relativeTo: anchor)
entity.transform.rotation = simd_quatf(angle: -.pi/2, axis: [1,0,0])
return
}
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
I am wondering how I can edit the func session(_ session: ARSession, didAdd anchors: [ARAnchor]) in the arView.session.delegate. I would like to run a function when the image is recognized.
struct ARViewWrapper: UIViewRepresentable {
let title: String
typealias UIViewType = ARView
func makeUIView(context: Context) -> ARView {
print("detected?")
let arView = ARView(frame: .zero, cameraMode: .ar, automaticallyConfigureSession: true)
let target = AnchorEntity(.image(group: "AR Resources", name: "qr1"))
arView.scene.anchors.append(target)
addARObjs(anchor: target, title: title, planeColor: .blue)
return arView
}
func updateUIView(_ uiView: ARView, context: Context) {
print("update!")
return()
}
}
Any and all guidance is appreciated! Thanks in advance.