{"id":1083,"date":"2017-09-25T17:31:15","date_gmt":"2017-09-25T08:31:15","guid":{"rendered":"http:\/\/blue-bear.jp\/kb\/?p=1083"},"modified":"2017-09-25T17:31:15","modified_gmt":"2017-09-25T08:31:15","slug":"swift-scenekit-pan%e3%82%b8%e3%82%a7%e3%82%b9%e3%83%81%e3%83%a3%e3%83%bc%e3%81%a7dae%e3%83%a2%e3%83%87%e3%83%ab%e3%82%92%e6%8b%a1%e5%a4%a7%e3%83%bb%e7%b8%ae%e5%b0%8f","status":"publish","type":"post","link":"https:\/\/blue-bear.jp\/kb\/swift-scenekit-pan%e3%82%b8%e3%82%a7%e3%82%b9%e3%83%81%e3%83%a3%e3%83%bc%e3%81%a7dae%e3%83%a2%e3%83%87%e3%83%ab%e3%82%92%e6%8b%a1%e5%a4%a7%e3%83%bb%e7%b8%ae%e5%b0%8f\/","title":{"rendered":"[swift] scenekit \/ Pan\u30b8\u30a7\u30b9\u30c1\u30e3\u30fc\u3067dae\u30e2\u30c7\u30eb\u3092\u62e1\u5927\u30fb\u7e2e\u5c0f"},"content":{"rendered":"<p>dae\u30e2\u30c7\u30eb\u304b\u3089\u4f5c\u6210\u3057\u305fSCNNode\u3092\u30d1\u30f3\u30b8\u30a7\u30b9\u30c1\u30e3\u30fc\u3067\u62e1\u5927\u7e2e\u5c0f\u3059\u308b\u30b3\u30fc\u30c9\u306f\u4ee5\u4e0b\u306e\u901a\u308a\u3002<\/p>\n<p>scale\u3067\u30e2\u30c7\u30eb\u306e\u898b\u305f\u76ee\u306e\u5927\u304d\u3055\u306f\u5909\u5316\u3055\u305b\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u304c\u3001\u7269\u7406\u60c5\u5831(Physicalbody)\u306e\u5927\u304d\u3055\u306fscale\u3092\u5909\u3048\u305f\u3060\u3051\u3067\u306f\u5909\u5316\u3055\u305b\u3089\u308c\u306a\u3044\u305f\u3081\u3001\u30d1\u30f3\u30b8\u30a7\u30b9\u30c1\u30e3\u30fc\u7d42\u4e86\u6642\u306b\u300cSCNPhysicsShape.Option.scale\u300d\u3067\u7269\u7406\u60c5\u5831(Physicalbody)\u306e\u5927\u304d\u3055\u3082\u540c\u3058\u5927\u304d\u3055\u306b\u5909\u66f4\u3059\u308b\u3002<\/p>\n<p>\u30d1\u30f3\u30b8\u30a7\u30b9\u30c1\u30e3\u30fc\u306e\u90fd\u5ea6\u306b\u7269\u7406\u60c5\u5831(Physicalbody)\u3092\u5909\u66f4\u3059\u308b\u3068\u3001\u304b\u306a\u308a\u30ac\u30bf\u3064\u304f\u306e\u3067\u3001\u7d42\u4e86\u6642\u306b\u5909\u66f4\u3057\u3066\u3044\u308b\u3002<\/p>\n<pre>\r\n    var targetedNode = SCNNode()\r\n    let gun = \"art.scnassets\/Handgun_dae.dae\"\r\n    let y:Float = 8\r\n    var currentScale = SCNVector3()\r\n\r\n    override func viewDidLoad() {\r\n        super.viewDidLoad()\r\n        \r\n        \/\/scene\u306e\u57fa\u672c\u8a2d\u5b9a\u306f\u7701\u7565.......\r\n\r\n        \/\/dae\u30e2\u30c7\u30eb\u304b\u3089scnNode\u3092\u4f5c\u6210\r\n        targetedNode = createObject(position: SCNVector3Make(-1.5, y, 0), restitution: 0.1, filepath: gun)\r\n\r\n        \/\/\u30d1\u30f3\u30b8\u30a7\u30b9\u30c1\u30e3\u30fc\u306e\u4f5c\u6210\r\n        let pinchGesture = UIPinchGestureRecognizer(target: self, action: #selector(handlePinch))\r\n\r\n        \/\/\u30d1\u30f3\u30b8\u30a7\u30b9\u30c1\u30e3\u30fc\u306e\u30a2\u30bf\u30c3\u30c1\r\n        scnView.addGestureRecognizer(pinchGesture)\r\n\r\n    }\r\n\r\n    @objc\r\n    func handlePinch(_ gesture: UIPinchGestureRecognizer) {\r\n\r\n            let scale = Float(gesture.scale)\r\n            let object = targetedNode\r\n            \r\n            switch gesture.state{\r\n\r\n            \/\/\u30d1\u30f3\u30b8\u30a7\u30b9\u30c1\u30e3\u30fc\u306e\u90fd\u5ea6    \r\n            case .changed:\r\n\r\n                \/\/\u30ce\u30fc\u30c9\u306e\u30b9\u30b1\u30fc\u30eb\u3092\u62e1\u5927\u30fb\u7e2e\u5c0f\r\n                object.scale = SCNVector3(currentScale.x*scale, currentScale.y*scale, currentScale.z*scale)\r\n               \r\n            \/\/\u30d1\u30f3\u30b8\u30a7\u30b9\u30c1\u30e3\u30fc\u306e\u7d42\u4e86 \r\n            case .ended , .cancelled:\r\n\r\n                \/\/\u30ce\u30fc\u30c9\u306e\u7269\u7406\u60c5\u5831\u3092\u62e1\u5927\u30fb\u7e2e\u5c0f\r\n                let aModelShape = SCNPhysicsShape(node: object, options: [\r\n                    SCNPhysicsShape.Option.scale: NSValue(scnVector3: SCNVector3(x: currentScale.x*scale, y: currentScale.y*scale, z: currentScale.z*scale))\r\n                    ])\r\n\r\n                \/\/\u62e1\u5927\u30fb\u7e2e\u5c0f\u3057\u305f\u7269\u7406\u60c5\u5831\u3092\u30ce\u30fc\u30c9\u306b\u30a2\u30bf\u30c3\u30c1\r\n                object.physicsBody = SCNPhysicsBody(type: SCNPhysicsBodyType.dynamic, shape: aModelShape)\r\n                \r\n                \/\/\u4f4d\u7f6e\u60c5\u5831\u3092\u73fe\u5728\u306e\u4f4d\u7f6e\u306b\u4fee\u6b63\r\n                object.position = object.presentation.position\r\n\r\n            default:\r\n                NSLog(\"not action\")\r\n            }\r\n    }\r\n\r\n    \/\/dae\u30e2\u30c7\u30eb\u3092\u751f\u6210\uff08\u8a73\u3057\u3044\u8a73\u7d30\u306f\u5225\u8a18\u4e8b\u306b\u3066\u89e3\u8aac\uff09\r\n    func createObject(position:SCNVector3, restitution:CGFloat,filepath:String) -> SCNNode {\r\n        let scene = SCNScene(named: filepath)\r\n        let node: SCNNode = scene!.rootNode.childNodes[0]\r\n        let aModelShape = SCNPhysicsShape(node: node, options: nil)\r\n        let physicsBody = SCNPhysicsBody(type: .dynamic, shape: nil)\r\n        physicsBody.restitution = restitution\r\n        node.physicsBody = physicsBody\r\n        node.position = position\r\n        node.name = \"object\"\r\n        \r\n        return node\r\n    }\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>dae\u30e2\u30c7\u30eb\u304b\u3089\u4f5c\u6210\u3057\u305fSCNNode\u3092<\/p>\n","protected":false},"author":1,"featured_media":1079,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13],"tags":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/posts\/1083"}],"collection":[{"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/comments?post=1083"}],"version-history":[{"count":1,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/posts\/1083\/revisions"}],"predecessor-version":[{"id":1084,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/posts\/1083\/revisions\/1084"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/media\/1079"}],"wp:attachment":[{"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/media?parent=1083"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/categories?post=1083"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/tags?post=1083"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}