I'm trying to add a video player in a GLB model mesh using Three.JS. Although this can done using VideoTexture, I'm trying to add all of the controls that a video player has by default.
Here's a code snippet by using VideoTexture:
let video = document.createElement( 'video' );
video.loop = true;
video.crossOrigin = 'anonymous';
video.muted = "muted";
video.load();
video.src = videoD;
video.controls = true
let texture = new THREE.VideoTexture( video );
texture.minFilter = THREE.NearestFilter;
texture.magFilter = THREE.LinearFilter;
texture.format = THREE.RGBFormat;
let material = new THREE.MeshBasicMaterial( { map : texture } );
// and then use this material as the material for the glb child mesh
The problem with the above approach is I can't add controls. I'm using react currently, so another way is to use HTML component and try to load that in place of the mesh, here's the approach for that using react refs
<>
<primitive ref={stall_ref} object={glb.scene} />
<Html>
<ReactPlayer ref={react_player_ref} id="widget2" url='https://www.youtube.com/watch?v=ysz5S6PUM-U' />
</Html>
</>
and then use this ref to modify the video player position
// I'm actually not sure what I'm doing here
react_player_ref.current.position.copy(meshChild.position)
react_player_ref.current.quaternion.copy(meshChild.quaternion)
react_player_ref.current.matrix.copy(meshChild.matrix)
react_player_ref.current.matrixWorld.copy(meshChild.matrixWorld)
react_player_ref.current.scale.copy(meshChild.scale)
react_player_ref.current.rotation.set(meshChild.rotation)