gpt4 book ai didi

swift - 如何将 ARHitTestResult "convert"转换为 ARRaycastResult?

转载 作者:行者123 更新时间:2023-12-04 08:22:25 27 4
gpt4 key购买 nike

我目前正在用 Swift 构建一个 AR 应用程序,并想转换这种类型的东西: let arHitTestResults : [ARHitTestResult] = sceneView.hitTest(screenCentre, types: [.featurePoint]) (iOS 14 中不再提供)对此:让 arResults: [ARRaycastResult] = sceneView.raycastQuery(from: tapLocation, allowed: existingPln, alignment: alignment)
但系统地收到此消息:无法转换“ARRaycastQuery”类型的值?到指定类型 '[ARRaycastResult]'
我能做什么?
感谢您的回答!

@objc func handleTap(gestureRecognize: UITapGestureRecognizer) {

let screenCentre: CGPoint = CGPoint(x: self.sceneView.bounds.midX,
y: self.sceneView.bounds.midY)
let tapLocation: CGPoint = screenCentre
let existingPln: ARRaycastQuery.Target = .existingPlaneGeometry
let alignment: ARRaycastQuery.TargetAlignment = .vertical

let arResults: [ARRaycastResult] = sceneView.raycastQuery(from: tapLocation,
allowing: existingPln,
alignment: alignment)
}

最佳答案

您无需转换已弃用的 ARHitTestResult类成ARRaycastResult因为这些类不可互换。在场景中使用光线转换时,请改用以下方法:

@IBAction func tapped(_ sender: UITapGestureRecognizer) {

let tapLocation: CGPoint = sender.location(in: arView)
let estimatedPlane: ARRaycastQuery.Target = .estimatedPlane
let alignment: ARRaycastQuery.TargetAlignment = .any

let result = arView.raycast(from: tapLocation,
allowing: estimatedPlane,
alignment: alignment)

guard let raycast: ARRaycastResult = result.first
else { return }

let anchor = AnchorEntity(world: raycast.worldTransform)
anchor.addChild(model)
arView.scene.anchors.append(anchor)

print(raycast.worldTransform.columns.3)
}
如果您需要更多光线转换示例,请查看 this SO post .

关于swift - 如何将 ARHitTestResult "convert"转换为 ARRaycastResult?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65438862/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com