ios - 将 ARCamera 旋转变换应用于节点 (ARKit)

标签 ios objective-c arkit

我想将 ARCamera 的旋转应用于 3D 节点,以便该节点始终面向相机。我怎样才能在 Objective-C 中实现这段代码?

最佳答案

您可以使用 SCNBillboardConstraint 使 SCNNode 面向 ARCamera:

An SCNBillboardConstraint object automatically adjusts a node’s orientation so that its local z-axis always points toward the pointOfView node currently being used to render the scene. For example, you can use a billboard constraint to efficiently render parts of a scene using two-dimensional sprite images instead of three-dimensional geometry—by mapping sprites onto planes affected by a billboard constraint, the sprites maintain their orientation with respect to the viewer. To attach constraints to an SCNNode object, use its constraints property.

Objective-C :

SCNBillboardConstraint *lookAtConstraint = [SCNBillboardConstraint billboardConstraint];

node.constraints = @[lookAtConstraint];

swift :

let lookAtConstraint = SCNBillboardConstraint()
node.constraints = [lookAtConstraint]

如果你想让一个 SCNNode 面向另一个节点,那么你可以使用一个 SCNLookAtConstraint:

For example, you can use a look-at constraint to ensure that a camera or spotlight always follows the movement of a game character. To attach constraints to an SCNNode object, use its constraints property. A node points in the direction of the negative z-axis of its local coordinate system. This axis defines the view direction for nodes containing cameras and the lighting direction for nodes containing spotlights or directional lights, as well as the orientation of the node’s geometry and child nodes. When Scene Kit evaluates a look-at constraint, it updates the constrained node’s transform property so that the node’s negative z-axis points toward the constraint’s target node.

Objective-C :

SCNLookAtConstraint * lookAtNode = [SCNLookAtConstraint lookAtConstraintWithTarget:secondNode];
fistNode.constraints = @[lookAtNode];

swift :

 let lookAtConstraint = SCNLookAtConstraint(target: secondNode)
 firstNode.constraints = [lookAtConstraint]

关于ios - 将 ARCamera 旋转变换应用于节点 (ARKit),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49151332/

相关文章:

ios - 如何将 CAGradient 应用于图片的下方?

ios - Collection View 与其容器之间的 20px 间距

objective-c - 单例释放方法产生警告?

ios - 通过 NSSecureCoding 解码 NSArray 时的奇怪行为

swift - "Scene is modified within a rendering callback of another scene."如何解决这个错误?

ios - ARKit 保存对象位置并在下一个 session 中查看它

ios - 升级到 Mavericks 后 Xcode 编译时间非常慢

ios - 如何在 iOS 上的 Office 中打开本地文件

iphone - UITableViewController 第二次加载时崩溃

同时使用 ARKit 和 AVCamera