SCNLookAtConstraint,指定节点如何看待目标节点?
SCNLookAtConstraint, specify how the node looks at the target node?
我有一个文本节点。我告诉节点总是这样看相机节点:
let lookAt = SCNLookAtConstraint(target: cameraNode)
textNode.constraints = [lookAt]
在我应用该约束之前,文本如下所示:(见图)
如果我应用该约束,节点看起来像图像中那样翻转(见图)。
因此,文本确实始终保持该方向并正确查看相机节点,因此约束起作用。
我正在尝试了解目标节点上的节点 "looks"。当相机四处移动时,我显然希望文本像第一张图片中显示的那样简单地保持不变。
我尝试对文本应用旋转以更正我在应用约束时出现的行为,但没有成功。
那么,我怎样才能让文本看到另一个节点而不像第二张图片那样被翻转?
The documentation for SCNLookAtConstraint
注释:
When SceneKit 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.
但是 SCNText
几何图形是沿着其 正 z 轴面向前方创建的,因此您的约束系统需要以某种方式考虑到这一点。我建议使用专为这种情况设计的 SCNBillboardConstraint
。 Its documentation 说:
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.
这样,您就不需要重新设置节点的父级了。
"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."
textNode.constraints = [SCNBillboardConstraint()]
您还可以通过 localFront 属性:
指定轴 "look" 来修改 lookAt 约束
let lookAtConstraint = SCNLookAtConstraint(target: distantNode)
lookAtConstraint.localFront = SCNVector3Make(0, 1, 0)
node.constraints = [lookAtConstraint]
以上代码将通过它的 Y 轴将 node 定向到 distantNode。
我有一个文本节点。我告诉节点总是这样看相机节点:
let lookAt = SCNLookAtConstraint(target: cameraNode)
textNode.constraints = [lookAt]
在我应用该约束之前,文本如下所示:(见图)
如果我应用该约束,节点看起来像图像中那样翻转(见图)。 因此,文本确实始终保持该方向并正确查看相机节点,因此约束起作用。
我正在尝试了解目标节点上的节点 "looks"。当相机四处移动时,我显然希望文本像第一张图片中显示的那样简单地保持不变。
我尝试对文本应用旋转以更正我在应用约束时出现的行为,但没有成功。
那么,我怎样才能让文本看到另一个节点而不像第二张图片那样被翻转?
The documentation for SCNLookAtConstraint
注释:
When SceneKit 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.
但是 SCNText
几何图形是沿着其 正 z 轴面向前方创建的,因此您的约束系统需要以某种方式考虑到这一点。我建议使用专为这种情况设计的 SCNBillboardConstraint
。 Its documentation 说:
An
SCNBillboardConstraint
object automatically adjusts a node's orientation so that its local z-axis always points toward thepointOfView
node currently being used to render the scene.
这样,您就不需要重新设置节点的父级了。
"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."
textNode.constraints = [SCNBillboardConstraint()]
您还可以通过 localFront 属性:
指定轴 "look" 来修改 lookAt 约束let lookAtConstraint = SCNLookAtConstraint(target: distantNode)
lookAtConstraint.localFront = SCNVector3Make(0, 1, 0)
node.constraints = [lookAtConstraint]
以上代码将通过它的 Y 轴将 node 定向到 distantNode。