Getting Started

Import CubeKit

import DigitalblendKit
import CubeKit

Configure CubeKit

By default CubeKit choose the best possible configuration for the current device.

// By default:
CKConfiguation.shared = .auto

// Force configuration with specific prefab:
CKConfiguration.shaared = .iPhone // or .iPad or .mac

// Set/Get properties from current configuration:
CKConfiguration.shared.cameraMoveLimit = 10 // degree
CKConfiguration.shared.cameraZoomLimit = 30 // percent

Create CubeKit Views

Create CubeKit Views.

class ViewController: UIViewController {
    @IBOutlet weak var ck3dview: SCNView!
    @IBOutlet weak var ckarview: ARSCNView!
}

Create CubeKit Cubes

class ViewController: UIViewController {
    ...
    private var ck3dcube: CK3DCube!
    private var ckarcube: CKARCube!

    override func viewDidLoad() {
        ...
        self.ck3dcube = CK3DCube(inView: self.ck3dview)
        self.ckarcube = CKARCube(inView: self.ckarview)
    }
}

Create CubeKit Scene

class ViewController: UIViewController {
    ...
    private var scene: CKScene!

    override func viewDidLoad() {
        ...
        // Create an empty scene
        self.scene = CKScene()

        // Loads a scene from a file with the specified name in a specific subdirectory of the app’s main bundle.
        self.scene = CKScene(named: "ship.scn", inSubDirectory: "art.scnassets")

        // Loads a scene from the specified URL.
        self.scene = CKScene(url: URL)
    }
}

Work with 3D Cube

  1. Start & Stop displaying scene in 3D Cube
self.ck3dcube.start(withScene: CKScene)
self.ck3dcube.stop()
  1. Change scene’s point of view
self.ck3dcube.camera.change(to: String)
  1. Receive events from 3D Cube with delegate
class ViewController: UIViewController {
    ...

    override func viewDidLoad() {
        ...
        self.ck3dcube.delegate = self
    }
}


extension ViewController: CK3DCubeDelegate {

    func gesture(didSinglePanWithVelocity: CGPoint) {
    }

    func gesture(didDoublePanWithVelocity: CGPoint) {
    }

    func gesture(didSingleTapAtPosition position: CGPoint) {
    }

    func gesture(didDoubleTapAtPosition position: CGPoint) {
    }

    func gesture(didPinchWithVelocity: CGFloat) {
    }

}

Work with AR Cube

  1. Start & Stop displaying scene in AR Cube
self.ckarcube.start(withScene: CKScene)
self.ckarcube.stop()
  1. Receive events from AR Cube with delegate
class ViewController: UIViewController {
    ...

    override func viewDidLoad() {
        ...
        self.ckarcube.delegate = self
    }


}


extension ViewController: CKARCubeDelegate {

    func trackingIsInitializing() {
    }

    func trackingWasInterrupted() {
    }

    func trackingInterruptionEnded() {
    }

    func tracking(didChangeState state: CKARCube.TrackingState) {
    }

    func tracking(didFailedWithError error: Error) {
    }

    func cubeDidPlaceScene() {
    }

}

Change the cube that display scene dynamicaly and animated

See CKCube iOS Specifics Helpers. CKCube iOS Specifics Helpers

Work with Scene

  1. Find scene’s node
// Get root node
let node: SCNNode = self.scene.rootNode

// Find node with name
let node: SCNNode? = self.scene.rootNode.childNode(withName: String, recursibely: Bool?)

// Find nodes with test
let node: SCNNode? = self.scene.rootNode.childNodes(passingTest: (SCNNode, UnsafeMutablePointer<ObjCBool)> -> Bool)
  1. Start or stop an animation attached to a scene’s node
// Start : for a looped animation -> repeatCount: .infinity
self.scene.startAnimation(forNodeName: String, animationName: String, repeatCount: Float)

// Stop
self.scene.stopAnimation(forNodeName: String, animationName: String)