Home Reference Source Repository
import SCNView from 'jscenekit/js/SceneKit/SCNView.js'
public class | source

SCNView

A view for displaying 3D SceneKit content.

See:

Static Member Summary

Static Public Members
public static get

Constructor Summary

Public Constructor
public

constructor(frame: CGRect, options: Map<string, Object>): void

Initializes and returns a newly allocated SceneKit view object with the specified frame rectangle and options.

Member Summary

Public Members
public

A Boolean value that determines whether the user can manipulate the current point of view that is used to render the scene.

public

The antialiasing mode used for rendering the view’s scene.

public get

audioEngine: AVAudioEngine

SceneKit uses this audio engine to play sounds from SCNAudioPlayer objects attached to nodes in the scene.

public get

audioEnvironmentNode: AVAudioEnvironmentNode

SceneKit uses this audio node to spatialize sounds from SCNAudioPlayer objects attached to nodes in the scene.

public set
public get

Required.

public set
public get

Required.

public get
public set
public get
public get

colorPixelFormat: MTLPixelFormat

Use this property, along with the depthPixelFormat and stencilPixelFormat properties, if you perform custom drawing with Metal (see the SCNSceneRendererDelegate and SCNNodeRendererDelegate classes) and need to create a new MTLRenderPipelineState object to change the GPU state as part of your rendering.NoteThis property is valid only for scene renderers whose renderingAPI value is metal.

public get

commandQueue: MTLCommandQueue

Use this property to schedule additional command buffers for the Metal device to execute as part of the render cycle.

public get

context: WebGLRenderingContext

In macOS, the value of this property is a Core OpenGL cglContextObj object.In iOS, the value of this property is an EAGLContext object.

public get

currentRenderCommandEncoder: MTLRenderCommandEncoder

Use this render command encoder to encode additional rendering commands before or after SceneKit draws its own content.This property is valid only during the SceneKit rendering loop—that is, within one of the methods defined in the SCNSceneRendererDelegate protocol.

public set
public get

Required.

public set
public get

Required.

public get

Required.

public set

Required.

public get

depthPixelFormat: MTLPixelFormat

Use this property, along with the colorPixelFormat and stencilPixelFormat properties, if you perform custom drawing with Metal (see the SCNSceneRendererDelegate and SCNNodeRendererDelegate classes) and need to create a new MTLRenderPipelineState object to change the GPU state as part of your rendering.NoteThis property is valid only for scene renderers whose renderingAPI value is metal.

public get

device: MTLDevice

Use this property to create or look up other Metal resources that use the same device as your SceneKit renderer.NoteThis property is valid only for scene renderers whose renderingAPI value is metal.

public get

Required.

public set
public get

Required.

public set

Required.

public get

Required.

public set

loops: *

public set
public get

Required.

public

pixelFormat: NSOpenGLPixelFormat

The view’s OpenGL pixel format.

public get

Required.

public set
public

The animation frame rate that the view uses to render its scene.

public get

You choose a graphics technology when initializing a scene renderer:When initializing a SCNView object, use the init(frame:options:) initializer and the preferredRenderingAPI key.

public set
public get

Required.

public set
public get

Required.

public get

stencilPixelFormat: MTLPixelFormat

Use this property, along with the depthPixelFormat and colorPixelFormat properties, if you perform custom drawing with Metal (see the SCNSceneRendererDelegate and SCNNodeRendererDelegate classes) and need to create a new MTLRenderPipelineState object to change the GPU state as part of your rendering.NoteThis property is valid only for scene renderers whose renderingAPI value is metal.

public

Required.

Method Summary

Public Methods
public

appendTo(element: HTMLElement): void

public
public
public

convertFrom(point: *, view: *): *

public
public

flagsChangedWith(theEvent: NSEvent): void

public

A 2D point in the rendered screen coordinate space can refer to any point along a line segment in the 3D scene coordinate space.

public

Any node containing a camera or spotlight may serve as a point of view (see the pointOfView property for details).

public

keyDownWith(theEvent: NSEvent): void

public

keyUpWith(theEvent: NSEvent): void

public

mouseDownWith(theEvent: NSEvent): void

public

mouseDraggedWith(theEvent: NSEvent): void

public

