【发布时间】:2016-01-03 06:29:40
【问题描述】:
我很难在 SceneKit 中通过不同的 Morph-Targets 制作动画。 我有一个变形目标数组,我想遍历它们,并在它们之间用动画显示它们。
因此,从一种几何图形到另一种几何图形,这很容易。 在SCNMorpher Class Reference 中有一个示例可以为一个变形几何 (morpher.weights[0]) 执行此操作:
let animation = CABasicAnimation(keyPath: "morpher.weights[0]")
animation.fromValue = 0.0;
animation.toValue = 1.0;
animation.autoreverses = true;
animation.repeatCount = Float.infinity;
animation.duration = 5;
我想要做的是,连续动画变形。我尝试为每个目标设置几个动画。但是在完成第一个动画之后,第一个目标的权重又被设置为0。
override func viewDidLoad() {
super.viewDidLoad()
// create a new scene
let scene = SCNScene()
let vbasic_geom: [Vertex] = [
[ [0, 0, 0], [+1.0, +0.0, +0.0] ],
[ [0, 2, 0], [+1.0, +0.0, +0.0] ],
[ [2, 2, 0], [+1.0, +0.0, +0.0] ]
]
let vmorph1: [Vertex] = [
[ [0, 0, 0], [+1.0, +0.0, +0.0] ],
[ [0, 4, 0], [+1.0, +0.0, +0.0] ],
[ [2, 2, 0], [+1.0, +0.0, +0.0] ]
]
let vmorph2: [Vertex] = [
[ [0, 0, 0], [+1.0, +0.0, +0.0] ],
[ [0, 2, 0], [+1.0, +0.0, +0.0] ],
[ [4, 2, 0], [+1.0, +0.0, +0.0] ]
]
let basic_geom = gen_geometry(vbasic_geom)
let morph1 = gen_geometry(vmorph1)
let morph2 = gen_geometry(vmorph2)
let morpher = SCNMorpher()
morpher.targets = [morph1, morph2]
let object = SCNNode(geometry: basic_geom)
object.morpher = morpher
//needed for model-layer refresh; implicit animation
morpher.setWeight(1.0, forTargetAtIndex: 0)
morpher.setWeight(1.0, forTargetAtIndex: 1)
//set up animations
let animation = CABasicAnimation(keyPath: "morpher.weights[0]")
animation.fromValue = 0.0
animation.toValue = 1.0
animation.duration = 5
animation.beginTime = 0.0
animation.removedOnCompletion = false
let animation2 = CABasicAnimation(keyPath: "morpher.weights[1]")
animation2.fromValue = 0.0;
animation2.toValue = 1.0
animation2.duration = 5
animation2.beginTime = 5.0
animation.removedOnCompletion = false
let animationgroup = CAAnimationGroup()
animationgroup.duration = 10.0
animationgroup.autoreverses = false
animationgroup.repeatCount = 10000;
animationgroup.animations = [animation, animation2]
object.addAnimation(animationgroup, forKey: "morpher.weights")
scene.rootNode.addChildNode(object)
OutputGIF
尝试了几个解决方案,但我都没有成功:
也许可以将 'keyPath: "morpher.weights[0]"' 更改为 'morpher.weights' 并将 from- 和 toValues 设置为类似数组的东西。包括改变 valueFunction。
因为动画发生在表示层上,所以它必须是一种将已动画属性保留为最终值的方法。它尝试了“removedOnCompletion”,但似乎不起作用。
有没有人提供线索或解决方案?
如果有必要,我可以发布一个指向整个代码的链接 - 不要认为这里需要它。
【问题讨论】:
标签: ios animation swift2 scenekit cabasicanimation