节点的 SceneKit 定位
SceneKit positioning of the node
我有两个 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的节点?[=13=]
我相信您混淆了坐标轴。 node2 的宽度为 20,但您只是将 node1(宽度为 10)移动 10。尝试将其移动 20(或 23 以获得小间隙)。
感谢您的帮助。
我找到了解决方案。
节点基于节点宽度中间的锚点定位。
我有两个 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的节点?[=13=]
我相信您混淆了坐标轴。 node2 的宽度为 20,但您只是将 node1(宽度为 10)移动 10。尝试将其移动 20(或 23 以获得小间隙)。
感谢您的帮助。 我找到了解决方案。 节点基于节点宽度中间的锚点定位。