diff --git a/RunningMan.xcodeproj/project.pbxproj b/RunningMan.xcodeproj/project.pbxproj index a5fab99..de0c77e 100644 --- a/RunningMan.xcodeproj/project.pbxproj +++ b/RunningMan.xcodeproj/project.pbxproj @@ -110,6 +110,7 @@ developmentRegion = English; hasScannedForEncodings = 0; knownRegions = ( + English, en, Base, ); @@ -253,6 +254,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = saltpig.RunningMan; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; }; name = Debug; }; @@ -265,6 +267,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = saltpig.RunningMan; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; }; name = Release; }; diff --git a/RunningMan/AppDelegate.swift b/RunningMan/AppDelegate.swift old mode 100644 new mode 100755 diff --git a/RunningMan/ColladaRig.swift b/RunningMan/ColladaRig.swift old mode 100644 new mode 100755 index 9ec47de..389b40c --- a/RunningMan/ColladaRig.swift +++ b/RunningMan/ColladaRig.swift @@ -28,18 +28,18 @@ class ColladaRig { playAnimation("rest") //position node on ground - var min = SCNVector3(0,0,0) - var max = SCNVector3(0,0,0) - node.getBoundingBoxMin(&min, max: &max) - node.position = SCNVector3(0, -min.y, 0) +// var min = SCNVector3(0,0,0) +// var max = SCNVector3(0,0,0) +// node.boundingBox(min:&min, max: &max) + node.position = SCNVector3(0,0, 0) } - static func getSceneSource(daeNamed: String) -> SCNSceneSource { - let collada = NSBundle.mainBundle().URLForResource("art.scnassets/\(daeNamed)", withExtension: "dae")! - return SCNSceneSource(URL: collada, options: nil)! + static func getSceneSource(_ daeNamed: String) -> SCNSceneSource { + let collada = Bundle.main.url(forResource: "art.scnassets/\(daeNamed)", withExtension: "dae")! + return SCNSceneSource(url: collada, options: nil)! } - func loadAnimation(withKey: String, daeNamed: String, fade: CGFloat = 0.3){ + func loadAnimation(_ withKey: String, daeNamed: String, fade: CGFloat = 0.3){ let sceneSource = ColladaRig.getSceneSource(daeNamed) let animation = sceneSource.entryWithIdentifier("\(daeNamed)-1", withClass: CAAnimation.self)! @@ -50,25 +50,25 @@ class ColladaRig { animations[withKey] = animation } - func playAnimation(named: String){ //also works for armature + func playAnimation(_ named: String){ //also works for armature if let animation = animations[named] { node.addAnimation(animation, forKey: named) } } func walk() { - node.pauseAnimationForKey("rest") + node.pauseAnimation(forKey: "rest") // node.removeAnimationForKey("rest", fadeOutDuration: 0.3) playAnimation("walk") - let run = SCNAction.repeatActionForever( SCNAction.moveByX(0, y: 0, z: 12, duration: 1)) - run.timingMode = .EaseInEaseOut //ease the action in to try to match the fade-in and fade-out of the animation + let run = SCNAction.repeatForever( SCNAction.moveBy(x: 0, y: 0, z: 12, duration: 1)) + run.timingMode = .easeInEaseOut //ease the action in to try to match the fade-in and fade-out of the animation node.runAction(run, forKey: "walk") } func stopWalking() { - node.resumeAnimationForKey("rest") + node.resumeAnimation(forKey:"rest") // node.addAnimation(animations["rest"]!, forKey: "rest") - node.removeAnimationForKey("walk", fadeOutDuration: 0.3) - node.removeActionForKey("walk") + node.removeAnimation(forKey:"walk", fadeOutDuration: 0.3) + node.removeAction(forKey:"walk") } } diff --git a/RunningMan/GameView.swift b/RunningMan/GameView.swift old mode 100644 new mode 100755 diff --git a/RunningMan/GameViewController.swift b/RunningMan/GameViewController.swift old mode 100644 new mode 100755 index 8a5c536..3b1f7c6 --- a/RunningMan/GameViewController.swift +++ b/RunningMan/GameViewController.swift @@ -28,14 +28,16 @@ class GameViewController: NSViewController { self.gameView!.showsStatistics = true // configure the view - self.gameView!.backgroundColor = NSColor.blackColor() + self.gameView!.backgroundColor = NSColor.black } - override func mouseDown(theEvent: NSEvent) { + override func mouseDown(with event: NSEvent) { + player!.walk() } - override func mouseUp(theEvent: NSEvent) { + override func mouseUp(with event: NSEvent) { + player!.stopWalking() } @@ -54,17 +56,17 @@ class GameViewController: NSViewController { // create and add a light to the scene let lightNode = SCNNode() lightNode.light = SCNLight() - lightNode.light!.type = SCNLightTypeOmni + lightNode.light!.type = SCNLight.LightType.omni lightNode.position = SCNVector3(x: 0, y: 10, z: 10) scene.rootNode.addChildNode(lightNode) - let skyCube = getCubeMap("miramar") + let skyCube = getCubeMap(inFolder: "miramar") // create and add an ambient light to the scene let ambientLightNode = SCNNode() ambientLightNode.light = SCNLight() - ambientLightNode.light!.type = SCNLightTypeAmbient - ambientLightNode.light!.color = NSColor.darkGrayColor() + ambientLightNode.light!.type = SCNLight.LightType.ambient + ambientLightNode.light!.color = NSColor.darkGray scene.rootNode.addChildNode(ambientLightNode) let floorNode = SCNNode(geometry: SCNFloor()) @@ -74,18 +76,18 @@ class GameViewController: NSViewController { let trans = SCNMatrix4Rotate(SCNMatrix4MakeScale(scale, scale, 1),CGFloat(M_PI_2) / 3 ,0, 0, 1) mat.diffuse.contents = "art.scnassets/floor07.tga" - mat.diffuse.wrapS = .Repeat - mat.diffuse.wrapT = .Repeat + mat.diffuse.wrapS = .repeat + mat.diffuse.wrapT = .repeat mat.diffuse.contentsTransform = trans mat.normal.contents = "art.scnassets/floor07_NRM.jpg" - mat.normal.wrapS = .Repeat - mat.normal.wrapT = .Repeat + mat.normal.wrapS = .repeat + mat.normal.wrapT = .repeat mat.normal.contentsTransform = trans // try to stop the floor textures trigger nasty moire jaggies at distance - mat.normal.mipFilter = .Linear + mat.normal.mipFilter = .linear mat.normal.maxAnisotropy = 0 mat.normal.intensity = 0.5 - mat.diffuse.mipFilter = .Linear + mat.diffuse.mipFilter = .linear mat.diffuse.maxAnisotropy = 0 // reflectivity mat.reflective.contents = skyCube @@ -95,7 +97,7 @@ class GameViewController: NSViewController { scene.rootNode.addChildNode(floorNode) let animation = CABasicAnimation(keyPath: "rotation") - animation.toValue = NSValue(SCNVector4: SCNVector4(x: CGFloat(0), y: CGFloat(1), z: CGFloat(0), w: CGFloat(M_PI)*2)) + animation.toValue = NSValue(scnVector4: SCNVector4(x: CGFloat(0), y: CGFloat(1), z: CGFloat(0), w: CGFloat(Double.pi)*2)) animation.duration = 28 animation.repeatCount = MAXFLOAT //repeat forever cameraArm.addAnimation(animation, forKey: nil) @@ -108,7 +110,7 @@ class GameViewController: NSViewController { let playerMat = SCNMaterial() - playerMat.diffuse.contents = NSColor.darkGrayColor() + playerMat.diffuse.contents = NSColor.darkGray playerMat.reflective.contents = skyCube playerMat.fresnelExponent = 2 playerMat.shininess = 1