我正在尝试为场景中的每个节点添加动画。我有一个问题是,在层次结构中 - 我将动画添加到哪个节点。我认为它是由您实际看到的节点表示的节点,它将是网格对象...但是我有一个节点,它持有两个灯光和网格对象...会动画那个也工作吗? / p>
这是我的代码 - 我使用委托方法等待填充场景,然后我尝试遍历场景的节点并添加动画:
func sceneLocationViewDidSetupSceneNode(sceneLocationView: SceneLocationView, sceneNode: SCNNode) {
let animation = CABasicAnimation(keyPath: "opacity")
animation.fromValue = 100.0
animation.toValue = 0.0
animation.duration = 2.0
animation.autoreverses = true
animation.repeatCount = .infinity
print("\(sceneNode) name name name name name" )
for node in sceneNode.childNodes {
for nodeInner in node.childNodes {
for nodeInnermost in nodeInner.childNodes {
if (nodeInnermost.name?.localizedStandardContains("ship"))! {
print(nodeInnermost.childNodes.first ?? "FIRST DOESNT EXIST")
nodeInnermost.childNodes.first?.addAnimation(animation, forKey: "opac")
}
}
}
}
}
根本不起作用,不透明度没有变化。
答案 0 :(得分:0)
请尝试以下操作:
let plane = SCNPlane(width: 0.2, height: 0.2)
plane.firstMaterial?.diffuse.contents = vc2
let planeNode = SCNNode(geometry: plane)
planeNode.opacity = 0
node.addChildNode(planeNode)
DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
SCNTransaction.animationDuration = 4
planeNode.opacity = 1
planeNode.position.z = -0.2
}
return node