我想为SCNNode的每一张脸设置一个不同的图像,我怎么做呢?我试过this,但它没有起作用,第一种材料出现在所有的脸上。我在用Swift 4.2。
我试过这个:
self.addChildNode(playerNode!)
let head = playerNode?.childNode(withName: "head",
recursively: true)!
let greenMaterial = SCNMaterial()
greenMaterial.diffuse.contents = UIColor.green
greenMaterial.locksAmbientWithDiffuse = true;
let redMaterial = SCNMaterial()
redMaterial.diffuse.contents = UIColor.red
redMaterial.locksAmbientWithDiffuse = true;
let blueMaterial = SCNMaterial()
blueMaterial.diffuse.contents = UIColor.blue
blueMaterial.locksAmbientWithDiffuse = true;
let yellowMaterial = SCNMaterial()
yellowMaterial.diffuse.contents = UIColor.yellow
yellowMaterial.locksAmbientWithDiffuse = true;
let purpleMaterial = SCNMaterial()
purpleMaterial.diffuse.contents = UIColor.purple
purpleMaterial.locksAmbientWithDiffuse = true
let WhiteMaterial = SCNMaterial()
WhiteMaterial.diffuse.contents = UIColor.white
WhiteMaterial.locksAmbientWithDiffuse = true
head?.geometry?.materials = [redMaterial,
greenMaterial,
blueMaterial,
WhiteMaterial,
yellowMaterial,
purpleMaterial]发布于 2018-08-21 18:59:43
我的解决方案是:由于我使用了一个.scn文件来设计播放器,所以我使用了另一个具有原始磁头属性的盒子,并将它添加到播放机中(在我删除原始磁头之后)。为了创建新的头部,我做了以下工作:
let head = playerNode?.childNode(withName: "head", recursively: true)!
let head2 = SCNNode(geometry: SCNBox(width: 0.3, height: 0.3, length: 0.3, chamferRadius: 0))
let greenMaterial = SCNMaterial()
greenMaterial.diffuse.contents = UIColor.green
greenMaterial.locksAmbientWithDiffuse = true;
let redMaterial = SCNMaterial()
redMaterial.diffuse.contents = UIColor.red
redMaterial.locksAmbientWithDiffuse = true;
let blueMaterial = SCNMaterial()
blueMaterial.diffuse.contents = UIColor.blue
blueMaterial.locksAmbientWithDiffuse = true;
let yellowMaterial = SCNMaterial()
yellowMaterial.diffuse.contents = UIColor.yellow
yellowMaterial.locksAmbientWithDiffuse = true;
let purpleMaterial = SCNMaterial()
purpleMaterial.diffuse.contents = UIColor.purple
purpleMaterial.locksAmbientWithDiffuse = true
let WhiteMaterial = SCNMaterial()
WhiteMaterial.diffuse.contents = UIColor.white
WhiteMaterial.locksAmbientWithDiffuse = true
head2.geometry?.materials = [redMaterial, greenMaterial, blueMaterial, WhiteMaterial, yellowMaterial, purpleMaterial]
head2.position = head?.position ?? SCNVector3(0, 0.95, 0)
head2.scale = head?.scale ?? SCNVector3(1, 1, 1)
head?.removeFromParentNode()
playerHead = head2
playerNode?.addChildNode(head2)Tnx所有人:)
https://stackoverflow.com/questions/51949792
复制相似问题