For some reason I cannot replace the texture of my room model’s panel into a videostream from the stream capture API. The panel turns into a black color instead.
<video id="video" playsinline muted autoplay style="display: none;" crossorigin="anonymous"></video>
const videoElem = document.getElementById("video");
async function startCapture() {
try {
videoElem.srcObject=await navigator.mediaDevices.getDisplayMedia({video: {cursor: "motion"},audio: false}); //parameter = displayMediaOptions
} catch(err) {
console.error("Error: " + err);
}
}
function stopCapture() {
videoElem.srcObject.getTracks().forEach(track => track.stop());
videoElem.srcObject = null;
}
document.body.appendChild(video);
startCapture();
const texture = new THREE.TextureLoader().load(new THREE.VideoTexture( videoElem ));
const renderer = new THREE.WebGLRenderer({ antialias: true });
var loader = new THREE.GLTFLoader();
renderer.setClearColor( 0x000000, 1 );
renderer.setSize( window.innerWidth, window.innerHeight );
//Imports room model
loader.load( 'room with directional lighting.glb', function ( gltf ) {
room=gltf.scene;
//Modify plane's material (video stream)
if(room.children[4].name=="Monitor-Plane"){
room.children[4].material = new THREE.MeshBasicMaterial({map: texture});
}
scene.add(room);
}, undefined, function ( error ) {
console.error( error );
} );