--- /dev/null
+//
+// GameViewController.swift
+// GameProjectTest
+//
+// Created by Alan Knowles on 29/3/2022.
+//
+
+import UIKit
+import QuartzCore
+import SceneKit
+
+
+
+
+
+
+class GameViewController: UIViewController {
+
+ override func viewDidLoad() {
+ super.viewDidLoad()
+
+ // create a new scene
+ let scene = SCNScene(named: "art.scnassets/ship.scn")!
+
+ // create and add a camera to the scene
+ let cameraNode = SCNNode()
+ cameraNode.camera = SCNCamera()
+ scene.rootNode.addChildNode(cameraNode)
+
+ // place the camera
+ cameraNode.position = SCNVector3(x: 0, y: 0, z: 15)
+
+ // create and add a light to the scene
+ let lightNode = SCNNode()
+ lightNode.light = SCNLight()
+ lightNode.light!.type = .omni
+ lightNode.position = SCNVector3(x: 0, y: 10, z: 10)
+ scene.rootNode.addChildNode(lightNode)
+
+ // create and add an ambient light to the scene
+ let ambientLightNode = SCNNode()
+ ambientLightNode.light = SCNLight()
+ ambientLightNode.light!.type = .ambient
+ ambientLightNode.light!.color = UIColor.darkGray
+ scene.rootNode.addChildNode(ambientLightNode)
+
+ // retrieve the ship node
+ let ship = scene.rootNode.childNode(withName: "ship", recursively: true)!
+
+ // animate the 3d object
+ ship.runAction(SCNAction.repeatForever(SCNAction.rotateBy(x: 0, y: 2, z: 0, duration: 1)))
+
+ // retrieve the SCNView
+ let scnView = self.view as! SCNView
+
+ // set the scene to the view
+ scnView.scene = scene
+
+ // allows the user to manipulate the camera
+ scnView.allowsCameraControl = true
+
+ // show statistics such as fps and timing information
+ scnView.showsStatistics = true
+
+ // configure the view
+ scnView.backgroundColor = UIColor.black
+
+ // add a tap gesture recognizer
+ let tapGesture = UITapGestureRecognizer(target: self, action: #selector(handleTap(_:)))
+ scnView.addGestureRecognizer(tapGesture)
+ scnView.isHidden = true
+
+ }
+
+ @objc
+ func handleTap(_ gestureRecognize: UIGestureRecognizer) {
+ // retrieve the SCNView
+ let scnView = self.view as! SCNView
+
+ // check what nodes are tapped
+ let p = gestureRecognize.location(in: scnView)
+ let hitResults = scnView.hitTest(p, options: [:])
+ // check that we clicked on at least one object
+ if hitResults.count > 0 {
+ // retrieved the first clicked object
+ let result = hitResults[0]
+
+ // get its material
+ let material = result.node.geometry!.firstMaterial!
+
+ // highlight it
+ SCNTransaction.begin()
+ SCNTransaction.animationDuration = 0.5
+
+ // on completion - unhighlight
+ SCNTransaction.completionBlock = {
+ SCNTransaction.begin()
+ SCNTransaction.animationDuration = 0.5
+
+ material.emission.contents = UIColor.black
+
+ SCNTransaction.commit()
+ }
+
+ material.emission.contents = UIColor.red
+
+ SCNTransaction.commit()
+ }
+ }
+
+ override var shouldAutorotate: Bool {
+ return true
+ }
+
+ override var prefersStatusBarHidden: Bool {
+ return true
+ }
+
+ override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
+ if UIDevice.current.userInterfaceIdiom == .phone {
+ return .allButUpsideDown
+ } else {
+ return .all
+ }
+ }
+
+}
--- /dev/null
+// !$*UTF8*$!
+{
+ archiveVersion = 1;
+ classes = {
+ };
+ objectVersion = 55;
+ objects = {
+
+/* Begin PBXBuildFile section */
+ E7F55F6327F2E26100A63CCF /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = E7F55F6227F2E26100A63CCF /* AppDelegate.swift */; };
+ E7F55F6527F2E26100A63CCF /* art.scnassets in Resources */ = {isa = PBXBuildFile; fileRef = E7F55F6427F2E26100A63CCF /* art.scnassets */; };
+ E7F55F6727F2E26100A63CCF /* GameViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E7F55F6627F2E26100A63CCF /* GameViewController.swift */; };
+ E7F55F6A27F2E26100A63CCF /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = E7F55F6827F2E26100A63CCF /* Main.storyboard */; };
+ E7F55F6C27F2E26200A63CCF /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = E7F55F6B27F2E26200A63CCF /* Assets.xcassets */; };
+ E7F55F6F27F2E26200A63CCF /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = E7F55F6D27F2E26200A63CCF /* LaunchScreen.storyboard */; };
+/* End PBXBuildFile section */
+
+/* Begin PBXFileReference section */
+ E7F55F5F27F2E26100A63CCF /* app.GameProjectTest.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = app.GameProjectTest.app; sourceTree = BUILT_PRODUCTS_DIR; };
+ E7F55F6227F2E26100A63CCF /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
+ E7F55F6427F2E26100A63CCF /* art.scnassets */ = {isa = PBXFileReference; lastKnownFileType = wrapper.scnassets; path = art.scnassets; sourceTree = "<group>"; };
+ E7F55F6627F2E26100A63CCF /* GameViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GameViewController.swift; sourceTree = "<group>"; };
+ E7F55F6927F2E26100A63CCF /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
+ E7F55F6B27F2E26200A63CCF /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
+ E7F55F6E27F2E26200A63CCF /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
+/* End PBXFileReference section */
+
+/* Begin PBXFrameworksBuildPhase section */
+ E7F55F5C27F2E26100A63CCF /* Frameworks */ = {
+ isa = PBXFrameworksBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+/* End PBXFrameworksBuildPhase section */
+
+/* Begin PBXGroup section */
+ E7F55F5627F2E26100A63CCF = {
+ isa = PBXGroup;
+ children = (
+ E7F55F6127F2E26100A63CCF /* GameProjectTest */,
+ E7F55F6027F2E26100A63CCF /* Products */,
+ );
+ sourceTree = "<group>";
+ };
+ E7F55F6027F2E26100A63CCF /* Products */ = {
+ isa = PBXGroup;
+ children = (
+ E7F55F5F27F2E26100A63CCF /* app.GameProjectTest.app */,
+ );
+ name = Products;
+ sourceTree = "<group>";
+ };
+ E7F55F6127F2E26100A63CCF /* GameProjectTest */ = {
+ isa = PBXGroup;
+ children = (
+ E7F55F6227F2E26100A63CCF /* AppDelegate.swift */,
+ E7F55F6427F2E26100A63CCF /* art.scnassets */,
+ E7F55F6627F2E26100A63CCF /* GameViewController.swift */,
+ E7F55F6827F2E26100A63CCF /* Main.storyboard */,
+ E7F55F6B27F2E26200A63CCF /* Assets.xcassets */,
+ E7F55F6D27F2E26200A63CCF /* LaunchScreen.storyboard */,
+ );
+ path = GameProjectTest;
+ sourceTree = "<group>";
+ };
+/* End PBXGroup section */
+
+/* Begin PBXNativeTarget section */
+ E7F55F5E27F2E26100A63CCF /* app.GameProjectTest */ = {
+ isa = PBXNativeTarget;
+ buildConfigurationList = E7F55F7227F2E26200A63CCF /* Build configuration list for PBXNativeTarget "app.GameProjectTest" */;
+ buildPhases = (
+ E7F55F5B27F2E26100A63CCF /* Sources */,
+ E7F55F5C27F2E26100A63CCF /* Frameworks */,
+ E7F55F5D27F2E26100A63CCF /* Resources */,
+ );
+ buildRules = (
+ );
+ dependencies = (
+ );
+ name = app.GameProjectTest;
+ productName = GameProjectTest;
+ productReference = E7F55F5F27F2E26100A63CCF /* app.GameProjectTest.app */;
+ productType = "com.apple.product-type.application";
+ };
+/* End PBXNativeTarget section */
+
+/* Begin PBXProject section */
+ E7F55F5727F2E26100A63CCF /* Project object */ = {
+ isa = PBXProject;
+ attributes = {
+ BuildIndependentTargetsInParallel = 1;
+ LastSwiftUpdateCheck = 1330;
+ LastUpgradeCheck = 1330;
+ TargetAttributes = {
+ E7F55F5E27F2E26100A63CCF = {
+ CreatedOnToolsVersion = 13.3;
+ };
+ };
+ };
+ buildConfigurationList = E7F55F5A27F2E26100A63CCF /* Build configuration list for PBXProject "app.GameProjectTest" */;
+ compatibilityVersion = "Xcode 13.0";
+ developmentRegion = en;
+ hasScannedForEncodings = 0;
+ knownRegions = (
+ en,
+ Base,
+ );
+ mainGroup = E7F55F5627F2E26100A63CCF;
+ productRefGroup = E7F55F6027F2E26100A63CCF /* Products */;
+ projectDirPath = "";
+ projectRoot = "";
+ targets = (
+ E7F55F5E27F2E26100A63CCF /* app.GameProjectTest */,
+ );
+ };
+/* End PBXProject section */
+
+/* Begin PBXResourcesBuildPhase section */
+ E7F55F5D27F2E26100A63CCF /* Resources */ = {
+ isa = PBXResourcesBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ E7F55F6527F2E26100A63CCF /* art.scnassets in Resources */,
+ E7F55F6F27F2E26200A63CCF /* LaunchScreen.storyboard in Resources */,
+ E7F55F6C27F2E26200A63CCF /* Assets.xcassets in Resources */,
+ E7F55F6A27F2E26100A63CCF /* Main.storyboard in Resources */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+/* End PBXResourcesBuildPhase section */
+
+/* Begin PBXSourcesBuildPhase section */
+ E7F55F5B27F2E26100A63CCF /* Sources */ = {
+ isa = PBXSourcesBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ E7F55F6727F2E26100A63CCF /* GameViewController.swift in Sources */,
+ E7F55F6327F2E26100A63CCF /* AppDelegate.swift in Sources */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+/* End PBXSourcesBuildPhase section */
+
+/* Begin PBXVariantGroup section */
+ E7F55F6827F2E26100A63CCF /* Main.storyboard */ = {
+ isa = PBXVariantGroup;
+ children = (
+ E7F55F6927F2E26100A63CCF /* Base */,
+ );
+ name = Main.storyboard;
+ sourceTree = "<group>";
+ };
+ E7F55F6D27F2E26200A63CCF /* LaunchScreen.storyboard */ = {
+ isa = PBXVariantGroup;
+ children = (
+ E7F55F6E27F2E26200A63CCF /* Base */,
+ );
+ name = LaunchScreen.storyboard;
+ sourceTree = "<group>";
+ };
+/* End PBXVariantGroup section */
+
+/* Begin XCBuildConfiguration section */
+ E7F55F7027F2E26200A63CCF /* Debug */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ ALWAYS_SEARCH_USER_PATHS = NO;
+ CLANG_ANALYZER_NONNULL = YES;
+ CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
+ CLANG_CXX_LANGUAGE_STANDARD = "gnu++17";
+ CLANG_ENABLE_MODULES = YES;
+ CLANG_ENABLE_OBJC_ARC = YES;
+ CLANG_ENABLE_OBJC_WEAK = YES;
+ CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
+ CLANG_WARN_BOOL_CONVERSION = YES;
+ CLANG_WARN_COMMA = YES;
+ CLANG_WARN_CONSTANT_CONVERSION = YES;
+ CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
+ CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
+ CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
+ CLANG_WARN_EMPTY_BODY = YES;
+ CLANG_WARN_ENUM_CONVERSION = YES;
+ CLANG_WARN_INFINITE_RECURSION = YES;
+ CLANG_WARN_INT_CONVERSION = YES;
+ CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
+ CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
+ CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
+ CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
+ CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
+ CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
+ CLANG_WARN_STRICT_PROTOTYPES = YES;
+ CLANG_WARN_SUSPICIOUS_MOVE = YES;
+ CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
+ CLANG_WARN_UNREACHABLE_CODE = YES;
+ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
+ COPY_PHASE_STRIP = NO;
+ DEBUG_INFORMATION_FORMAT = dwarf;
+ ENABLE_STRICT_OBJC_MSGSEND = YES;
+ ENABLE_TESTABILITY = YES;
+ GCC_C_LANGUAGE_STANDARD = gnu11;
+ GCC_DYNAMIC_NO_PIC = NO;
+ GCC_NO_COMMON_BLOCKS = YES;
+ GCC_OPTIMIZATION_LEVEL = 0;
+ GCC_PREPROCESSOR_DEFINITIONS = (
+ "DEBUG=1",
+ "$(inherited)",
+ );
+ GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
+ GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
+ GCC_WARN_UNDECLARED_SELECTOR = YES;
+ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
+ GCC_WARN_UNUSED_FUNCTION = YES;
+ GCC_WARN_UNUSED_VARIABLE = YES;
+ IPHONEOS_DEPLOYMENT_TARGET = 15.4;
+ MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
+ MTL_FAST_MATH = YES;
+ ONLY_ACTIVE_ARCH = YES;
+ SDKROOT = iphoneos;
+ SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
+ SWIFT_OPTIMIZATION_LEVEL = "-Onone";
+ };
+ name = Debug;
+ };
+ E7F55F7127F2E26200A63CCF /* Release */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ ALWAYS_SEARCH_USER_PATHS = NO;
+ CLANG_ANALYZER_NONNULL = YES;
+ CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
+ CLANG_CXX_LANGUAGE_STANDARD = "gnu++17";
+ CLANG_ENABLE_MODULES = YES;
+ CLANG_ENABLE_OBJC_ARC = YES;
+ CLANG_ENABLE_OBJC_WEAK = YES;
+ CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
+ CLANG_WARN_BOOL_CONVERSION = YES;
+ CLANG_WARN_COMMA = YES;
+ CLANG_WARN_CONSTANT_CONVERSION = YES;
+ CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
+ CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
+ CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
+ CLANG_WARN_EMPTY_BODY = YES;
+ CLANG_WARN_ENUM_CONVERSION = YES;
+ CLANG_WARN_INFINITE_RECURSION = YES;
+ CLANG_WARN_INT_CONVERSION = YES;
+ CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
+ CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
+ CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
+ CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
+ CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
+ CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
+ CLANG_WARN_STRICT_PROTOTYPES = YES;
+ CLANG_WARN_SUSPICIOUS_MOVE = YES;
+ CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
+ CLANG_WARN_UNREACHABLE_CODE = YES;
+ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
+ COPY_PHASE_STRIP = NO;
+ DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
+ ENABLE_NS_ASSERTIONS = NO;
+ ENABLE_STRICT_OBJC_MSGSEND = YES;
+ GCC_C_LANGUAGE_STANDARD = gnu11;
+ GCC_NO_COMMON_BLOCKS = YES;
+ GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
+ GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
+ GCC_WARN_UNDECLARED_SELECTOR = YES;
+ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
+ GCC_WARN_UNUSED_FUNCTION = YES;
+ GCC_WARN_UNUSED_VARIABLE = YES;
+ IPHONEOS_DEPLOYMENT_TARGET = 15.4;
+ MTL_ENABLE_DEBUG_INFO = NO;
+ MTL_FAST_MATH = YES;
+ SDKROOT = iphoneos;
+ SWIFT_COMPILATION_MODE = wholemodule;
+ SWIFT_OPTIMIZATION_LEVEL = "-O";
+ VALIDATE_PRODUCT = YES;
+ };
+ name = Release;
+ };
+ E7F55F7327F2E26200A63CCF /* Debug */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
+ ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
+ CODE_SIGN_STYLE = Automatic;
+ CURRENT_PROJECT_VERSION = 1;
+ GENERATE_INFOPLIST_FILE = YES;
+ INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
+ INFOPLIST_KEY_UILaunchStoryboardName = LaunchScreen;
+ INFOPLIST_KEY_UIMainStoryboardFile = Main;
+ INFOPLIST_KEY_UIStatusBarHidden = YES;
+ INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
+ INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
+ LD_RUNPATH_SEARCH_PATHS = (
+ "$(inherited)",
+ "@executable_path/Frameworks",
+ );
+ MARKETING_VERSION = 1.0;
+ PRODUCT_BUNDLE_IDENTIFIER = roojs.GameProjectTest;
+ PRODUCT_NAME = "$(TARGET_NAME)";
+ SWIFT_EMIT_LOC_STRINGS = YES;
+ SWIFT_VERSION = 5.0;
+ TARGETED_DEVICE_FAMILY = "1,2";
+ };
+ name = Debug;
+ };
+ E7F55F7427F2E26200A63CCF /* Release */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
+ ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
+ CODE_SIGN_STYLE = Automatic;
+ CURRENT_PROJECT_VERSION = 1;
+ GENERATE_INFOPLIST_FILE = YES;
+ INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
+ INFOPLIST_KEY_UILaunchStoryboardName = LaunchScreen;
+ INFOPLIST_KEY_UIMainStoryboardFile = Main;
+ INFOPLIST_KEY_UIStatusBarHidden = YES;
+ INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
+ INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
+ LD_RUNPATH_SEARCH_PATHS = (
+ "$(inherited)",
+ "@executable_path/Frameworks",
+ );
+ MARKETING_VERSION = 1.0;
+ PRODUCT_BUNDLE_IDENTIFIER = roojs.GameProjectTest;
+ PRODUCT_NAME = "$(TARGET_NAME)";
+ SWIFT_EMIT_LOC_STRINGS = YES;
+ SWIFT_VERSION = 5.0;
+ TARGETED_DEVICE_FAMILY = "1,2";
+ };
+ name = Release;
+ };
+/* End XCBuildConfiguration section */
+
+/* Begin XCConfigurationList section */
+ E7F55F5A27F2E26100A63CCF /* Build configuration list for PBXProject "app.GameProjectTest" */ = {
+ isa = XCConfigurationList;
+ buildConfigurations = (
+ E7F55F7027F2E26200A63CCF /* Debug */,
+ E7F55F7127F2E26200A63CCF /* Release */,
+ );
+ defaultConfigurationIsVisible = 0;
+ defaultConfigurationName = Release;
+ };
+ E7F55F7227F2E26200A63CCF /* Build configuration list for PBXNativeTarget "app.GameProjectTest" */ = {
+ isa = XCConfigurationList;
+ buildConfigurations = (
+ E7F55F7327F2E26200A63CCF /* Debug */,
+ E7F55F7427F2E26200A63CCF /* Release */,
+ );
+ defaultConfigurationIsVisible = 0;
+ defaultConfigurationName = Release;
+ };
+/* End XCConfigurationList section */
+ };
+ rootObject = E7F55F5727F2E26100A63CCF /* Project object */;
+}