简体   繁体   English

动画 SceneKit SCNNode 位置不起作用

[英]Animating SceneKit SCNNode position not working

I followed this exactly: https://developer.apple.com/documentation/scenekit/animation/animating_scenekit_content我完全按照这个: https : //developer.apple.com/documentation/scenekit/animation/animating_scenekit_content

I have a SCNNode on another SCNNode that has the geometry of the user face.我在另一个具有用户面部几何形状的 SCNNode 上有一个 SCNNode。

The SCNNode that is on the face SCNNode, I would like the movement to be animated.面部 SCNNode 上的 SCNNode,我希望运动具有动画效果。 I'm calling this function which is in a subclass of the SCNNode I want to animate.我正在调用这个函数,它位于我想要动画的 SCNNode 的子类中。 The property it takes is a location on the face.它需要的属性是脸上的一个位置。 This function doesn't work at all:此功能根本不起作用:

 func move(to vertex: SCNVector3) {
  let animation = CABasicAnimation(keyPath: "move")
  animation.fromValue = SCNVector3(self.position.x, self.position.y, self.position.z)
  animation.toValue = vertex
  animation.duration = 3.0
  self.addAnimation(animation, forKey: "move")
 }

This function works perfectly fine:这个函数工作得很好:

 func move(to vertex: SCNVector3) {
  self.position.x = vertex.x
  self.position.y = vertex.y
  self.position.z = vertex.z
 }

The function call to both functions:对两个函数的函数调用:

move(to: SCNVector3(anchor.geometry.vertices[Node.oldVertexPos].x, anchor.geometry.vertices[Node.oldVertexPos].y, anchor.geometry.vertices[Node.oldVertexPos].z))

SCNNode 上不存在 keyPath“move”,您应该为位置设置动画。

let animation = CABasicAnimation(keyPath: "position")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM