0

我需要更改模型中某些材料的纹理/颜色。当我创建一个新材料并像这样分配它时

var materials = geometry.materials

for (index, material) in materials.enumerated()
{
   if (shouldChangeMaterial)
   {
      let updated = SCNMaterial()
      updated.isDoubleSided = false
      updated.diffuse.contents = UIColor.red
      materials[index] = updated
   }
}

geometry.materials = materials

它按预期工作

在此处输入图像描述

但是当我尝试像这样更改现有的

var materials = geometry.materials

for (index, material) in materials.enumerated()
{
   if (shouldChangeMaterial)
   {
      let updated = materials[index]
      updated.isDoubleSided = false
      updated.diffuse.contents = UIColor.red
      materials[index] = updated
   }
}

geometry.materials = materials

或这个

for (index, material) in materials.enumerated()
{
   if (shouldChangeMaterial)
   {
      geometry.materials[index].diffuse.contents = UIColor.red
   }
}

我得到一个全黑模型

在此处输入图像描述

我无法用新材料替换材料,因为材料名称用于计算shouldChangeMaterial变量。

4

0 回答 0