ΠΠ΅ΠΎΠ±Ρ
ΠΎΠ΄ΠΈΠΌΠΎ Π²Π½Π΅ΡΡΠΈ Π½Π΅Π±ΠΎΠ»ΡΡΠΈΠ΅ ΠΈΠ·ΠΌΠ΅Π½Π΅Π½ΠΈΡ Π² ΠΊΠΎΠ΄. ΠΠ΅ΠΎΠ±Ρ
ΠΎΠ΄ΠΈΠΌΠΎ ΠΈΠ·ΠΌΠ΅Π½ΠΈΡΡ ΠΈΠ»ΠΈ Π½Π° ΠΎΠ±ΠΎΡΠΎΡ Π΄ΠΎΡΠ°Π±ΠΎΡΠ°ΡΡ ΠΏΠ΅ΡΡΠΉ ΡΡΠ°ΠΏ Π²Ρ
ΠΎΠ΄Π° ΠΠΏΠΏΠΊΠ° Π½Π΅ Π·Π°ΠΏΡΡΠΊΠ°Π΅ΡΡΡ ΠΏΠΎΠΊΠ° Π½Π΅ Π²ΡΠ±Π΅ΡΠ΅ΡΡ ΠΊΠ°ΠΌΠ΅ΡΡ Π½Π° ΡΠ΅Π»Π΅ΡΠΎΠ½Π΅, ΠΏΠΎΡΠ»Π΅ ΡΠ΅Π³ΠΎ Π·Π°Π³ΡΡΠΆΠ°Π΅ΡΡΡ Π°ΠΏΠΏΠΊΠ° ΠΈ ΡΠΆΠ΅ ΡΠ΅Π»Π΅ΡΠΎΠ½ Π·Π°ΠΏΡΠ°ΡΠΈΠ²Π°Π΅Ρ Π΄ΠΎΡΡΡΠΏ ΠΊ ΠΊΠ°ΠΌΠ΅ΡΠ΅. ΠΡΠΆΠ½ΠΎ: - Π»ΠΈΠ±ΠΎ ΡΠ±ΡΠ°ΡΡ ΡΡΠ°ΠΏ Π²ΡΠ±ΠΎΡΠ° ΠΊΠ°ΠΌΠ΅ΡΡ ΠΈ Π½Π°Π·Π½Π°ΡΠ°ΡΡ Π·Π°Π΄Π½ΡΡ ΠΊΠ°ΠΌΠ΅ΡΡ ΠΏΠΎ Π΄Π΅ΡΠΎΠ»ΡΡ (ΡΠΎΠΎΡΠ²Π΅ΡΡΠ²Π΅Π½Π½ΠΎ ΡΡΠΎΠ± ΡΡΡΠ°Π½ΠΈΡΠ° Π·Π°ΠΏΡΡΠΊΠ°Π»Π°ΡΡ Ρ loader bar ΠΈ Π·Π°ΠΏΡΠΎΡ Π½Π° Π΄ΠΎΡΡΡΠΏ ΠΊ ΠΊΠ°ΠΌΠ΅ΡΠ΅, ΠΏΠΎΡΠ»Π΅ ΡΠ΅Π³ΠΎ ΠΈΠ½ΠΈΡΠΈΠ°Π»ΠΈΠ·Π°ΡΠΈΡ ΠΊΠ°ΠΌΠ΅ΡΡ) - Π»ΠΈΠ±ΠΎ ΠΏΠΎΠ΄ΠΊΠ»ΡΡΠΈΡΡ Π²ΡΠ±ΠΎΡ ΠΌΠ΅ΡΠΎΠ΄ΠΎΠ² user ΠΈ environment Π² ΡΠΎΠΎΡΠ²Π΅ΡΡΡΠ²ΠΈΠΈ Ρ Π²ΡΠ±ΠΎΡΠΎΠΌ ΠΏΠΎΠ»ΡΠ·ΠΎΠ²Π°ΡΠ΅Π»Ρ, ΡΠ°ΠΊ ΠΊΠ°ΠΊ ΡΠ΅ΠΉΡΠ°Ρ ΡΡΠΎΠΈΡ ΠΌΠ΅ΡΠΎΠ΄ environment ΠΈ ΠΏΡΠΈ Π²ΡΠ±ΠΎΡΠ΅ ΠΊΠ°ΠΌΠ΅ΡΡ ΠΏΠ΅ΡΠ΅Π΄Π½Π΅Π³ΠΎ Π²ΠΈΠ΄Π°, Π²ΠΊΠ»ΡΡΠ°Π΅ΡΡΡ Π²ΡΠ΅ ΡΠ°Π²Π½ΠΎ Π·Π°Π΄Π½ΡΡ var initialize = async() =>{ var unityCanvas = document.querySelector(“#unity-canvas“); var videoCanvas = document.querySelector(“#video-canvas“); window.arCamera = new ARCamera(unityCanvas, videoCanvas); window.iTracker = new ImageTracker(arCamera); try{ await window.iTracker.initialize(); console.log(“ImageTracker initialized!“); } catch{ console.error(“Failed to initialize ImageTracker. Are you missing opencv.js? “ + error); ShowError(“Failed to initialize the experience.“); return; } await LoadWebcams(); document.getElementById(“startARButton“).style.display = “block“; } initialize(); var container = document.querySelector(“#unity-container“); var canvas = document.querySelector(“#unity-canvas“); var loadingBar = document.querySelector(“#unity-loading-bar“); var progressBarFull = document.querySelector(“#unity-progress-bar-full“); function StartAR() { canvas.style.width = window.innerWidth + “px“; canvas.style.height = window.innerHeight + “px“; document.getElementById(“startARDiv“).style.display = “none“; createUnityInstance(document.querySelector(“#unity-canvas“), { dataUrl: “Build/AR Arts.data“, frameworkUrl: “Build/AR Arts.framework.js“, codeUrl: “Build/AR Arts.wasm“, streamingAssetsUrl: “StreamingAssets“, companyName: “DefaultCompany“, productName: “AR Web“, productVersion: “0.1“, //webglContextAttributes: { “preserveDrawingBuffer“: true }, // matchWebGLToCanvasSize: false, // Uncomment this to separately control WebGL canvas render size and DOM element size. // devicePixelRatio: 1, // Uncomment this to override low DPI rendering on high DPI displays. }, (progress) => { progressBarFull.style.width = 100 * progress + “%“; } ).then((unityInstance) => { window.unityInstance = unityInstance; RequestWebcam(); loadingBar.style.display = “none“; }); loadingBar.style.display = “block“; } //Set Facing Mode here ('environment', 'user', '') window.unityFacingMode = “environment“ window.WEBCAM_SETTINGS = { video: { facingMode: unityFacingMode, }, audio: false }; window.requestingForPermissions = false; async function RequestWebcam(){ window.requestingForPermissions = true; try{ window.webcamStream = await navigator.mediaDevices.getUserMedia(window.WEBCAM_SETTINGS); console.log(“Webcam access granted“); requestingForPermissions = false; } catch (err) { //user denied camera permission - show error panel console.error(“getUserMedia error - “ , err); ShowError(“Failed to start the experience. Camera permission was denied“); window.requestingForPermissions = false; } } async function StartWebcam(){ console.log(“StartWebcam“) while (window.requestingForPermissions) { // Wait until requestingForPermissions becomes true. console.log(“Waiting for permissions...“); await new Promise(resolve => setTimeout(resolve, 100)); // Adjust the delay time as needed. } console.log(“Got Permissions“); if(window.webcamStream) { const video = document.querySelector(“#webcam-video“); video.srcObject = webcamStream; try { await arCamera.startWebcam(video); console.log(“Webcam started successfully“); window.unityInstance.SendMessage('ARCamera', 'OnStartWebcamSuccess'); } catch(err){ console.error(“Webcam failed to start - “, err); window.unityInstance.SendMessage('ARCamera', 'OnStartWebcamFail'); } } else{ console.error(“Webcam failed to start - permission not yet granted“); window.unityInstance.SendMessage('ARCamera', 'OnStartWebcamFail'); } } async function LoadWebcams(){ let camDevices = []; // let backCams = []; let devices = await navigator.mediaDevices.enumerateDevices(); var ctr = 0; devices.forEach(mediaDevice => { if (mediaDevice.kind === 'videoinput') { if(window.unityFacingMode == 'environment' && !mediaDevice.label.includes('facing front')){ //back cam only camDevices.push(mediaDevice); } else if(window.unityFacingMode == 'user' && mediaDevice.label.includes('facing front')){ //front cam only camDevices.push(mediaDevice); } else{ //back and front camDevices.push(mediaDevice); } ctr++; } }); var select = document.getElementById(“chooseCamSel“); select.style.display = “block“; var count = 0; //reverse array because some Android phones can't distinguish front and back cams at first load //and when this happens, most of the time, front cam goes first and back cam goes last camDevices = camDevices.reverse(); camDevices.forEach(mediaDevice => { const option = document.createElement('option'); option.value = mediaDevice.deviceId; let label = `Camera ${count}`; if (mediaDevice.label) { label = mediaDevice.label } const textNode = document.createTextNode(label); option.appendChild(textNode); select.appendChild(option); count++; }); iTracker.WEBCAM_NAME = select.options[select.selectedIndex].innerHTML; } function SelectCam(){ var select = document.getElementById(“chooseCamSel“); window.deviceId = select.value; window.WEBCAM_SETTINGS.video['deviceId'] = deviceId; //console.log(window.WEBCAM_SETTINGS); iTracker.WEBCAM_NAME = select.options[select.selectedIndex].innerHTML; } async function FlipCam(){ arCamera.stopWebcam(); window.WEBCAM_SETTINGS.video.deviceId = ''; if(window.WEBCAM_SETTINGS.video.facingMode == 'user'){ window.WEBCAM_SETTINGS.video.facingMode = 'environment'; arCamera.setFlipped(false); } else{ window.WEBCAM_SETTINGS.video.facingMode = 'user'; arCamera.setFlipped(true); } window.webcamStream = await navigator.mediaDevices.getUserMedia(window.WEBCAM_SETTINGS); const video = document.querySelector(“#webcam-video“); video.srcObject = webcamStream; await arCamera.startWebcam(video); } function ShowError(error){ document.getElementById(“errorDiv“).style.display = “flex“; document.getElementById(“errorText“).innerHTML = error; } function ShowScreenshot(dataUrl){ document.getElementById(“screenshotDiv“).style.display = “flex“; document.getElementById(“screenshotImg“).src = dataUrl; document.getElementById(“screenshotImg“).style.width = “80vw“; document.getElementById(“screenshotImg“).style.height = 80 / window.innerWidth * window.innerHeight + “vw“; } function ShowConfirmUrl(url){ document.getElementById(“confirmUrlDiv“).style.display = “flex“; window.newUrlString = url; document.getElementById(“confirmUrlText“).innerText = “Are you sure you want to visit “ + url; } window.ITRACKER_GLOBALS = { //place global settings here INTERNAL_SMOOTHFACTOR_POS: .075, }.