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

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

7e6a79d3fd57e49905f6f4fe53550021?s=47 zukkey
August 23, 2018

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

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

7e6a79d3fd57e49905f6f4fe53550021?s=128

zukkey

August 23, 2018
Tweet

Transcript

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

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

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

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

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

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

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

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

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

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

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

  12. 12 wγʔϯΛߏஙͯ͠ɺੜ੒͞ΕΔԾ૝ΦϒδΣΫτͰ͋Δ/PEFΛ௥Ճ͢Δ ARΛදࣔ͢ΔྲྀΕ Scene ௥Ճͨ͠ࢠͷNode͸ɺ Ҡಈͨ͠Γɺઃఆ͢Ε͹֦ॖͨ͠Γɺճసͨ͠ΓͰ͖Δ

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

  14. wද͍ࣔͨ͠8JEHFUͷϨΠΞ΢τΛผʹ༻ҙ͢Δ JUFN@JNBHFYNM <?xml version="1.0" encoding="utf-8"?> <ImageView android:id="@+id/image" 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ͷදࣔ
  15. 15 w7JFX3FOEFSBCMFΫϥεΛ༻͍ͯɺϨΠΞ΢τͷYNMΛࢦఆͯ͠  7JFX"DUJWJUZKBWB ViewRenderable.builder() .setView(this, R.layout.item_image) .build() .thenAccept(renderable ->

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

    viewRenderable = renderable); AndroidͷWidgetͷදࣔ
  17. 17 wϨϯμϦϯάͨ͠΋ͷΛԾ૝ΦϒδΣΫτͷ/PEFʹͯ͠  7JFX"DUJWJUZKBWB TransformableNode view = new TransformableNode(arFragment.getTransformationSystem()); view.setParent(anchorNode);

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

    TransformableNode(arFragment.getTransformationSystem()); view.setParent(anchorNode); view.setRenderable(viewRenderable); AndroidͷWidgetͷදࣔ
  19. 19 wؙɺ࢛֯ɺԁபͳͲͷදࣔΛ͢Δ͜ͱ͕Ͱ͖Δ ؙɺ࢛֯ɺԁபͳͲͷදࣔ

  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); } ); ؙɺ࢛֯ɺԁபͳͲͷදࣔ
  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); } ); ؙɺ࢛֯ɺԁபͳͲͷදࣔ
  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); ؙɺ࢛֯ɺԁபͳͲͷදࣔ
  23. 23 wϞσϦϯάͨ͠%ϞσϧΛදࣔ͢Δ͜ͱ͕Ͱ͖Δ 3DϞσϧͷදࣔ

  24. 24 w೚ҙͷϞσϦϯάϑΝΠϧΛಡΈࠐΉʹ͸ɺBQQͷCVJMEHSBEMFʹ ԼهΛهड़͢Δ͜ͱ͕ඞཁ CVJMEHSBEMF BQQ  apply plugin: 'com.google.ar.sceneform.plugin' 3DϞσϧͷදࣔ

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

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

  27. 27 • Sync͢Δͱɺappͷbuild.gradleͷதʹԼهͷίʔυ͕௥Ճ͞ΕΔ CVJMEHSBEMF BQQ  sceneform.asset('sampledata/andy.obj', 'default', 'sampledata/andy.sfa', 'src/main/res/raw/andy')

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

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

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

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

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

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

    build.gradleʹهड़ͱ֬ೝ
  36. 36 wΧϝϥΛ࢖͏ͨΊҎԼΛهड़ <manifest xmlns:android="http://schemas.android.com/apk/res/android" package=“zukkey.whiskey.arcoresample"> … // ҎԼΛهड़ <uses-permission android:name="android.permission.CAMERA"

    /> … </manifest> Android Manifestʹهड़
  37. 37 w"3$PSFΛ༗ޮʹ͢Δ <application … > // ARαϙʔτ୺຤ඞਢͷ৔߹͸value=”required”, ඞਢʹ͠ͳ͍৔߹͸value=”optional” <meta-data android:name="com.google.ar.core"

    android:value="required" /> </application> Android Manifestʹهड़
  38. 38 w1SFGFSFODFT1MVHJOT #SPXTF3FQPTJUPSJFTͰ (PPHMF4DFOFGPSN5PPMTΛݕࡧ͠ɺ ϓϥάΠϯΛೖΕΔ 3DϞσϧಋೖ࣌ʹඞཁͳϓϥάΠϯΛೖΕΔ