mouseEnteredWith(theEvent: NSEvent): void

public

mouseExitedWith(theEvent: NSEvent): void

public

mouseMovedWith(theEvent: NSEvent): void

public

mouseUpWith(theEvent: NSEvent): void

public

Any node containing a camera or spotlight may serve as a point of view (see the pointOfView property for details).

public

otherMouseDownWith(theEvent: NSEvent): void

public

otherMouseDraggedWith(theEvent: NSEvent): void

public

otherMouseUpWith(theEvent: NSEvent): void

public

pause(sender: Object): void

This method has no effect if the scene is already paused.

public

play(sender: Object): void

This method has no effect if the scene is not paused.

public

prepare(objects: Object[], completionHandler: function(arg1: boolean): void): void

By default, SceneKit lazily loads resources onto the GPU for rendering.

public

By default, SceneKit lazily loads resources onto the GPU for rendering.

public

presentWithIncomingPointOfView(scene: SCNScene, transition: SKTransition, pointOfView: SCNNode, completionHandler: function(): void): void

Use this method to change the scene displayed in a SceneKit view (or other renderer) with an animated transition.

public

The z-coordinate of the returned point describes the depth of the projected point relative to the near and far clipping planes of the renderer’s viewing frustum (defined by its pointOfView node).

public

rightMouseDraggedWith(theEvent: NSEvent): void

public

rightMouseUpWith(theEvent: NSEvent): void

public

scrollWheelWith(theEvent: NSEvent): void

public

setFrameSize(newSize: *)

public

snapshot(): Image

This method is thread-safe and may be called at any time.

public

stop(sender: Object): void

Stops playback of the view’s scene and resets the scene time to its start time.

public

tablePointWith(theEvent: NSEvent): void

public

tableProximityWith(theEvent: NSEvent): void

public

The z-coordinate of the point parameter describes the depth at which to unproject the point relative to the near and far clipping planes of the renderer’s viewing frustum (defined by its pointOfView node).

public

Static Public Members

public static get Option: Object source

Properties:

NameTypeAttributeDescription
preferLowPowerDevice string

An option for whether to select low-power-usage devices for Metal rendering.

preferredDevice string

The device to use for Metal rendering.

preferredRenderingAPI string

The rendering API to use for rendering the view (for example, Metal or OpenGL).

See:

Public Constructors

public constructor(frame: CGRect, options: Map<string, Object>): void source

Initializes and returns a newly allocated SceneKit view object with the specified frame rectangle and options.

Params:

NameTypeAttributeDescription
frame CGRect

The frame rectangle for the view, measured in points and specified in the coordinate system of its superview.

options Map<string, Object>
  • optional
  • default: null
  • nullable: true

Rendering options for the view. See SCNView.

Return:

void

See:

Public Members

public allowsCameraControl: boolean source

A Boolean value that determines whether the user can manipulate the current point of view that is used to render the scene.

See:

public antialiasingMode: SCNAntialiasingMode source

The antialiasing mode used for rendering the view’s scene.

See:

public get audioEngine: AVAudioEngine source

SceneKit uses this audio engine to play sounds from SCNAudioPlayer objects attached to nodes in the scene. You can use this object directly to add other sound sources not related to scene contents, or to add other sound processing nodes or mixing nodes to the audio engine. To identify the node SceneKit uses for spatializing scene sounds when connecting other nodes, use the audioEnvironmentNode property.

See:

public get audioEnvironmentNode: AVAudioEnvironmentNode source

SceneKit uses this audio node to spatialize sounds from SCNAudioPlayer objects attached to nodes in the scene. You can use this object in conjunction with the audioEngine property to rearrange the audio graph to add other, non-spatialized audio sources or mix in audio processing effects.

See:

public set audioListener: * source

public get audioListener: SCNNode source

Required. The node representing the listener’s position in the scene for use with positional audio effects.

See:

public set autoenablesDefaultLighting: * source

public get autoenablesDefaultLighting: boolean source

Required. A Boolean value that determines whether SceneKit automatically adds lights to a scene.

See:

public get backgroundColor: * source

public set backgroundColor: * source

public get bounds: CGRect source

public get colorPixelFormat: MTLPixelFormat source

