[英]Define position for SCNNode
I create the SCNBox
based on the SCNVector3
.我创建了SCNBox
基础上, SCNVector3
。 But I don't understand the concept of the creation.但我不明白创造的概念。
For 2D rectangle, the x and y represent the rectangle top right corner.对于 2D 矩形, x和y表示矩形右上角。 For ARKit 3D SCNBox
, what is the x, y and z represent for?对于 ARKit 3D SCNBox
, x、y和z代表什么? Is that represent the center of the SCNBox
?那是代表SCNBox
的中心吗?
When you're setting position of your SCNNode
, you're initializating SCNVector3
which describing node's position.当您设置SCNNode
位置时,您正在初始化描述节点位置的SCNVector3
。
You have to define position of node's center point in relation to the position of the parent ( center point is not necessarily in the center of your custom node, but if you have basic nodes with geometry like SCNBox
or SCNSphere
, center point is in the center)您必须定义节点中心点相对于父节点位置的位置(中心点不一定在自定义节点的中心,但如果您有具有SCNBox
或SCNSphere
等几何形状的基本节点,中心点在中心)
A simple example can be adding node with geometry SCNBox
to rootNode
of sceneView
's scene
which you get when you in Xcode create new Augmented Reality App .一个简单的例子可以添加带有几何节点SCNBox
到rootNode
的sceneView
的scene
,你得到,当你在Xcode中创建新的增强现实应用程序。
let cube = SCNBox(width: 0.1, height: 0.1, length: 0.1, chamferRadius: 0)
let material = SCNMaterial()
material.diffuse.contents = UIColor.red
cube.materials = [material]
let node = SCNNode()
node.position = SCNVector3(x: 0, y: 0, z: -0.5)
node.geometry = cube
sceneView.scene.rootNode.addChildNode(node)
As you can see, to initialize SCNVector3
you have to define x, y and z positions of node's center point .如您所见,要初始化SCNVector3
您必须定义节点中心点的x、y和z位置。 Note that units are in meters.请注意,单位以米为单位。
I created (very nice) picture with x,y and z axises which should help you to understand how to position your SCNNode
:我用x、y和z 轴创建了(非常好的)图片,这应该可以帮助您了解如何定位SCNNode
:
...origin is origin of the node's parent's coordinate system when node is added. ...origin 是添加节点时节点父级坐标系的原点。 Image origin of AR world simplified as position of the center of ARSCNView
AR世界的图像原点简化为ARSCNView
的中心位置
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.