缩放节点的问题(.simdPivot 与 simdScale 和 .scale 属性)

Issues with scaling a node (.simdPivot vs. simdScale & .scale properties)

我不明白节点上的节点缩放是如何工作的。

我正在尝试了解 Apple 的 Creating Face Based AR Experiences 示例项目中的代码是如何工作的。具体来说,我试图了解 TransformVisualization.swift 文件和应用于其节点的转换。

调用方法 addEyeTransformNodes() 并使用 simdScale 属性缩放左右眼节点。这就是我感到困惑的部分。

我尝试使用 .scale 和 .simdScale 属性缩放同一个节点,但它们都没有执行任何操作。

此外,更令人困惑的是,即使 .simdPivot 的值大于 1,节点也会按比例缩小。我预计节点会扩大。

为什么我们需要设置 .simdPivot 来缩放节点而不是 .scale 和 .simdScale 属性?

我说的就是这个函数。

func addEyeTransformNodes() {
  guard #available(iOS 12.0, *), let anchorNode = contentNode else { return }

  // Scale down the coordinate axis visualizations for eyes.
  rightEyeNode.simdPivot = float4x4(diagonal: float4(3, 3, 3, 1))
  leftEyeNode.simdPivot = float4x4(diagonal: float4(3, 3, 3, 1))

  anchorNode.addChildNode(rightEyeNode)
  anchorNode.addChildNode(leftEyeNode)
}

这是我尝试过的:

func addEyeTransformNodes() {
  guard #available(iOS 12.0, *), let anchorNode = contentNode else { return }

  // Does nothing
  rightEyeNode.simdScale = float3(3, 3, 3)
  // Does nothing
  leftEyeNode.scale = SCNVector3(x: 3, y: 3, z: 3)

  anchorNode.addChildNode(rightEyeNode)
  anchorNode.addChildNode(leftEyeNode)
}

我希望按照我的方式缩放节点,但什么也没发生。

期待您的解答和帮助。

如果您需要偏移轴心点(在应用旋转 and/or 比例之前)点使用 simdPivot 实例 属性.

使用我的测试代码来了解它是如何工作的:

let sphereNode1 = SCNNode(geometry: SCNSphere(radius: 1))
sphereNode1.geometry?.firstMaterial?.diffuse.contents = UIColor.red
sphereNode1.position = SCNVector3(-5, 0, 0)
scene.rootNode.addChildNode(sphereNode1)

let sphereNode2 = SCNNode(geometry: SCNSphere(radius: 1))
sphereNode2.geometry?.firstMaterial?.diffuse.contents = UIColor.green
sphereNode2.simdPivot.columns.3.x = -1

sphereNode2.scale = SCNVector3(2, 2, 2)           // WORKS FINE
//sphereNode2.simdScale = float3(2, 2, 2)         // WORKS FINE

scene.rootNode.addChildNode(sphereNode2)

let sphereNode3 = SCNNode(geometry: SCNSphere(radius: 1))
sphereNode3.geometry?.firstMaterial?.diffuse.contents = UIColor.blue
sphereNode3.position = SCNVector3(5, 0, 0)
scene.rootNode.addChildNode(sphereNode3)

枢轴偏移量为 x: -1:

枢轴偏移量为 x: 0:

Using init(diagonal:) initializer helps you creating a new 4x4 Matrix with the specified vector on the main diagonal. This method has an issue: it scales down objects when you're assigning diagonal values greater than 1, and vice versa. So, if you want to scale up character's eyes use the following approach as a workaround:

rightEyeNode.simdPivot = float4x4(diagonal: float4(1/3, 1/3, 1/3, 1))
leftEyeNode.simdPivot = float4x4(diagonal: float4(1/3, 1/3, 1/3, 1))

我想 Apple 工程师会在未来解决这个问题。

希望对您有所帮助。