Skip to content

Commit 0834487

Browse files
committed
chore: fix code formatting and update image extension
1 parent b6d9cd1 commit 0834487

File tree

4 files changed

+37
-28
lines changed

4 files changed

+37
-28
lines changed

.gitignore

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
### Xcode ###
2+
## User settings
3+
xcuserdata/
4+
5+
## Xcode 8 and earlier
6+
*.xcscmblueprint
7+
*.xccheckout
8+
9+
### Xcode Patch ###
10+
*.xcodeproj/*
11+
!*.xcodeproj/project.pbxproj
12+
!*.xcodeproj/xcshareddata/
13+
!*.xcworkspace/contents.xcworkspacedata
14+
/*.gcno
15+
**/xcshareddata/WorkspaceSettings.xcsettings

ARImageTracking/AppDelegate.swift

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,14 @@
55
// Created by Qi on 8/1/21.
66
//
77

8-
import UIKit
98
import SwiftUI
9+
import UIKit
1010

1111
@main
1212
class AppDelegate: UIResponder, UIApplicationDelegate {
13-
1413
var window: UIWindow?
1514

16-
1715
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
18-
1916
// Create the SwiftUI view that provides the window contents.
2017
let contentView = ContentView()
2118

@@ -43,7 +40,4 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
4340
func applicationDidBecomeActive(_ application: UIApplication) {
4441
// 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.
4542
}
46-
47-
4843
}
49-

ARImageTracking/Assets.xcassets/AR Resources.arresourcegroup/xs.arreferenceimage/Contents.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"images" : [
33
{
4-
"filename" : "xs.JPG",
4+
"filename" : "xs.jpg",
55
"idiom" : "universal"
66
}
77
],

ARImageTracking/ContentView.swift

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
//
77

88
import ARKit
9-
import SwiftUI
109
import RealityKit
10+
import SwiftUI
1111

12-
//Displays as a SwiftUI View
13-
struct ContentView : View {
12+
// Displays as a SwiftUI View
13+
struct ContentView: View {
1414
var body: some View {
1515
return ARViewContainer().edgesIgnoringSafeArea(.all)
1616
}
@@ -23,7 +23,7 @@ struct ARViewContainer: UIViewRepresentable {
2323
Coordinator(parent: self)
2424
}
2525

26-
class Coordinator: NSObject, ARSessionDelegate{
26+
class Coordinator: NSObject, ARSessionDelegate {
2727
var parent: ARViewContainer
2828
var videoPlayer: AVPlayer!
2929

@@ -37,7 +37,7 @@ struct ARViewContainer: UIViewRepresentable {
3737
return
3838
}
3939

40-
//Assigns video to be overlaid
40+
// Assigns video to be overlaid
4141
guard let path = Bundle.main.path(forResource: "iphonevideo", ofType: "mp4") else {
4242
print("Unable to find video file.")
4343
return
@@ -48,30 +48,30 @@ struct ARViewContainer: UIViewRepresentable {
4848
videoPlayer = AVPlayer(playerItem: playerItem)
4949
let videoMaterial = VideoMaterial(avPlayer: videoPlayer)
5050

51-
// size of video plane depending of the image
52-
let width: Float = Float(imageAnchor.referenceImage.physicalSize.width * 1.03)
53-
let height: Float = Float(imageAnchor.referenceImage.physicalSize.height * 1.03)
51+
// size of video plane depending of the image
52+
let width = Float(imageAnchor.referenceImage.physicalSize.width * 1.03)
53+
let height = Float(imageAnchor.referenceImage.physicalSize.height * 1.03)
5454

55-
//Sets the aspect ratio of the video to be played, and the corner radius of the video
55+
// Sets the aspect ratio of the video to be played, and the corner radius of the video
5656
let videoPlane = ModelEntity(mesh: .generatePlane(width: width, depth: height, cornerRadius: 0.3), materials: [videoMaterial])
5757

58-
//Assigns reference image that will be detected
59-
if let imageName = imageAnchor.name, imageName == "xs" {
58+
// Assigns reference image that will be detected
59+
if let imageName = imageAnchor.name, imageName == "xs" {
6060
let anchor = AnchorEntity(anchor: imageAnchor)
61-
//Adds specified video to the anchor
61+
// Adds specified video to the anchor
6262
anchor.addChild(videoPlane)
6363
parent.arView.scene.addAnchor(anchor)
6464
}
6565
}
6666

67-
//Checks for tracking status
67+
// Checks for tracking status
6868
func session(_ session: ARSession, didUpdate anchors: [ARAnchor]) {
6969
guard let imageAnchor = anchors[0] as? ARImageAnchor else {
7070
print("Problems loading anchor.")
7171
return
7272
}
7373

74-
//Plays/pauses the video when tracked/loses tracking
74+
// Plays/pauses the video when tracked/loses tracking
7575
if imageAnchor.isTracked {
7676
videoPlayer.play()
7777
} else {
@@ -82,19 +82,20 @@ struct ARViewContainer: UIViewRepresentable {
8282

8383
func makeUIView(context: Context) -> ARView {
8484
guard let referenceImages = ARReferenceImage.referenceImages(
85-
inGroupNamed: "AR Resources", bundle: nil) else {
86-
fatalError("Missing expected asset catalog resources.")
87-
}
85+
inGroupNamed: "AR Resources", bundle: nil)
86+
else {
87+
fatalError("Missing expected asset catalog resources.")
88+
}
8889

89-
//Assigns coordinator to delegate the AR View
90+
// Assigns coordinator to delegate the AR View
9091
arView.session.delegate = context.coordinator
9192

9293
let configuration = ARImageTrackingConfiguration()
9394
configuration.isAutoFocusEnabled = true
9495
configuration.trackingImages = referenceImages
9596
configuration.maximumNumberOfTrackedImages = 1
9697

97-
//Enables People Occulusion on supported iOS Devices
98+
// Enables People Occulusion on supported iOS Devices
9899
if ARWorldTrackingConfiguration.supportsFrameSemantics(.personSegmentationWithDepth) {
99100
configuration.frameSemantics.insert(.personSegmentationWithDepth)
100101
} else {
@@ -107,4 +108,3 @@ struct ARViewContainer: UIViewRepresentable {
107108

108109
func updateUIView(_ uiView: ARView, context: Context) {}
109110
}
110-

0 commit comments

Comments
 (0)