Git Product home page Git Product logo

arkitenvironmentmapper's Introduction

ARKitEnvironmentMapper

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.

Output

Below is a sample output ARKitEnvironmentMapper generates when initialized with a base environment map:

=>

Here is another sample output when initialized with a white background in the same environment:

Author

Halil Ibrahim Kayim

Software Engineer @ Surreal
Twitter Github LinkedIn

License

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

arkitenvironmentmapper's People

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.