How do I replace a USD model's material with a VideoMaterial?

59 views Asked by At

Using RealityKit, it is possible to create a ModelEntity and put a VideoMaterial in it, and it will render and play a video perfectly.

I got a premade 3D model from Blender, exported to USDZ and it renders fine on visionOS, but if I replace the material with the VideoMaterial, its surface becomes totally black.

I am a complete newbie in 3D, so I have no idea if there is anything in the model that is interfering with this behavior.

Any suggestions of troubleshooting steps?

RealityView { content in
  let player = AVPlayer(url: Bundle.main.url(forResource: "Onboarding", withExtension: "mp4")!)
  let videoMaterial = VideoMaterial(avPlayer: player)

  if let scene = try? await Entity(named: "Cube") {
    if let screenEntity = scene.children[0].children[0] as? ModelEntity {
      screenEntity.model?.materials[4] = videoMaterial
    }

    content.add(scene)
    player.play()
  }
}

If I replace the material with something like this, it does render the color:

screenEntity.model?.materials[4] = SimpleMaterial(color: .red, isMetallic: true)
1

There are 1 answers

0
Wes Souza On

I ended up discovering my 3D model lacked UV mapping, adding that solved the issue.