diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3fc7fe0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,15 @@ +### Xcode ### +## User settings +xcuserdata/ + +## Xcode 8 and earlier +*.xcscmblueprint +*.xccheckout + +### Xcode Patch ### +*.xcodeproj/* +!*.xcodeproj/project.pbxproj +!*.xcodeproj/xcshareddata/ +!*.xcworkspace/contents.xcworkspacedata +/*.gcno +**/xcshareddata/WorkspaceSettings.xcsettings diff --git a/ARImageTracking.xcodeproj/project.pbxproj b/ARImageTracking.xcodeproj/project.pbxproj index 098bbb7..614d633 100644 --- a/ARImageTracking.xcodeproj/project.pbxproj +++ b/ARImageTracking.xcodeproj/project.pbxproj @@ -273,7 +273,7 @@ ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; CODE_SIGN_STYLE = Automatic; DEVELOPMENT_ASSET_PATHS = "\"ARImageTracking/Preview Content\""; - DEVELOPMENT_TEAM = GGXD5E6AF8; + DEVELOPMENT_TEAM = G6E5589J7L; ENABLE_PREVIEWS = YES; INFOPLIST_FILE = ARImageTracking/Info.plist; LD_RUNPATH_SEARCH_PATHS = ( @@ -294,7 +294,7 @@ ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; CODE_SIGN_STYLE = Automatic; DEVELOPMENT_ASSET_PATHS = "\"ARImageTracking/Preview Content\""; - DEVELOPMENT_TEAM = GGXD5E6AF8; + DEVELOPMENT_TEAM = G6E5589J7L; ENABLE_PREVIEWS = YES; INFOPLIST_FILE = ARImageTracking/Info.plist; LD_RUNPATH_SEARCH_PATHS = ( diff --git a/ARImageTracking.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/ARImageTracking.xcodeproj/project.xcworkspace/contents.xcworkspacedata deleted file mode 100644 index 919434a..0000000 --- a/ARImageTracking.xcodeproj/project.xcworkspace/contents.xcworkspacedata +++ /dev/null @@ -1,7 +0,0 @@ - - - - - diff --git a/ARImageTracking.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/ARImageTracking.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist deleted file mode 100644 index 18d9810..0000000 --- a/ARImageTracking.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +++ /dev/null @@ -1,8 +0,0 @@ - - - - - IDEDidComputeMac32BitWarning - - - diff --git a/ARImageTracking.xcodeproj/project.xcworkspace/xcuserdata/Johnqi.xcuserdatad/UserInterfaceState.xcuserstate b/ARImageTracking.xcodeproj/project.xcworkspace/xcuserdata/Johnqi.xcuserdatad/UserInterfaceState.xcuserstate deleted file mode 100644 index a7d3d8e..0000000 Binary files a/ARImageTracking.xcodeproj/project.xcworkspace/xcuserdata/Johnqi.xcuserdatad/UserInterfaceState.xcuserstate and /dev/null differ diff --git a/ARImageTracking.xcodeproj/project.xcworkspace/xcuserdata/laurentb.xcuserdatad/UserInterfaceState.xcuserstate b/ARImageTracking.xcodeproj/project.xcworkspace/xcuserdata/laurentb.xcuserdatad/UserInterfaceState.xcuserstate deleted file mode 100644 index b4aab30..0000000 Binary files a/ARImageTracking.xcodeproj/project.xcworkspace/xcuserdata/laurentb.xcuserdatad/UserInterfaceState.xcuserstate and /dev/null differ diff --git a/ARImageTracking.xcodeproj/xcuserdata/Johnqi.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/ARImageTracking.xcodeproj/xcuserdata/Johnqi.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist deleted file mode 100644 index a92248e..0000000 --- a/ARImageTracking.xcodeproj/xcuserdata/Johnqi.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +++ /dev/null @@ -1,6 +0,0 @@ - - - diff --git a/ARImageTracking.xcodeproj/xcuserdata/Johnqi.xcuserdatad/xcschemes/xcschememanagement.plist b/ARImageTracking.xcodeproj/xcuserdata/Johnqi.xcuserdatad/xcschemes/xcschememanagement.plist deleted file mode 100644 index 517a7fc..0000000 --- a/ARImageTracking.xcodeproj/xcuserdata/Johnqi.xcuserdatad/xcschemes/xcschememanagement.plist +++ /dev/null @@ -1,14 +0,0 @@ - - - - - SchemeUserState - - ARImageTracking.xcscheme_^#shared#^_ - - orderHint - 0 - - - - diff --git a/ARImageTracking.xcodeproj/xcuserdata/laurentb.xcuserdatad/xcschemes/xcschememanagement.plist b/ARImageTracking.xcodeproj/xcuserdata/laurentb.xcuserdatad/xcschemes/xcschememanagement.plist deleted file mode 100644 index 517a7fc..0000000 --- a/ARImageTracking.xcodeproj/xcuserdata/laurentb.xcuserdatad/xcschemes/xcschememanagement.plist +++ /dev/null @@ -1,14 +0,0 @@ - - - - - SchemeUserState - - ARImageTracking.xcscheme_^#shared#^_ - - orderHint - 0 - - - - diff --git a/ARImageTracking/AppDelegate.swift b/ARImageTracking/AppDelegate.swift index a869a52..47f7d93 100644 --- a/ARImageTracking/AppDelegate.swift +++ b/ARImageTracking/AppDelegate.swift @@ -5,17 +5,14 @@ // Created by Qi on 8/1/21. // -import UIKit import SwiftUI +import UIKit @main class AppDelegate: UIResponder, UIApplicationDelegate { - var window: UIWindow? - func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { - // Create the SwiftUI view that provides the window contents. let contentView = ContentView() @@ -43,7 +40,4 @@ class AppDelegate: UIResponder, UIApplicationDelegate { func applicationDidBecomeActive(_ application: UIApplication) { // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. } - - } - diff --git a/ARImageTracking/Assets.xcassets/AR Resources.arresourcegroup/xs.arreferenceimage/Contents.json b/ARImageTracking/Assets.xcassets/AR Resources.arresourcegroup/xs.arreferenceimage/Contents.json index 0f75c1c..0aeb0bd 100644 --- a/ARImageTracking/Assets.xcassets/AR Resources.arresourcegroup/xs.arreferenceimage/Contents.json +++ b/ARImageTracking/Assets.xcassets/AR Resources.arresourcegroup/xs.arreferenceimage/Contents.json @@ -1,7 +1,7 @@ { "images" : [ { - "filename" : "xs.JPG", + "filename" : "xs.jpg", "idiom" : "universal" } ], diff --git a/ARImageTracking/ContentView.swift b/ARImageTracking/ContentView.swift index a65590f..acd989f 100644 --- a/ARImageTracking/ContentView.swift +++ b/ARImageTracking/ContentView.swift @@ -6,11 +6,11 @@ // import ARKit -import SwiftUI import RealityKit +import SwiftUI -//Displays as a SwiftUI View -struct ContentView : View { +// Displays as a SwiftUI View +struct ContentView: View { var body: some View { return ARViewContainer().edgesIgnoringSafeArea(.all) } @@ -23,7 +23,7 @@ struct ARViewContainer: UIViewRepresentable { Coordinator(parent: self) } - class Coordinator: NSObject, ARSessionDelegate{ + class Coordinator: NSObject, ARSessionDelegate { var parent: ARViewContainer var videoPlayer: AVPlayer! @@ -37,7 +37,7 @@ struct ARViewContainer: UIViewRepresentable { return } - //Assigns video to be overlaid + // Assigns video to be overlaid guard let path = Bundle.main.path(forResource: "iphonevideo", ofType: "mp4") else { print("Unable to find video file.") return @@ -48,30 +48,30 @@ struct ARViewContainer: UIViewRepresentable { videoPlayer = AVPlayer(playerItem: playerItem) let videoMaterial = VideoMaterial(avPlayer: videoPlayer) - // size of video plane depending of the image - let width: Float = Float(imageAnchor.referenceImage.physicalSize.width * 1.03) - let height: Float = Float(imageAnchor.referenceImage.physicalSize.height * 1.03) + // size of video plane depending of the image + let width = Float(imageAnchor.referenceImage.physicalSize.width * 1.03) + let height = Float(imageAnchor.referenceImage.physicalSize.height * 1.03) - //Sets the aspect ratio of the video to be played, and the corner radius of the video + // Sets the aspect ratio of the video to be played, and the corner radius of the video let videoPlane = ModelEntity(mesh: .generatePlane(width: width, depth: height, cornerRadius: 0.3), materials: [videoMaterial]) - //Assigns reference image that will be detected - if let imageName = imageAnchor.name, imageName == "xs" { + // Assigns reference image that will be detected + if let imageName = imageAnchor.name, imageName == "xs" { let anchor = AnchorEntity(anchor: imageAnchor) - //Adds specified video to the anchor + // Adds specified video to the anchor anchor.addChild(videoPlane) parent.arView.scene.addAnchor(anchor) } } - //Checks for tracking status + // Checks for tracking status func session(_ session: ARSession, didUpdate anchors: [ARAnchor]) { guard let imageAnchor = anchors[0] as? ARImageAnchor else { print("Problems loading anchor.") return } - //Plays/pauses the video when tracked/loses tracking + // Plays/pauses the video when tracked/loses tracking if imageAnchor.isTracked { videoPlayer.play() } else { @@ -82,11 +82,12 @@ struct ARViewContainer: UIViewRepresentable { func makeUIView(context: Context) -> ARView { guard let referenceImages = ARReferenceImage.referenceImages( - inGroupNamed: "AR Resources", bundle: nil) else { - fatalError("Missing expected asset catalog resources.") - } + inGroupNamed: "AR Resources", bundle: nil) + else { + fatalError("Missing expected asset catalog resources.") + } - //Assigns coordinator to delegate the AR View + // Assigns coordinator to delegate the AR View arView.session.delegate = context.coordinator let configuration = ARImageTrackingConfiguration() @@ -94,7 +95,7 @@ struct ARViewContainer: UIViewRepresentable { configuration.trackingImages = referenceImages configuration.maximumNumberOfTrackedImages = 1 - //Enables People Occulusion on supported iOS Devices + // Enables People Occulusion on supported iOS Devices if ARWorldTrackingConfiguration.supportsFrameSemantics(.personSegmentationWithDepth) { configuration.frameSemantics.insert(.personSegmentationWithDepth) } else { @@ -107,4 +108,3 @@ struct ARViewContainer: UIViewRepresentable { func updateUIView(_ uiView: ARView, context: Context) {} } - diff --git a/README.md b/README.md index cdb75aa..0c6dd17 100644 --- a/README.md +++ b/README.md @@ -5,4 +5,4 @@ This is an Augmented Reality Xcode project that uses Apple's newest RealityKit f The example video and image used in my project is of an iPhone Xs screen recording and iPhone Xs box. Do swap the video and image out to whatever you want to track and overlay. I've commented the entire project to help you adapt the code to your needs! Contributions are welcome. -Tested on iOS 14.3 and requires an iDevice with an A12 chip or higher to run. +Tested on iOS 15.6 and requires an iDevice with an A12 chip or higher to run.