+1 vote

Is it possible in godot to play a video file (ogg) ontop of a 3d mesh - use the video as the texture?
I can see there is a videoplayer class, but it doesnt seem to have that or at least I see no examples of it anywhere.

Appgamekit has a function to play a video to an image:
https://www.appgamekit.com/documentation/Reference/Video/PlayVideoToImage.htm

Unity has many ways to do it too -
https://www.assetstore.unity3d.com/en/#!/content/86778
https://www.assetstore.unity3d.com/en/#!/content/10032

Can godot do that too? Also How?

Here are some 360 video files to play with
https://www.videoblocks.com/videos/footage/360-files

asked Jul 25, 2017 in Engine by blurymind (90 points)

1 Answer

+1 vote

You can use VideoPlayer.get_video_texture() to get a video texture, and then simply assign the texture to the material of your mesh and it should work. Here's a basic example using a TestCube:

extends TestCube

var stream = preload("my_video.ogv")

func _ready():
    var player = VideoPlayer.new()
    player.set_stream(stream)
    add_child(player)
    var texture = player.get_video_texture()
    var material = FixedMaterial.new()
    material.set_texture(FixedMaterial.PARAM_DIFFUSE, texture)
    material.set_flag(Material.FLAG_UNSHADED, true)
    set_material_override(material)
    player.play()
answered Jul 25, 2017 by mollusca (1,524 points)

Hi, would it be possible to update this for godot 3? I think FixedMaterial is now SpatialMaterial and I can't find PARAM_DIFFUSE anywhere.

Here you go:

(I just do not know how to loop it or how to fit it to mesh :( )

    extends MeshInstance

# class member variables go here, for example:
# var a = 2
# var b = "textvar"

var stream = preload("res://tex/video.ogv")

func _ready():
    var player = VideoPlayer.new()
    player.set_stream(stream)

    add_child(player)

    var texture = player.get_video_texture()

    var material = SpatialMaterial.new()
    material.albedo_texture = texture
    material.set_flag(material.FLAG_UNSHADED, true)
    set_material_override(material)


    player.play()
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.