Use this property, along with the depthPixelFormat and stencilPixelFormat properties, if you perform custom drawing with Metal (see the SCNSceneRendererDelegate and SCNNodeRendererDelegate classes) and need to create a new MTLRenderPipelineState object to change the GPU state as part of your rendering.NoteThis property is valid only for scene renderers whose renderingAPI value is metal. You create a SceneKit view that renders using Metal with the preferredRenderingAPI initialization option or in Interface Builder, or an SCNRenderer that uses Metal with the init(device:options:) method. For OpenGL-based scene renderers, this property’s value is always nil.

See:

public get commandQueue: MTLCommandQueue source

Use this property to schedule additional command buffers for the Metal device to execute as part of the render cycle. For example, you can use a compute command encoder to modify the vertex data in a Metal buffer for use by a SCNGeometrySource object.NoteThis property is valid only for scene renderers whose renderingAPI value is metal. You create a SceneKit view that renders using Metal with the preferredRenderingAPI initialization option or in Interface Builder, or an SCNRenderer that uses Metal with the init(device:options:) method. For OpenGL-based scene renderers, this property’s value is always nil.

See:

public get context: WebGLRenderingContext source

In macOS, the value of this property is a Core OpenGL cglContextObj object.In iOS, the value of this property is an EAGLContext object.

See:

public get currentRenderCommandEncoder: MTLRenderCommandEncoder source

Use this render command encoder to encode additional rendering commands before or after SceneKit draws its own content.This property is valid only during the SceneKit rendering loop—that is, within one of the methods defined in the SCNSceneRendererDelegate protocol. Accessing this property at any other time returns nil.

See:

public set currentTime: * source

public set debugOptions: * source

public get debugOptions: SCNDebugOptions source

Required. Options for drawing overlay content in a scene that can aid debugging.

See:

public get delegate: SCNSceneRendererDelegate source

Required. A delegate object that receives messages about SceneKit’s rendering process.

See:

public set delegate(newValue: SCNSceneRendererDelegate): SCNSceneRendererDelegate source

Required. A delegate object that receives messages about SceneKit’s rendering process.

See:

public get depthPixelFormat: MTLPixelFormat source

Use this property, along with the colorPixelFormat and stencilPixelFormat properties, if you perform custom drawing with Metal (see the SCNSceneRendererDelegate and SCNNodeRendererDelegate classes) and need to create a new MTLRenderPipelineState object to change the GPU state as part of your rendering.NoteThis property is valid only for scene renderers whose renderingAPI value is metal. You create a SceneKit view that renders using Metal with the preferredRenderingAPI initialization option or in Interface Builder, or an SCNRenderer that uses Metal with the init(device:options:) method. For OpenGL-based scene renderers, this property’s value is always nil.

See:

public get device: MTLDevice source

Use this property to create or look up other Metal resources that use the same device as your SceneKit renderer.NoteThis property is valid only for scene renderers whose renderingAPI value is metal. You create a SceneKit view that renders using Metal with the preferredRenderingAPI initialization option or in Interface Builder, or an SCNRenderer that uses Metal with the init(device:options:) method. For OpenGL-based scene renderers, this property’s value is always nil.

See:

public get isJitteringEnabled: boolean source

Required. A Boolean value that determines whether SceneKit applies jittering to reduce aliasing artifacts.

See:

public set isJitteringEnabled: * source

public get isPlaying: boolean source

Required. A Boolean value that determines whether the scene is playing.

See:

public set isPlaying: boolean source

Required. A Boolean value that determines whether the scene is playing.

See:

public get loops: boolean source

Required. A Boolean value that determines whether SceneKit restarts the scene time after all animations in the scene have played.

See:

public set loops: * source

public set overlaySKScene: * source

public get overlaySKScene: SKScene source

Required. A Sprite Kit scene to be rendered on top of the SceneKit content.

See:

public pixelFormat: NSOpenGLPixelFormat source

The view’s OpenGL pixel format.

See:

public get pointOfView: SCNNode source

Required. The node from which the scene’s contents are viewed for rendering.

See:

public set pointOfView: * source

public preferredFramesPerSecond: number source

The animation frame rate that the view uses to render its scene.

See:

public get renderingAPI: SCNRenderingAPI source

