现实工具包 – 拖动的对象切换平面



如何开发这个功能?

当用户拖动模型实体时,模型实体可以切换平面。

请看这个演示视频。

您应该使用光线投射实例方法来获得所需的行为:

@IBOutlet 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
let anchor = AnchorEntity(raycastResult: raycastResult)
// yourModel.transform = worldTransform
// or...
// anchor.transform = worldTransform
anchor.addChild(yourModel)
arView.scene.anchors.append(anchor)

最新更新