Class

SCNNode

A structural element of a scene graph, representing a position and transform in a 3D coordinate space, to which you can attach geometry, lights, cameras, or other displayable content.

Overview

An SCNNode object by itself has no visible content when the scene containing it is rendered—it represents only a coordinate space transform (position, orientation, and scale) relative to its parent node. To construct a scene, you use a hierarchy of nodes to create its structure, then add lights, cameras, and geometry to nodes to create visible content.

Nodes Determine the Structure of a Scene

The hierarchy of nodes, or scene graph, in a scene defines both the organization of its contents and your ability to present and manipulate those contents using SceneKit. You may create a node hierarchy programmatically using SceneKit, load one from a file created using 3D authoring tools, or combine the two approaches. SceneKit provides many utilities for organizing and searching the scene graph—for details, see the methods in Managing the Node Hierarchy and Searching the Node Hierarchy.

The root​Node object in a scene defines the coordinate system of the world rendered by SceneKit. Each child node you add to this root node creates its own coordinate system, which is in turn inherited by its own children. You determine the transformation between coordinate systems using the node’s position, rotation, and scale properties properties (or directly using its transform property).

You use a hierarchy of nodes and transformations to model the contents of your scene in a way that suits the needs of your app. For example, if your app presents an animated view of a solar system, you can construct a node hierarchy that models celestial bodies relative to one another: Each planet can be a node, with its orbit and its current position in that orbit defined in the coordinate system of the sun. A planet node defines its own coordinate space, useful both for specifying the planet’s rotation and the orbits of its moons (each of which is a child node of its planet). With this scene hierarchy, you can easily add realistic animation to the scene—animating both the revolution of a moon around its planet and the planet around the sun will combine the animations so that the moon follows the planet.

A Node’s Attachments Define Visual Content and Behavior

The node hierarchy determines the spatial and logical structure of a scene, but not its visible contents. You add 2D and 3D objects to a scene by attaching SCNGeometry objects to nodes. (Geometries, in turn, have attached SCNMaterial objects that determine their appearance.) To shade the geometries in a scene with light and shadow effects, add nodes with attached SCNLight objects. To control the viewpoint from which the scene appears when rendered, add nodes with attached SCNCamera objects.

To add physics-based behaviors and special effects to SceneKit content, use other types of node attachments. For example, an SCNPhysics​Body object defines a node’s characteristics for physics simulation, and an SCNPhysics​Field object applies forces to physics bodies in an area around the node. An SCNParticle​System object attached to a node renders particle effects such as fire, rain, or falling leaves in the space defined by a node.

To improve performance, SceneKit can share attachments between multiple nodes. For example, in a racing game that includes many identical cars, the scene graph would contain many nodes—one to position and animate each car—but all car nodes would reference the same geometry object.

Symbols

Creating a Node

init(geometry:​ SCNGeometry?)

Creates and returns a node object with the specified geometry attached.

init(mdl​Object:​ MDLObject)

Creates a node from the specified Model I/O object.

Managing Node Attributes

var name:​ String?

A name associated with the node.

var light:​ SCNLight?

The light attached to the node.

var camera:​ SCNCamera?

The camera attached to the node.

var geometry:​ SCNGeometry?

The geometry attached to the node.

var morpher:​ SCNMorpher?

The morpher object responsible for blending the node’s geometry.

var skinner:​ SCNSkinner?

The skinner object responsible for skeletal animations of node’s contents.

var category​Bit​Mask:​ Int

A mask that defines which categories the node belongs to.

Working With Node Animation

var presentation:​ SCNNode

A node object representing the state of the node as it currently appears onscreen.

var is​Paused:​ Bool

A Boolean value that determines whether to run actions and animations attached to the node and its child nodes.

Managing the Node’s Transformation

var transform:​ SCNMatrix4

The transformation applied to the node relative to its parent. Animatable.

var position:​ SCNVector3

The translation applied to the node. Animatable.

var rotation:​ SCNVector4

The node’s orientation, expressed as a rotation angle about an axis. Animatable.

var euler​Angles:​ SCNVector3

The node’s orientation, expressed as pitch, yaw, and roll angles, each in radians. Animatable.

var orientation:​ SCNQuaternion

The node’s orientation, expressed as a quaternion. Animatable.

var scale:​ SCNVector3

The scale factor applied to the node. Animatable.

var pivot:​ SCNMatrix4