You choose a graphics technology when initializing a scene renderer:When initializing a SCNView object, use the init(frame:options:) initializer and the preferredRenderingAPI key. Alternatively, create a view in Interface Builder and use the Rendering API control in the inspector. During initialization, the view will attempt to use the preferred API, but will fall back to a different API if the preferred one is not supported on the current hardware.To create a SCNRenderer object that renders into your own OpenGL contect, use the init(context:options:) initializer. To create a renderer for use in your own Metal workflow, use the init(device:options:) initializer.The rendering technology used by a SCNLayer object is determined by Core Animation.After initializing a renderer, this property reflects the rendering technology in use.

See:

public set sceneTime: * source

public set showsStatistics: * source

public get showsStatistics: boolean source

Required. A Boolean value that determines whether SceneKit displays rendering performance statistics in an accessory view.

See:

public get stencilPixelFormat: MTLPixelFormat source

Use this property, along with the depthPixelFormat and colorPixelFormat properties, if you perform custom drawing with Metal (see the SCNSceneRendererDelegate and SCNNodeRendererDelegate classes) and need to create a new MTLRenderPipelineState object to change the GPU state as part of your rendering.NoteThis property is valid only for scene renderers whose renderingAPI value is metal. You create a SceneKit view that renders using Metal with the preferredRenderingAPI initialization option or in Interface Builder, or an SCNRenderer that uses Metal with the init(device:options:) method. For OpenGL-based scene renderers, this property’s value is always nil.

See:

public technique: SCNTechnique source

Required. The technique SceneKit uses when rendering the object.

See:

Public Methods

public appendTo(element: HTMLElement): void source

Params:

NameTypeAttributeDescription
element HTMLElement

parent element to append this view

Return:

void

public attributeChangedCallback() source

public connectedCallback() source

public convertFrom(point: *, view: *): * source

Params:

NameTypeAttributeDescription
point *
view *

Return:

*

public disconnectedCallback() source

public flagsChangedWith(theEvent: NSEvent): void source

Params:

NameTypeAttributeDescription
theEvent NSEvent

Return:

void

public hitTest(point: CGPoint, options: Map<SCNHitTestOption, Object>): SCNHitTestResult[] source

A 2D point in the rendered screen coordinate space can refer to any point along a line segment in the 3D scene coordinate space. Hit-testing is the process of finding elements of a scene located along this line segment. For example, you can use this method to find the geometry corresponding to a click event in a SceneKit view.

Params:

NameTypeAttributeDescription
point CGPoint
options Map<SCNHitTestOption, Object>
  • optional
  • default: null
  • nullable: true

A dictionary of options affecting the search. See Hit Testing Options Keys for acceptable values.

Return:

SCNHitTestResult[]

See:

public isNodeInsideFrustumOf(node: SCNNode, pointOfView: SCNNode): boolean source

Any node containing a camera or spotlight may serve as a point of view (see the pointOfView property for details). Such a node defines a viewing frustum—a portion of the scene’s coordinate space, shaped like a truncated pyramid, that encloses all points visible from that point of view.Use this method to test whether a node lies within the viewing frustum defined by another node (which may or may not be the scene renderer’s current pointOfView node). For example, in a game scene containing multiple camera nodes, you could use this method to determine which camera is currently best for viewing a moving player character.Note that this method does not perform occlusion testing. That is, it returns true if the tested node lies within the specified viewing frustum regardless of whether that node’s contents are obscured by other geometry.

Params:

NameTypeAttributeDescription
node SCNNode

The node whose visibility is to be tested.

pointOfView SCNNode

A node defining a point of view, as used by the pointOfView property.

Return:

boolean

See:

public keyDownWith(theEvent: NSEvent): void source

Params:

NameTypeAttributeDescription
theEvent NSEvent

Return:

void

public keyUpWith(theEvent: NSEvent): void source

Params:

NameTypeAttributeDescription
theEvent NSEvent

Return:

void

public mouseDownWith(theEvent: NSEvent): void source

Params:

NameTypeAttributeDescription
theEvent NSEvent

Return:

void

public mouseDraggedWith(theEvent: NSEvent): void source

Params:

NameTypeAttributeDescription
theEvent NSEvent

Return:

void

public mouseEnteredWith(theEvent: NSEvent): void source

