Texture纹理贴图需要使用TextureLoader()异步加载图片,而视频纹理(VideoTexture)创建一个使用视频来作为贴图的纹理对象时,需要在当前文档创建使用的Video元素。
具体代码如下:
CSS:
#video { position: absolute; width: 0; height: 0; }
HTML:
<!--视频材质素材--> <video id="video" autoplay loop muted> <source src="images/texture/videoPlane.mp4"> </video>
JS:
//加载视频贴图; var texture = new THREE.VideoTexture(video); //创建网格; var geometry = new THREE.BoxGeometry(100, 100, 100); var material = new THREE.MeshBasicMaterial({ map: texture, }); var mesh = new THREE.Mesh(geometry, material); scene.add(mesh);
Done!