gpt4 book ai didi

ios - 为每个 SCNNode 人脸设置不同的图像

转载 作者:行者123 更新时间:2023-11-28 07:42:25 25 4
gpt4 key购买 nike

我想为SCNNode的每张脸设置不同的图像,我该怎么做?我试过了 this但它没有用,第一种 Material 出现在所有的脸上。我正在使用 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]

最佳答案

我的解决方案:因为我用了一个.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)

谢谢大家:)

关于ios - 为每个 SCNNode 人脸设置不同的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51949792/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com