项目作者: VoxxxelAR

项目描述 :
Voxel graphics framework using ARKit + SceneKit
高级语言: Swift
项目地址: git://github.com/VoxxxelAR/ARVoxelKit.git
创建时间: 2017-09-26T16:49:57Z
项目社区:https://github.com/VoxxxelAR/ARVoxelKit

开源协议:MIT License

下载


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:
  1. import ARVoxelKit
  2. import ARKit
  3. import SceneKit
  1. Setup your ARSCNView with VKSceneManager manager in you ViewContoller:
  1. var sceneManager: VKSceneManager?
  2. @IBOutlet open var sceneView: ARSCNView! {
  3. didSet { sceneManager = VKSceneManager(with: sceneView) }
  4. }
  5. override open func viewDidLoad() {
  6. super.viewDidLoad()
  7. sceneManager.delegate = self
  8. }
  9. override open func viewDidAppear(_ animated: Bool) {
  10. super.viewDidAppear(animated)
  11. sceneManager?.launchSession()
  12. }
  13. override open func viewWillDisappear(_ animated: Bool) {
  14. super.viewWillDisappear(animated)
  15. sceneManager?.pauseSession()
  16. }
  1. Conform your delegate instance to VKSceneManagerDelegate:
  1. public protocol VKSceneManagerDelegate: class {
  2. var voxelSize: CGFloat { get }
  3. func vkSceneManager(_ manager: VKSceneManager, shouldResetSessionFor state: VKARSessionState) -> Bool
  4. func vkSceneManager(_ manager: VKSceneManager, didUpdateState state: VKARSessionState)
  5. func vkSceneManager(_ manager: VKSceneManager, didFocus node: VKDisplayable, face: VKVoxelFace)
  6. func vkSceneManager(_ manager: VKSceneManager, didDefocus node: VKDisplayable?)
  7. func vkSceneManager(_ manager: VKSceneManager, countOfVoxelsIn scene: ARSCNView) -> Int
  8. func vkSceneManager(_ manager: VKSceneManager, voxelFor index: Int) -> VKVoxelNode
  9. }
  1. You can add/remove voxels by calling manager methods:

    1. public func add(new voxel: VKVoxelNode)
    2. public func add(new voxel: VKVoxelNode, to otherVoxel: VKVoxelNode, face: VKVoxelFace)
    3. public func add(new voxel: VKVoxelNode, to tile: VKTileNode)
    4. public func remove(_ voxel: VKVoxelNode)
  2. Edit surfaces, tiles, voxels using paint command:

    1. public enum VKPaintCommand {
    2. case color(content: UIColor)
    3. case faceColor(content: UIColor, face: VKVoxelFace)
    4. case colors(contents: [UIColor])
    5. case image(content: UIImage)
    6. case faceImage(content: UIImage, face: VKVoxelFace)
    7. case images(contents: [UIImage])
    8. case gradient(contents: [UIColor], start: CGPoint, end: CGPoint)
    9. case faceGradient(contents: [UIColor], start: CGPoint, end: CGPoint, face: VKVoxelFace)
    10. case transparency(value: CGFloat)
    11. case faceTransparency(value: CGFloat, face: VKVoxelFace)
    12. }

    for example:

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

Example

Check our example by running ARVoxelKitExample target