PhysicallyBasedMaterial being converted to SimpleMaterial

I am creating a ModelEntity with a programatic mesh.

var mat = PhysicallyBasedMaterial()
mat.baseColor = .init(tint: .lightGray)
mat.roughness = 0.0
mat.metallic = 1.0

let newEnt = ModelEntity(mesh: try! .generate(from: [hex.generateMeshDescriptor()]), materials: [mat])
    
stages.worldStage.addChild(newEnt)

where hex.generateMeshDescriptor() generates the custom mesh. On the screen, everything looks great. The material looks exactly like I expect it to. However, a simple, print shows that my ModelEntity has a single material in its list and its a SimpleMaterial, not a PhysicallyBasedMaterial. This causes my program to crash as I am using PhysicallyBasedMaterial's emissiveColor and emissiveIntensity later on to highlight the objects.

print(newEnt.components[ModelComponent.self]!.materials)

shows

[RealityKit.SimpleMaterial(__resource: RealityKit.__MaterialResource, ...
...]

I even try to force the material to be PhysicallyBasedMaterial and it doesn't stick. It's always somehow converted to a SimpleMaterial.

I figured I would ask on the forums before I submit a bug report in case there is something basic that I am not understanding.

Mac OS Monterey Beta 8. iMac Pro. Xcode 13 Beta 5.

Thanks in advance.

-Matt

Replies

Hi, can you confirm that your entity's ModelComponent only has one material? Also, can you try using some of the parameters specific to PhysicallyBasedMaterial and see if they show up on your entity? Also are you running this on iOS or macOS? I see you're using Xcode beta 5, have you tried building with RC Xcode? This looks like a bug to me, so if none of those things work feel free to file this on Feedback Assistant and post the feedback number here.

  • I can confirm that it only has one material. I tried setting the emissive colors and emissive intensity to values in mat (I don't believe that SimpleMaterial has these properties) and I can confirm that it still converted to a SimpleMaterial when accessing the material list. Although the object looks to be emissive when I make this change?

    This is MacOS so I am currently forced to use the latest beta of Xcode since I am using MacOS v12 functionality in RealityKit and the RC Xcode doesn't have the ability to compile for MacOS v12.

    I will submit a bug report and post the bug # to this site.

    Thanks for your quick response.

  • No problem, yes please file the bug report. Also, I've been told that this is a known issue, and we have a unit test that had to be disabled because of this issue. However, if you file the bug report we can mark this issue as a developer-facing regression, which means we can prioritize it higher on the list of issues to fix. Also, it seems like the bug is with getting the material from the engine, not setting it. So just keep around a reference to your PBR material if you need to 'get' it until this issue is resolved.

  • FB9680131

    I have implemented the workaround you mentioned and that is working just great for my application. Thanks again.

Add a Comment