Je travaille sur une application de réalité augmentée utilisant ARKit et RealityKit pour le suivi d’images. Le suivi d’image fonctionne bien, mais je souhaite modifier le code pour encadrer l’image détectée. Voici une portion du code actuel ,Mon objectif est d’encadrer l’image suivie en créant une boîte ayant les mêmes dimensions que l’image détectée, avec une profondeur très faible pour simuler un cadre. Cependant, je rencontre des difficultés pour ajuster le code afin d’obtenir ce résultat.
Comment puis-je modifier ce code pour encadrer l’image détectée correctement ?
private func updateImage(_ anchor: ImageAnchor) {
if entityMap[anchor.id] == nil {
let imageID = anchor.referenceImage.name
print("Recognized image with ID: (imageID)")
// Convert CGFloat to Float
let width = Float(anchor.referenceImage.physicalSize.width)
let height = Float(anchor.referenceImage.physicalSize.height)
let depth: Float = 0.01 // Set an arbitrary small depth
// Generate the box with the converted values
let entity = ModelEntity(mesh: .generateSphere(radius: 0.05))
let material = UnlitMaterial(color: UIColor.blue.withAlphaComponent(0.65))
entity.model?.materials = [material]
entityMap[anchor.id] = entity
contentEntity.addChild(entity)
}
if anchor.isTracked {
entityMap[anchor.id]?.transform = Transform(matrix: anchor.originFromAnchorTransform)
}
}