Create 3D games and add 3D content to apps using high-level scene descriptions. Easily add animations, physics simulation, particle effects, and realistic physically based rendering.
- iOS 8.0+
- macOS 10.8+
- tvOS 9.0+
- watchOS 3.0+
SceneKit combines a high-performance rendering engine with a descriptive API for import, manipulation, and rendering of 3D assets. Unlike lower-level APIs such as Metal and OpenGL that require you to implement in precise detail the rendering algorithms that display a scene, SceneKit only requires descriptions of your scene’s contents and the actions or animations you want it to perform.
Getting Started with SceneKit
SceneKit implements content as a hierarchical tree structure of nodes, also known as scene graph. A scene consists of a root node, which defines a coordinate space for the world of the scene, and other nodes that populate the world with visible content. SceneKit displays scenes in a view, processing the scene graph and performing animations before efficiently rendering each frame on the GPU.
Before working with SceneKit, you should be familiar with basic graphics concepts such as coordinate systems and the mathematics of three-dimensional geometry. SceneKit uses a right-handed coordinate system where (by default) the direction of view is along the negative z-axis, as illustrated in Figure 1.
Animating SceneKit Content
SceneKit animation support is based on the Core Animation framework. (For background on Core Animation, read Core Animation Programming Guide.) Several SceneKit classes define animatable properties—you can create animations that transition smoothly between two values of the property. For example, animating a node’s
opacity property fades the node’s visible content in or out. You can create animations implicitly or explicitly.
You create an animation implicitly by changing the value of an animatable property. SceneKit automatically combines all changes you make to a scene during one pass through the run loop into a single atomic operation called a transaction, represented by the
SCNTransaction class. The default transaction’s duration is zero, so the changes you make to animatable properties occur immediately. However, if you increase the transaction’s animation duration, all changes to animatable properties automatically animate. Implicit animation is useful when you want to quickly animate a one-time change or animate several property changes together without writing a lot of animation code, as in Listing 1 below. For more details on implicit animation, see
For more complex animations, you can explicitly create an animation object and attach it to the scene element being animated. To explicitly create an animation, you choose a
CAAnimation subclass for the type of animation you want to create, specify the property to be animated using key-value coding, then set animation parameters. You then set the animation in motion by attaching it to one or more elements of your scene, as shown in Listing 2. Using different Core Animation classes you can combine or sequence several animations or create animations that interpolate a property’s value between several keyframe values. For details on creating animation objects, see Core Animation Programming Guide. For details on attaching animations to SceneKit objects, see
SceneKit also uses
CAAnimation objects for animations created using external 3D authoring tools and saved in scene files. For example, an artist might create a game character with animations for walking, jumping, and other actions. You incorporate these animations into your game by loading animation objects from the scene file using the
SCNScene class and attaching them to the
SCNNode object that represents the game character.