Reputation: 103
I want to be able to apply animations in real time to an SCNNode. Basically, I have a node and I want to continuously input angles to it and have it animate in near real time. I've tried runActions:
var action1:SCNAction = SCNAction.rotateByX(CGFloat(45 / 180.0 * M_PI), y: 0.0, z: 0.0, duration: 0.5);
but the problem with actions is that if I have a stream of actions on the same node, it will only animate the latest action, you can't have it animate multiple actions. Then I ran across sequences, but sequences are a static array and so they cannot be populated dynamically in real time.
So my question is does anyone know of a way to animate an scnnode with streaming data. It doesn't have to be in real time, but that would be nice
Upvotes: 2
Views: 939
Reputation: 2924
Have you tried simply setting the rotation? If you have enough data per frame it should be as smooth as it can be. That's what I use for VR.
Else, you can use the lerp()
function, very popular with Unity to do this. I do not think this is built in Scenekit but we can use GLKVector4Lerp. Here's an Objective-C sample:
- (void)renderer:(id <SCNSceneRenderer>)aRenderer updateAtTime:(NSTimeInterval)time
{
yourNode.rotation = GLKVector4Lerp(yourNode.rotation, newRotation, (float)time);
}
That way you can continuously send data and the node will smoothly follow, without jumping.
Upvotes: 2