[Reality Composer Pro] Is it possible to play video over a specific mesh like a material?

Hi!

I'm trying to play video on monitor 3D model like a material. I wanna know if it's possible work. I searched about it, but I couldn't get enough information. Thank you in advance.

Answered by Vision Pro Engineer in 812875022

Hi @PLAY4

Here's more detail on how you can get this to work by using a VideoMaterial.

Start by placing your video file somewhere inside of your Xcode project. In my case, I created a "Videos" folder in my project and placed a .mp4 file with the name "MyMovie" inside of it.

Next, define a RealityView that loads your video file and applies it to the surface of a model with a VideoMaterial, as shown below:

RealityView { content in
    // Create a URL that points to the movie file.
    if let url = Bundle.main.url(forResource: "MyMovie", withExtension: "mp4") {
        
        // Create an AVPlayer instance to control playback of that movie.
        let player = AVPlayer(url: url)

        // Instantiate and configure the video material.
        let material = VideoMaterial(avPlayer: player)

        // Create a new model entity using the video material.
        let modelEntity = ModelEntity(mesh: .generateBox(size: 1.0), materials: [material])
        modelEntity.position = [0, 1, -1]
        content.add(modelEntity)

        // Start playing the video.
        player.play()
    }
}

In this example, VideoMaterial is applied to a cube model positioned in front of the viewer, but you can apply it to the screen on your 3D monitor model instead.

Hi @PLAY4

You can play a video on the surface of an entity with a VideoMaterial.

Let me know if you have any questions!

Accepted Answer

Hi @PLAY4

Here's more detail on how you can get this to work by using a VideoMaterial.

Start by placing your video file somewhere inside of your Xcode project. In my case, I created a "Videos" folder in my project and placed a .mp4 file with the name "MyMovie" inside of it.

Next, define a RealityView that loads your video file and applies it to the surface of a model with a VideoMaterial, as shown below:

RealityView { content in
    // Create a URL that points to the movie file.
    if let url = Bundle.main.url(forResource: "MyMovie", withExtension: "mp4") {
        
        // Create an AVPlayer instance to control playback of that movie.
        let player = AVPlayer(url: url)

        // Instantiate and configure the video material.
        let material = VideoMaterial(avPlayer: player)

        // Create a new model entity using the video material.
        let modelEntity = ModelEntity(mesh: .generateBox(size: 1.0), materials: [material])
        modelEntity.position = [0, 1, -1]
        content.add(modelEntity)

        // Start playing the video.
        player.play()
    }
}

In this example, VideoMaterial is applied to a cube model positioned in front of the viewer, but you can apply it to the screen on your 3D monitor model instead.

[Reality Composer Pro] Is it possible to play video over a specific mesh like a material?
 
 
Q