Sei sulla pagina 1di 34

Getting started with Unity and Android Studio

Akram Zeyada
Solutions Engineer at orange and Team leader of GDG Delta
Proprietary and Confidential
Agenda

ARCore Overview

ARCore with Unity

ARCore with Sceneform


ARCore Overview
Proprietary and Confidential
ARCore Overview

Augmented Reality
AR can bring anything to you. It adds
computer-generated information and
objects to your everyday world.
Proprietary and Confidential
ARCore Overview

AR can be useful Image


Proprietary and Confidential
ARCore Overview

AR can be fun
Proprietary and Confidential
ARCore Overview

AR can be fun Image


Proprietary and Confidential
ARCore Overview

ARCore

Image
Proprietary and Confidential
ARCore Overview

Who can run ARCore Applications

ARCore is compatible with 100+ million Supported in China too!


devices (and growing!)
Proprietary and Confidential
ARCore Overview

ARCore Android Capabilities

Motion Environmental Light


Tracking Understanding Estimation
Proprietary and Confidential
ARCore Overview

Light Estimation
ARCore captures information about the
lighting of the environment.
Proprietary and Confidential
ARCore Overview

Motion Tracking
ARCore combines visual data from the
device’s camera and motion data from the
device’s IMU to compute the position and
orientation of the phone.
Proprietary and Confidential
ARCore Overview

Environmental Understanding
ARCore detects surfaces - like tables and
desks, and makes these surfaces
available to your app as planes.
Proprietary and Confidential
ARCore Overview

Oriented Points
Oriented points lets you place virtual
objects on non-horizontal surfaces.
Proprietary and Confidential
ARCore Overview

Vertical Planes
Proprietary and Confidential
ARCore Overview

Augmented Images
Images are matched from a database of
know images.
Proprietary and Confidential
ARCore Overview

Anchors to Attach the Virtual


to the Real

Anchors should be used whenever you


need to attach virtual objects to
features in the world. ARCore will
automatically handle drift correction.
Proprietary and Confidential
ARCore Overview

Cloud Anchors
Sharing anchors between people and
across platforms.
ARCore with Unity
Proprietary and Confidential
ARCore with Unity

ARCore & Unity Specifics


Use Unity 2017.4 LTS or later.

Set Player Properties:


Proprietary and Confidential
ARCore with Unity

Anatomy of an ARCore Scene - Unity


Proprietary and Confidential
ARCore with Unity

Plane Discovery
Plane detection is the foundation of
understanding the physical world.
Proprietary and Confidential
ARCore with Unity

Code: Plane Discovery - Unity


void OnUpdate() {

// Screen Space Canvas object showing animation.


GameObject SearchingForPlaneUI;

// Show searching if not tracking or no planes.


if(Session.Status != SessionStatus.Tracking) {
SearchingForPlaneUI.SetActive(true);
return;
}

Session.GetTrackables<TrackedPlane>(m_AllPlanes);

bool showSearchingUI = true;


for (int i = 0; i < m_AllPlanes.Count; i++) {
if (m_AllPlanes[i].TrackingState == TrackingState.Tracking) {
showSearchingUI = false;
break;
}
}
SearchingForPlaneUI.SetActive(showSearchingUI);
}
Proprietary and Confidential
ARCore with Unity

Plane Visualization
Planes should be easily identified, but still
an opportunity to create your own look
and feel.
Proprietary and Confidential
ARCore with Unity

Code: Plane Visualization - Unity

/* Leverage TrackedPlaneVisualizer to procedurally create the plane geometry.


The PlaneGrid material uses a texture for the pattern and parameters for
the color and rotation.
*/

m_MeshRenderer.material.SetColor("_GridColor",
k_PlaneColors[s_PlaneCount++ % k_PlaneColors.Length]);
m_MeshRenderer.material.SetFloat("_UvRotation",Random.Range(0.0f, 360.0f));
m_MeshRenderer.material.mainTexture = myCustomTexture;
Proprietary and Confidential
ARCore with Unity

Checking ARCore for Support


ARCore checking is automatic for ARCore
Required applications.

ARCore optional applications need to


check explicitly.

Image
Proprietary and Confidential
ARCore with Unity

Code: Check for ARCore on Device

public void Start () {


// Start the asynchronous check for ARCore on the device.
Session.CheckApkAvailability().ThenAction(HandleAvailabilityStatus);
}

// Callback for CheckApkAvailability


private void HandleAvailabilityStatus (ApkAvailabilityStatus status) {
switch (status) {
case ApkAvailabilityStatus.SupportedApkTooOld:
case ApkAvailabilityStatus.SupportedNotInstalled:
// Need to start installation or updating
of ARCore Services.
Session.RequestApkInstallation (true).ThenAction
(HandleInstallationStatus);
break;
case ApkAvailabilityStatus.SupportedInstalled:
// Everything is ready!
EnableARFeatures (true);
break;
default:
// Other error conditions, can't use ARCore.
EnableARFeatures (false);
break;
}
}
ARCore with Sceneform
Proprietary and Confidential
ARCore with Sceneform

Anatomy of an ARCore Scene - Android Studio


Proprietary and Confidential
ARCore with Sceneform

Code: Hello Sceneform

// When you build a Renderable, Sceneform loads its resources in the background while returning
// a CompletableFuture. Call thenAccept(), handle(), or check isDone() before calling get().
ModelRenderable.builder()
.setSource(this, R.raw.andy)
.build()
.thenAccept(renderable -> andyRenderable = renderable);

arFragment.setOnTapArPlaneListener(
(HitResult hitResult, Plane plane, MotionEvent motionEvent) -> {

// Create the Anchor.


Anchor anchor = hitResult.createAnchor();
AnchorNode anchorNode = new AnchorNode(anchor);
anchorNode.setParent(arFragment.getArSceneView().getScene());

// Create the transformable andy and add it to the anchor.


TransformableNode andy = new TransformableNode(arFragment.getTransformationSystem());
andy.setParent(anchorNode);
andy.setRenderable(andyRenderable);
andy.select();
});
Proprietary and Confidential
ARCore with Sceneform

Code: Plane Visualization - Android Studio

/**
* Sets the plane texture to the image in the assets directory.
* @param texturePath - the assets/ relative path.
*/
private void setPlaneTexture(String texturePath) {

Texture.Sampler sampler = Texture.Sampler.builder()


.setMinFilter(Texture.Sampler.MinFilter.LINEAR_MIPMAP_LINEAR)
.setMagFilter(Texture.Sampler.MagFilter.LINEAR)
.setWrapMode(Texture.Sampler.WrapMode.REPEAT)
.build();
Texture.builder().setSource(() -> getAssets().open(texturePath))
.setSampler(sampler)
.build().thenAccept((texture) -> {
arFragment.getArSceneView().getPlaneRenderer().getMaterial()
.thenAccept((material) -> {
material.setTexture(MATERIAL_TEXTURE, texture);
material.setFloat(MATERIAL_UV_SCALE,10f);
});
});
}
Proprietary and Confidential
ARCore with Sceneform

Build Your App with Assets from Poly


Poly has thousands of free 3D assets that
you can use to quickly bootstrap your app.
Proprietary and Confidential
ARCore with Sceneform

Instant Preview - Unity


Eliminates round trip of building, deploying,
testing.
Proprietary and Confidential
Thank you

Thank you!
@Akram Zeyada
akramziada12@gmail.com

developers.google.com/ar

github.com/google-ar

stackoverflow.com/questions/tagged/arcore

Potrebbero piacerti anche