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.

Declaration

@interface SCNNode : NSObject

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 rootNode 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 SCNPhysicsBody object defines a node’s characteristics for physics simulation, and an SCNPhysicsField object applies forces to physics bodies in an area around the node. An SCNParticleSystem 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.

Topics

Creating a Node

+ node

Creates and returns a node object.

+ nodeWithGeometry:

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

+ nodeWithMDLObject:

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

Managing the Node's Transform

simdTransform

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

simdPosition

The translation applied to the node. Animatable.

simdRotation

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

simdEulerAngles

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

simdOrientation

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

simdScale

The scale factor applied to the node. Animatable.

simdPivot

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

Managing Node Content

name

A name associated with the node.

light

The light attached to the node.

camera

The camera attached to the node.

geometry

The geometry attached to the node.

morpher

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

skinner

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

categoryBitMask

A mask that defines which categories the node belongs to.

SCNBoundingVolume

Methods common to the SCNNode and SCNGeometry classes for measuring location and size.

Constraining Node Behavior

constraints

A list of constraints affecting the node’s transformation.

Working with Node Animation

presentationNode

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

paused

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

Modifying the Node Visibility

hidden

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

opacity

The opacity value of the node. Animatable.

renderingOrder

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

castsShadow

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

movabilityHint

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

SCNMovabilityHint

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

Managing the Node Hierarchy

parentNode

The node’s parent in the scene graph hierarchy.

childNodes

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

- addChildNode:

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

- insertChildNode:atIndex:

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

- removeFromParentNode

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

- replaceChildNode:with:

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

Searching the Node Hierarchy

- childNodesPassingTest:

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

- childNodeWithName:recursively:

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

- enumerateChildNodesUsingBlock:

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

- enumerateHierarchyUsingBlock:

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

Customizing Node Rendering

filters

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

rendererDelegate

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

Adding Physics to a Node

physicsBody

The physics body associated with the node.

physicsField

The physics field associated with the node.

Working with Particle Systems

- addParticleSystem:

Attaches a particle system to the node.

particleSystems

The particle systems attached to the node.

- removeParticleSystem:

Removes a particle system attached to the node.

- removeAllParticleSystems

Removes any particle systems directly attached to the node.

Working with Positional Audio

- addAudioPlayer:

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

audioPlayers

The audio players currently attached to the node.

- removeAudioPlayer:

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

- removeAllAudioPlayers

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

Copying a Node

- clone

Creates a copy of the node and its children.

- flattenedClone

Creates an optimized copy of the node and its children.

Hit-Testing

- hitTestWithSegmentFromPoint:toPoint:options:

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

SCNHitTestOption

Options affecting the behavior of SceneKit hit-testing methods.

Performing Node-Relative Operations

- simdRotateBy:aroundTarget:

Changes the node's position and orientation, relative to its current transform, through a rotation around the specified point in scene space.

- simdLocalTranslateBy:

Changes the node's position relative to its current position.

- simdLocalRotateBy:

Changes the node's orientation relative to its current orientation.

- simdLookAt:

Changes the node's orientation so that its local forward vector points toward the specified location.

- simdLookAt:up:localFront:

Changes the node's orientation so that the specified forward vector points toward the specified location.

Calculating Node-Relative Transforms

simdLocalRight

The direction SceneKit treats as "right" in local space for all nodes.

simdLocalUp

The direction SceneKit treats as "up" in local space for all nodes.

simdLocalFront

The unit vector SceneKit treats as "forward" in local space for all nodes.

simdWorldRight

The "right" (+X) direction vector relative to the node, expressed in world space.

simdWorldUp

The "up" (+Y) direction vector relative to the node, expressed in world space.

simdWorldFront

The "forward" (-Z) direction vector relative to the node, expressed in world space.

Managing Transforms in World Space

simdWorldTransform

The world transform applied to the node.

simdWorldOrientation

The node's orientation relative to the scene's world coordinate space.

simdWorldPosition

The node's position relative to the scene's world coordinate space.

Converting Between Coordinate Spaces

- simdConvertPosition:fromNode:

Converts a position to the node’s local coordinate space from that of another node.

- simdConvertPosition:toNode:

Converts a position from the node’s local coordinate space to that of another node.

- simdConvertTransform:fromNode:

Converts a transform to the node’s local coordinate space from that of another node.

- simdConvertTransform:toNode:

Converts a transform from the node’s local coordinate space to that of another node.

- simdConvertVector:fromNode:

Converts a direction vector to the node’s local coordinate space from that of another node.

- simdConvertVector:toNode:

Converts a direction vector from the node’s local coordinate space to that of another node.

Handling UI Focus

focusBehavior

The focus behavior for a node.

SCNNodeFocusBehavior

Options for the focusable states of a SceneKit node.

Working with GameplayKit

entity

The GameplayKit entity this node represents.

Managing the Node’s Transform (SceneKit Types)

transform

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

position

The translation applied to the node. Animatable.

rotation

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

eulerAngles

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

orientation

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

scale

The scale factor applied to the node. Animatable.

pivot

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

Performing Node-Relative Operations (SceneKit Types)

- rotateBy:aroundTarget:

Changes the node's position and orientation, relative to its current transform, through a rotation around the specified point in scene space.

- localTranslateBy:

Changes the node's position relative to its current position.

- localRotateBy:

Changes the node's orientation relative to its current orientation.

- lookAt:

Changes the node's orientation so that its local forward vector points toward the specified location.

- lookAt:up:localFront:

Changes the node's orientation so that the specified forward vector points toward the specified location.

Calculating Node-Relative Transforms (SceneKit Types)

localRight

The direction SceneKit treats as "right" in local space for all nodes.

localUp

The direction SceneKit treats as "up" in local space for all nodes.

localFront

The unit vector SceneKit treats as "forward" in local space for all nodes.

worldRight

The "right" (+X) direction vector relative to the node, expressed in world space.

worldUp

The "up" (+Y) direction vector relative to the node, expressed in world space.

worldFront

The "forward" (-Z) direction vector relative to the node, expressed in world space.

Managing Transforms in World Space (SceneKit Types)

worldTransform

The world transform applied to the node.

- setWorldTransform:

Sets the world transform applied to the node.

worldOrientation

The node's orientation relative to the scene's world coordinate space.

worldPosition

The node's position relative to the scene's world coordinate space.

Converting Between Coordinate Spaces (SceneKit Types)

- convertPosition:fromNode:

Converts a position to the node’s local coordinate space from that of another node.

- convertPosition:toNode:

Converts a position from the node’s local coordinate space to that of another node.

- convertTransform:fromNode:

Converts a transform to the node’s local coordinate space from that of another node.

- convertTransform:toNode:

Converts a transform from the node’s local coordinate space to that of another node.

- convertVector:fromNode:

Converts a direction vector to the node’s local coordinate space from that of another node.

- convertVector:toNode:

Converts a direction vector from the node’s local coordinate space to that of another node.

See Also

Scene Structure

Organizing a Scene with Nodes

Use nodes to define the structure of a scene.

SCNReferenceNode

A scene graph node that serves as a placeholder for content to be loaded from a separate scene file.

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