SceneKit 节点不会随着场景的根节点改变位置 [英] SceneKit nodes aren't changing position with scene's root node

查看:29
本文介绍了SceneKit 节点不会随着场景的根节点改变位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用带有 ARKit 的 SceneKit,现在有一个简单的应用程序,我点击屏幕,它会向我的场景添加一个 ARAnchor 和一个 SCNNode.

I'm using SceneKit with ARKit, and right now have a simple app where I tap on the screen and it adds an ARAnchor and a SCNNode to my scene.

在某些时候,我想要移动整个场景,所以我尝试更改 sceneView.scene.rootNode.position.x += 10 来测试这一点.如果我在任何特定节点上调用它,该节点确实会适当移动.但是在 rootNode 上调用它,没有任何反应,我希望每个子节点(即场景中的每个节点)都随之移动.

At some point, I'm going to want to move the entire scene, so I tried changing sceneView.scene.rootNode.position.x += 10 to test this out. If I call this on any particular node, that node does move appropriately. But calling this on rootNode, nothing happens, where I'd expect every child node (which is every node in the scene) to move along with it.

为什么我的其他节点没有正确移动,我可以做些什么来解决这个问题?还是我想错了?

Why are my other nodes not moving appropriately, and is there something I can do to fix this? Or am I thinking about this wrong?

推荐答案

根据 SCNScene.rootNode:

您不应修改根节点的 transform 属性.

You should not modify the transform property of the root node.

根节点定义了世界坐标系的原点——所有其他测量都与它相关.因此,改变它的位置、方向、比例或其变换的任何其他方面是没有意义的(并且通常是有问题的).

The root node defines the origin of the world coordinate system — all other measurements are relative to it. Hence, it's not meaningful (and is often problematic) to change its position, orientation, scale, or any other aspect of its transform.

如果要移动 SceneKit 场景中的所有内容,请创建一个新节点以包含所有其他内容,并更改该节点的变换.(对于由 ARSCNView 添加的节点,您不能这样做,因为 ARKit 生成根节点的直接子节点,但重点是将它们定位在世界空间中.)

If you want to move all the content in your SceneKit scene, create a new node to contain all of the others, and change that node's transform. (You can't do this for nodes added by ARSCNView, because ARKit makes those direct children of the root node, but the whole point of those is positioning them in world space.)

这篇关于SceneKit 节点不会随着场景的根节点改变位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