Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Animated GIF as texture in THREE.js

I'm looking for a way to use a GIF animation as texture in THREE.js. I am currently able to load a texture (even GIF format), but it doesn't play its animation.

Is there any way to do it? I found some links like these:

https://github.com/JordiRos/GLGif

http://stemkoski.github.io/Three.js/Texture-Animation.html

But I need to play GIF animation as a texture, not in a Canvas.

like image 395
Fran Verona Avatar asked Feb 11 '14 18:02

Fran Verona


People also ask

Can you use a GIF as texture in unity?

Unity not support Gif. Save individual frames and make an array of textures.

Can we animated GIF in JavaScript?

I think the short answer is no. If you want to use JavaScript, you're most likely alternatives are controlling genuine video or using CSS sprites. The benefit of using CSS sprites is that you end up transferring a single image, and that image has better overall compression than multiple individual images.

Can I use a GIF as a texture in blender?

You can't. Blender does not support the gif format. Long answer: You would need some other software to convert your gifs to a format that blender understands to be able to import them.


1 Answers

Create a video element, load that element using VideoTexture and add the texture to your mesh.

// Create video and play
let textureVid = document.createElement("video")
textureVid.src = `texture.mp4`; // transform gif to mp4
textureVid.loop = true;
textureVid.play();


// Load video texture
let videoTexture = new THREE.VideoTexture(textureVid);
videoTexture.format = THREE.RGBFormat;
videoTexture.minFilter = THREE.NearestFilter;
videoTexture.maxFilter = THREE.NearestFilter;
videoTexture.generateMipmaps = false;

// Create mesh
var geometry = new THREE.SphereGeometry( 1, 1, 1 );
var material = new THREE.MeshBasicMaterial( { map: videoTexture } );
mesh = new THREE.Mesh( geometry, material );
scene.add(mesh);
like image 55
Guilherme IA Avatar answered Sep 20 '22 19:09

Guilherme IA