2. https://www.weheartswift.com/introduction-scenekit-part-2/
Macbook pro (OS X EI Captian 10.11.5)
Xcode 7.3.1案例以Game Template 開始,移除原範本加入的Ship與動畫(Animation),再參考Ref1 將匯入的DAE檔案轉為node物件,再加入至場景內
1. 開啟遊戲範本專案
2. GameViewController.swft2.1 關閉ship節點與“動畫”指令
2.2 參考Ref1將DAE檔案轉為節點,並加入場景
...
// create a new scene
//let scene = SCNScene(named: "art.scnassets/ship.scn")!
let scene = SCNScene();
//-- 2016-8-10
var nodeS = SCNNode()
let sceneS = SCNScene(named: "mug.dae")
var nodeArrayS = sceneS!.rootNode.childNodes
for childNode in nodeArrayS {
nodeS.addChildNode(childNode as SCNNode)
}
scene.rootNode.addChildNode(nodeS)
// create and add a camera to the scene
let cameraNode = SCNNode()
...
3. 結果4. 參考Ref1,將DAE轉換node動作轉為方法.
class GameViewController: UIViewController {
//----- Def DAE2Node方法
func collada2SCNNode(filepath:String) -> SCNNode {
var node = SCNNode()
let scene = SCNScene(named: filepath)
var nodeArray = scene!.rootNode.childNodes
for childNode in nodeArray {
node.addChildNode(childNode as SCNNode)
}
return node
}
//------
override func viewDidLoad() {
super.viewDidLoad()
...
//-- 2016-8-10-B
/*
var nodeS = SCNNode()
let sceneS = SCNScene(named: "mug.dae")
var nodeArrayS = sceneS!.rootNode.childNodes
for childNode in nodeArrayS {
nodeS.addChildNode(childNode as SCNNode)
}
*/
let nodeS = collada2SCNNode("mug.dae")
scene.rootNode.addChildNode(nodeS)
...
5. 用迴圈呼叫方法,產生系列3D物件
...
*/
6. 結果
5. 用迴圈呼叫方法,產生系列3D物件
...
*/
for zz in 1...3 {
let nodeS = collada2SCNNode("mug.dae")
nodeS.position = SCNVector3(x:0, y:0, z:Float(zz)*3)
scene.rootNode.addChildNode(nodeS)
}
...6. 結果
沒有留言:
張貼留言