【发布时间】:2022-01-12 06:51:17
【问题描述】:
【问题讨论】:
标签: swift augmented-reality arkit realitykit
【问题讨论】:
标签: swift augmented-reality arkit realitykit
我认为您应该使用 ray-casting 实例方法来获得所需的行为:
@IBOutlet weak var arView: ARView!
guard let raycastQuery = arView.makeRaycastQuery(from: arView.center, // CGPoint
allowing: .estimatedPlane, // Target
alignment: .horizontal) // TargetAlignment
else {
return
}
// This method checks once for intersections between a ray and real-world surfaces
guard let raycastResult = arView.session.raycast(raycastQuery).first
else {
return
}
let worldTransform = Transform(matrix: raycastResult.worldTransform) // simd_float4x4
// yourModel.transform = worldTransform
let anchor = AnchorEntity(raycastResult: raycastResult)
anchor.addChild(yourModel)
arView.scene.anchors.append(anchor)
【讨论】: