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

ARKit Maniacs

satoshi0212
September 01, 2018

ARKit Maniacs

satoshi0212

September 01, 2018
Tweet

More Decks by satoshi0212

Other Decks in Technology

Transcript

  1. "3,JU.BOJBDT
    גࣜձࣾ"CFNB57෰෦ஐ
    TBUPTIJ!TINEFWFMPQ
    J04%$
    J04%$

    View Slide

  2. "3,JU.BOJBDT
    גࣜձࣾ"CFNB57෰෦ஐ
    TBUPTIJ!TINEFWFMPQ
    J04%$
    J04%$

    View Slide

  3. ஫εϥΠυ಺༰͸CFUB൛ͷެ։৘ใΛݩʹ͍ͯ͠·͢ɻ

    View Slide

  4. View Slide

  5. "3Ϊϧυ

    View Slide

  6. "3Ϊϧυ

    View Slide

  7. "3Ϊϧυ

    View Slide

  8. "3Ϊϧυ

    View Slide

  9. "3Ϊϧυ

    View Slide

  10. "3Ϊϧυ

    View Slide

  11. ຊ୊

    View Slide

  12. "3,JU

    View Slide

  13. 4BWJOHBOEMPBEJOHNBQT
    8PSMEUSBDLJOHFOIBODFNFOUT
    &OWJSPONFOUUFYUVSJOH
    *NBHFUSBDLJOH
    0CKFDUEFUFDUJPO
    (B[FBOEUPOHVF
    ARKit 2 - Summary

    View Slide

  14. TPVSDF8IBU`T/FXJO"3,JU IUUQTEFWFMPQFSBQQMFDPNWJEFPTQMBZXXED

    View Slide

  15. 8PSME.BQ1FSTJTUFODFͷ࣮ݧ
    &OWJSPONFOU5FYUVSJOHͷ࣮ݧ
    ฏ໘Λݟ͚͔ͭͯΒͷ޻෉

    View Slide

  16. 8PSME.BQ1FSTJTUFODFͷ࣮ݧ
    &OWJSPONFOU5FYUVSJOHͷ࣮ݧ
    ฏ໘Λݟ͚͔ͭͯΒͷ޻෉

    View Slide

  17. 4BWJOHBOEMPBEJOHNBQT
    8PSMEUSBDLJOHFOIBODFNFOUT
    &OWJSPONFOUUFYUVSJOH
    *NBHFUSBDLJOH
    0CKFDUEFUFDUJPO
    (B[FBOEUPOHVF
    ARKit 2 - Summary

    View Slide

  18. "38PSME4IBSJOHBOE1FSTJTUFODF

    View Slide

  19. ͲΕ͚ͩͷػೳΛ͍࣋ͬͯΔͷ͔

    View Slide

  20. ੈք͸γΣΞͰ͖Δͷ͔

    View Slide

  21. ௚ײʮͰ͖ͳͦ͞͏ʯ

    View Slide

  22. ͦ΋ͦ΋ԿΛอଘ͍ͯ͠Δͷ͔

    View Slide

  23. "38PSME.BQ

    View Slide

  24. TPVSDF8IBU`T/FXJO"3,JU IUUQTEFWFMPQFSBQQMFDPNWJEFPTQMBZXXED

    View Slide

  25. import ARKit
    @available(iOS 12.0, *)
    open class ARWorldMap : NSObject, NSCopying, NSSecureCoding {
    /**
    The position of the center of the mapped world in meters.
    */
    open var center: simd_float3 { get }
    /**
    The extent of the mapped world in meters.
    */
    open var extent: simd_float3 { get }
    /**
    A list of anchors in the map.
    */
    open var anchors: [ARAnchor]
    /**
    The feature points in the map.
    */
    open var rawFeaturePoints: ARPointCloud { get }
    }

    View Slide

  26. import ARKit
    @available(iOS 11.0, *)
    open class ARAnchor : NSObject, ARAnchorCopying, NSSecureCoding {
    /**
    Unique identifier of the anchor.
    */
    open var identifier: UUID { get }
    /**
    An optional name used to associate with the anchor.
    */
    @available(iOS 12.0, *)
    open var name: String? { get }
    /**
    The transformation matrix that defines the anchor’s rotation, translation and scale in world coordinates.
    */
    open var transform: simd_float4x4 { get }
    /**
    Initializes a new anchor object.
    @param transform The transformation matrix that defines the anchor’s rotation, translation and scale in world coordinates.
    */
    public init(transform: simd_float4x4)
    /**
    Initializes a new anchor object with the provided identifier and name.
    @param name A name to associate with the anchor.
    @param transform The transformation matrix that defines the anchor’s rotation, translation and scale in world coordinates.
    */
    @available(iOS 12.0, *)
    public init(name: String, transform: simd_float4x4)
    }

    View Slide

  27. import ARKit
    @available(iOS 11.0, *)
    open class ARPointCloud : NSObject, NSSecureCoding {
    /**
    The number of points in the point cloud.
    */
    open var __count: Int { get }
    /**
    The 3D points comprising the point cloud.
    */
    open var __points: UnsafePointer { get }
    /**
    The 3D point identifiers comprising the point cloud.
    */
    open var __identifiers: UnsafePointer { get }
    }
    @available(iOS 11.0, *)
    extension ARPointCloud {
    /**
    The 3D points comprising the point cloud.
    */
    @nonobjc public var points: [vector_float3] { get }
    /**
    The 3D point identifiers comprising the point cloud.
    */
    @nonobjc public var identifiers: [UInt64] { get }
    }

    View Slide

  28. อଘ

    View Slide

  29. sceneView.session.getCurrentWorldMap { worldMap, error in
    guard let map = worldMap else { return }
    do {
    let data = try NSKeyedArchiver.archivedData(withRootObject: map,
    requiringSecureCoding: true)
    try data.write(to: self.mapSaveURL, options: [.atomic])
    } catch {
    fatalError("Can't save map: \(error.localizedDescription)")
    }
    }

    View Slide

  30. ಡࠐ

    View Slide

  31. do {
    guard let worldMap = try NSKeyedUnarchiver.unarchivedObject(ofClass: ARWorldMap.self,
    from: data)
    else { fatalError("No ARWorldMap in archive.") }
    return worldMap
    } catch {
    fatalError("Can't unarchive ARWorldMap from file data: \(error)")
    }

    View Slide

  32. 3FMPDBMJ[F

    View Slide

  33. let configuration = self.defaultConfiguration // this app's standard settings
    configuration.initialWorldMap = worldMap
    sceneView.session.run(configuration, options: [.resetTracking, .removeExistingAnchors])

    View Slide

  34. ੈք͸γΣΞͰ͖Δͷ͔
    ͸ର৅͕େ͖͍ͷͰ

    View Slide

  35. ݐ෺͸γΣΞͰ͖Δͷ͔ʁ

    View Slide

  36. ֊ݐͯϏϧ಺ͷ͍͔ͭ͘ͷΤϦΞͰ࣮ଌ

    View Slide

  37. γϯϓϧͳ෦԰
    GFBUVSFT BODIPST ,#
    ࡶଟͳ෦԰

    GFBUVSFT BODIPST .#
    ϥ΢ϯδ

    GFBUVSFT BODIPST .#
    ݐ෺ͷݰ͔ؔΒ࿓Լͱ֊ஈΛ௨Γ'·Ͱ

    GFBUVSFT BODIPST ,#

    View Slide

  38. ࡶଟͳ෦԰ͷೖޱΛੈքͷத৺ͱͯ͠Έͨ
    ίʔώʔΧοϓ഑ஔ

    View Slide

  39. View Slide

  40. ݐ෺ͰγΣΞ੒ޭ

    View Slide

  41. ߴ௿ࠩ͋ΔൣғͰӬଓԽ෮ݩ
    σʔλαΠζͷ໨ॲ
    ਺.#ఔ౓Ͱ͸4FTTJPO։࢝଎౓ʹେࠩͳ͠
    த৺఺Ͱ͸ͳͯ͘΋։࢝Մೳ
    อଘ͢Δ৘ใ͸ׂͱࣗ༝

    View Slide

  42. ߴ௿ࠩ͋ΔൣғͰӬଓԽ෮ݩ
    ˢ'΁ͷҠಈͰ΋େ͖ͳζϨͳ͠
    σʔλαΠζͷ໨ॲ
    ˢ'΁ͷҠಈέʔεͰ͸,#
    ਺.#ఔ౓Ͱ͸4FTTJPOͷ։࢝଎౓ʹେࠩͳ͠
    ˢ4FTTJPO։࢝͸Tɻͨͩ͠SFMPDBMJ[F·Ͱʹ͸਺ඵɻ
    த৺఺Ͱ͸ͳͯ͘΋SFMPDBMJ[F։࢝Մೳ
    ˢ'Λத৺ͱͨ͠ੈքͰݰؔͰSFMPDBMJ[FՄ
    อଘ͢Δ৘ใ͸ׂͱࣗ༝
    ˢ4OBQ4IPU"ODIPSͳͲ

    View Slide

  43. class SnapshotAnchor: ARAnchor {
    let imageData: Data
    convenience init?(capturing view: ARSCNView) {
    guard let frame = view.session.currentFrame
    else { return nil }
    let image = CIImage(cvPixelBuffer: frame.capturedImage)
    let orientation = CGImagePropertyOrientation(cameraOrientation:
    UIDevice.current.orientation)
    let context = CIContext(options: [.useSoftwareRenderer: false])
    guard let data = context.jpegRepresentation(of: image.oriented(orientation),
    colorSpace:
    CGColorSpaceCreateDeviceRGB(),
    options:
    [kCGImageDestinationLossyCompressionQuality as CIImageRepresentationOption: 0.7])
    else { return nil }
    self.init(imageData: data, transform: frame.camera.transform)
    }
    ...

    View Slide

  44. ੈքγΣΞ࣮ݱͷલʹौ୩γΣΞ͔
    ࣍ͷน͸σʔλαΠζ

    View Slide

  45. ଓใ͓଴ͪԼ͍͞

    View Slide

  46. 8PSME.BQ1FSTJTUFODFͷ࣮ݧ
    &OWJSPONFOU5FYUVSJOHͷ࣮ݧ
    ฏ໘Λݟ͚͔ͭͯΒͷ޻෉

    View Slide

  47. 4BWJOHBOEMPBEJOHNBQT
    8PSMEUSBDLJOHFOIBODFNFOUT
    &OWJSPONFOUUFYUVSJOH
    *NBHFUSBDLJOH
    0CKFDUEFUFDUJPO
    (B[FBOEUPOHVF
    ARKit 2 - Summary

    View Slide

  48. "EEJOH3FBMJTUJD3FqFDUJPOTUPBO"3&YQFSJFODF

    View Slide

  49. TPVSDF"EEJOH3FBMJTUJD3FqFDUJPOTUPBO"3&YQFSJFODF [email protected]@[email protected]@[email protected]@FYQFSJFODF

    View Slide

  50. let configuration = ARWorldTrackingConfiguration()
    configuration.planeDetection = .horizontal
    configuration.environmentTexturing = .automatic
    sceneView.session.run(configuration)

    View Slide

  51. let configuration = ARWorldTrackingConfiguration()
    configuration.planeDetection = .horizontal
    configuration.environmentTexturing = .automatic
    sceneView.session.run(configuration)

    View Slide

  52. View Slide

  53. BVUPNBUJD

    View Slide

  54. "3,JUHFOFSBUFTFOWJSPONFOUUFYUVSFTCZDPMMFDUJOHDBNFSBJNBHFSZ
    EVSJOHUIF"3TFTTJPO#FDBVTF"3,JUDBOOPUTFFUIFTDFOFJOBMM
    EJSFDUJPOT JUVTFT
    NBDIJOFMFBSOJOHUPFYUSBQPMBUFB
    SFBMJTUJDFOWJSPONFOUGSPNBWBJMBCMFJNBHFSZ
    TPVSDF"EEJOH3FBMJTUJD3FqFDUJPOTUPBO"3&YQFSJFODF [email protected]@[email protected]@[email protected]@FYQFSJFODF

    View Slide

  55. View Slide

  56. NBOVBM

    View Slide

  57. let configuration = ARWorldTrackingConfiguration()
    configuration.planeDetection = .horizontal
    configuration.environmentTexturing = .manual
    sceneView.session.run(configuration)

    View Slide

  58. let configuration = ARWorldTrackingConfiguration()
    configuration.planeDetection = .horizontal
    configuration.environmentTexturing = .manual
    sceneView.session.run(configuration)

    View Slide

  59. TPVSDF"EEJOH3FBMJTUJD3FqFDUJPOTUPBO"3&YQFSJFODF [email protected]@[email protected]@[email protected]@FYQFSJFODF

    View Slide

  60. func updateEnvironmentProbe(atTime time: TimeInterval) {
    guard let object = virtualObject else { return }
    ...
    // Make sure the probe encompasses the object and provides some surrounding area to
    appear in reflections.
    var extent = object.extents * object.simdScale
    extent.x *= 3 // Reflect an area 3x the width of the object.
    extent.z *= 3 // Reflect an area 3x the depth of the object.
    // Also include some vertical area around the object, but keep the bottom of the probe
    at the
    // bottom of the object so that it captures the real-world surface underneath.
    let verticalOffset = float3(0, extent.y, 0)
    let transform = float4x4(translation: object.simdPosition + verticalOffset)
    extent.y *= 2
    // Create the new environment probe anchor and add it to the session.
    let probeAnchor = AREnvironmentProbeAnchor(transform: transform, extent: extent)
    sceneView.session.add(anchor: probeAnchor)
    ...
    }

    View Slide

  61. func updateEnvironmentProbe(atTime time: TimeInterval) {
    guard let object = virtualObject else { return }
    ...
    // Make sure the probe encompasses the object and provides some surrounding area to
    appear in reflections.
    var extent = object.extents * object.simdScale
    extent.x *= 3 // Reflect an area 3x the width of the object.
    extent.z *= 3 // Reflect an area 3x the depth of the object.
    // Also include some vertical area around the object, but keep the bottom of the probe
    at the
    // bottom of the object so that it captures the real-world surface underneath.
    let verticalOffset = float3(0, extent.y, 0)
    let transform = float4x4(translation: object.simdPosition + verticalOffset)
    extent.y *= 2
    // Create the new environment probe anchor and add it to the session.
    let probeAnchor = AREnvironmentProbeAnchor(transform: transform, extent: extent)
    sceneView.session.add(anchor: probeAnchor)
    ...
    }

    View Slide

  62. // MARK: - ARSCNViewDelegate
    func renderer(_ renderer: SCNSceneRenderer, updateAtTime time: TimeInterval) {
    updateEnvironmentProbe(atTime: time)
    }

    View Slide

  63. View Slide

  64. ͳΜͱػցֶशͰݟ͑ͳ͍ྖҬΛࣗಈੜ੒ͯ͘͠Ε͍ͯΔ
    NBOVBMͰ͸ൣғͷϕετϓϥΫςΟε͕ࣔ͞Ε͍ͯΔ
    ಛఆ༻్ͳ͚Ε͹BVUPNBUJDͰྑ͍ͷͰ͸
    ͦͷଞʹ΋5JQT͋Γ

    View Slide

  65. "WPJEWJSUVBMDPOUFOUUIBUSFRVJSFTBDDVSBUFSFqFDUJPOT TVDI
    BTNJSSPSpOJTITVSGBDFT
    )BOEMFNPWJOHPCKFDUT
    %PO`UHFOFSBUFFOWJSPONFOUUFYUVSFTUPPPGUFO
    "WPJEBCSVQUUSBOTJUJPOTCFUXFFOEJ⒎FSFOUFOWJSPONFOU
    UFYUVSFT
    Use Environment Texturing Wisely

    View Slide

  66. 8PSME.BQ1FSTJTUFODFͷ࣮ݧ
    &OWJSPONFOU5FYUVSJOHͷ࣮ݧ
    ฏ໘Λݟ͚͔ͭͯΒͷ޻෉

    View Slide

  67. View Slide

  68. ฏ໘ൃݟޙ
    λοϓ͢Δͱݕ஌͸ࢭ·Γ
    αΠζͱ޲͖ͷௐ੔Ϟʔυ΁

    View Slide

  69. View Slide

  70. %FTJHO"3FYQFSJFODFTGPSQSFEJDUBCMFMJHIUJOHDPOEJUJPOT
    6TFUSBDLJOHRVBMJUZJOGPSNBUJPOUPQSPWJEFVTFS
    GFFECBDL
    "MMPXUJNFGPSQMBOFEFUFDUJPOUPQSPEVDFDMFBSSFTVMUT
    BOEEJTBCMFQMBOFEFUFDUJPOXIFOZPVIBWFUIFSFTVMUTZPV
    OFFE
    Best Practices and Limitations

    View Slide

  71. ৼΓฦΓ

    View Slide

  72. 8PSME.BQ1FSTJTUFODFͷ࣮ݧ
    ˠσʔλαΠζͷ՝୊
    &OWJSPONFOU5FYUVSJOHͷ࣮ݧ
    ˠಛఆ༻్ͳ͚Ε͹BVUPNBUJDͰྑ͍ͷͰ͸
    ฏ໘Λݟ͚͔ͭͯΒͷ޻෉
    ˠετϨεݮΒ͢࢓૊ΈͷҰྫ

    View Slide

  73. 6OEFSTUBOEJOH8PSME5SBDLJOHJO"3,JU
    [email protected]@[email protected]@BSLJU
    4XJGU4IPU$SFBUJOHB(BNFGPS"VHNFOUFE3FBMJUZ
    [email protected]@[email protected]@[email protected]@SFBMJUZ
    $SFBUJOHB1FSTJTUFOU"3&YQFSJFODF
    [email protected]@[email protected]@FYQFSJFODF
    "EEJOH3FBMJTUJD3FqFDUJPOTUPBO"3&YQFSJFODF
    [email protected]@[email protected]@[email protected]@FYQFSJFODF
    "SDIJWJOH8PSME.BQ%BUBGPS1FSTJTUFODFPS4IBSJOH
    [email protected][email protected]@[email protected]@[email protected]@TIBSJOH
    8IBU`T/FXJO"3,JU
    IUUQTEFWFMPQFSBQQMFDPNWJEFPTQMBZXXED
    6OEFSTUBOEJOH"3,JU5SBDLJOHBOE%FUFDUJPO
    IUUQTEFWFMPQFSBQQMFDPNWJEFPTQMBZXXED
    *OTJEF4XJGU4IPU$SFBUJOHBO"3(BNF
    IUUQTEFWFMPQFSBQQMFDPNWJEFPTQMBZXXED
    $SFBUJOH(SFBU"3&YQFSJFODFT
    IUUQTEFWFMPQFSBQQMFDPNWJEFPTQMBZXXED
    ࢀߟ

    View Slide