Hi @Kabe , thank you for your patience!
PhysicallyBasedMaterial
s can be created in Reality Composer Pro and can be assigned to and referenced by Entities there, or they can be instantiated and assigned at runtime to entities in your scene. Check out the documentation for a list of all of the parameters you can adjust.
You can assign a ShaderGraphMaterial
created in Reality Composer Pro by using a specific ShaderGraphMaterial
initializer. For example, I added a material I created in Shader Graph called "TealMaterial" to a scene I created in RCP called "MaterialsInScene.usda". I can load it in and apply it to a cube I created at runtime like this:
do {
// the "named" string will match the hierarchy in Reality Composer Pro, don't forget the "Root" entity!
let mat = try await ShaderGraphMaterial(named: "/Root/TealMaterial", from: "MaterialsInScene.usda", in: realityKitContentBundle)
let shape = ShapeResource.generateBox(size: [0.1, 0.1, 0.1])
let mesh = await MeshResource.init(shape: shape)
let modelEntity = ModelEntity.init(mesh: mesh, materials: [mat])
content.add(modelEntity)
}
catch {
print("could not load material: \(error)")
}
With regard to references, I apologize, I'm not sure I understand the issue you are seeing. When you said the data is kept even when removing the original usdz, do you mean at runtime or when you have it open in RCP? When the scene with references gets loaded into memory, referenced entities are also loaded, recursively, and placed in the entity hierarchy alongside all the "original data" that already existed in the scene. If you've ever worked with Unity, USD references are kind of like prefabs in a Unity scene.
If you're interested, the official docs for USD may help you understand more about what is happening "under the hood":
https://openusd.org/release/api/class_usd_references.html
Let me know if that helps!