2016-12-28 89 views
0

我有一个'attach node',它有两个Blender模型的子节点。我已经添加了第三个节点到这个SCNCone的附加节点。出于某种原因,我无法改变锥形节点的颜色,只有透明度。我似乎看不出代码有什么问题,但是在运行期间,无论我将其设置为何种颜色,锥体始终是黑色。无法更改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,alpha:0.2)'已经完成了。再次感谢。 – P3rry

0
coneGeo.materials = [coneMaterial] 

这也行得通。我通过将锥节点添加到空场景来测试您的代码。 我只是得到一个黑色的屏幕。

但是,如果我改变alpha值来说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)