Skip to content
Create animations over Bezier curves of any number of points
Swift Ruby Shell
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github/workflows
Example added example project which uses ARKit for visualising the 3d bezier … Jul 7, 2019
Sources/SCNBezier
media
.gitignore added example project which uses ARKit for visualising the 3d bezier … Jul 7, 2019
LICENSE updated badsges, added workflows, updated License, deprecated travis Aug 31, 2019
Package.swift lowered minimum version to ios 8, added macos, tvos, watchos Jul 5, 2019
README.md Release 1.3.1 Aug 31, 2019
SCNBezier.podspec Release 1.3.1 Aug 31, 2019
install_swiftlint.sh updated badsges, added workflows, updated License, deprecated travis Aug 31, 2019
old.travis.yml

README.md

SceneKit-Bezier-Animations

Animate a SCNNode along a curved path in SceneKit.

Linter Status Build Status

License Platform SwiftPM Swift 5.0


Installation

Swift Package Manager

Add the URL of this repository to Xcode 11 with minimum version 1.3.0

Cocoapods

Add the following to your Podfile pod 'SCNBezier'


Usage

Animating

Using this framework you can animate a Node along a bézier path using the following example code:

let myNode = SCNNode(geometry: SCNBox(width: 0.1, height: 0.1, length: 0.1, chamferRadius: 0))
let bezPositions = [
  SCNVector3(-1, 1, 0.01),
  SCNVector3(1, 0.5, 0.4),
  SCNVector3(1.0, -1, 0.1),
  SCNVector3(0.4, -0.5, 0.01)
]
myNode.runAction(SCNAction.moveAlong(points: bezPositions, duration: 3, fps: 12))

The animation will use duration * fps points to animated between; this requires type Double, or its TypeAlias TimeInterval. This does not mean it will not be smooth, it just means it will make the curve out of that many points, so in this example it will use 36 points along the Bézier curve.

Getting a Bézier curve

The class SCNBezierPath can be created if you want to collect n points along a path for positioning objects etc. as such:

let path = SCNBezierPath(points: points)
for point in path.getNPoints(count: 20) {
	let newNode = SCNNode(geometry: nodeGeometry)
	newNode.position = point
	parent.addChildNode(newNode)
}

Position on a Bézier curve

If you want to get a point some percentage along the curve, there's a function that makes that easy for you too.

let path = SCNBezierPath(points: points)
let quaterWay = path.posAt(time: 0.25) // gets the point 25% along from start to end

With points, nodeGeometry and parent being arbitrary values.


Bézier example

You can’t perform that action at this time.