11

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?

Community
  • 1
  • 1
Nat Budin
  • 291
  • 1
  • 7

2 Answers2

3

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

Kevin Tonon
  • 965
  • 10
  • 18
  • I created an "interpolation node" that did just this: I animated things like CIFilter properties and evaluated the presentation values every frame to do what I needed. It worked pretty well. – CIFilter Apr 21 '16 at 19:47
-1

SceneKit doesn't support custom animatable keypath

Toyos
  • 59
  • 1
  • That certainly seems plausible, but before just giving up, I'd like to confirm that in fact what I want to do is impossible. Can you point me to docs, or anything else, that confirms this? – Nat Budin Jul 31 '12 at 15:59
  • The docs for SceneKit are pretty sparse. I looked and didn't find anything. The error message might be the best you'll get. – jblocksom Aug 02 '12 at 17:18
  • Yeah, I was hoping someone else would be able to jump in with a different answer, but it looks like this is probably the best we can figure at least until Apple releases better documentation. Accepting. – Nat Budin Aug 03 '12 at 12:49