2016-12-28 2 views
0

Blenderモデルである2つの子ノードを持つ「接続ノード」があります。私はSCNConeであるこのアタッチノードに3番目のノードを追加しました。何らかの理由で、私は円錐のノードの色を変更することはできません、透明のみ。私はコードに何か間違っているように見ることはできませんが、実行時には私が設定した色に関係なくコーンは常に黒色です。SCNCone - Scenekitの色を変更できません

let coneGeo = SCNCone(topRadius: 0.1, bottomRadius: 0.7, height: 4) 
let coneMaterial = SCNMaterial() 

coneMaterial.diffuse.contents = UIColor(red: 255.0/255.0, green: 108.0/255.0, blue: 91.0/255.0, alpha: 0.2) 
coneGeo.materials = [coneMaterial] 

let coneNode = SCNNode(geometry: coneGeo) 
coneNode.position = SCNVector3(0, -1.5, 0) 
coneNode.name = "coneNode" 

AttachNode.addChildNode(coneNode) 

答えて

1

coneMaterial.diffuse.contents = UIColor(red: 255.0/255.0, green: 108.0/255.0, blue: 91.0/255.0, alpha: 0.2)coneGeo.geometry?.firstMaterial?.diffuse.contents.diffuse.contents = UIColor(red: 255.0/255.0, green: 108.0/255.0, blue: 91.0/255.0, alpha: 0.2)に置き換えます。ジオメトリなしで円錐の材料色を変更する代わりに、そのジオメトリパラメータを使用して材料色にアクセスする必要があります。

+0

であなたのアルファ値をチェックし、言うでしょう! 'coneNode.geometry?.firstMaterial?.diffuse.contents = UIColor(赤色:255.0/255.0、緑色:108.0/255.0、青色:91.0/255.0、ア​​ルファ:0.2)'はこのトリックを行っています。再度、感謝します。 – P3rry

0
coneGeo.materials = [coneMaterial] 

これも機能します。コーンノードを空のシーンに追加して、コードをテストしました。 私はちょうど黒い画面を取得します。

しかし、アルファ値を0.5と変更すると、これが得られます。

enter image description here

コード。

override func viewDidLoad() 
    { 
     super.viewDidLoad() 

     // create a new scene 
     let scene = SCNScene() 

     let coneGeo = SCNCone(topRadius: 0.1, bottomRadius: 0.7, height: 4) 
     let coneMaterial = SCNMaterial() 

     coneMaterial.diffuse.contents = UIColor(red: 255.0/255.0, 
               green: 108.0/255.0, 
               blue: 91.0/255.0, alpha: 0.5) 
     coneGeo.materials = [coneMaterial] 

     let coneNode = SCNNode(geometry 
            : coneGeo) 
     coneNode.position = SCNVector3(0, -1.5, 0) 
     coneNode.name = "coneNode" 

     scene.rootNode.addChildNode(coneNode) 

     // 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 
    } 

だから私はありがとうUIColor(red: 255.0/255.0, green: 108.0/255.0, blue: 91.0/255.0, alpha: 0.2)

関連する問題