I am loading a USDZ model with RealityKit in Swift. The model loads fine with it's texture.
However, I am unable to change the diffuse property of the material, the material always comes back as AnyMaterial
.
I can override the material completely with a SimpleMaterial
or I can change the USDZ diffuse colour before running the app, but can't seem to do this at run time, any ideas?
I just want to be able to change the one property
/*
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)
}