Params:

NameTypeAttributeDescription
theEvent NSEvent

Return:

void

public mouseExitedWith(theEvent: NSEvent): void source

Params:

NameTypeAttributeDescription
theEvent NSEvent

Return:

void

public mouseMovedWith(theEvent: NSEvent): void source

Params:

NameTypeAttributeDescription
theEvent NSEvent

Return:

void

public mouseUpWith(theEvent: NSEvent): void source

Params:

NameTypeAttributeDescription
theEvent NSEvent

Return:

void

public nodesInsideFrustumOf(pointOfView: SCNNode): SCNNode[] source

Any node containing a camera or spotlight may serve as a point of view (see the pointOfView property for details). Such a node defines a viewing frustum—a portion of the scene’s coordinate space, shaped like a truncated pyramid, that encloses all points visible from that point of view.Use this method find all nodes whose content lies within the viewing frustum defined by another node (which may or may not be the scene renderer’s current pointOfView node).Note that this method does not perform occlusion testing. That is, the returned array includes any node that lies within the specified viewing frustum regardless of whether that node’s contents are obscured by other geometry.

Params:

NameTypeAttributeDescription
pointOfView SCNNode

A node defining a point of view, as used by the pointOfView property.

Return:

SCNNode[]

See:

public otherMouseDownWith(theEvent: NSEvent): void source

Params:

NameTypeAttributeDescription
theEvent NSEvent

Return:

void

public otherMouseDraggedWith(theEvent: NSEvent): void source

Params:

NameTypeAttributeDescription
theEvent NSEvent

Return:

void

public otherMouseUpWith(theEvent: NSEvent): void source

Params:

NameTypeAttributeDescription
theEvent NSEvent

Return:

void

public pause(sender: Object): void source

This method has no effect if the scene is already paused.

Params:

NameTypeAttributeDescription
sender Object
  • nullable: true

The object requesting the action (used when connecting a control in Interface Builder). SceneKit ignores this parameter.

Return:

void

See:

public play(sender: Object): void source

This method has no effect if the scene is not paused.

Params:

NameTypeAttributeDescription
sender Object
  • nullable: true

The object requesting the action (used when connecting a control in Interface Builder). SceneKit ignores this parameter.

Return:

void

See:

public prepare(objects: Object[], completionHandler: function(arg1: boolean): void): void source

By default, SceneKit lazily loads resources onto the GPU for rendering. This approach uses memory and GPU bandwidth efficiently, but can lead to stutters in an otherwise smooth frame rate when you add large amounts of new content to an animated scene. To avoid such issues, use this method to prepare content for drawing before adding it to the scene. SceneKit uses a secondary thread to prepare content asynchronously.SceneKit prepares all content associated with the objects you provide. If you provide an SCNMaterial object, SceneKit loads any texture images assigned to its material properties. If you provide an SCNGeometry object, SceneKit loads all materials attached to the geometry, as well as its vertex data. If you provide an SCNNode or SCNScene object, SceneKit loads all geometries and materials associated with the node and all its child nodes, or with the entire node hierarchy of the scene.You can observe the progress of this operation with the Progress class. For details, see Progress.

Params:

NameTypeAttributeDescription
objects Object[]

An array of containing one or more SCNScene, SCNNode, SCNGeometry, or SCNMaterial instances.

completionHandler function(arg1: boolean): void
  • optional
  • default: null
  • nullable: true

A block that SceneKit calls when object preparation fails or completes.The block takes the following parameter:successtrue if all content was successfully prepared for rendering; otherwise, false.

Return:

void

See:

public prepareShouldAbortBlock(object: Object, block: function(): boolean): boolean source

By default, SceneKit lazily loads resources onto the GPU for rendering. This approach uses memory and GPU bandwidth efficiently, but can lead to stutters in an otherwise smooth frame rate when you add large amounts of new content to an animated scene. To avoid such issues, use this method to prepare content for drawing before adding it to the scene. You can call this method on a secondary thread to prepare content asynchronously. SceneKit prepares all content associated with the object parameter you provide. If you provide an SCNMaterial object, SceneKit loads any texture images assigned to its material properties. If you provide an SCNGeometry object, SceneKit loads all materials attached to the geometry, as well as its vertex data. If you provide an SCNNode or SCNScene object, SceneKit loads all geometries and materials associated with the node and all its child nodes, or with the entire node hierarchy of the scene.You can use the block parameter to cancel preparation if content is no longer needed. For example, in a game you might use this method to preload areas of the game world the player is soon to enter, but if the player character dies before entering those areas, you can return true from the block to cancel preloading.You can observe the progress of this operation with the Progress class. For details, see Progress.

