├── Gif └── measure.gif ├── Measure.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ ├── xcshareddata │ │ └── IDEWorkspaceChecks.plist │ └── xcuserdata │ │ └── c5234399.xcuserdatad │ │ └── UserInterfaceState.xcuserstate ├── xcshareddata │ └── xcschemes │ │ └── AMMeasure.xcscheme └── xcuserdata │ └── c5234399.xcuserdatad │ └── xcschemes │ └── xcschememanagement.plist ├── Measure ├── AppDelegate.swift ├── Assets.xcassets │ ├── AppIcon.appiconset │ │ └── Contents.json │ ├── Contents.json │ ├── Oval.imageset │ │ ├── Contents.json │ │ ├── Oval@2x.png │ │ └── Oval@3x.png │ └── add_point.imageset │ │ ├── Contents.json │ │ ├── add_point@2x.png │ │ └── add_point@3x.png ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard ├── Info.plist └── Measure module │ ├── AreaViewController.swift │ ├── DistanceMeasureViewController.swift │ ├── LineNode.swift │ ├── MeasureSCNView.swift │ ├── MeasureViewController.swift │ └── SCNSphere+Init.swift └── README.md /Gif/measure.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adithyabhat/Measure/48a1de49323eef459cfc81038e67bd6b779fd2d0/Gif/measure.gif -------------------------------------------------------------------------------- /Measure.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 50; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 132961D4225B4AD5003BCC23 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 132961C6225B4AD5003BCC23 /* Assets.xcassets */; }; 11 | 132961D5225B4AD5003BCC23 /* MeasureViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 132961C8225B4AD5003BCC23 /* MeasureViewController.swift */; }; 12 | 132961D6225B4AD5003BCC23 /* MeasureSCNView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 132961C9225B4AD5003BCC23 /* MeasureSCNView.swift */; }; 13 | 132961D7225B4AD5003BCC23 /* SCNSphere+Init.swift in Sources */ = {isa = PBXBuildFile; fileRef = 132961CA225B4AD5003BCC23 /* SCNSphere+Init.swift */; }; 14 | 132961D8225B4AD5003BCC23 /* AreaViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 132961CB225B4AD5003BCC23 /* AreaViewController.swift */; }; 15 | 132961D9225B4AD5003BCC23 /* DistanceMeasureViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 132961CC225B4AD5003BCC23 /* DistanceMeasureViewController.swift */; }; 16 | 132961DA225B4AD5003BCC23 /* LineNode.swift in Sources */ = {isa = PBXBuildFile; fileRef = 132961CD225B4AD5003BCC23 /* LineNode.swift */; }; 17 | 132961DB225B4AD5003BCC23 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 132961CE225B4AD5003BCC23 /* LaunchScreen.storyboard */; }; 18 | 132961DC225B4AD5003BCC23 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 132961D0225B4AD5003BCC23 /* Main.storyboard */; }; 19 | 132961DD225B4AD5003BCC23 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 132961D2225B4AD5003BCC23 /* AppDelegate.swift */; }; 20 | /* End PBXBuildFile section */ 21 | 22 | /* Begin PBXFileReference section */ 23 | 132961A32255E00C003BCC23 /* Measure.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Measure.app; sourceTree = BUILT_PRODUCTS_DIR; }; 24 | 132961C6225B4AD5003BCC23 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 25 | 132961C8225B4AD5003BCC23 /* MeasureViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MeasureViewController.swift; sourceTree = ""; }; 26 | 132961C9225B4AD5003BCC23 /* MeasureSCNView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MeasureSCNView.swift; sourceTree = ""; }; 27 | 132961CA225B4AD5003BCC23 /* SCNSphere+Init.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "SCNSphere+Init.swift"; sourceTree = ""; }; 28 | 132961CB225B4AD5003BCC23 /* AreaViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AreaViewController.swift; sourceTree = ""; }; 29 | 132961CC225B4AD5003BCC23 /* DistanceMeasureViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DistanceMeasureViewController.swift; sourceTree = ""; }; 30 | 132961CD225B4AD5003BCC23 /* LineNode.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LineNode.swift; sourceTree = ""; }; 31 | 132961CF225B4AD5003BCC23 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 32 | 132961D1225B4AD5003BCC23 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 33 | 132961D2225B4AD5003BCC23 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 34 | 132961D3225B4AD5003BCC23 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 35 | /* End PBXFileReference section */ 36 | 37 | /* Begin PBXFrameworksBuildPhase section */ 38 | 132961A02255E00C003BCC23 /* Frameworks */ = { 39 | isa = PBXFrameworksBuildPhase; 40 | buildActionMask = 2147483647; 41 | files = ( 42 | ); 43 | runOnlyForDeploymentPostprocessing = 0; 44 | }; 45 | /* End PBXFrameworksBuildPhase section */ 46 | 47 | /* Begin PBXGroup section */ 48 | 1329619A2255E00C003BCC23 = { 49 | isa = PBXGroup; 50 | children = ( 51 | 132961C5225B4AD5003BCC23 /* Measure */, 52 | 132961A42255E00C003BCC23 /* Products */, 53 | ); 54 | sourceTree = ""; 55 | }; 56 | 132961A42255E00C003BCC23 /* Products */ = { 57 | isa = PBXGroup; 58 | children = ( 59 | 132961A32255E00C003BCC23 /* Measure.app */, 60 | ); 61 | name = Products; 62 | sourceTree = ""; 63 | }; 64 | 132961C5225B4AD5003BCC23 /* Measure */ = { 65 | isa = PBXGroup; 66 | children = ( 67 | 132961C6225B4AD5003BCC23 /* Assets.xcassets */, 68 | 132961C7225B4AD5003BCC23 /* Measure module */, 69 | 132961CE225B4AD5003BCC23 /* LaunchScreen.storyboard */, 70 | 132961D0225B4AD5003BCC23 /* Main.storyboard */, 71 | 132961D2225B4AD5003BCC23 /* AppDelegate.swift */, 72 | 132961D3225B4AD5003BCC23 /* Info.plist */, 73 | ); 74 | path = Measure; 75 | sourceTree = ""; 76 | }; 77 | 132961C7225B4AD5003BCC23 /* Measure module */ = { 78 | isa = PBXGroup; 79 | children = ( 80 | 132961C8225B4AD5003BCC23 /* MeasureViewController.swift */, 81 | 132961C9225B4AD5003BCC23 /* MeasureSCNView.swift */, 82 | 132961CA225B4AD5003BCC23 /* SCNSphere+Init.swift */, 83 | 132961CB225B4AD5003BCC23 /* AreaViewController.swift */, 84 | 132961CC225B4AD5003BCC23 /* DistanceMeasureViewController.swift */, 85 | 132961CD225B4AD5003BCC23 /* LineNode.swift */, 86 | ); 87 | path = "Measure module"; 88 | sourceTree = ""; 89 | }; 90 | /* End PBXGroup section */ 91 | 92 | /* Begin PBXNativeTarget section */ 93 | 132961A22255E00C003BCC23 /* Measure */ = { 94 | isa = PBXNativeTarget; 95 | buildConfigurationList = 132961B52255E010003BCC23 /* Build configuration list for PBXNativeTarget "Measure" */; 96 | buildPhases = ( 97 | 1329619F2255E00C003BCC23 /* Sources */, 98 | 132961A02255E00C003BCC23 /* Frameworks */, 99 | 132961A12255E00C003BCC23 /* Resources */, 100 | ); 101 | buildRules = ( 102 | ); 103 | dependencies = ( 104 | ); 105 | name = Measure; 106 | productName = AMMeasure; 107 | productReference = 132961A32255E00C003BCC23 /* Measure.app */; 108 | productType = "com.apple.product-type.application"; 109 | }; 110 | /* End PBXNativeTarget section */ 111 | 112 | /* Begin PBXProject section */ 113 | 1329619B2255E00C003BCC23 /* Project object */ = { 114 | isa = PBXProject; 115 | attributes = { 116 | LastSwiftUpdateCheck = 1020; 117 | LastUpgradeCheck = 1020; 118 | ORGANIZATIONNAME = SAP; 119 | TargetAttributes = { 120 | 132961A22255E00C003BCC23 = { 121 | CreatedOnToolsVersion = 10.2; 122 | }; 123 | }; 124 | }; 125 | buildConfigurationList = 1329619E2255E00C003BCC23 /* Build configuration list for PBXProject "Measure" */; 126 | compatibilityVersion = "Xcode 9.3"; 127 | developmentRegion = en; 128 | hasScannedForEncodings = 0; 129 | knownRegions = ( 130 | en, 131 | Base, 132 | ); 133 | mainGroup = 1329619A2255E00C003BCC23; 134 | productRefGroup = 132961A42255E00C003BCC23 /* Products */; 135 | projectDirPath = ""; 136 | projectRoot = ""; 137 | targets = ( 138 | 132961A22255E00C003BCC23 /* Measure */, 139 | ); 140 | }; 141 | /* End PBXProject section */ 142 | 143 | /* Begin PBXResourcesBuildPhase section */ 144 | 132961A12255E00C003BCC23 /* Resources */ = { 145 | isa = PBXResourcesBuildPhase; 146 | buildActionMask = 2147483647; 147 | files = ( 148 | 132961DC225B4AD5003BCC23 /* Main.storyboard in Resources */, 149 | 132961D4225B4AD5003BCC23 /* Assets.xcassets in Resources */, 150 | 132961DB225B4AD5003BCC23 /* LaunchScreen.storyboard in Resources */, 151 | ); 152 | runOnlyForDeploymentPostprocessing = 0; 153 | }; 154 | /* End PBXResourcesBuildPhase section */ 155 | 156 | /* Begin PBXSourcesBuildPhase section */ 157 | 1329619F2255E00C003BCC23 /* Sources */ = { 158 | isa = PBXSourcesBuildPhase; 159 | buildActionMask = 2147483647; 160 | files = ( 161 | 132961D7225B4AD5003BCC23 /* SCNSphere+Init.swift in Sources */, 162 | 132961DA225B4AD5003BCC23 /* LineNode.swift in Sources */, 163 | 132961D9225B4AD5003BCC23 /* DistanceMeasureViewController.swift in Sources */, 164 | 132961D6225B4AD5003BCC23 /* MeasureSCNView.swift in Sources */, 165 | 132961DD225B4AD5003BCC23 /* AppDelegate.swift in Sources */, 166 | 132961D5225B4AD5003BCC23 /* MeasureViewController.swift in Sources */, 167 | 132961D8225B4AD5003BCC23 /* AreaViewController.swift in Sources */, 168 | ); 169 | runOnlyForDeploymentPostprocessing = 0; 170 | }; 171 | /* End PBXSourcesBuildPhase section */ 172 | 173 | /* Begin PBXVariantGroup section */ 174 | 132961CE225B4AD5003BCC23 /* LaunchScreen.storyboard */ = { 175 | isa = PBXVariantGroup; 176 | children = ( 177 | 132961CF225B4AD5003BCC23 /* Base */, 178 | ); 179 | name = LaunchScreen.storyboard; 180 | sourceTree = ""; 181 | }; 182 | 132961D0225B4AD5003BCC23 /* Main.storyboard */ = { 183 | isa = PBXVariantGroup; 184 | children = ( 185 | 132961D1225B4AD5003BCC23 /* Base */, 186 | ); 187 | name = Main.storyboard; 188 | sourceTree = ""; 189 | }; 190 | /* End PBXVariantGroup section */ 191 | 192 | /* Begin XCBuildConfiguration section */ 193 | 132961B32255E010003BCC23 /* Debug */ = { 194 | isa = XCBuildConfiguration; 195 | buildSettings = { 196 | ALWAYS_SEARCH_USER_PATHS = NO; 197 | CLANG_ANALYZER_NONNULL = YES; 198 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 199 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 200 | CLANG_CXX_LIBRARY = "libc++"; 201 | CLANG_ENABLE_MODULES = YES; 202 | CLANG_ENABLE_OBJC_ARC = YES; 203 | CLANG_ENABLE_OBJC_WEAK = YES; 204 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 205 | CLANG_WARN_BOOL_CONVERSION = YES; 206 | CLANG_WARN_COMMA = YES; 207 | CLANG_WARN_CONSTANT_CONVERSION = YES; 208 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 209 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 210 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 211 | CLANG_WARN_EMPTY_BODY = YES; 212 | CLANG_WARN_ENUM_CONVERSION = YES; 213 | CLANG_WARN_INFINITE_RECURSION = YES; 214 | CLANG_WARN_INT_CONVERSION = YES; 215 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 216 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 217 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 218 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 219 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 220 | CLANG_WARN_STRICT_PROTOTYPES = YES; 221 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 222 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 223 | CLANG_WARN_UNREACHABLE_CODE = YES; 224 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 225 | CODE_SIGN_IDENTITY = "iPhone Developer"; 226 | COPY_PHASE_STRIP = NO; 227 | DEBUG_INFORMATION_FORMAT = dwarf; 228 | ENABLE_STRICT_OBJC_MSGSEND = YES; 229 | ENABLE_TESTABILITY = YES; 230 | GCC_C_LANGUAGE_STANDARD = gnu11; 231 | GCC_DYNAMIC_NO_PIC = NO; 232 | GCC_NO_COMMON_BLOCKS = YES; 233 | GCC_OPTIMIZATION_LEVEL = 0; 234 | GCC_PREPROCESSOR_DEFINITIONS = ( 235 | "DEBUG=1", 236 | "$(inherited)", 237 | ); 238 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 239 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 240 | GCC_WARN_UNDECLARED_SELECTOR = YES; 241 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 242 | GCC_WARN_UNUSED_FUNCTION = YES; 243 | GCC_WARN_UNUSED_VARIABLE = YES; 244 | IPHONEOS_DEPLOYMENT_TARGET = 12.2; 245 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; 246 | MTL_FAST_MATH = YES; 247 | ONLY_ACTIVE_ARCH = YES; 248 | SDKROOT = iphoneos; 249 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 250 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 251 | }; 252 | name = Debug; 253 | }; 254 | 132961B42255E010003BCC23 /* Release */ = { 255 | isa = XCBuildConfiguration; 256 | buildSettings = { 257 | ALWAYS_SEARCH_USER_PATHS = NO; 258 | CLANG_ANALYZER_NONNULL = YES; 259 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 260 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 261 | CLANG_CXX_LIBRARY = "libc++"; 262 | CLANG_ENABLE_MODULES = YES; 263 | CLANG_ENABLE_OBJC_ARC = YES; 264 | CLANG_ENABLE_OBJC_WEAK = YES; 265 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 266 | CLANG_WARN_BOOL_CONVERSION = YES; 267 | CLANG_WARN_COMMA = YES; 268 | CLANG_WARN_CONSTANT_CONVERSION = YES; 269 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 270 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 271 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 272 | CLANG_WARN_EMPTY_BODY = YES; 273 | CLANG_WARN_ENUM_CONVERSION = YES; 274 | CLANG_WARN_INFINITE_RECURSION = YES; 275 | CLANG_WARN_INT_CONVERSION = YES; 276 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 277 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 278 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 279 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 280 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 281 | CLANG_WARN_STRICT_PROTOTYPES = YES; 282 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 283 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 284 | CLANG_WARN_UNREACHABLE_CODE = YES; 285 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 286 | CODE_SIGN_IDENTITY = "iPhone Developer"; 287 | COPY_PHASE_STRIP = NO; 288 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 289 | ENABLE_NS_ASSERTIONS = NO; 290 | ENABLE_STRICT_OBJC_MSGSEND = YES; 291 | GCC_C_LANGUAGE_STANDARD = gnu11; 292 | GCC_NO_COMMON_BLOCKS = YES; 293 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 294 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 295 | GCC_WARN_UNDECLARED_SELECTOR = YES; 296 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 297 | GCC_WARN_UNUSED_FUNCTION = YES; 298 | GCC_WARN_UNUSED_VARIABLE = YES; 299 | IPHONEOS_DEPLOYMENT_TARGET = 12.2; 300 | MTL_ENABLE_DEBUG_INFO = NO; 301 | MTL_FAST_MATH = YES; 302 | SDKROOT = iphoneos; 303 | SWIFT_COMPILATION_MODE = wholemodule; 304 | SWIFT_OPTIMIZATION_LEVEL = "-O"; 305 | VALIDATE_PRODUCT = YES; 306 | }; 307 | name = Release; 308 | }; 309 | 132961B62255E010003BCC23 /* Debug */ = { 310 | isa = XCBuildConfiguration; 311 | buildSettings = { 312 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 313 | CODE_SIGN_IDENTITY = "iPhone Developer"; 314 | CODE_SIGN_STYLE = Manual; 315 | DEVELOPMENT_TEAM = ""; 316 | INFOPLIST_FILE = "$(SRCROOT)/Measure/Info.plist"; 317 | IPHONEOS_DEPLOYMENT_TARGET = 11.1; 318 | LD_RUNPATH_SEARCH_PATHS = ( 319 | "$(inherited)", 320 | "@executable_path/Frameworks", 321 | ); 322 | PRODUCT_BUNDLE_IDENTIFIER = com.AB.Measure; 323 | PRODUCT_NAME = "$(TARGET_NAME)"; 324 | PROVISIONING_PROFILE_SPECIFIER = ""; 325 | SWIFT_VERSION = 5.0; 326 | TARGETED_DEVICE_FAMILY = 1; 327 | }; 328 | name = Debug; 329 | }; 330 | 132961B72255E010003BCC23 /* Release */ = { 331 | isa = XCBuildConfiguration; 332 | buildSettings = { 333 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 334 | CODE_SIGN_IDENTITY = "iPhone Developer"; 335 | CODE_SIGN_STYLE = Manual; 336 | DEVELOPMENT_TEAM = ""; 337 | INFOPLIST_FILE = "$(SRCROOT)/Measure/Info.plist"; 338 | IPHONEOS_DEPLOYMENT_TARGET = 11.1; 339 | LD_RUNPATH_SEARCH_PATHS = ( 340 | "$(inherited)", 341 | "@executable_path/Frameworks", 342 | ); 343 | PRODUCT_BUNDLE_IDENTIFIER = com.AB.Measure; 344 | PRODUCT_NAME = "$(TARGET_NAME)"; 345 | PROVISIONING_PROFILE_SPECIFIER = ""; 346 | SWIFT_VERSION = 5.0; 347 | TARGETED_DEVICE_FAMILY = 1; 348 | }; 349 | name = Release; 350 | }; 351 | /* End XCBuildConfiguration section */ 352 | 353 | /* Begin XCConfigurationList section */ 354 | 1329619E2255E00C003BCC23 /* Build configuration list for PBXProject "Measure" */ = { 355 | isa = XCConfigurationList; 356 | buildConfigurations = ( 357 | 132961B32255E010003BCC23 /* Debug */, 358 | 132961B42255E010003BCC23 /* Release */, 359 | ); 360 | defaultConfigurationIsVisible = 0; 361 | defaultConfigurationName = Release; 362 | }; 363 | 132961B52255E010003BCC23 /* Build configuration list for PBXNativeTarget "Measure" */ = { 364 | isa = XCConfigurationList; 365 | buildConfigurations = ( 366 | 132961B62255E010003BCC23 /* Debug */, 367 | 132961B72255E010003BCC23 /* Release */, 368 | ); 369 | defaultConfigurationIsVisible = 0; 370 | defaultConfigurationName = Release; 371 | }; 372 | /* End XCConfigurationList section */ 373 | }; 374 | rootObject = 1329619B2255E00C003BCC23 /* Project object */; 375 | } 376 | -------------------------------------------------------------------------------- /Measure.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Measure.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Measure.xcodeproj/project.xcworkspace/xcuserdata/c5234399.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adithyabhat/Measure/48a1de49323eef459cfc81038e67bd6b779fd2d0/Measure.xcodeproj/project.xcworkspace/xcuserdata/c5234399.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /Measure.xcodeproj/xcshareddata/xcschemes/AMMeasure.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 43 | 44 | 54 | 56 | 62 | 63 | 64 | 65 | 66 | 67 | 73 | 75 | 81 | 82 | 83 | 84 | 86 | 87 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /Measure.xcodeproj/xcuserdata/c5234399.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | AMMeasure.xcscheme_^#shared#^_ 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | 132961A22255E00C003BCC23 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /Measure/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // AMMeasure 4 | // 5 | // Created by Bhat, Adithya H on 04/04/19. 6 | // 7 | 8 | import UIKit 9 | 10 | @UIApplicationMain 11 | class AppDelegate: UIResponder, UIApplicationDelegate { 12 | 13 | var window: UIWindow? 14 | 15 | 16 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { 17 | // Override point for customization after application launch. 18 | return true 19 | } 20 | 21 | 22 | } 23 | 24 | -------------------------------------------------------------------------------- /Measure/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "20x20", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "20x20", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "29x29", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "29x29", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "40x40", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "40x40", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "size" : "60x60", 36 | "scale" : "2x" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "size" : "60x60", 41 | "scale" : "3x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "20x20", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "20x20", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "29x29", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "29x29", 61 | "scale" : "2x" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "size" : "40x40", 66 | "scale" : "1x" 67 | }, 68 | { 69 | "idiom" : "ipad", 70 | "size" : "40x40", 71 | "scale" : "2x" 72 | }, 73 | { 74 | "idiom" : "ipad", 75 | "size" : "76x76", 76 | "scale" : "1x" 77 | }, 78 | { 79 | "idiom" : "ipad", 80 | "size" : "76x76", 81 | "scale" : "2x" 82 | }, 83 | { 84 | "idiom" : "ipad", 85 | "size" : "83.5x83.5", 86 | "scale" : "2x" 87 | }, 88 | { 89 | "idiom" : "ios-marketing", 90 | "size" : "1024x1024", 91 | "scale" : "1x" 92 | } 93 | ], 94 | "info" : { 95 | "version" : 1, 96 | "author" : "xcode" 97 | } 98 | } -------------------------------------------------------------------------------- /Measure/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /Measure/Assets.xcassets/Oval.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "filename" : "Oval@2x.png", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "filename" : "Oval@3x.png", 15 | "scale" : "3x" 16 | } 17 | ], 18 | "info" : { 19 | "version" : 1, 20 | "author" : "xcode" 21 | } 22 | } -------------------------------------------------------------------------------- /Measure/Assets.xcassets/Oval.imageset/Oval@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adithyabhat/Measure/48a1de49323eef459cfc81038e67bd6b779fd2d0/Measure/Assets.xcassets/Oval.imageset/Oval@2x.png -------------------------------------------------------------------------------- /Measure/Assets.xcassets/Oval.imageset/Oval@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adithyabhat/Measure/48a1de49323eef459cfc81038e67bd6b779fd2d0/Measure/Assets.xcassets/Oval.imageset/Oval@3x.png -------------------------------------------------------------------------------- /Measure/Assets.xcassets/add_point.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "filename" : "add_point@2x.png", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "filename" : "add_point@3x.png", 15 | "scale" : "3x" 16 | } 17 | ], 18 | "info" : { 19 | "version" : 1, 20 | "author" : "xcode" 21 | } 22 | } -------------------------------------------------------------------------------- /Measure/Assets.xcassets/add_point.imageset/add_point@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adithyabhat/Measure/48a1de49323eef459cfc81038e67bd6b779fd2d0/Measure/Assets.xcassets/add_point.imageset/add_point@2x.png -------------------------------------------------------------------------------- /Measure/Assets.xcassets/add_point.imageset/add_point@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adithyabhat/Measure/48a1de49323eef459cfc81038e67bd6b779fd2d0/Measure/Assets.xcassets/add_point.imageset/add_point@3x.png -------------------------------------------------------------------------------- /Measure/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Measure/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 52 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 80 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 108 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 204 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | -------------------------------------------------------------------------------- /Measure/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | NSCameraUsageDescription 24 | For measurement using AR 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationPortraitUpsideDown 37 | 38 | UISupportedInterfaceOrientations~ipad 39 | 40 | UIInterfaceOrientationLandscapeLeft 41 | UIInterfaceOrientationLandscapeRight 42 | 43 | UIViewControllerBasedStatusBarAppearance 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /Measure/Measure module/AreaViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // AMMeasure 4 | // 5 | // Created by Bhat, Adithya H on 04/04/19. 6 | // 7 | 8 | import UIKit 9 | import ARKit 10 | 11 | class AreaViewController: MeasureViewController { 12 | 13 | enum MeasureState { 14 | case lengthCalc 15 | case breadthCalc 16 | } 17 | 18 | struct FloorRect { 19 | var length: CGFloat 20 | var breadth: CGFloat 21 | var area: CGFloat { 22 | get { 23 | return length * breadth 24 | } 25 | } 26 | } 27 | 28 | var floorRect = FloorRect(length: 0, breadth: 0) 29 | var lengthNodes = NSMutableArray() 30 | var breadthNodes = NSMutableArray() 31 | var lineNodes = NSMutableArray() 32 | var currentState: MeasureState = MeasureState.lengthCalc 33 | 34 | var allPointNodes: [Any] { 35 | get { 36 | return lengthNodes as! [Any] + breadthNodes 37 | } 38 | } 39 | var nodeColor: UIColor { 40 | get { 41 | return nodeColor(forState: currentState, alphaComponent: 0.7) 42 | } 43 | } 44 | 45 | 46 | @IBOutlet weak var areaLabel: UILabel! 47 | @IBOutlet weak var breadthLabel: UILabel! 48 | @IBOutlet weak var lengthLabel: UILabel! 49 | 50 | override func viewDidLoad() { 51 | super.viewDidLoad() 52 | sceneView.delegate = self 53 | lengthLabel.textColor = nodeColor(forState: .lengthCalc, alphaComponent: 1) 54 | breadthLabel.textColor = nodeColor(forState: .breadthCalc, alphaComponent: 1) 55 | } 56 | 57 | //MARK: - Private helper methods 58 | 59 | private func nodeColor(forState state: MeasureState, alphaComponent: CGFloat) -> UIColor { 60 | switch state { 61 | case .lengthCalc: 62 | return UIColor.red.withAlphaComponent(alphaComponent) 63 | case .breadthCalc: 64 | return UIColor.green.withAlphaComponent(alphaComponent) 65 | } 66 | } 67 | 68 | 69 | private func nodesList(forState state: MeasureState) -> NSMutableArray { 70 | switch state { 71 | case .lengthCalc: 72 | return lengthNodes 73 | case .breadthCalc: 74 | return breadthNodes 75 | } 76 | } 77 | 78 | func clearScene() { 79 | removeNodes(fromNodeList: nodesList(forState: .lengthCalc)) 80 | removeNodes(fromNodeList: nodesList(forState: .breadthCalc)) 81 | removeNodes(fromNodeList: lineNodes) 82 | } 83 | 84 | private func resetMeasurement() { 85 | clearScene() 86 | floorRect = FloorRect(length: 0, breadth: 0) 87 | currentState = .lengthCalc 88 | lengthLabel.text = "--" 89 | breadthLabel.text = "--" 90 | areaLabel.text = "--" 91 | } 92 | 93 | 94 | //MARK: - IBActions 95 | 96 | @IBAction func addPoint(_ sender: UIButton) { 97 | 98 | let pointLocation = view.convert(screenCenterPoint, to: sceneView) 99 | guard let hitResultPosition = sceneView.hitResult(forPoint: pointLocation) else { 100 | return 101 | } 102 | 103 | //To prevent multiple taps 104 | sender.isUserInteractionEnabled = false 105 | defer { 106 | sender.isUserInteractionEnabled = true 107 | } 108 | 109 | if allPointNodes.count >= 4 { 110 | resetMeasurement() 111 | } 112 | let nodes = nodesList(forState: currentState) 113 | 114 | let sphere = SCNSphere(color: nodeColor, radius: nodeRadius) 115 | let node = SCNNode(geometry: sphere) 116 | node.position = hitResultPosition 117 | sceneView.scene.rootNode.addChildNode(node) 118 | 119 | // Add the Sphere to the list. 120 | nodes.add(node) 121 | 122 | if nodes.count == 1 { 123 | 124 | //Add a realtime line 125 | let realTimeLine = LineNode(from: hitResultPosition, 126 | to: hitResultPosition, 127 | lineColor: nodeColor, 128 | lineWidth: lineWidth) 129 | realTimeLine.name = realTimeLineName 130 | realTimeLineNode = realTimeLine 131 | sceneView.scene.rootNode.addChildNode(realTimeLine) 132 | 133 | } else if nodes.count == 2 { 134 | let startNode = nodes[0] as! SCNNode 135 | let endNode = nodes[1] as! SCNNode 136 | 137 | // Create a node line between the nodes 138 | let measureLine = LineNode(from: startNode.position, 139 | to: endNode.position, 140 | lineColor: nodeColor, 141 | lineWidth: lineWidth) 142 | sceneView.scene.rootNode.addChildNode(measureLine) 143 | lineNodes.add(measureLine) 144 | 145 | //calc distance 146 | let distance = sceneView.distance(betweenPoints: startNode.position, point2: endNode.position) 147 | 148 | //Remove realtime line node 149 | realTimeLineNode?.removeFromParentNode() 150 | realTimeLineNode = nil 151 | 152 | //Change state 153 | switch currentState { 154 | case .lengthCalc: 155 | floorRect.length = distance 156 | currentState = .breadthCalc 157 | lengthLabel.text = String(format: "%.2fm", distance) 158 | case .breadthCalc: 159 | floorRect.breadth = distance 160 | breadthLabel.text = String(format: "%.2fm", distance) 161 | areaLabel.text = String(format: "%.2fm", floorRect.area) 162 | } 163 | } 164 | } 165 | 166 | } 167 | 168 | extension AreaViewController: ARSCNViewDelegate { 169 | 170 | func renderer(_ renderer: SCNSceneRenderer, updateAtTime time: TimeInterval) { 171 | let dotNodes = allPointNodes as! [SCNNode] 172 | if dotNodes.count > 0, let currentCameraPosition = self.sceneView.pointOfView { 173 | updateScaleFromCameraForNodes(dotNodes, fromPointOfView: currentCameraPosition) 174 | } 175 | 176 | //Update realtime line node 177 | if let realTimeLineNode = self.realTimeLineNode, 178 | let hitResultPosition = sceneView.hitResult(forPoint: screenCenterPoint), 179 | let startNode = self.nodesList(forState: self.currentState).firstObject as? SCNNode { 180 | realTimeLineNode.updateNode(vectorA: startNode.position, vectorB: hitResultPosition, color: nil) 181 | 182 | let distance = sceneView.distance(betweenPoints: startNode.position, point2: hitResultPosition) 183 | let label = currentState == .lengthCalc ? lengthLabel : breadthLabel 184 | DispatchQueue.main.async { [unowned self] in 185 | label?.text = String(format: "%.2fm", distance) 186 | label?.textColor = self.nodeColor 187 | } 188 | } 189 | } 190 | 191 | func session(_ session: ARSession, cameraDidChangeTrackingState camera: ARCamera) { 192 | switch camera.trackingState { 193 | case .normal: 194 | break 195 | default: 196 | break 197 | } 198 | } 199 | 200 | } 201 | -------------------------------------------------------------------------------- /Measure/Measure module/DistanceMeasureViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // AMMeasure 4 | // 5 | // Created by Bhat, Adithya H on 04/04/19. 6 | // 7 | 8 | import UIKit 9 | import ARKit 10 | 11 | class DistanceMeasureViewController: MeasureViewController { 12 | 13 | struct FloorRect { 14 | var length: CGFloat 15 | var breadth: CGFloat 16 | var area: CGFloat { 17 | get { 18 | return length * breadth 19 | } 20 | } 21 | } 22 | 23 | var distance: CGFloat = 0 24 | var distanceNodes = NSMutableArray() 25 | var lineNodes = NSMutableArray() 26 | 27 | var nodeColor = UIColor.white.withAlphaComponent(0.7) 28 | 29 | @IBOutlet weak var lengthLabel: UILabel! 30 | 31 | override func viewDidLoad() { 32 | super.viewDidLoad() 33 | sceneView.delegate = self 34 | } 35 | 36 | //MARK: - Private helper methods 37 | 38 | func clearScene() { 39 | removeNodes(fromNodeList: distanceNodes) 40 | removeNodes(fromNodeList: lineNodes) 41 | } 42 | 43 | private func resetMeasurement() { 44 | clearScene() 45 | distance = 0 46 | } 47 | 48 | 49 | //MARK: - IBActions 50 | 51 | @IBAction func addPoint(_ sender: UIButton) { 52 | 53 | let pointLocation = view.convert(screenCenterPoint, to: sceneView) 54 | guard let hitResultPosition = sceneView.hitResult(forPoint: pointLocation) else { 55 | return 56 | } 57 | 58 | //To prevent multiple taps 59 | sender.isUserInteractionEnabled = false 60 | defer { 61 | sender.isUserInteractionEnabled = true 62 | } 63 | 64 | if distanceNodes.count >= 2 { 65 | resetMeasurement() 66 | } 67 | let nodes = distanceNodes 68 | 69 | let sphere = SCNSphere(color: nodeColor, radius: nodeRadius) 70 | let node = SCNNode(geometry: sphere) 71 | node.position = hitResultPosition 72 | sceneView.scene.rootNode.addChildNode(node) 73 | 74 | // Add the Sphere to the list. 75 | nodes.add(node) 76 | 77 | if nodes.count == 1 { 78 | 79 | //Add a realtime line 80 | let realTimeLine = LineNode(from: hitResultPosition, 81 | to: hitResultPosition, 82 | lineColor: nodeColor, 83 | lineWidth: lineWidth) 84 | realTimeLine.name = realTimeLineName 85 | realTimeLineNode = realTimeLine 86 | sceneView.scene.rootNode.addChildNode(realTimeLine) 87 | 88 | } else if nodes.count == 2 { 89 | let startNode = nodes[0] as! SCNNode 90 | let endNode = nodes[1] as! SCNNode 91 | 92 | // Create a node line between the nodes 93 | let measureLine = LineNode(from: startNode.position, 94 | to: endNode.position, 95 | lineColor: nodeColor, 96 | lineWidth: lineWidth) 97 | sceneView.scene.rootNode.addChildNode(measureLine) 98 | lineNodes.add(measureLine) 99 | 100 | //Remove realtime line node 101 | realTimeLineNode?.removeFromParentNode() 102 | realTimeLineNode = nil 103 | 104 | distance = sceneView.distance(betweenPoints: startNode.position, point2: endNode.position) 105 | lengthLabel.text = String(format: "%.2fm", distance) 106 | } 107 | } 108 | 109 | } 110 | 111 | extension DistanceMeasureViewController: ARSCNViewDelegate { 112 | 113 | func renderer(_ renderer: SCNSceneRenderer, updateAtTime time: TimeInterval) { 114 | let dotNodes = distanceNodes as! [SCNNode] 115 | if dotNodes.count > 0, let currentCameraPosition = self.sceneView.pointOfView { 116 | updateScaleFromCameraForNodes(dotNodes, fromPointOfView: currentCameraPosition) 117 | } 118 | 119 | //Update realtime line node 120 | if let realTimeLineNode = self.realTimeLineNode, 121 | let hitResultPosition = sceneView.hitResult(forPoint: screenCenterPoint), 122 | let startNode = distanceNodes.firstObject as? SCNNode { 123 | realTimeLineNode.updateNode(vectorA: startNode.position, vectorB: hitResultPosition, color: nil) 124 | 125 | let distance = sceneView.distance(betweenPoints: startNode.position, point2: hitResultPosition) 126 | DispatchQueue.main.async { [unowned self] in 127 | self.lengthLabel.text = String(format: "%.2fm", distance) 128 | } 129 | } 130 | } 131 | 132 | func session(_ session: ARSession, cameraDidChangeTrackingState camera: ARCamera) { 133 | switch camera.trackingState { 134 | case .normal: 135 | break 136 | default: 137 | break 138 | } 139 | } 140 | 141 | } 142 | -------------------------------------------------------------------------------- /Measure/Measure module/LineNode.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LineNode.swift 3 | // Measure 4 | // 5 | // Created by Bhat, Adithya H (external - Project) on 06/02/19. 6 | // Copyright © 2019 Bhat, Adithya H (external - Project). All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import SceneKit 11 | 12 | class LineNode: SCNNode { 13 | 14 | let lineThickness = CGFloat(0.001) 15 | let radius = CGFloat(0.1) 16 | private var boxGeometry: SCNBox! 17 | private var nodeLine: SCNNode! 18 | 19 | init(from vectorA: SCNVector3, to vectorB: SCNVector3, lineColor color: UIColor, lineWidth width: CGFloat) { 20 | super.init() 21 | 22 | self.position = vectorA 23 | 24 | let nodeZAlign = SCNNode() 25 | nodeZAlign.eulerAngles.x = Float.pi/2 26 | 27 | let height = self.distance(from: vectorA, to: vectorB) 28 | boxGeometry = SCNBox(width: width, height: height, length: lineThickness, chamferRadius: radius) 29 | let material = SCNMaterial() 30 | material.diffuse.contents = color 31 | boxGeometry.materials = [material] 32 | 33 | let nodeLine = SCNNode(geometry: boxGeometry) 34 | nodeLine.position.y = Float(-height/2) + 0.001 35 | nodeZAlign.addChildNode(nodeLine) 36 | 37 | self.addChildNode(nodeZAlign) 38 | 39 | let orientationNode = SCNNode() 40 | orientationNode.position = vectorB 41 | self.constraints = [SCNLookAtConstraint(target: orientationNode)] 42 | 43 | } 44 | 45 | required init?(coder aDecoder: NSCoder) { 46 | super.init(coder: aDecoder) 47 | } 48 | 49 | func distance(from vectorA: SCNVector3, to vectorB: SCNVector3)-> CGFloat { 50 | return 51 | CGFloat (sqrt( 52 | (vectorA.x - vectorB.x) * (vectorA.x - vectorB.x) + 53 | (vectorA.y - vectorB.y) * (vectorA.y - vectorB.y) + 54 | (vectorA.z - vectorB.z) * (vectorA.z - vectorB.z))) 55 | } 56 | 57 | func updateNode(vectorA: SCNVector3? = nil, vectorB: SCNVector3? = nil, color: UIColor?) { 58 | if let vectorA = vectorA, let vectorB = vectorB { 59 | let height = self.distance(from: vectorA, to: vectorB) 60 | boxGeometry.height = height 61 | nodeLine.position.y = Float(-height/2) + 0.001 62 | 63 | let orientationNode = SCNNode() 64 | orientationNode.position = vectorB 65 | self.constraints = [SCNLookAtConstraint(target: orientationNode)] 66 | } 67 | if let color = color { 68 | let material = SCNMaterial() 69 | material.diffuse.contents = color 70 | boxGeometry.materials = [material] 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /Measure/Measure module/MeasureSCNView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // MeasureSCNView.swift 3 | // MeasureARKit 4 | // 5 | // Created by Bhat, Adithya H (external - Project) on 25/03/19. 6 | // Copyright © 2019 Bhat, Adithya H (external - Project). All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import ARKit 11 | 12 | open class MeasureSCNView: ARSCNView { 13 | 14 | private var configuration = ARWorldTrackingConfiguration() 15 | var markedPoints = [SCNVector3]() 16 | 17 | public required init?(coder aDecoder: NSCoder) { 18 | super.init(coder: aDecoder) 19 | setUp() 20 | } 21 | 22 | //MARK: - Private helper methods 23 | 24 | private func setUp() { 25 | let scene = SCNScene() 26 | 27 | self.automaticallyUpdatesLighting = true 28 | self.scene = scene 29 | configuration.planeDetection = [.horizontal] 30 | } 31 | 32 | func hitResult(forPoint point: CGPoint) -> SCNVector3? { 33 | let hitTestResults = hitTest(point, types: .featurePoint) 34 | if let result = hitTestResults.first { 35 | let vector = result.worldTransform.columns.3 36 | return SCNVector3(vector.x, vector.y, vector.z) 37 | } else { 38 | return nil 39 | } 40 | } 41 | 42 | //MARK: - Public helper methods 43 | 44 | func run() { 45 | self.session.run(configuration, options: [.resetTracking, .removeExistingAnchors]) 46 | } 47 | 48 | func pause() { 49 | self.session.pause() 50 | } 51 | 52 | func distance(betweenPoints point1: SCNVector3, point2: SCNVector3) -> CGFloat { 53 | let dx = point2.x - point1.x 54 | let dy = point2.y - point1.y 55 | let dz = point2.z - point1.z 56 | return CGFloat(sqrt(dx*dx + dy*dy + dz*dz)) 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /Measure/Measure module/MeasureViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // MeasureViewController.swift 3 | // AMMeasure 4 | // 5 | // Created by Bhat, Adithya H on 04/04/19. 6 | // 7 | 8 | import UIKit 9 | import ARKit 10 | 11 | class MeasureViewController: UIViewController { 12 | 13 | let lineWidth = CGFloat(0.003) 14 | let nodeRadius = CGFloat(0.015) 15 | let realTimeLineName = "realTimeLine" 16 | 17 | var realTimeLineNode: LineNode? 18 | 19 | @IBOutlet weak var centerPointImageView: UIImageView! 20 | @IBOutlet weak var sceneView: MeasureSCNView! 21 | 22 | lazy var screenCenterPoint: CGPoint = { 23 | return centerPointImageView.center 24 | }() 25 | 26 | override func viewWillAppear(_ animated: Bool) { 27 | super.viewWillAppear(animated) 28 | sceneView.run() 29 | } 30 | 31 | override func viewWillDisappear(_ animated: Bool) { 32 | sceneView.pause() 33 | super.viewWillDisappear(animated) 34 | } 35 | 36 | override var prefersStatusBarHidden: Bool { 37 | return true 38 | } 39 | 40 | //MARK: - Helper methods 41 | 42 | func removeNodes(fromNodeList nodes: NSMutableArray) { 43 | for node in nodes { 44 | if let node = node as? SCNNode { 45 | node.removeFromParentNode() 46 | nodes.remove(node) 47 | } 48 | } 49 | } 50 | 51 | func updateScaleFromCameraForNodes(_ nodes: [SCNNode], fromPointOfView pointOfView: SCNNode){ 52 | 53 | nodes.forEach { (node) in 54 | 55 | //1. Get The Current Position Of The Node 56 | let positionOfNode = SCNVector3ToGLKVector3(node.worldPosition) 57 | 58 | //2. Get The Current Position Of The Camera 59 | let positionOfCamera = SCNVector3ToGLKVector3(pointOfView.worldPosition) 60 | 61 | //3. Calculate The Distance From The Node To The Camera 62 | let distanceBetweenNodeAndCamera = GLKVector3Distance(positionOfNode, positionOfCamera) 63 | 64 | //4. Animate Their Scaling & Set Their Scale Based On Their Distance From The Camera 65 | SCNTransaction.begin() 66 | SCNTransaction.animationDuration = 0.5 67 | switch distanceBetweenNodeAndCamera { 68 | case 0 ... 0.5: 69 | node.simdScale = simd_float3(0.25, 0.25, 0.25) 70 | case 0.5 ... 1.5: 71 | node.simdScale = simd_float3(0.5, 0.5, 0.5) 72 | case 1.5 ... 2.5: 73 | node.simdScale = simd_float3(1, 1, 1) 74 | case 2.5 ... 3: 75 | node.simdScale = simd_float3(1.5, 1.5, 1.5) 76 | case 3 ... 3.5: 77 | node.simdScale = simd_float3(2, 2, 2) 78 | case 3.5 ... 5: 79 | node.simdScale = simd_float3(2.5, 2.5, 2.5) 80 | default: 81 | node.simdScale = simd_float3(3, 3, 3) 82 | } 83 | SCNTransaction.commit() 84 | } 85 | 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /Measure/Measure module/SCNSphere+Init.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SCNSphere+Init.swift 3 | // Measure 4 | // 5 | // Created by Bhat, Adithya H (external - Project) on 23/01/19. 6 | // Copyright © 2019 Bhat, Adithya H (external - Project). All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import SceneKit 11 | 12 | extension SCNSphere { 13 | convenience init(color: UIColor, radius: CGFloat) { 14 | self.init(radius: radius) 15 | 16 | let material = SCNMaterial() 17 | material.diffuse.contents = color 18 | materials = [material] 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Measure 2 | iOS App that replicates measuring functionality of the iOS 12 Measure App. The App is written in Swift 4 and makes use of ARKit to achieve the same. 3 | 4 | ![](https://github.com/adithyabhat/Measure/blob/master/Gif/measure.gif) 5 | --------------------------------------------------------------------------------