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.
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.