RealityKit在运行时更改USDZ扩散材质

问题描述 投票:1回答:1

我正在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)
}
swift arkit realitykit
1个回答
0
投票

您不能在运行时更改RealityKit 1.0着色器。

© www.soinside.com 2019 - 2024. All rights reserved.