The pivot point for the node’s position, rotation, and scale. Animatable.

var world​Transform:​ SCNMatrix4

The world transform applied to the node.

var constraints:​ [SCNConstraint]?

A list of constraints affecting the node’s transformation.

Modifying the Node Visibility

var is​Hidden:​ Bool

A Boolean value that determines the visibility of the node’s contents. Animatable.

var opacity:​ CGFloat

The opacity value of the node. Animatable.

var rendering​Order:​ Int

The order the node’s content is drawn in relative to that of other nodes.

var casts​Shadow:​ Bool

A Boolean value that determines whether SceneKit renders the node’s contents into shadow maps.

var movability​Hint:​ SCNMovability​Hint

A value that indicates how SceneKit should handle the node when rendering movement-related effects.

Managing the Node Hierarchy

var parent:​ SCNNode?

The node’s parent in the scene graph hierarchy.

var child​Nodes:​ [SCNNode]

An array of the node’s children in the scene graph hierarchy.

func add​Child​Node(SCNNode)

Adds a node to the node’s array of children.

func insert​Child​Node(SCNNode, at:​ Int)

Adds a node to the node’s array of children at a specified index.

func remove​From​Parent​Node()

Removes the node from its parent’s array of child nodes.

func replace​Child​Node(SCNNode, with:​ SCNNode)

Removes a child from the node’s array of children and inserts another node in its place.

Searching the Node Hierarchy

func child​Nodes(passing​Test:​ (SCNNode, Unsafe​Mutable​Pointer<Obj​CBool>) -> Bool)

Returns all nodes in the node’s child node subtree that satisfy the test applied by a block.

func child​Node(with​Name:​ String, recursively:​ Bool)

Returns the first node in the node’s child node subtree with the specified name.

func enumerate​Child​Nodes((SCNNode, Unsafe​Mutable​Pointer<Obj​CBool>) -> Void)

Executes the specified block for each of the node’s child and descendant nodes.

func enumerate​Hierarchy((SCNNode, Unsafe​Mutable​Pointer<Obj​CBool>) -> Void)

Executes the specified block for each of the node’s child and descendant nodes, as well as for the node itself.

Customizing Node Rendering

var filters:​ [CIFilter]?

An array of Core Image filters to be applied to the rendered contents of the node.

var renderer​Delegate:​ SCNNode​Renderer​Delegate?

An object responsible for rendering custom contents for the node using Metal or OpenGL.

Adding Physics to a Node

var physics​Body:​ SCNPhysics​Body?

The physics body associated with the node.

var physics​Field:​ SCNPhysics​Field?

The physics field associated with the node.

Working With Particle Systems

func add​Particle​System(SCNParticle​System)

Attaches a particle system to the node.

var particle​Systems:​ [SCNParticle​System]?

The particle systems attached to the node.

func remove​Particle​System(SCNParticle​System)

Removes a particle system attached to the node.

func remove​All​Particle​Systems()

Removes any particle systems directly attached to the node.

Working With Positional Audio

func add​Audio​Player(SCNAudio​Player)

Adds the specified auto player to the node and begins playback.

var audio​Players:​ [SCNAudio​Player]

The audio players currently attached to the node.

func remove​Audio​Player(SCNAudio​Player)

Removes the specified audio player from the node, stopping playback.

func remove​All​Audio​Players()

Removes all audio players attached to the node, stopping playback.

Copying a Node

func clone()

Creates a copy of the node and its children.

func flattened​Clone()

Creates an optimized copy of the node and its children.

Hit-Testing

func hit​Test​With​Segment(from:​ SCNVector3, to:​ SCNVector3, options:​ [String :​ Any]? = nil)

Searches the node’s child node subtree for objects intersecting a line segment between two specified points.

Converting Between Node Coordinate Spaces

func convert​Position(SCNVector3, from:​ SCNNode?)

Converts a position to the node’s coordinate space from that defined by another node.

func convert​Position(SCNVector3, to:​ SCNNode?)

Converts a position from the node’s coordinate space to that defined by another node.

func convert​Transform(SCNMatrix4, from:​ SCNNode?)

Converts a transformation to the node’s coordinate space from that defined by another node.

func convert​Transform(SCNMatrix4, to:​ SCNNode?)

Converts a transformation from the node’s coordinate space to that defined by another node.

Constants

SCNMovability​Hint

Values that inform SceneKit’s rendering for movement-related effects, used by the movability​Hint property.