밍맹의 생각날 때 적는 블로그

[Kotlin] ARCore를 이용한 AR 구현 (1) - 세팅 본문

안드로이드

[Kotlin] ARCore를 이용한 AR 구현 (1) - 세팅

mingmaeng 2020. 4. 1. 11:07

옛날부터 AR에 대한 흥미는 어느정도 있었지만 어떻게 만들어야할지 몰라 막막했을 때가 있었다. 그 때 당시 실력도 그렇게 좋지 못했고, 기초적인 부분에 대해서도 많이 부족했기 때문에 미뤄뒀다가 최근에 AR을 살짝 다루어 보았다.

구글에서 ARCore라는 아주 편리한 기능을 제공해주기 때문에 ARCore의 Sceneform을 이용해 볼 예정이다.

 


ARCore란?

ARCore는 구글에서 증강 현실 어플리케이션을 빌드할 수 있도록 만든 소프트웨어 개발 키트다. 그 중 Scenceform이라는 라이브러리가 존재하는데 이것을 이용하면 굉장히 쉽게 AR을 구현할 수 있게 된다.

자세한 내용은 링크를 참조하길 바란다.

 

ARCore.

https://developers.google.com/ar

 

ARCore - Google Developers

With ARCore, build new augmented reality experiences that seamlessly blend the digital and physical worlds. Transform the way people play, shop, learn, create, and experience the world together—at Google scale.

developers.google.com

 

Scenceform.

https://developers.google.com/sceneform/develop

 

Sceneform overview  |  Sceneform (1.15.0)  |  Google Developers

Sceneform makes it straightforward to render realistic 3D scenes in AR and non-AR apps, without having to learn OpenGL. It includes:

developers.google.com

 

주의사항

이번 실습에는 에뮬레이터가 아닌 실제 안드로이드 기기를 이용하여 실습할 예정이다. (물론 에뮬레이터로도 가능은 하다.)

먼저 본인의 기기가 ARCore가 지원되는 기기인지 다음 링크를 통해 확인해보길 바란다.

https://developers.google.com/ar/develop/

 

Choose your development environment  |  ARCore  |  Google Developers

 

developers.google.com

 


Setting

새로운 프로젝트를 만들고 ARCore를 사용하기 위해 몇 가지 세팅이 필요하다.

그 전에 안드로이드 스튜디오에서 ARCore를 사용하기 위해서 다음과 같은 조건이 필요하다.

 

  1. 안드로이드 스튜디오 버전 3.1 이상
  2. SDK API level 24 이상 ( minSdkVersion 24 이상 )

해당 조건을 만족하는 프로젝트를 생성하고 시작하면 된다.

먼저 SDK Manager -> plugins로 들어가 검색창에 scene을 검색하여 나오는 Google Sceneform Tools를 인스톨한다.

 

우측 상단 빨간 동그라미 클릭

 

검색창에 scene 검색 후 빨간 동그라미 plugin 인스톨(필자는 이미 돼있는 상태)

 

인스톨이 완료되었으면 gradle 설정을 한다. App Gradle에 다음과 같이 추가해 준다.

 

android {
	...
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    ...
}

 

ARCore는 Java8을 이용하기 때문에 권한을 설정 해준다.

 

dependencies {
	...

    // Provides ARCore Session and related resources.
    implementation 'com.google.ar:core:1.15.0'

    // Provides ArFragment, and other UX resources.
    implementation 'com.google.ar.sceneform.ux:sceneform-ux:1.15.0'

    // Alternatively, use ArSceneView without the UX dependency.
    implementation 'com.google.ar.sceneform:core:1.15.0'
}

 

그 다음 위의 코드와 같이 의존성을 추가해 준다.

의존성 추가가 완료되었으면 manifest파일에 추가적인 설정을 해주면 모든 준비가 끝나게 된다.

 

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="org.techtown.samplear">

    <uses-permission android:name="android.permission.CAMERA"/>
    <uses-feature android:glEsVersion="0x00030000" android:required="true" />
    <uses-feature android:name="android.hardware.camera.ar" android:required="true"/>

    <application
   		...

        <meta-data android:name="com.google.ar.core" android:value="required"/>
    </application>

</manifest>

 

ARCore에는 required와 optional이라는 두 가지 설정이 존재한다. required는 ARCore가 필수적으로 설치되어야 한다는 것이고, optional은 ARCore 설치가 선택적이라는 것이다. 대부분의 경우 required 타입을 사용한다.

 


세팅은 이것으로 모두 끝났고, 글이 길어질 수도 있기 때문에 다음 포스팅에 본격적인 구현으로 들어가 보겠다.

Comments