diff --git a/AR Ruler.xcodeproj/project.pbxproj b/AR Ruler.xcodeproj/project.pbxproj index 556fb1e..c70942e 100644 --- a/AR Ruler.xcodeproj/project.pbxproj +++ b/AR Ruler.xcodeproj/project.pbxproj @@ -289,6 +289,7 @@ CODE_SIGN_STYLE = Automatic; DEVELOPMENT_TEAM = AXJ887472H; INFOPLIST_FILE = "AR Ruler/Info.plist"; + IPHONEOS_DEPLOYMENT_TARGET = 13.6; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", @@ -308,6 +309,7 @@ CODE_SIGN_STYLE = Automatic; DEVELOPMENT_TEAM = AXJ887472H; INFOPLIST_FILE = "AR Ruler/Info.plist"; + IPHONEOS_DEPLOYMENT_TARGET = 13.6; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", diff --git a/AR Ruler/Assets.xcassets/AppIcon.appiconset/Contents.json b/AR Ruler/Assets.xcassets/AppIcon.appiconset/Contents.json index 9221b9b..65b74d7 100644 --- a/AR Ruler/Assets.xcassets/AppIcon.appiconset/Contents.json +++ b/AR Ruler/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -1,98 +1 @@ -{ - "images" : [ - { - "idiom" : "iphone", - "scale" : "2x", - "size" : "20x20" - }, - { - "idiom" : "iphone", - "scale" : "3x", - "size" : "20x20" - }, - { - "idiom" : "iphone", - "scale" : "2x", - "size" : "29x29" - }, - { - "idiom" : "iphone", - "scale" : "3x", - "size" : "29x29" - }, - { - "idiom" : "iphone", - "scale" : "2x", - "size" : "40x40" - }, - { - "idiom" : "iphone", - "scale" : "3x", - "size" : "40x40" - }, - { - "idiom" : "iphone", - "scale" : "2x", - "size" : "60x60" - }, - { - "idiom" : "iphone", - "scale" : "3x", - "size" : "60x60" - }, - { - "idiom" : "ipad", - "scale" : "1x", - "size" : "20x20" - }, - { - "idiom" : "ipad", - "scale" : "2x", - "size" : "20x20" - }, - { - "idiom" : "ipad", - "scale" : "1x", - "size" : "29x29" - }, - { - "idiom" : "ipad", - "scale" : "2x", - "size" : "29x29" - }, - { - "idiom" : "ipad", - "scale" : "1x", - "size" : "40x40" - }, - { - "idiom" : "ipad", - "scale" : "2x", - "size" : "40x40" - }, - { - "idiom" : "ipad", - "scale" : "1x", - "size" : "76x76" - }, - { - "idiom" : "ipad", - "scale" : "2x", - "size" : "76x76" - }, - { - "idiom" : "ipad", - "scale" : "2x", - "size" : "83.5x83.5" - }, - { - "idiom" : "ios-marketing", - "scale" : "1x", - "size" : "1024x1024" - } - ], - "info" : { - "author" : "xcode", - "version" : 1 - } -} +{"images":[{"size":"60x60","expected-size":"180","filename":"180.png","folder":"Assets.xcassets/AppIcon.appiconset/","idiom":"iphone","scale":"3x"},{"size":"40x40","expected-size":"80","filename":"80.png","folder":"Assets.xcassets/AppIcon.appiconset/","idiom":"iphone","scale":"2x"},{"size":"40x40","expected-size":"120","filename":"120.png","folder":"Assets.xcassets/AppIcon.appiconset/","idiom":"iphone","scale":"3x"},{"size":"60x60","expected-size":"120","filename":"120.png","folder":"Assets.xcassets/AppIcon.appiconset/","idiom":"iphone","scale":"2x"},{"size":"57x57","expected-size":"57","filename":"57.png","folder":"Assets.xcassets/AppIcon.appiconset/","idiom":"iphone","scale":"1x"},{"size":"29x29","expected-size":"58","filename":"58.png","folder":"Assets.xcassets/AppIcon.appiconset/","idiom":"iphone","scale":"2x"},{"size":"29x29","expected-size":"29","filename":"29.png","folder":"Assets.xcassets/AppIcon.appiconset/","idiom":"iphone","scale":"1x"},{"size":"29x29","expected-size":"87","filename":"87.png","folder":"Assets.xcassets/AppIcon.appiconset/","idiom":"iphone","scale":"3x"},{"size":"57x57","expected-size":"114","filename":"114.png","folder":"Assets.xcassets/AppIcon.appiconset/","idiom":"iphone","scale":"2x"},{"size":"20x20","expected-size":"40","filename":"40.png","folder":"Assets.xcassets/AppIcon.appiconset/","idiom":"iphone","scale":"2x"},{"size":"20x20","expected-size":"60","filename":"60.png","folder":"Assets.xcassets/AppIcon.appiconset/","idiom":"iphone","scale":"3x"},{"size":"1024x1024","filename":"1024.png","expected-size":"1024","idiom":"ios-marketing","folder":"Assets.xcassets/AppIcon.appiconset/","scale":"1x"},{"size":"40x40","expected-size":"80","filename":"80.png","folder":"Assets.xcassets/AppIcon.appiconset/","idiom":"ipad","scale":"2x"},{"size":"72x72","expected-size":"72","filename":"72.png","folder":"Assets.xcassets/AppIcon.appiconset/","idiom":"ipad","scale":"1x"},{"size":"76x76","expected-size":"152","filename":"152.png","folder":"Assets.xcassets/AppIcon.appiconset/","idiom":"ipad","scale":"2x"},{"size":"50x50","expected-size":"100","filename":"100.png","folder":"Assets.xcassets/AppIcon.appiconset/","idiom":"ipad","scale":"2x"},{"size":"29x29","expected-size":"58","filename":"58.png","folder":"Assets.xcassets/AppIcon.appiconset/","idiom":"ipad","scale":"2x"},{"size":"76x76","expected-size":"76","filename":"76.png","folder":"Assets.xcassets/AppIcon.appiconset/","idiom":"ipad","scale":"1x"},{"size":"29x29","expected-size":"29","filename":"29.png","folder":"Assets.xcassets/AppIcon.appiconset/","idiom":"ipad","scale":"1x"},{"size":"50x50","expected-size":"50","filename":"50.png","folder":"Assets.xcassets/AppIcon.appiconset/","idiom":"ipad","scale":"1x"},{"size":"72x72","expected-size":"144","filename":"144.png","folder":"Assets.xcassets/AppIcon.appiconset/","idiom":"ipad","scale":"2x"},{"size":"40x40","expected-size":"40","filename":"40.png","folder":"Assets.xcassets/AppIcon.appiconset/","idiom":"ipad","scale":"1x"},{"size":"83.5x83.5","expected-size":"167","filename":"167.png","folder":"Assets.xcassets/AppIcon.appiconset/","idiom":"ipad","scale":"2x"},{"size":"20x20","expected-size":"20","filename":"20.png","folder":"Assets.xcassets/AppIcon.appiconset/","idiom":"ipad","scale":"1x"},{"size":"20x20","expected-size":"40","filename":"40.png","folder":"Assets.xcassets/AppIcon.appiconset/","idiom":"ipad","scale":"2x"}]} \ No newline at end of file diff --git a/AR Ruler/Base.lproj/LaunchScreen.storyboard b/AR Ruler/Base.lproj/LaunchScreen.storyboard index 865e932..674cd60 100644 --- a/AR Ruler/Base.lproj/LaunchScreen.storyboard +++ b/AR Ruler/Base.lproj/LaunchScreen.storyboard @@ -1,7 +1,9 @@ - - + + + - + + @@ -11,15 +13,27 @@ - + - + + + + + + + + - + diff --git a/AR Ruler/ViewController.swift b/AR Ruler/ViewController.swift index bdeee8d..da80291 100644 --- a/AR Ruler/ViewController.swift +++ b/AR Ruler/ViewController.swift @@ -13,20 +13,16 @@ class ViewController: UIViewController, ARSCNViewDelegate { @IBOutlet var sceneView: ARSCNView! + var dotNodes = [SCNNode]() + + var textNode = SCNNode() + override func viewDidLoad() { super.viewDidLoad() - // Set the view's delegate sceneView.delegate = self - // Show statistics such as fps and timing information - sceneView.showsStatistics = true - - // Create a new scene - let scene = SCNScene(named: "art.scnassets/ship.scn")! - // Set the scene to the view - sceneView.scene = scene } override func viewWillAppear(_ animated: Bool) { @@ -45,30 +41,74 @@ class ViewController: UIViewController, ARSCNViewDelegate { // Pause the view's session sceneView.session.pause() } - - // MARK: - ARSCNViewDelegate -/* - // Override to create and configure nodes for anchors added to the view's session. - func renderer(_ renderer: SCNSceneRenderer, nodeFor anchor: ARAnchor) -> SCNNode? { - let node = SCNNode() - - return node - } -*/ - func session(_ session: ARSession, didFailWithError error: Error) { - // Present an error message to the user + override func touchesBegan(_ touches: Set, with event: UIEvent?) { + + + if dotNodes.count >= 2 { + for dot in dotNodes { + dot.removeFromParentNode() + } + dotNodes = [SCNNode]() + } + if let touchLocation = touches.first?.location(in: sceneView) { + let hitTestResults = sceneView.hitTest(touchLocation, types: .featurePoint) + + if let hitResult = hitTestResults.first { + addDot(at: hitResult) + } + } } - func sessionWasInterrupted(_ session: ARSession) { - // Inform the user that the session has been interrupted, for example, by presenting an overlay + func addDot(at hitResult: ARHitTestResult) { + let dotGeometry = SCNSphere(radius: 0.005) + let material = SCNMaterial() + material.diffuse.contents = UIColor.red + + dotGeometry.materials = [material] + + let dotNode = SCNNode(geometry: dotGeometry) + + dotNode.position = SCNVector3( + x: hitResult.worldTransform.columns.3.x, + y: hitResult.worldTransform.columns.3.y, + z: hitResult.worldTransform.columns.3.z) + sceneView.scene.rootNode.addChildNode(dotNode) + + dotNodes.append(dotNode) + + if dotNodes.count >= 2 { + calculate() + } } - - func sessionInterruptionEnded(_ session: ARSession) { - // Reset tracking and/or remove existing anchors if consistent tracking is required + + func calculate() { + let start = dotNodes[0] + let end = dotNodes[1] + + let distance = sqrt( + pow(end.position.x - start.position.x, 2) + + pow(end.position.y - start.position.y, 2) + + pow(end.position.z - start.position.z, 2) + ) + updateText(text: "\(abs(distance)) cm", atPosition: end.position) + } + + func updateText(text: String, atPosition position: SCNVector3) { + + textNode.removeFromParentNode() + + let textGeometry = SCNText(string: text, extrusionDepth: 1.0) + textGeometry.firstMaterial?.diffuse.contents = UIColor.red + + textNode = SCNNode(geometry: textGeometry) + + textNode.position = SCNVector3(position.x, position.y + 0.01, position.z) + textNode.scale = SCNVector3(0.01, 0.01, 0.01) + sceneView.scene.rootNode.addChildNode(textNode) } }