I wanted to make a very simple AR Viewer that is based on Reality Composer and RealityKit, following Apple's video "Building Apps With RealityKit" session 605. I started with an XCode Project the basic Box AR anchored to the floor, it has Reality Project loaded with a Box. That part is working fine.
I modified the RC Project and adding my own USDZ asset.
What I would like to know is just super basics:
- To be able to register Tap Gesture to trigger my Reality Setup (run animation)
- Ability to Modify Material, maybe changing color
- Adding Occlusion Material into Entity
So far I got to this by watching Apple's Video:
- I cannot seem to get a print out of where I tap on screen. I thought it would be fairly simple.
- I cannot seem to be able to see my object with Occlusion Material. I mean it is probably already in the scene but not sure where I anchor it exacly.
What is wrong exactly with my code?
import UIKit
import RealityKit
class ViewController: UIViewController {
@IBOutlet var arView: ARView!
override func viewDidLoad() {
super.viewDidLoad()
// Load the "Box" scene from the "Experience" Reality File
let boxAnchor = try! Experience.loadBox()
// Add the box anchor to the scene
arView.scene.anchors.append(boxAnchor)
// Occlusion Plane
let planeMesh = MeshResource.generatePlane(width: 2.5, depth: 2.5)
//let planeMesh = MeshResource.generateBox(size: 2.0)
let material = OcclusionMaterial()
let occlusionPlane = ModelEntity(mesh: planeMesh, materials: [material])
occlusionPlane.position.y = 1.5
// add to anchor
boxAnchor.addChild(occlusionPlane)
}
// Hit Testing
@IBAction func onTap(_ sender: UITapGestureRecognizer){
let tapLocation = sender.location(in: arView)
if let blah = arView.entity(at: tapLocation){
print(blah.name)
}
}
}