1

如何开发这个功能?

当用户拖动 ModelEntity 时,ModelEntity 可以切换平面。

看看这个演示视频

4

1 回答 1

3

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

@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)
于 2020-01-10T14:55:17.627 回答