TorchProjectNode

public class TorchProjectNode : SCNNode

TorchProjectNode is the class that loads a .torchkitproj and generates child nodes to execute a Torch project. It handles asset loading and unloading, creating child nodes, and responding to updates in the scene. However, there are a few support functions that must be called in order for everything to work:

  • tick must be called once a frame to advance the project state.
  • tap must be called when an object has been tapped. This is handled automatically if the TorchGestureManager is used.
  • The path to the uncompressed project this node has loaded.

    Declaration

    Swift

    @objc
    public var projectPath: URL!
  • If set, any open URL requested made from the Torch project are routed to this callback. Otherwise, the URL is loaded by the system open URL call.

    Declaration

    Swift

    @objc
    public var openURLHandler: ((URL) -> Void)?
  • If set, any call API requested made from the Torch project are routed to this callback. Otherwise, the API request is made using URLSession.

    Declaration

    Swift

    @objc
    public var callAPIHandler: ((URL) -> Void)?
  • If set, this callback will be called when the scene changes in the Torch project.

    Declaration

    Swift

    @objc
    public var sceneChanged: ((TorchKitSceneIdName) -> Void)?
  • If set, this callback will be called when a trigger is fired in the Torch project.

    Declaration

    Swift

    @objc
    public var triggerFired: ((TorchKitSceneObjectIdName) -> Void)?
  • If set, this callback will be called when all of the responses to a trigger have finished.

    Declaration

    Swift

    @objc
    public var triggerFinished: ((TorchKitSceneObjectIdName) -> Void)?
  • If the application is using ARKit, the project’s arSessionDelegate methods must be called, either by setting the ARSession.delegate to TorchProjectNode.arSessionDelegate or by calling the delegate methods from the application’s ARSessionDelegate implementation.

    Declaration

    Swift

    @objc
    public var arSessionDelegate: ARSessionDelegate? { get }
  • This returns the list of scenes in the project.

    Declaration

    Swift

    @objc
    public lazy var scenes: [TorchKitSceneIdName] { get set }
  • This is the currently displayed scene in the project.

    Declaration

    Swift

    @objc
    public var currentScene: TorchKitSceneIdName { get }
  • This is a list of all of the triggers in a project.

    Declaration

    Swift

    @objc
    public var projectTriggers: [TorchKitSceneObjectIdName] { get }
  • This is a list of all of the triggers in the current scene.

    Declaration

    Swift

    @objc
    public var currentSceneTriggers: [TorchKitSceneObjectIdName] { get }
  • init is called to initialize a new TorchProjectNode.

    Declaration

    Swift

    @objc
    public init(withProjectURL projectURL: URL, andDevice device: MTLDevice, arSession: ARSession? = nil) throws

    Parameters

    withProjectURL

    URL pointing to the .torchkitproj to load. Only local file URL’s are supported at the moment.

    andDevice

    The Metal device used for rendering, this can be grabbed from the SCNView normally.

    arSession

    The current ARSession from ARKit, can be null if ARKit is not being used.

  • Call closeProject after the application is done displaying this Torch Project to cleanup resources. It is automatically called during deinit.

    Declaration

    Swift

    @objc
    public func closeProject()
  • tick advances the project state. It should be called from SCNSceneRendererDelegate renderer(_:updateAtTime:) method.

    Declaration

    Swift

    @objc
    public func tick(delta: Double, cameraTransform: simd_float4x4, currentGazedNode: SCNNode?)

    Parameters

    delta

    The change in time from the last tick. Units are seconds.

    cameraTransform

    The current camera transform, can be passed directly from arSession.currentFrame.camera.transform if using ARKit.

    currentGazedNode

    The SCNNode that the camera is currently pointing at. Use the .hitTest method on SCNScene to find this node.

  • tap should be called when an SCNNode has been tapped by the user. This is handled automatically if TorchGestureManager is used.

    Declaration

    Swift

    @objc
    public func tap(node: SCNNode)
  • setSceneById sets the current scene using the id field of TorchKitScene.

    Declaration

    Swift

    @objc
    public func setScene(sceneId: String, resetCurrentScene: Bool)

    Parameters

    sceneId

    The scene id to switch to

    resetCurrentScene

    If true, the current scene’s state will be reset to its initial state.

  • setSceneByName sets the current scene using the name field of TorchKitScene.

    Declaration

    Swift

    @objc
    public func setScene(sceneName: String, resetCurrentScene: Bool)

    Parameters

    sceneName

    The name of the scene to switch to, if there are multiple scenes with the same name it will select the first one.

    resetCurrentScene

    If true, the current scene’s state will be reset to its initial state.

  • Declaration

    Swift

    @objc
    public func resetScene(sceneId: String)
  • fireTriggerById will manually fire trigger and cause the interaction associated with the trigger to run.

    Declaration

    Swift

    @objc
    public func fireTrigger(triggerId: String)

    Parameters

    triggerId

    The id of the trigger to fire.

  • fireTriggerByName will manually fire trigger and cause the interaction associated with the trigger to run.

    Declaration

    Swift

    @objc
    public func fireTrigger(triggerName: String)

    Parameters

    triggerName

    The name of the trigger to fire.