Introduction
What's AR?
AR = R + VR
Key Problems:
- Space Recognization.
- Image processiong.
- User's interaction with vitual 3D world.
What's ARCore?
A SDK for AR
- Recognize the real world's feature points and planes.
- Put vitual 3D/2D model into the real world video stream.
- Recognize user interaction with the 3D world.
Applications
Foundamental Concepts
Motion tracking
www.youtube.com/watch?v=gU1…Environmental understanding
Light estimation
Principles
Camera Structure
Light Path
www.desmos.com/calculator/…Processing Pipeline
Location and Rotation Detection
Code
关键API
- Scene
- Plane
- HitResult
- Anchor
- Node
- Renderable
- ExternalTexture
Demo Andy
ModelRenderable.builder()
.setSource(this, R.raw.deer)
.build()
.thenAccept(renderable -> andyRenderable = renderable)
.exceptionally(
throwable -> {
Toast toast =
Toast.makeText(this, "Unable to load andy renderable", Toast.LENGTH_LONG);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.show();
return null;
});
arFragment.setOnTapArPlaneListener(
(HitResult hitResult, Plane plane, MotionEvent motionEvent) -> {
if (andyRenderable == null) {
return;
}
// 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();
});
复制代码
Demo: Solar System
CompletableFuture<ViewRenderable> solarControlsStage =
ViewRenderable.builder().setView(this, R.layout.solar_controls).build();
private Node createSolarSystem() {
Node base = new Node();
Node sun = new Node();
sun.setParent(base);
sun.setLocalPosition(new Vector3(0.0f, 0.5f, 0.0f));
Node sunVisual = new Node();
sunVisual.setParent(sun);
sunVisual.setRenderable(sunRenderable);
sunVisual.setLocalScale(new Vector3(0.5f, 0.5f, 0.5f));
Node solarControls = new Node();
solarControls.setParent(sun);
solarControls.setRenderable(solarControlsRenderable);
solarControls.setLocalPosition(new Vector3(0.0f, 0.25f, 0.0f));
View solarControlsView = solarControlsRenderable.getView();
SeekBar orbitSpeedBar = solarControlsView.findViewById(R.id.orbitSpeedBar);
orbitSpeedBar.setProgress((int) (solarSettings.getOrbitSpeedMultiplier() * 10.0f));
orbitSpeedBar.setOnSeekBarChangeListener(
new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
float ratio = (float) progress / (float) orbitSpeedBar.getMax();
solarSettings.setOrbitSpeedMultiplier(ratio * 10.0f);
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {}
});
SeekBar rotationSpeedBar = solarControlsView.findViewById(R.id.rotationSpeedBar);
rotationSpeedBar.setProgress((int) (solarSettings.getRotationSpeedMultiplier() * 10.0f));
rotationSpeedBar.setOnSeekBarChangeListener(
new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
float ratio = (float) progress / (float) rotationSpeedBar.getMax();
solarSettings.setRotationSpeedMultiplier(ratio * 10.0f);
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {}
});
// Toggle the solar controls on and off by tapping the sun.
sunVisual.setOnTapListener(
(hitTestResult, motionEvent) -> solarControls.setEnabled(!solarControls.isEnabled()));
createPlanet("Mercury", sun, 0.4f, 47f, mercuryRenderable, 0.019f);
createPlanet("Venus", sun, 0.7f, 35f, venusRenderable, 0.0475f);
Node earth = createPlanet("Earth", sun, 1.0f, 29f, earthRenderable, 0.05f);
createPlanet("Moon", earth, 0.15f, 100f, lunaRenderable, 0.018f);
createPlanet("Mars", sun, 1.5f, 24f, marsRenderable, 0.0265f);
createPlanet("Jupiter", sun, 2.2f, 13f, jupiterRenderable, 0.16f);
createPlanet("Saturn", sun, 3.5f, 9f, saturnRenderable, 0.1325f);
createPlanet("Uranus", sun, 5.2f, 7f, uranusRenderable, 0.1f);
createPlanet("Neptune", sun, 6.1f, 5f, neptuneRenderable, 0.074f);
return base;
}
复制代码
Demo: Video
ExternalTexture texture = new ExternalTexture();
// Create an Android MediaPlayer to capture the video on the external texture's surface.
mediaPlayer = MediaPlayer.create(this, R.raw.lion_chroma);
mediaPlayer.setSurface(texture.getSurface());
mediaPlayer.setLooping(true);
// Create a renderable with a material that has a parameter of type 'samplerExternal' so that
// it can display an ExternalTexture. The material also has an implementation of a chroma key
// filter.
ModelRenderable.builder()
.setSource(this, R.raw.chroma_key_video)
.build()
.thenAccept(
renderable -> {
videoRenderable = renderable;
renderable.getMaterial().setExternalTexture("videoTexture", texture);
renderable.getMaterial().setFloat4("keyColor", CHROMA_KEY_COLOR);
})
.exceptionally(
throwable -> {
Toast toast =
Toast.makeText(this, "Unable to load video renderable", Toast.LENGTH_LONG);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.show();
return null;
});
复制代码
Trending
ARCore Release Notes
V1.0.0 on Feb 24, 2018
V1.6.0 on Dec 7, 2018
github.com/google-ar/a…
Support Device
developers.google.com/ar/discover…