欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

An Introduction to ARCore

程序员文章站 2022-06-15 18:44:02
...

Introduction


What's AR?

AR = R + VR

Key Problems:

  1. Space Recognization.
  2. Image processiong.
  3. User's interaction with vitual 3D world.

What's ARCore?

A SDK for AR

  1. Recognize the real world's feature points and planes.
  2. Put vitual 3D/2D model into the real world video stream.
  3. 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…

Gartner Hype Cycle 2010 - 2018

juejin.im/post/5c488d…

www.idc.com/getdoc.jsp?…

www.idc.com/getdoc.jsp?…

AR/VR未来五年市场预测报告:2022年AR市场规模将达900亿美元,远超VR的150亿美元 www.ctocio.com/ccnews/2636…

Others


Pose Estimation using TensorFlow.js

medium.com/tensorflow/…

MicroSoft Hololens

www.microsoft.com/en-us/holol…

ARKit

other ar sdk