A webcam mirror
Updated
Start camera publishes your camera as the stream me/camera, which a Video entity with a Media Stream plays; pressing again unpublishes it and stops the camera.
Press Start camera and allow the camera to see yourself on the screen; press it again to stop. Needs a camera and your permission.
A webcam mirror
#pragma lifecycle(startup)
// Scene: a "Start Camera" UI Button with a Signal Emitter on 'mirror/start', and a// Video entity "Mirror" with a Media Stream on 'me/camera' and a Signal Emitter on 'mirror'.let unpublish;
function startup() { on('mirror', (event) => { if (event.eventType === EventType.MediaStream.Connected) log('Mirror is live'); if (event.eventType === EventType.MediaStream.Disconnected) log('Mirror stopped'); });
on('mirror/start', async (event) => { if (event.eventType !== EventType.UIButton.Press) return; if (unpublish) { unpublish(); unpublish = undefined; Input.camera.stop(); return; } if (!(await Input.camera.start())) { log('No camera, or permission refused'); return; } unpublish = Streams.publish('me/camera', Input.camera.stream()); });}How it works
Section titled “How it works”The script is explained step by step in A webcam mirror.
Open it in XR Creator
Section titled “Open it in XR Creator”Download the project file below, then import it in XR Hub with Projects › New › Import, as described in Projects and templates. It opens in XR Creator with the same scene you see running above, each script already attached to its Behavior entity. From there you can edit the scripts, adjust components and their props, preview your changes, and deploy the result as a world of your own.
WebcamMirror.xrproj