Latest 0.3.0
Homepage https://github.com/svtek/ARKitEnvironmentMapper
License MIT
Platforms ios 11.0
Frameworks Metal, MetalKit, ARKit, SceneKit, CoreGraphics, QuartzCore
Authors

CI Status
Version
License
Platform

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Installation

ARKitEnvironmentMapper is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod 'ARKitEnvironmentMapper'

Usage

To initialize with a base environment map with an image asset named, for example, "room", use the following code:

let environmentMapper = ARKitEnvironmentMapper(withImageName: "room")

Note that the input image has to have a 2:1 aspect ratio.

Alternatively, you can initialize it with a height and a color:

let environmentMapper = ARKitEnvironmentMapper(withMapHeight: 512, withDefaultColor: .red)

To start the mapping process, call the startMapping() method. You should call this method a couple of seconds after running your ARSession in order not to get wrong mappings on your environment map.

To stop the mapping process, simply call stopMapping().

To update the environment map with the current feed of the camera, you can use the following code in your class implementing ARSessionDelegate:

func session(_ session: ARSession, didUpdate frame: ARFrame) {
  environmentMapper.updateMap(withFrame: frame)
}

You can call updateMap(withFrame:) in didUpdate regardless of the preferred FPS, as it is not executed every frame. Its frequency is bound by the value ARKitEnvironmentMapper.Options.updatesPerSecond and the default value is 10 updates per second.

After mapping the environment for a while you can get the current generated environment map and set it as the environment map of your ARSCNView with the following code:

sceneView.scene.lightingEnvironment.contents = environmentMapper.currentEnvironmentMap(as: .cgImage)

Note: The ideal way to set this should be to use .mtlTexture as input to bypass any image conversion and memory operation overhead. However, due to an Apple bug, setting a MTLTexture as the environment map currently has no effect. If you think this is not an Apple bug and you do have a solution, please don’t hesitate to send a pull request.

Author

ARKitEnvironmentMapper Halil Ibrahim Kayim

Software Engineer @ Surreal
Twitter Github LinkedIn

License

ARKitEnvironmentMapper is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "ARKitEnvironmentMapper",
    "version": "0.3.0",
    "summary": "Real-time environment map generator for ARKit",
    "description": "A library that allows you to generate and update environment maps in real-time using the camera feed and ARKit's tracking capabilities.",
    "homepage": "https://github.com/svtek/ARKitEnvironmentMapper",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "halileohalilei": "[email protected]"
    },
    "source": {
        "git": "https://github.com/svtek/ARKitEnvironmentMapper.git",
        "tag": "0.3.0"
    },
    "social_media_url": "https://twitter.com/halileohalilei",
    "platforms": {
        "ios": "11.0"
    },
    "source_files": "ARKitEnvironmentMapper/Classes/**/*",
    "frameworks": [
        "Metal",
        "MetalKit",
        "ARKit",
        "SceneKit",
        "CoreGraphics",
        "QuartzCore"
    ],
    "pushed_with_swift_version": "4.0"
}

Pin It on Pinterest

Share This