gpt4 book ai didi

ios - 如何将固定的 SCNNode 附加到 ARKit 的 pointOfView?

转载 作者:搜寻专家 更新时间:2023-10-31 22:56:24 25 4
gpt4 key购买 nike

我正在尝试做一些简单的事情,但我遇到了一个破坏 ARKit 体验的问题。

我想将 3d 模型 (SCNNode) 固定到手机屏幕上的某个位置。我能够做到这一点,但目前的体验似乎很糟糕。当我将我的节点添加到场景中时,我的节点在它卡住到位之前有大约一秒钟左右的时间移动。这种初始移动非常糟糕,因为节点可能会卡住在相机的视野之外(因此您不会在屏幕上看到它)。

我使用的代码:

let scene = SCNScene(named: "resources.scnassets/model.scn")!
let node = scene.rootNode.childNode(withName: "model", recursively: true)!

// this puts the node in front & slightly below the camera
let orientation = SCNVector3(x: 0, y: -0.4, z: -1)

node.position = orientation

let physicsBody = SCNPhysicsBody(
type: .static,
shape: SCNPhysicsShape(geometry: SCNSphere(radius: 0.1))
)
node.physicsBody = physicsBody

sceneView.pointOfView?.addChildNode(node)

这段代码很简单,就是在场景的camera节点前面添加节点。但是我遇到了一个问题,当节点被添加到场景中时,它在卡住到位之前有一秒钟在屏幕上移动(当我移动手机时)。我需要做的是让节点出现在屏幕上的固定位置(固定在相机的视角)。

我不想将我的节点锚定到现实世界中的某个地方。我希望我的节点的位置取决于相机的视角。

附加节点以使其停留在手机屏幕上的同一位置的正确方法是什么?

最佳答案

你应该使用 .kinematic而不是 .static

Use kinematic bodies for scene elements that you want to control directly directly but whose movement manipulates other elements. For example, to allow the user to push objects around with a finger, you might create a kinematic body and attach it to an invisible node that you move to follow touch events.

关于ios - 如何将固定的 SCNNode 附加到 ARKit 的 pointOfView?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45810956/

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