使用 ARKit 可视化表面上的放置点

Visualize placement point on surface with ARKit

我想在我放置的对象下方的平面上绘制一个 Focus Circle 和其中的阴影,就像在 IKEA AR 应用程序中一样。

我该怎么做?

Follow this AR project created by Apple Engineers: Handling 3D Interaction and UI Controls in Augmented Reality to find out how to create a Focus Square programmatically.

There's the blue Download button at the top of web page.

To create a Focus Circle like in IKEA app I'd recommend you use a png file with a premultiplied RGBA channels like this one (drag-and-drop it on your Desktop for testing):

要创建 阴影,您需要在场景中添加 directional 灯光。要以编程方式执行此操作,请使用以下代码:

let lightFixture = SCNNode()
lightFixture.light = SCNLight()
lightFixture.light!.type = .directional
lightFixture.light!.castsShadow = true
lightFixture.light!.shadowMode = .deferred
lightFixture.light!.shadowColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0.5)
lightFixture.position = SCNVector3(x: 0, y: 20, z: 0)
lightFixture.rotation = SCNVector4(x: -1, y: 0, z: 0, w: .pi/2)
scene.rootNode.addChildNode(lightFixture)

然后你需要为你的半透明阴影创建一个不可见平面:

let shadowPlane = SCNNode()
shadowPlane.geometry = SCNFloor()
shadowPlane.geometry?.firstMaterial!.colorBufferWriteMask = []
shadowPlane.geometry?.firstMaterial!.readsFromDepthBuffer = true
shadowPlane.geometry?.firstMaterial!.writesToDepthBuffer = true
shadowPlane.geometry?.firstMaterial!.lightingModel = .constant
scene.rootNode.addChildNode(shadowPlane)