Params:

NameTypeAttributeDescription
object Object

An SCNScene, SCNNode, SCNGeometry, or SCNMaterial instance.

block function(): boolean
  • optional
  • default: null
  • nullable: true

A block that SceneKit calls periodically while preparing the object. The block takes no parameters.Your block should return false to tell SceneKit to continue preparing the object, or true to cancel preparation.Pass nil for this parameter if you do not need an opportunity to cancel preparing the object.

Return:

boolean

See:

public presentWithIncomingPointOfView(scene: SCNScene, transition: SKTransition, pointOfView: SCNNode, completionHandler: function(): void): void source

Use this method to change the scene displayed in a SceneKit view (or other renderer) with an animated transition. For details on transition styles, see SKTransition.

Params:

NameTypeAttributeDescription
scene SCNScene

The new scene to be displayed.

transition SKTransition

An object that specifies the duration and style of the animated transition.

pointOfView SCNNode
  • nullable: true

The node to use as the pointOfView property when displaying the new scene.

completionHandler function(): void
  • optional
  • default: null
  • nullable: true

A block that SceneKit calls after the transition animation has completed.This block takes no parameters and has no return value.

Return:

void

See:

public projectPoint(point: SCNVector3): SCNVector3 source

The z-coordinate of the returned point describes the depth of the projected point relative to the near and far clipping planes of the renderer’s viewing frustum (defined by its pointOfView node). Projecting a point on the near clipping plane returns a point whose z-coordinate is 0.0; projecting a point on the far clipping plane returns a point whose z-coordinate is 1.0.

Params:

NameTypeAttributeDescription
point SCNVector3

A point in the world coordinate system of the renderer’s scene.

Return:

SCNVector3

See:

public rightMouseDraggedWith(theEvent: NSEvent): void source

Params:

NameTypeAttributeDescription
theEvent NSEvent

Return:

void

public rightMouseUpWith(theEvent: NSEvent): void source

Params:

NameTypeAttributeDescription
theEvent NSEvent

Return:

void

public scrollWheelWith(theEvent: NSEvent): void source

Params:

NameTypeAttributeDescription
theEvent NSEvent

Return:

void

public setFrameSize(newSize: *) source

Params:

NameTypeAttributeDescription
newSize *

public snapshot(): Image source

This method is thread-safe and may be called at any time.

Return:

Image

See:

public stop(sender: Object): void source

Stops playback of the view’s scene and resets the scene time to its start time.

Params:

NameTypeAttributeDescription
sender Object
  • nullable: true

The object requesting the action (used when connecting a control in Interface Builder). SceneKit ignores this parameter.

Return:

void

See:

public tablePointWith(theEvent: NSEvent): void source

Params:

NameTypeAttributeDescription
theEvent NSEvent

Return:

void

public tableProximityWith(theEvent: NSEvent): void source

Params:

NameTypeAttributeDescription
theEvent NSEvent

Return:

void

public unprojectPoint(point: SCNVector3): SCNVector3 source

The z-coordinate of the point parameter describes the depth at which to unproject the point relative to the near and far clipping planes of the renderer’s viewing frustum (defined by its pointOfView node). Unprojecting a point whose z-coordinate is 0.0 returns a point on the near clipping plane; unprojecting a point whose z-coordinate is 1.0 returns a point on the far clipping plane.A 2D point in the rendered screen coordinate space can refer to any point along a line segment in the 3D scene coordinate space. To test for scene contents along this line—for example, to find the geometry corresponding to the location of a click event in a view—use the hitTest(_:options:) method.

Params:

NameTypeAttributeDescription
point SCNVector3

A point in the screen-space (view, layer, or GPU viewport) coordinate system of the scene renderer.

Return:

SCNVector3

See:

public viewDidMoveToWindow() source