Search code examples
objective-cmacoscore-animationosx-mountain-lionscenekit

Custom animatable properties in SceneKit


I know it's possible to create custom animatable properties in Core Animation, but what about in OS X 10.8's SceneKit framework? SCNAnimatable doesn't seem to expose the same APIs that CALayer does for making properties animatable.

In my application, I've got a SCNNode subclass called Starfield, which I've ported from an old OpenGL application by using a SCNNodeRendererDelegate. Starfields expose a GLfloat property called warpFactor:

@interface Starfield : SCNNode<SCNNodeRendererDelegate> {
    // other stuff that's not really important for this question
    GLfloat warpFactor;
}

@property(nonatomic) GLfloat warpFactor;
@end

But when I try to add an animation to it, like so:

CABasicAnimation *warp = [CABasicAnimation animationWithKeyPath:@"warpFactor"];
warp.toValue = @1.0;
warp.duration = 5.0;
[starfield addAnimation:warp forKey:@"warp"];

I get the following in the console:

[SCNKit ERROR] warpFactor is not an animatable path (from <unnamed SCNNode 0x1016473c0, no children>)

I know SceneKit is brand new, but does anyone happen to know how to make this work?


Solution

  • SceneKit doesn't support custom animatable keypath