How can we change color of USDZ format asset using Model3d

I am trying to change the color of usdz asset provide by my designer. But I am unable to do. Can some help me with some sample code

Replies

There's two methods that might be useful for you. The first one is probably your best bet if using Model3D, as models shown through that cannot be altered from what's on disk.

Method 1 - Modify the USDZ

First you'll need to figure out the way the USDZ file is made up. Using examples from Quick Look Gallery, such as the tv and chair.

Inspect the USDZ by opening it with Archive Utility. and you'll end up seeing something like these:

TVChair

From here, you can replace the image directly, and then put it back together by importing + exporting with Reality Composer Pro or USDZ Python Tools.


Method 2 - Modify at runtime

Alternatively, if you want to just do it with code, load the model in using the Entity initialiser:

let chair = try? await Entity(named: "chair_swan")

Get the seat entity:

let seat = tv.findEntity(named: "RedChairSeat") as? ModelEntity

The name of this entity will be shown in Reality Composer Pro if you import the model there.

Get the material used for the seat entity:

var mat = seat.model?.materials.first as? PhysicallyBasedMaterial

Change the base color to either another texture, or a solid color:

mat.baseColor = .init(tint: .blue, texture: nil)

Then re-assign the material:

seat.model?.materials = [mat]