2016-04-07 4 views

答えて

0

借入:https://stackoverflow.com/a/24127282/887210

あなたの質問のための重要な部分は、次のとおりです。

SCNBox(width: 1, height: 4, length: 9, chamferRadius: 0) 

これはSceneKitとUIKitの持つ長方形のボックスを描画します。これは、プロジェクトのカスタムUIViewControllerで使用するように設定されていますが、他の用途にも簡単に適用できます。

コード例:

override func loadView() { 
    // create a scene view with an empty scene 
    let sceneView = SCNView(frame: CGRect(x: 0, y: 0, width: 300, height: 300)) 
    let scene = SCNScene() 
    sceneView.scene = scene 

    // default lighting 
    sceneView.autoenablesDefaultLighting = true 

    // a camera 
    let cameraNode = SCNNode() 
    cameraNode.camera = SCNCamera() 
    cameraNode.position = SCNVector3(x: 0, y: 0, z: 15) 
    scene.rootNode.addChildNode(cameraNode) 

    // a geometry object 
    let box = SCNBox(width: 1, height: 4, length: 9, chamferRadius: 0) 
    let boxNode = SCNNode(geometry: box) 
    scene.rootNode.addChildNode(boxNode) 

    // configure the geometry object 
    box.firstMaterial?.diffuse.contents = UIColor.redColor() 
    box.firstMaterial?.specular.contents = UIColor.whiteColor() 

    // set a rotation axis (no angle) to be able to 
    // use a nicer keypath below and avoid needing 
    // to wrap it in an NSValue 
    boxNode.rotation = SCNVector4(x: 1, y: 1, z: 0.0, w: 0.0) 

    // animate the rotation of the torus 
    let spin = CABasicAnimation(keyPath: "rotation.w") // only animate the angle 
    spin.toValue = 2.0*M_PI 
    spin.duration = 10 
    spin.repeatCount = HUGE // for infinity 
    boxNode.addAnimation(spin, forKey: "spin around") 

    view = sceneView // Set the view property to the sceneView created here. 
} 
+0

だから私はゲームではないプロジェクトにこれを組み込むだろうか。 viewControllerにsceneViewを追加しますか? – Tob

+0

私は、UIViewControllerサブクラスに埋め込む方法を見られるようにサンプルを更新しました。基本的に 'loadView()'メソッドをオーバーライドし、 'view'プロパティを' sceneView'変数に設定します。 – ColGraff

+0

ありがとうございます:) – Tob