我正在Swift中使用RealityKit加载USDZ模型。该模型的纹理可以很好地加载。
但是,我无法更改材质的漫反射特性,该材质始终返回为AnyMaterial
。
我可以使用SimpleMaterial
完全覆盖材质,也可以在运行应用程序之前更改USDZ漫反射颜色,但似乎无法在运行时执行此操作,有什么主意吗?
我只想能够更改一个属性
/*
Find an entity within the parent, and find the material, test to try and change it's material
**/
private func updateColor(entity: Entity) {
guard
let found = entity.findEntity(named: "MyItem"),
var modelComponent = found.components[ModelComponent] as? ModelComponent,
let existingMaterial = modelComponent.materials.first else {
return
}
// This is `AnyMaterial` - no diffuse property
// What can I use here to change the diffuse?
modelComponent.materials = [existingMaterial]
// Change to yellow for testing
//var material = SimpleMaterial()
//material.baseColor = .color(.yellow)
//modelComponent.materials = [material]
found.components.set(modelComponent)
}
您不能在运行时更改RealityKit 1.0着色器。