Class

SCNScene

A container for the node hierarchy and global properties that together form a displayable 3D scene.

Declaration

@interface SCNScene : NSObject

Overview

To display 3D content with SceneKit, you create a scene containing a hierarchy of the nodes and attributes that together represent your visual elements. Typically, you build your assets in a 3D visual editor, then assemble them into a scene using Xcode’s SceneKit Scene Editor, ready for SceneKit to render.

At the left, a diagram showing a simple scene composed of the node hierarchy and presentation attributes. At the right, the resulting rendered scene.

To display your scene, you need to load it at runtime, then set it as the scene property of an SCNView:

guard let myScene = SCNScene(named: "MyScene") 
    else { fatalError("Unable to load scene file.") }
scnView.scene = myScene // Your app's SCNView

Creating a Scene

The simplest way to create a scene is through Xcode’s SceneKit Scene Editor. Start by importing one or more assets from a 3D editor, such as Blender. Then you adjust the positions and attributes of the assets, and set global scene properties, such as lighting environment, to compose your scene. The scene editor creates a .scn file, which you save to a .scnassets folder in the app bundle. When you build your project, Xcode optimizes the scene file for your target platform.

Topics

Creating a Scene from a File

+ scene

Creates and returns an empty scene.

+ sceneNamed:

Loads a scene from a file with the specified name in the app’s main bundle.

+ sceneNamed:inDirectory:options:

Loads a scene from a file with the specified name in a specific subdirectory of the app’s main bundle.

+ sceneWithURL:options:error:

Loads a scene from the specified URL.

Creating a Scene from a Model I/O Asset

+ sceneWithMDLAsset:

Creates a scene from the specified Model I/O asset.

Managing Animated Effects in a Scene

paused

A Boolean value that determines whether to run actions, animations, particle systems, and physics simulations in the scene graph.

Accessing Scene Contents

rootNode

The root node of the scene graph.

background

A background to be rendered before the rest of the scene.

lightingEnvironment

A cube map texture that depicts the environment surrounding the scene’s contents, used for advanced lighting effects.

Managing Scene Attributes

- attributeForKey:

Returns the scene attribute for the specified key.

- setAttribute:forKey:

Sets a scene attribute for the specified key.

Exporting a Scene File

- writeToURL:options:delegate:progressHandler:

Exports the scene and its contents to a file at the specified URL.

SCNSceneExportDelegate

Methods you can implement to participate in the process of exporting a scene to a file.

Adding Fog to a Scene

fogStartDistance

The distance from a point of view at which the scene’s contents begin to be obscured by fog. Animatable.

fogEndDistance

The distance from a point of view at which the scene’s contents are completely obscured by fog. Animatable.

fogDensityExponent

The transition curve for the fog’s intensity between its start and end distances. Animatable.

fogColor

The color of the fog effect to be rendered with the scene. Animatable.

Working With Physics in the Scene

physicsWorld

The physics simulation associated with the scene.

Working with Particle Systems in the Scene

- addParticleSystem:withTransform:

Attaches a particle system to the scene, using the specified transform.

particleSystems

The particle systems attached to the scene.

- removeParticleSystem:

Removes a particle system attached to the scene.

- removeAllParticleSystems

Removes any particle systems directly attached to the scene.

Constants

Scene Attributes

Attribute keys available in the options dictionary for the methods attributeForKey: and setAttribute:forKey:

SCNSceneExportProgressHandler

The signature for the block that SceneKit calls during scene export.

Relationships

Inherits From

Conforms To

See Also

First Steps

SCNView

A view for displaying 3D SceneKit content.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software