A scene graph—a hierarchy of nodes with attached geometries, lights, cameras and other attributes that together form a displayable 3D scene.
- iOS 8.0+
- macOS 10.8+
- tvOS 9.0+
- watchOS 2.0+
SCNScene object represents a three-dimensional scene and its contents. To render a scene for display, see the
SCNLayer (macOS only), or
SCNRenderer class, and the
SCNScene protocol, which defines properties and methods shared by those classes. The
SCNScene class also provides an interface for reading and writing scene files.
Obtaining or Creating a Scene
Typically, you obtain a scene from a file created using external 3D authoring tools. If you include scene files in your app’s bundle resources directory, Xcode compresses them for optimal SceneKit loading performance. To load a scene file, use the
init(url: method or an instance of the
Alternatively, you can create an empty scene with the
scene method and populate it with content by creating a hierarchy of nodes and their contents and adding them as children of the scene’s
Saving a Scene
Use the the
write(to: method to save a scene to a file. The format of the file created depends on OS version and on the filename extension you specify:
In iOS 10.0, tvOS 10.0, watchOS 3.0, OS X v10.11, and later versions, specify the
.scnextension to save a file in SceneKit’s native format. This format supports all features of SceneKit (including physics, constraints, and particle systems), and reading files in this format is faster than importing from other scene file formats.
In macOS only, specify the
.daeextension to export in Digital Asset Exchange (DAE) format for use by other apps. Exported DAE files do not contain scene elements specific to SceneKit, such as physics bodies and fields, constraints, and particle systems.
Older versions of iOS and tvOS don’t include the
write(to:method, but you can still produce a file in
options: delegate: progress Handler:)
.scnformat through SceneKit’s support for the
NSSecureprotocol. Use the
NSKeyedclass to serialize a scene and all its contents, and the
NSKeyedclass to load an archived scene.