【发布时间】:2021-04-26 21:22:28
【问题描述】:
当我触摸屏幕时,我使用光线投射将对象(实体和锚点)放置到它的 worldTransform
然后我尝试触摸这个对象以获取它的锚点(或它自己的实体)
我正在尝试使用 raycast (或 hitTest )找到以前放置的锚点,但每件事都会返回 nil
像这样:
这是我的onTap 代码:
@IBAction func onTap(_ sender: UITapGestureRecognizer){
let tapLocation = sender.location(in: arView)
guard let result = arView.raycast(from: tapLocation, allowing: .estimatedPlane, alignment: .any).first else { return }
print("we have anchor??")
print(result.anchor) // always nil
// never hit
if let existResult = arView.hitTest(tapLocation).first {
print("hit test trigger")
if let entity = existResult.entity as Entity? {
NSLog("we have an entity \(entity.name)")
...
}
}
}
这就是我创建一些对象和锚点的方式:
let anchor = AnchorEntity(world: position)
anchor.addChild(myObj)
arView.scene.anchors.append(anchor)
// my obj is now visible
你知道为什么我不能抓住我触摸的锚吗?
编辑:
ARview 配置:
arView.session.delegate = self
arView.automaticallyConfigureSession = true
let config = ARWorldTrackingConfiguration()
config.planeDetection = [.horizontal, .vertical]
NSLog("FINISHED INIT")
if ARWorldTrackingConfiguration.supportsSceneReconstruction(.mesh) {
config.sceneReconstruction = .mesh // .meshWithClassification
arView.environment.sceneUnderstanding.options.insert([.occlusion])
arView.debugOptions.insert(.showSceneUnderstanding)
NSLog("FINISHED with scene reco")
} else {
NSLog("no not support scene Reconstruction")
}
let tapGesture = UITapGestureRecognizer(target: self, action:#selector(onTap))
arView.addGestureRecognizer(tapGesture)
arView.session.run(config)
【问题讨论】:
标签: swift arkit realitykit