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?

Answers


SceneKit doesn't support custom animatable keypath


A workaround/hack:

  • create a geometry-less node and animate some animatable property on that node, for example the opacity
  • use a SCNSceneRendererDelegate to hook into the appropriate stage of the rendering process and manually update your custom property with the value of the geometry-less node's animated property (make sure to read the animated property from the node's presentationNode)

This solution is ugly, but it allows you to synchronize the animation of the custom property with other animations via SCNTransaction or CAAnimationGroup


Need Your Help

I received an auto-reply for an email that was sent over two years ago. How did this happen?

email auto-responder

I administer a web app that occasionally sends re-engagement and marketing emails. I recently received an auto-reply from a marketing email that was sent over two years ago, which made me concerned...

JS URL persistence to create templates

javascript jquery persistence

I have an interactive UI of elements, and I was encouraged to use divs and spans exclusively, and avoid checkboxes. I have converted the site over to the same functionality, but don't know much ab...