SceneKit定位节点

时间:2016-09-28 21:09:06

标签: swift swift2 scenekit

我有两个SCNNode,其几何类型设置为SCNBox。

let node1 = SCNNode(geometry: SCNBox(width: 10.0, height: 10.0, length: 10.0, chamferRadius: 0.0))
let node2 = SCNNode(geometry: SCNBox(width: 20.0, height: 10.0, length: 10.0, chamferRadius: 0.0))

node1.position.x = 0.0
node2.position.x = 10.0

scene.rootNode.addChildNode(node1)
scene.rootNode.addChildNode(node2)

当我看到我的场景时,节点是重叠的,但它们不应该,或者它们应该?我不会同时操纵相机。目前我没有任何物理场设置。

当我打印以下内容时:

node1.presentationNode.position.x
node2.presentationNode.position.x

(node1.geometry as! SCNBox).width
(node2.geometry as! SCNBox).width

然后打印的值与最初设置的值相同。 默认情况下,节点的锚点是左下角吗? 奇怪的是,当我在touchesBegan / touchesEnded中移动节点并将其定位在相同位置时,节点不会重叠。 如何正确放置SceneKit的节点?

2 个答案:

答案 0 :(得分:0)

我相信你让你的轴混乱了。 node2的宽度为20,但是你只将node1(宽度为10)移动10.请尝试将其移动20(或23以获得小间隙)。

答案 1 :(得分:0)

谢谢你的帮助。 我找到了解决方案。 节点基于锚点定位,该锚点位于节点宽度的中间。