Upgrade to Pro — share decks privately, control downloads, hide ads and more …

1日でできる!ARCoreことはじめ

zukkey
August 23, 2018

 1日でできる!ARCoreことはじめ

初心者でARCoreに興味がある人のために
AR初心者の私が、1日あれば大体できることをまとめてみました

zukkey

August 23, 2018
Tweet

More Decks by zukkey

Other Decks in Programming

Transcript

  1. ̍೔ͰͰ͖Δʂ
    ARCore͜ͱ͸͡Ί
    @zukkey59
    potatotips #54
    1

    View full-size slide

  2. 2
    w FVSFLB*OD
    w 1BJST"OESPJE&OHJOFFS
    w 5XJUUFS![VLLFZ
    ࣗݾ঺հ
    ٕज़ॻయ̐Ͱɺຊग़͠·ͨ͠ʂ

    View full-size slide

  3. 3
    w6OJUZͰ͸ͳ͘"OESPJE4UVEJPͰ
    w"3$PSFʹڵຯ͕͋Δਓ͕खܰʹࢼͤΔΑ͏ʹ̍೔͋Ε͹Ͱ͖Δ͜ͱͷ঺հ
    ࠓ೔࿩͢͜ͱ

    View full-size slide

  4. 4
    w4DFOFGPSN
    w"SHVNFOUFE*NBHFT
    w$MPVE"ODIPST
    ARCoreͰͰ͖Δ͜ͱ

    View full-size slide

  5. 5
    w4DFOFGPSNࠓ೔࿩͢ͷ͸ίίʂ
    w"SHVNFOUFE*NBHFT
    w$MPVE"ODIPST
    ARCoreͰͰ͖Δ͜ͱ

    View full-size slide

  6. 6
    w Α͋͘Δ̏%ϞσϧΛදࣔͯ͠ಈ͔ͨ͠ΓͰ͖Δ΍ͭ
    Sceneform

    View full-size slide

  7. 7
    wγʔϯΛߏஙͯ͠ɺੜ੒͞ΕΔԾ૝ΦϒδΣΫτͰ͋Δ/PEFΛ௥Ճ͢Δ
    ARΛදࣔ͢ΔྲྀΕ

    View full-size slide

  8. 8
    wγʔϯΛߏஙͯ͠ɺੜ੒͞ΕΔԾ૝ΦϒδΣΫτͰ͋Δ/PEFΛ௥Ճ͢Δ
    ARΛදࣔ͢ΔྲྀΕ
    Scene

    View full-size slide

  9. 9
    wγʔϯΛߏஙͯ͠ɺੜ੒͞ΕΔԾ૝ΦϒδΣΫτͰ͋Δ/PEFΛ௥Ճ͢Δ
    ARΛදࣔ͢ΔྲྀΕ
    Scene
    Anchor Node
    ਌ͷNodeੜ੒ʂ

    View full-size slide

  10. 10
    wγʔϯΛߏஙͯ͠ɺੜ੒͞ΕΔԾ૝ΦϒδΣΫτͰ͋Δ/PEFΛ௥Ճ͢Δ
    ARΛදࣔ͢ΔྲྀΕ
    Scene
    Anchor Node
    Transform Node ੜ੒ʂ

    View full-size slide

  11. 11
    wγʔϯΛߏஙͯ͠ɺੜ੒͞ΕΔԾ૝ΦϒδΣΫτͰ͋Δ/PEFΛ௥Ճ͢Δ
    ARΛදࣔ͢ΔྲྀΕ
    Scene
    Anchor Node
    Transform Node
    ௥Ճʂ

    View full-size slide

  12. 12
    wγʔϯΛߏஙͯ͠ɺੜ੒͞ΕΔԾ૝ΦϒδΣΫτͰ͋Δ/PEFΛ௥Ճ͢Δ
    ARΛදࣔ͢ΔྲྀΕ
    Scene
    ௥Ճͨ͠ࢠͷNode͸ɺ

    Ҡಈͨ͠Γɺઃఆ͢Ε͹֦ॖͨ͠Γɺճసͨ͠ΓͰ͖Δ

    View full-size slide

  13. 13
    wඪ४Ͱ༻ҙ͞Ε͍ͯΔ"OESPJEͷ8JEHFUΛදࣔ͢Δ͜ͱ͕Ͱ͖Δ
    AndroidͷWidgetͷදࣔ

    View full-size slide

  14. wද͍ࣔͨ͠8JEHFUͷϨΠΞ΢τΛผʹ༻ҙ͢Δ
    JUFN@JNBHFYNM

    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/eure"
    xmlns:android="http://schemas.android.com/apk/res/android" />
    14
    AndroidͷWidgetͷදࣔ

    View full-size slide

  15. 15
    w7JFX3FOEFSBCMFΫϥεΛ༻͍ͯɺϨΠΞ΢τͷYNMΛࢦఆͯ͠

    7JFX"DUJWJUZKBWB
    ViewRenderable.builder()
    .setView(this, R.layout.item_image)
    .build()
    .thenAccept(renderable -> viewRenderable = renderable);
    AndroidͷWidgetͷදࣔ

    View full-size slide

  16. 16
    w7JFX3FOEFSBCMFΫϥεΛ༻͍ͯɺϨΠΞ΢τͷYNMΛࢦఆͯ͠
    ϦιʔεΛಡΈࠐΈɺϨϯμϦϯά͢Δ
    7JFX"DUJWJUZKBWB
    ViewRenderable.builder()
    .setView(this, R.layout.item_image)
    .build()
    .thenAccept(renderable -> viewRenderable = renderable);
    AndroidͷWidgetͷදࣔ

    View full-size slide

  17. 17
    wϨϯμϦϯάͨ͠΋ͷΛԾ૝ΦϒδΣΫτͷ/PEFʹͯ͠

    7JFX"DUJWJUZKBWB
    TransformableNode view = new TransformableNode(arFragment.getTransformationSystem());
    view.setParent(anchorNode);
    view.setRenderable(viewRenderable);
    AndroidͷWidgetͷදࣔ

    View full-size slide

  18. 18
    wϨϯμϦϯάͨ͠΋ͷΛԾ૝ΦϒδΣΫτͷ/PEFʹͯ͠
    ਌ͷ/PEF ΞϯΧʔ
    ʹ௥Ճ͢Δ
    7JFX"DUJWJUZKBWB
    TransformableNode view = new TransformableNode(arFragment.getTransformationSystem());
    view.setParent(anchorNode);
    view.setRenderable(viewRenderable);
    AndroidͷWidgetͷදࣔ

    View full-size slide

  19. 19
    wؙɺ࢛֯ɺԁபͳͲͷදࣔΛ͢Δ͜ͱ͕Ͱ͖Δ
    ؙɺ࢛֯ɺԁபͳͲͷදࣔ

    View full-size slide

  20. 20
    w࢛֯ΛྫʹͱΔͱɺԼهͷΑ͏ʹ.BUFSJBM'BDUPSZΫϥεΛ༻͍ͯ$PMPSΛࢦఆ͠
    7JFX"DUJWJUZKBWB
    MaterialFactory.makeOpaqueWithColor(this, new Color(android.graphics.Color.BLUE))
    .thenAccept(
    material -> {
    blueSquareRenderable =
    ShapeFactory.makeCube(new Vector3(0.2f, 0.15f, 0.2f),
    new Vector3(0.0f, 0.15f, 0.0f), material);
    }
    );
    ؙɺ࢛֯ɺԁபͳͲͷදࣔ

    View full-size slide

  21. 21
    w࢛֯ΛྫʹͱΔͱɺԼهͷΑ͏ʹ.BUFSJBM'BDUPSZΫϥεΛ༻͍ͯ$PMPSΛࢦఆ͠
    ࢛֯ܗΛ࡞੒ͯ͠ϨϯμϦϯά͢Δ
    7JFX"DUJWJUZKBWB
    MaterialFactory.makeOpaqueWithColor(this, new Color(android.graphics.Color.BLUE))
    .thenAccept(
    material -> {
    blueSquareRenderable =
    ShapeFactory.makeCube(new Vector3(0.2f, 0.15f, 0.2f),
    new Vector3(0.0f, 0.15f, 0.0f), material);
    }
    );
    ؙɺ࢛֯ɺԁபͳͲͷදࣔ

    View full-size slide

  22. 22
    wؙ΍ԁபΛද͍ࣔͨ͠৔߹͸4IBQF'BDUPSZΫϥεʹ͋ΔNBLF4QIFSFͱ
    NBLF$ZMJOEFSΛ༻͍Δ͜ͱͰ࣮ݱͰ͖Δ
    #BMM"DUJWJUZKBWB
    ShapeFactory.makeSphere(0.1f, new Vector3(0.0f, 0.15f, 0.0f), material); });
    $ZMJOEFS"DUJWJUZKBWB
    ShapeFactory.makeCylinder(0.1f, 0.3f, new Vector3(0.0f, 0.15f, 0.0f), material);
    ؙɺ࢛֯ɺԁபͳͲͷදࣔ

    View full-size slide

  23. 23
    wϞσϦϯάͨ͠%ϞσϧΛදࣔ͢Δ͜ͱ͕Ͱ͖Δ
    3DϞσϧͷදࣔ

    View full-size slide

  24. 24
    w೚ҙͷϞσϦϯάϑΝΠϧΛಡΈࠐΉʹ͸ɺBQQͷCVJMEHSBEMFʹ
    ԼهΛهड़͢Δ͜ͱ͕ඞཁ
    CVJMEHSBEMF BQQ

    apply plugin: 'com.google.ar.sceneform.plugin'
    3DϞσϧͷදࣔ

    View full-size slide

  25. 25
    • Project > app ͷԼʹsampledataσΟϨΫτϦΛੜ੒͠ɺ
    objϑΝΠϧΛೖΕΔ(objϑΝΠϧҎ֎ʹ΋ɺFBXɺgITFͳͲରԠ͍ͯ͠Δ)
    3DϞσϧͷදࣔ

    View full-size slide

  26. 26
    • sampledataΛӈΫϦοΫͯ͠ɺ
    ɹNew > Sceneform Asset͔ΒӈͷΑ͏ʹ
    ɹઌ΄ͲೖΕͨobjϑΝΠϧΛಡΈࠐΉ
    3DϞσϧͷදࣔ

    View full-size slide

  27. 27
    • Sync͢Δͱɺappͷbuild.gradleͷதʹԼهͷίʔυ͕௥Ճ͞ΕΔ
    CVJMEHSBEMF BQQ

    sceneform.asset('sampledata/andy.obj',
    'default',
    'sampledata/andy.sfa',
    'src/main/res/raw/andy')
    3DϞσϧͷදࣔ

    View full-size slide

  28. 3DϞσϧͷಋೖ͕Ͱ͖ͨʂ
    28

    View full-size slide

  29. 29
    w%σʔλͷϦιʔεΛಡΈࠐΜͰϨϯμϦϯά͢Δ
    3DϞσϧͷදࣔ
    .PEFM"DUJWJUZKBWB
    ModelRenderable.builder()
    .setSource(this, R.raw.andy)
    .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;
    });

    View full-size slide

  30. 30
    w%σʔλͷϦιʔεΛಡΈࠐΜͰϨϯμϦϯά͢Δ
    3DϞσϧͷදࣔ
    .PEFM"DUJWJUZKBWB
    ModelRenderable.builder()
    .setSource(this, R.raw.andy)
    .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;
    });

    View full-size slide

  31. 31
    wಋೖ͔Β"3Λදࣔ͢Δ·Ͱɺׂͱ؆୯ʹͰ͖Δ
    w6OJUZͰ΍Δํ๏͕Α͘঺հ͞Ε͍ͯΔ͕ɺ
    طଘͷϓϩδΣΫτʹ௥Ճ͍ͨ͠ͱ͔͋Ε͹ɺ
    "OESPJE4UVEJPͰ΋ಋೖ͸؆୯ʹͰ͖ͦ͏
    ͓ΘΓʹ

    View full-size slide

  32. 32
    wࠓճ঺հͨ͠αϯϓϧ͸HJUIVCʹ͓͍ͯ͋ΔͷͰɺԼهΛ͝ཡ͍ͩ͘͞
    IUUQTHJUIVCDPNZVUBSP"3$PSF4BNQMF
    ͓ΘΓʹ

    View full-size slide

  33. 33
    CVJMEHSBEMFʹهड़ͱ֬ೝ
    "OESPJE.BOJGFTUʹهड़
    %Ϟσϧಋೖ࣌ʹඞཁͳϓϥάΠϯΛೖΕΔ
    ิ଍ - ಋೖํ๏

    View full-size slide

  34. 34
    wBQQͷCVJMEHSBEMFʹҎԼΛهड़͢Δ
    EFQFOEFODJFT\
    ʜ
    JNQMJDBUJPObDPNHPPHMFBSTDFOFGPSNVYTDFOFGPSNVY`
    JNQMJDBUJPObDPNHPPHMFBSTDFOFGPSNVYDPSF`
    ʜ
    ^
    build.gradleʹهड़ͱ֬ೝ

    View full-size slide

  35. 35
    wϓϩδΣΫτͷCVJMEHSBEMFʹҎԼ͕هड़͞Ε͍ͯΔ͜ͱΛ֬ೝ
    BMMQSPKFDUT\
    SFQPTJUPSJFT\
    ʜ
    HPPHMF

    ʜ
    ^
    ^
    build.gradleʹهड़ͱ֬ೝ

    View full-size slide

  36. 36
    wΧϝϥΛ࢖͏ͨΊҎԼΛهड़
    package=“zukkey.whiskey.arcoresample">

    // ҎԼΛهड़



    Android Manifestʹهड़

    View full-size slide

  37. 37
    w"3$PSFΛ༗ޮʹ͢Δ
    … >
    // ARαϙʔτ୺຤ඞਢͷ৔߹͸value=”required”, ඞਢʹ͠ͳ͍৔߹͸value=”optional”


    Android Manifestʹهड़

    View full-size slide

  38. 38
    w1SFGFSFODFT1MVHJOT
    #SPXTF3FQPTJUPSJFTͰ
    (PPHMF4DFOFGPSN5PPMTΛݕࡧ͠ɺ
    ϓϥάΠϯΛೖΕΔ
    3DϞσϧಋೖ࣌ʹඞཁͳϓϥάΠϯΛೖΕΔ

    View full-size slide