Share
Embed
Transcript
73 slides
-
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 } } -
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) } -
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<simd_float3> { get } /** The 3D point identifiers comprising the point cloud. */ open var __identifiers: UnsafePointer<UInt64> { 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 } } -
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)") } } -
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)") } -
let configuration = self.defaultConfiguration // this app's standard settings configuration.initialWorldMap
= worldMap sceneView.session.run(configuration, options: [.resetTracking, .removeExistingAnchors]) -
γϯϓϧͳ෦ GFBUVSFT BODIPST ,# ࡶଟͳ෦ GFBUVSFT BODIPST .# ϥϯδ GFBUVSFT
BODIPST .# ݐͷݰ͔ؔΒ࿓Լͱ֊ஈΛ௨Γ'·Ͱ GFBUVSFT BODIPST ,# -
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) } ... -
let configuration = ARWorldTrackingConfiguration() configuration.planeDetection = .horizontal configuration.environmentTexturing = .automatic
sceneView.session.run(configuration) -
let configuration = ARWorldTrackingConfiguration() configuration.planeDetection = .horizontal configuration.environmentTexturing = .automatic
sceneView.session.run(configuration) -
let configuration = ARWorldTrackingConfiguration() configuration.planeDetection = .horizontal configuration.environmentTexturing = .manual
sceneView.session.run(configuration) -
let configuration = ARWorldTrackingConfiguration() configuration.planeDetection = .horizontal configuration.environmentTexturing = .manual
sceneView.session.run(configuration) -
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) ... } -
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) ... } -
// MARK: - ARSCNViewDelegate func renderer(_ renderer: SCNSceneRenderer, updateAtTime time:
TimeInterval) { updateEnvironmentProbe(atTime: time) } -
6OEFSTUBOEJOH8PSME5SBDLJOHJO"3,JU IUUQTEFWFMPQFSBQQMFDPNEPDVNFOUBUJPOBSLJUVOEFSTUBOEJOH@XPSME@USBDLJOH@JO@BSLJU 4XJGU4IPU$SFBUJOHB(BNFGPS"VHNFOUFE3FBMJUZ IUUQTEFWFMPQFSBQQMFDPNEPDVNFOUBUJPOBSLJUTXJGUTIPU@DSFBUJOH@B@HBNF@GPS@BVHNFOUFE@SFBMJUZ $SFBUJOHB1FSTJTUFOU"3&YQFSJFODF IUUQTEFWFMPQFSBQQMFDPNEPDVNFOUBUJPOBSLJUDSFBUJOH@B@QFSTJTUFOU@BS@FYQFSJFODF "EEJOH3FBMJTUJD3FqFDUJPOTUPBO"3&YQFSJFODF IUUQTEFWFMPQFSBQQMFDPNEPDVNFOUBUJPOBSLJUBEEJOH@SFBMJTUJD@SFqFDUJPOT@UP@BO@BS@FYQFSJFODF "SDIJWJOH8PSME.BQ%BUBGPS1FSTJTUFODFPS4IBSJOH IUUQTEFWFMPQFSBQQMFDPNEPDVNFOUBUJPOBSLJUBSXPSMENBQBSDIJWJOH@XPSME@NBQ@EBUB@GPS@QFSTJTUFODF@PS@TIBSJOH
8IBU`T/FXJO"3,JU IUUQTEFWFMPQFSBQQMFDPNWJEFPTQMBZXXED 6OEFSTUBOEJOH"3,JU5SBDLJOHBOE%FUFDUJPO IUUQTEFWFMPQFSBQQMFDPNWJEFPTQMBZXXED *OTJEF4XJGU4IPU$SFBUJOHBO"3(BNF IUUQTEFWFMPQFSBQQMFDPNWJEFPTQMBZXXED $SFBUJOH(SFBU"3&YQFSJFODFT IUUQTEFWFMPQFSBQQMFDPNWJEFPTQMBZXXED ࢀߟ