Manipulate objects in Reality Composer Pro

The documentation at https://developer.apple.com/documentation/visionos/designing-realitykit-content-with-reality-composer-pro states:

Reality Composer Pro treats your imported assets as read-only.

This is a huge obstacle for me, as I need to do multiple adjustments to the scene.

I somehow managed to actually import one of my assets into the scene and can manipulate it directly, but now I can't figure out how I did this.

As I have to prepare further assets and would like to do this directly in Reality Composer Pro, I'm looking for a way to actually load them into the scene.

Any idea how this can be done?

I managed to do this again, but I have still no idea why it worked now.

Same for materials.

Isn't there simple a command to resolve external references?

Hi @Kabe

EDIT: I realize you may mean you'd like to edit a USDZ file directly with Reality Composer Pro. This is indeed not possible (do you have access to a DCC like Blender or Maya that is designed for this sort of task?), although you can create a new USD using References to entities in your imported asset.

(If that's not what you meant, please keep reading!)

When you load an Entity from an asset at runtime, you are free to add, remove, and modify any Components you like.

When the documentation says "Reality Composer Pro treats your imported assets as read-only" this means that Reality Composer Pro will not modify the assets that you import into your project. It is not referring to your ability to manipulate and change entities at runtime once you have loaded them from those assets.

Here's an example of what I mean by modifying an Entity at runtime: I'll change the first material on an asset called "Robot.usdz" in realityKitContentBundle so that it is completely red:

var modelEntity = try await ModelEntity.init(named: "Robot", in: realityKitContentBundle)
var model = modelEntity.components[ModelComponent.self]!
var materials = model.materials
materials[0] = SimpleMaterial(color: .red, isMetallic: false)
model.materials = materials;
modelEntity.components.set(model)

Sorry for the confusion, let me know if this helps!

Actually, I'm using Blender for creating these entities, but there are problems with the output, i.e. Blender exports an environment light (even if lights are disabled in export), which creates issues when compiling the package).

Also, I need to assign new materials in Composer Pro, as I need universal inputs to alter textures at runtime in my scenario.

I understand references, but the funny thing is that somehow (still haven't figured out a sequence of steps how to do it) I manage to convert these references to original data within the scene. These data are kept even when removing the originally referenced *.usdz.

For me that makes stuff so much easier than dealing with the exports from Blender.

Ah, understood! For that issue you mentioned with Blender, does it go away if you disable "Convert World Material" under the "Materials" section of Blender's export to USD dialog? If you do try this out, I'd love to hear if it works for you or not.

Are the materials you are trying to assign ones created in Shader Graph inside Reality Composer Pro? These materials will exist inside the scene, and should be available for you to assign to entities after you load the scene.

... but let me get back to you on how to assign those materials, I need to take some time to think through it before I share any example code. I just wanted to mention that Blender setting since I've seen that come up before.

Hi @Kabe , thank you for your patience!

PhysicallyBasedMaterials 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!

Manipulate objects in Reality Composer Pro
 
 
Q