Giter Club home page Giter Club logo

arvoxelkit's Introduction

ARVoxelKit

Lightweight Framework for Voxel graphic using AR + SceneKit

Build Status

Requirements

ARVoxelKit requires iOS 11 and devices, which support ARKit

Usage

  1. Import libraries as follows:
import ARVoxelKit
import ARKit
import SceneKit
  1. Setup your ARSCNView with VKSceneManager manager in you ViewContoller:
var sceneManager: VKSceneManager?

@IBOutlet open var sceneView: ARSCNView! {
    didSet { sceneManager = VKSceneManager(with: sceneView) }
}

override open func viewDidLoad() {
    super.viewDidLoad()
    sceneManager.delegate = self
}

override open func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)
    sceneManager?.launchSession()
}

override open func viewWillDisappear(_ animated: Bool) {
    super.viewWillDisappear(animated)
    sceneManager?.pauseSession()
}
  1. Conform your delegate instance to VKSceneManagerDelegate:
public protocol VKSceneManagerDelegate: class {
    var voxelSize: CGFloat { get }
    
    func vkSceneManager(_ manager: VKSceneManager, shouldResetSessionFor state: VKARSessionState) -> Bool
    func vkSceneManager(_ manager: VKSceneManager, didUpdateState state: VKARSessionState)
    func vkSceneManager(_ manager: VKSceneManager, didFocus node: VKDisplayable, face: VKVoxelFace)
    func vkSceneManager(_ manager: VKSceneManager, didDefocus node: VKDisplayable?)
    func vkSceneManager(_ manager: VKSceneManager, countOfVoxelsIn scene: ARSCNView) -> Int
    func vkSceneManager(_ manager: VKSceneManager, voxelFor index: Int) -> VKVoxelNode
}
  1. You can add/remove voxels by calling manager methods:
public func add(new voxel: VKVoxelNode)
public func add(new voxel: VKVoxelNode, to otherVoxel: VKVoxelNode, face: VKVoxelFace)
public func add(new voxel: VKVoxelNode, to tile: VKTileNode)
public func remove(_ voxel: VKVoxelNode)
  1. Edit surfaces, tiles, voxels using paint command:
public enum VKPaintCommand {
    
    case color(content: UIColor)
    case faceColor(content: UIColor, face: VKVoxelFace)
    case colors(contents: [UIColor])
    
    case image(content: UIImage)
    case faceImage(content: UIImage, face: VKVoxelFace)
    case images(contents: [UIImage])
    
    case gradient(contents: [UIColor], start: CGPoint, end: CGPoint)
    case faceGradient(contents: [UIColor], start: CGPoint, end: CGPoint, face: VKVoxelFace)
    
    case transparency(value: CGFloat)
    case faceTransparency(value: CGFloat, face: VKVoxelFace)
}

for example:

voxel.apply([.color(content: VKConstants.defaultFaceColor),
             .transparency(value: 1)], animated: true)
  1. Change default setup by changing VKConstants values

Example

Check our example by running ARVoxelKitExample target

arvoxelkit's People

Contributors

la4 avatar la4ce avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.