VideoMaterial
A material that supports animated textures.
Declaration
struct VideoMaterialOverview
In RealityKit, a material is an object that defines the surface properties of a rendered 3D object. A VideoMaterial is a material that maps a movie file on to the surface of an entity. Video materials are unlit, which means that scene lighting doesn’t affect them. Video materials support transparency if the source video’s file format also supports transparency.
Video materials use an AVPlayer instance to control movie playback. You can use any movie file format that AVPlayer supports to create a video material. To control playback of the material’s video, use the avPlayer property, which offers methods like play() and pause().
The following code demonstrates how to create and start playing a video material using a movie file from your application bundle.
// 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)
// Configure audio playback mode.
material.controller.audioInputMode = .spatial
// Create a new model entity using the video material.
let modelEntity = ModelEntity(mesh: cube, materials: [material])
// Start playing the video.
player.play()
}To see an example of using a video texture in RealityKit, see Creating a game with scene understanding.