-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathaframe-motion-capture-components.min.js
1 lines (1 loc) · 22.7 KB
/
aframe-motion-capture-components.min.js
1
!function(t){function e(i){if(r[i])return r[i].exports;var o=r[i]={exports:{},id:i,loaded:!1};return t[i].call(o.exports,o,o.exports,e),o.loaded=!0,o.exports}var r={};return e.m=t,e.c=r,e.p="",e(0)}([function(t,e,r){if("undefined"==typeof AFRAME)throw new Error("Component attempted to register before AFRAME was available.");r(4),r(5),r(2),r(3),r(6),r(7),r(8)},function(t,e){t.exports.LOCALSTORAGE_RECORDINGS="avatarRecordings",t.exports.DEFAULT_RECORDING_NAME="default"},function(t,e,r){var i=r(1),o=AFRAME.utils.debug("aframe-motion-capture:avatar-recorder:info"),a=AFRAME.utils.debug("aframe-motion-capture:avatar-recorder:warn");AFRAME.registerComponent("avatar-recorder",{schema:{autoPlay:{default:!1},autoRecord:{default:!1},cameraOverride:{type:"selector"},localStorage:{default:!0},recordingName:{default:i.DEFAULT_RECORDING_NAME},loop:{default:!0}},init:function(){this.cameraEl=null,this.isRecording=!1,this.trackedControllerEls={},this.recordingData=null,this.onKeyDown=AFRAME.utils.bind(this.onKeyDown,this),this.tick=AFRAME.utils.throttle(this.throttledTick,100,this)},throttledTick:function(){var t=this,e=this.el.querySelectorAll("[tracked-controls]");this.trackedControllerEls={},e.forEach(function(e){return e.id?(e.setAttribute("motion-capture-recorder",{autoRecord:!1,visibleStroke:!1}),t.trackedControllerEls[e.id]=e,void(t.isRecording&&e.components["motion-capture-recorder"].startRecording())):void a("Found a tracked controller entity without an ID. Provide an ID or this controller will not be recorded")})},play:function(){window.addEventListener("keydown",this.onKeyDown)},pause:function(){window.removeEventListener("keydown",this.onKeyDown)},onKeyDown:function(t){var e=t.keyCode,r={space:32};switch(e){case r.space:this.toggleRecording()}},toggleRecording:function(){this.isRecording?this.stopRecording():this.startRecording()},setupCamera:function(t){function e(e){i.cameraEl&&i.cameraEl.removeAttribute("motion-capture-recorder"),i.cameraEl=e,e.setAttribute("motion-capture-recorder",{autoRecord:!1,visibleStroke:!1}),t(e)}var r=this.el,i=this;return this.data.cameraOverride?void e(this.data.cameraOverride):r.camera&&r.camera.el?void e(r.camera.el):void r.addEventListener("camera-set-active",function t(i){e(i.detail.cameraEl),r.removeEventListener("camera-set-active",t)})},startRecording:function(){var t=this.trackedControllerEls,e=this;this.isRecording||(o("Starting recording!"),this.el.components["avatar-replayer"]&&this.el.components["avatar-replayer"].stopReplaying(),this.setupCamera(function(){e.isRecording=!0,e.cameraEl.components["motion-capture-recorder"].startRecording(),Object.keys(t).forEach(function(e){t[e].components["motion-capture-recorder"].startRecording()})}))},stopRecording:function(){var t=this.trackedControllerEls;this.isRecording&&(o("Stopped recording."),this.isRecording=!1,this.cameraEl.components["motion-capture-recorder"].stopRecording(),Object.keys(t).forEach(function(e){t[e].components["motion-capture-recorder"].stopRecording()}),this.recordingData=this.getJSONData(),this.storeRecording(this.recordingData),this.data.autoPlay&&this.replayRecording())},getJSONData:function(){var t={},e=this.trackedControllerEls;if(!this.isRecording)return t.camera=this.cameraEl.components["motion-capture-recorder"].getJSONData(),Object.keys(e).forEach(function(r){t[r]=e[r].components["motion-capture-recorder"].getJSONData()}),t},storeRecording:function(t){var e=this.data;e.localStorage&&(o("Recording stored in localStorage."),this.el.systems.recordingdb.addRecording(e.recordingName,t))}})},function(t,e,r){var i=r(1),o=AFRAME.utils.bind,a=AFRAME.utils.debug("aframe-motion-capture:avatar-replayer:error"),n=AFRAME.utils.debug("aframe-motion-capture:avatar-replayer:info"),s=AFRAME.utils.debug("aframe-motion-capture:avatar-replayer:warn"),c=new THREE.FileLoader;AFRAME.registerComponent("avatar-replayer",{schema:{autoPlay:{default:!0},cameraOverride:{type:"selector"},loop:{default:!1},recordingName:{default:i.DEFAULT_RECORDING_NAME},spectatorMode:{default:!1},spectatorPosition:{default:{x:0,y:1.6,z:2},type:"vec3"},src:{default:""}},init:function(){var t=this.el;this.onKeyDown=o(this.onKeyDown,this),this.setupCamera=o(this.setupCamera,this),t.camera?this.setupCamera():t.addEventListener("camera-set-active",this.setupCamera),this.data.autoPlay&&this.replayRecordingFromSource()},update:function(t){var e,r=this.data;e=window.location.search.indexOf("spectatormode")!==-1||window.location.search.indexOf("spectatorMode")!==-1,(t.spectatorMode!==r.spectatorMode||e)&&(r.spectatorMode||e?this.activateSpectatorCamera():t.spectatorMode===!0&&this.deactivateSpectatorCamera()),r.src&&t.src!==r.src&&r.autoPlay&&this.replayRecordingFromSource()},play:function(){window.addEventListener("keydown",this.onKeyDown)},pause:function(){window.removeEventListener("keydown",this.onKeyDown)},remove:function(){this.stopReplaying(),this.cameraEl.removeObject3D("replayerMesh")},setupCamera:function(){var t=this.data,e=this.el;t.cameraOverride?this.cameraEl=t.cameraOverride:(this.cameraEl=e.camera.el,this.cameraEl.removeAttribute("data-aframe-default-camera")),this.cameraEl.setAttribute("data-aframe-avatar-replayer-camera",""),e.removeEventListener("camera-set-active",this.setupCamera),this.configureHeadGeometry(),this.initSpectatorCamera()},onKeyDown:function(t){switch(t.keyCode){case 81:this.el.setAttribute("avatar-replayer","spectatorMode",!this.data.spectatorMode)}},activateSpectatorCamera:function(){var t=this.spectatorCameraEl;return t?t.hasLoaded?(n("Activating spectator camera"),t.setAttribute("camera","active",!0),void(this.cameraEl.getObject3D("replayerMesh").visible=!0)):void t.addEventListener("loaded",o(this.activateSpectatorCamera,this)):void this.el.addEventListener("spectatorcameracreated",o(this.activateSpectatorCamera,this))},deactivateSpectatorCamera:function(){n("Deactivating spectator camera"),this.cameraEl.setAttribute("camera","active",!0),this.cameraEl.getObject3D("replayerMesh").visible=!1},initSpectatorCamera:function(){var t,e,r=this.data,i=this.el;return this.el.querySelector("#spectatorCameraRig")?void(this.spectatorCameraEl=i.querySelector("#spectatorCameraRig")):(e=i.querySelector("#spectatorCameraRig")||document.createElement("a-entity"),e.id="spectatorCameraRig",e.setAttribute("position",r.spectatorPosition),this.spectatorCameraRigEl=e,t=i.querySelector("#spectatorCamera")||document.createElement("a-entity"),t.id="spectatorCamera",t.setAttribute("camera",{active:r.spectatorMode,userHeight:0}),t.setAttribute("look-controls",""),t.setAttribute("wasd-controls",{fly:!0}),this.spectatorCameraEl=t,e.appendChild(t),i.appendChild(e),void i.emit("spectatorcameracreated"))},replayRecordingFromSource:function(){var t,e=(this.data,this.el.systems.recordingdb),r=this;null===new URLSearchParams(window.location.search).get("avatar-replayer-disabled")&&e.getRecordingNames().then(function(i){var a=r.getSrcFromSearchParam();return i.indexOf(a)!==-1?(n("Replaying `"+a+"` from IndexedDB."),void e.getRecording(a).then(o(r.startReplaying,r))):(t=a||r.data.src)?(r.data.src?n("Replaying from component `src`",t):a&&n("Replaying from query parameter `recording`",t),void r.loadRecordingFromUrl(t,!1,o(r.startReplaying,r))):void(i.indexOf(r.data.recordingName)!==-1&&(n("Replaying `"+r.data.recordingName+"` from IndexedDB."),e.getRecording(r.data.recordingName).then(o(r.startReplaying,r))))})},getSrcFromSearchParam:function(){var t=new URLSearchParams(window.location.search);return t.get("recording")||t.get("avatar-recording")},startReplaying:function(t){var e=this.data,r=this,i=this.el;if(!this.isReplaying){if(!this.el.camera)return void this.el.addEventListener("camera-set-active",function e(){r.startReplaying(t),r.el.removeEventListener("camera-set-active",e)});this.replayData=t,this.isReplaying=!0,this.cameraEl.removeAttribute("motion-capture-replayer"),Object.keys(t).forEach(function(o){var s;if("camera"===o)s=r.cameraEl;else if(s=i.querySelector("#"+o),!s)return void a("No element found with ID "+o+".");n("Setting motion-capture-replayer on "+o+"."),s.setAttribute("motion-capture-replayer",{loop:e.loop}),s.components["motion-capture-replayer"].startReplaying(t[o])})}},configureHeadGeometry:function(){var t,e,r,i,o,a=this.cameraEl;a.getObject3D("mesh")||a.getObject3D("replayerMesh")||(t=new THREE.Mesh,t.geometry=new THREE.BoxBufferGeometry(.3,.3,.2),t.material=new THREE.MeshStandardMaterial({color:"pink"}),t.visible=this.data.spectatorMode,e=new THREE.Mesh,e.geometry=new THREE.SphereBufferGeometry(.05),e.material=new THREE.MeshBasicMaterial({color:"white"}),e.position.x-=.1,e.position.y+=.1,e.position.z-=.1,i=new THREE.Mesh,i.geometry=new THREE.SphereBufferGeometry(.025),i.material=new THREE.MeshBasicMaterial({color:"black"}),i.position.z-=.04,e.add(i),t.add(e),r=new THREE.Mesh,r.geometry=new THREE.SphereBufferGeometry(.05),r.material=new THREE.MeshBasicMaterial({color:"white"}),r.position.x+=.1,r.position.y+=.1,r.position.z-=.1,o=new THREE.Mesh,o.geometry=new THREE.SphereBufferGeometry(.025),o.material=new THREE.MeshBasicMaterial({color:"black"}),o.position.z-=.04,r.add(o),t.add(r),a.setObject3D("replayerMesh",t))},stopReplaying:function(){var t=this;this.isReplaying&&this.replayData&&(this.isReplaying=!1,Object.keys(this.replayData).forEach(function(e){if("camera"===e)t.cameraEl.removeComponent("motion-capture-replayer");else{if(el=document.querySelector("#"+e),!el)return void s("No element with id "+e);el.removeComponent("motion-capture-replayer")}}))},loadRecordingFromUrl:function(t,e,r){var i,o=this;c.crossOrigin="anonymous",e===!0&&c.setResponseType("arraybuffer"),c.load(t,function(t){i=e===!0?o.loadStrokeBinary(t):JSON.parse(t),r&&r(i)})}})},function(t,e){var r={axismove:{id:0,props:["id","axis","changed"]},buttonchanged:{id:1,props:["id","state"]},buttondown:{id:2,props:["id","state"]},buttonup:{id:3,props:["id","state"]},touchstart:{id:4,props:["id","state"]},touchend:{id:5,props:["id","state"]}};AFRAME.registerComponent("motion-capture-recorder",{schema:{autoRecord:{default:!1},enabled:{default:!0},hand:{default:"right"},recordingControls:{default:!1},persistStroke:{default:!1},visibleStroke:{default:!0}},init:function(){this.drawing=!1,this.recordedEvents=[],this.recordedPoses=[],this.addEventListeners()},addEventListeners:function(){var t=this.el;this.recordEvent=this.recordEvent.bind(this),t.addEventListener("axismove",this.recordEvent),t.addEventListener("buttonchanged",this.onTriggerChanged.bind(this)),t.addEventListener("buttonchanged",this.recordEvent),t.addEventListener("buttonup",this.recordEvent),t.addEventListener("buttondown",this.recordEvent),t.addEventListener("touchstart",this.recordEvent),t.addEventListener("touchend",this.recordEvent)},recordEvent:function(t){var e;this.isRecording&&("detail"in t&&"state"in t.detail&&"object"==typeof t.detail.state&&"target"in t.detail.state&&delete t.detail.state.target,e={},r[t.type].props.forEach(function(r){if("state"!==r)e[r]=t.detail[r];else{var i;e.state={};for(i in t.detail.state)e.state[i]=t.detail.state[i]}}),this.recordedEvents.push({name:t.type,detail:e,timestamp:this.lastTimestamp}))},onTriggerChanged:function(t){var e,r=this.data;if(r.enabled&&!r.autoRecord&&1===t.detail.id&&this.data.recordingControls)return e=t.detail.state.value,e<=.1?void(this.isRecording&&this.stopRecording()):void(this.isRecording||this.startRecording())},getJSONData:function(){var t,e=this.el.components["tracked-controls"],r=e&&e.controller;if(this.recordedPoses)return t={poses:this.getStrokeJSON(this.recordedPoses),events:this.recordedEvents},r&&(t.gamepad={id:r.id,hand:r.hand,index:r.index}),t},getStrokeJSON:function(t){for(var e,r=[],i=0;i<t.length;i++)e=t[i],r.push({position:e.position,rotation:e.rotation,timestamp:e.timestamp});return r},saveCapture:function(t){var e=JSON.stringify(this.getJSONData()),r=t?"application/octet-binary":"application/json",i=new Blob([e],{type:r}),o=URL.createObjectURL(i),a="motion-capture-"+document.title+"-"+Date.now()+".json",n=document.createElement("a");n.setAttribute("class","motion-capture-download"),n.href=o,n.setAttribute("download",a),n.innerHTML="downloading...",n.style.display="none",document.body.appendChild(n),setTimeout(function(){n.click(),document.body.removeChild(n)},1)},update:function(){var t=this.el,e=this.data;if(this.data.autoRecord)this.startRecording();else{if(t.components.camera)return;e.recordingControls&&(t.setAttribute("vive-controls",{hand:e.hand}),t.setAttribute("oculus-touch-controls",{hand:e.hand})),t.setAttribute("stroke","")}},tick:function(){var t=new THREE.Vector3,e=new THREE.Quaternion,r=new THREE.Vector3;return function(i,o){var a,n;this.lastTimestamp=i,this.data.enabled&&this.isRecording&&(a={position:AFRAME.utils.clone(this.el.getAttribute("position")),rotation:AFRAME.utils.clone(this.el.getAttribute("rotation")),timestamp:i},this.recordedPoses.push(a),this.data.visibleStroke&&(this.el.object3D.updateMatrixWorld(),this.el.object3D.matrixWorld.decompose(t,e,r),n=this.getPointerPosition(t,e),this.el.components.stroke.drawPoint(t,e,i,n)))}}(),getPointerPosition:function(){var t=new THREE.Vector3,e=new THREE.Vector3(0,.7,1);return function(r,i){var o=e.clone().applyQuaternion(i).normalize().multiplyScalar(-.03);return t.copy(r).add(o),t}}(),startRecording:function(){var t=this.el;this.isRecording||(t.components.stroke&&t.components.stroke.reset(),this.isRecording=!0,this.recordedPoses=[],this.recordedEvents=[],t.emit("strokestarted",{entity:t,poses:this.recordedPoses}))},stopRecording:function(){var t=this.el;this.isRecording&&(t.emit("strokeended",{poses:this.recordedPoses}),this.isRecording=!1,this.data.visibleStroke&&!this.data.persistStroke&&t.components.stroke.reset())}})},function(t,e){function r(t,e){t.setAttribute("position",e.position),t.setAttribute("rotation",e.rotation)}AFRAME.registerComponent("motion-capture-replayer",{schema:{enabled:{default:!0},recorderEl:{type:"selector"},loop:{default:!1},src:{default:""},spectatorCamera:{default:!1}},init:function(){this.currentPoseTime=0,this.currentEventTime=0,this.currentPoseIndex=0,this.currentEventIndex=0,this.onStrokeStarted=this.onStrokeStarted.bind(this),this.onStrokeEnded=this.onStrokeEnded.bind(this),this.playComponent=this.playComponent.bind(this),this.el.addEventListener("pause",this.playComponent),this.discardedFrames=0,this.playingEvents=[],this.playingPoses=[],this.gamepadData=null},remove:function(){var t,e=this.el,r=this.gamepadData,i=-1;e.removeEventListener("pause",this.playComponent),this.stopReplaying(),e.pause(),e.play(),this.gamepadData&&(t=e.sceneEl.systems["motion-capture-replayer"].gamepads,t.forEach(function(t,e){t===r&&(i=e)}),i!==-1&&t.splice(i,1))},update:function(t){var e=this.data;this.updateRecorder(e.recorderEl,t.recorderEl),this.el.isPlaying||this.playComponent(),t.src!==e.src&&e.src&&this.updateSrc(e.src)},updateRecorder:function(t,e){e&&e!==t&&(e.removeEventListener("strokestarted",this.onStrokeStarted),e.removeEventListener("strokeended",this.onStrokeEnded)),t&&e!==t&&(t.addEventListener("strokestarted",this.onStrokeStarted),t.addEventListener("strokeended",this.onStrokeEnded))},updateSrc:function(t){this.el.sceneEl.systems["motion-capture-recorder"].loadRecordingFromUrl(t,!1,this.startReplaying.bind(this))},onStrokeStarted:function(t){this.reset()},onStrokeEnded:function(t){this.startReplayingPoses(t.detail.poses)},play:function(){this.playingStroke&&this.playStroke(this.playingStroke)},playComponent:function(){this.el.isPlaying=!0,this.play()},startReplaying:function(t){var e=this.el;this.ignoredFrames=0,this.storeInitialPose(),this.isReplaying=!0,this.startReplayingPoses(t.poses),this.startReplayingEvents(t.events),t.gamepad&&(this.gamepadData=t.gamepad,e.sceneEl.systems["motion-capture-replayer"].gamepads.push(t.gamepad),e.emit("gamepadconnected")),e.emit("replayingstarted")},stopReplaying:function(){this.isReplaying=!1,this.restoreInitialPose(),this.el.emit("replayingstopped")},storeInitialPose:function(){var t=this.el;this.initialPose={position:AFRAME.utils.clone(t.getAttribute("position")),rotation:AFRAME.utils.clone(t.getAttribute("rotation"))}},restoreInitialPose:function(){var t=this.el;this.initialPose&&(t.setAttribute("position",this.initialPose.position),t.setAttribute("rotation",this.initialPose.rotation))},startReplayingPoses:function(t){this.isReplaying=!0,this.currentPoseIndex=0,0!==t.length&&(this.playingPoses=t,this.currentPoseTime=t[0].timestamp)},startReplayingEvents:function(t){var e;this.isReplaying=!0,this.currentEventIndex=0,0!==t.length&&(e=t[0],this.playingEvents=t,this.currentEventTime=e.timestamp,this.el.emit(e.name,e.detail))},reset:function(){this.playingPoses=null,this.currentTime=void 0,this.currentPoseIndex=void 0},playRecording:function(t){var e,i,o=this.playingPoses,a=this.playingEvents;for(e=o&&o[this.currentPoseIndex],i=a&&a[this.currentEventIndex],this.currentPoseTime+=t,this.currentEventTime+=t;e&&this.currentPoseTime>=e.timestamp||i&&this.currentPoseTime>=i.timestamp;)e&&this.currentPoseTime>=e.timestamp&&(this.currentPoseIndex===o.length-1&&(this.data.loop?(this.currentPoseIndex=0,this.currentPoseTime=o[0].timestamp):this.stopReplaying()),r(this.el,e),this.currentPoseIndex+=1,e=o[this.currentPoseIndex]),i&&this.currentPoseTime>=i.timestamp&&(this.currentEventIndex===a.length&&this.data.loop&&(this.currentEventIndex=0,this.currentEventTime=a[0].timestamp),this.el.emit(i.name,i.detail),this.currentEventIndex+=1,i=this.playingEvents[this.currentEventIndex])},tick:function(t,e){return 2===this.ignoredFrames||window.debug?void(this.isReplaying&&this.playRecording(e)):void this.ignoredFrames++}})},function(t,e){AFRAME.registerComponent("stroke",{schema:{enabled:{default:!0},color:{default:"#ef2d5e",type:"color"}},init:function(){var t,e=this.maxPoints=3e3;this.idx=0,this.numPoints=0,this.vertices=new Float32Array(3*e*3),this.normals=new Float32Array(3*e*3),this.uvs=new Float32Array(2*e*2),this.geometry=new THREE.BufferGeometry,this.geometry.setDrawRange(0,0),this.geometry.addAttribute("position",new THREE.BufferAttribute(this.vertices,3).setDynamic(!0)),this.geometry.addAttribute("uv",new THREE.BufferAttribute(this.uvs,2).setDynamic(!0)),this.geometry.addAttribute("normal",new THREE.BufferAttribute(this.normals,3).setDynamic(!0)),this.material=new THREE.MeshStandardMaterial({color:this.data.color,roughness:.75,metalness:.25,side:THREE.DoubleSide});var r=new THREE.Mesh(this.geometry,this.material);r.drawMode=THREE.TriangleStripDrawMode,r.frustumCulled=!1,t=document.createElement("a-entity"),t.setObject3D("stroke",r),this.el.sceneEl.appendChild(t)},update:function(){this.material.color.set(this.data.color)},drawPoint:function(){var t=new THREE.Vector3,e=new THREE.Vector3,r=new THREE.Vector3;return function(o,a,n,s){var c=0,d=this.numPoints,l=.01;if(d!==this.maxPoints){for(i=0;i<d;i++)this.uvs[c++]=i/(d-1),this.uvs[c++]=0,this.uvs[c++]=i/(d-1),this.uvs[c++]=1;return t.set(1,0,0),t.applyQuaternion(a),t.normalize(),e.copy(s),r.copy(s),e.add(t.clone().multiplyScalar(l/2)),r.add(t.clone().multiplyScalar(-l/2)),this.vertices[this.idx++]=e.x,this.vertices[this.idx++]=e.y,this.vertices[this.idx++]=e.z,this.vertices[this.idx++]=r.x,this.vertices[this.idx++]=r.y,this.vertices[this.idx++]=r.z,this.computeVertexNormals(),this.geometry.attributes.normal.needsUpdate=!0,this.geometry.attributes.position.needsUpdate=!0,this.geometry.attributes.uv.needsUpdate=!0,this.geometry.setDrawRange(0,2*d),this.numPoints+=1,!0}}}(),reset:function(){var t=0,e=this.vertices;for(i=0;i<this.numPoints;i++)e[t++]=0,e[t++]=0,e[t++]=0,e[t++]=0,e[t++]=0,e[t++]=0;this.geometry.setDrawRange(0,0),this.idx=0,this.numPoints=0},computeVertexNormals:function(){for(var t=new THREE.Vector3,e=new THREE.Vector3,r=new THREE.Vector3,i=new THREE.Vector3,o=new THREE.Vector3,a=0,n=this.idx;a<n;a++)this.normals[a]=0;var s=!0;for(a=0,n=this.idx;a<n;a+=3)s?(t.fromArray(this.vertices,a),e.fromArray(this.vertices,a+3),r.fromArray(this.vertices,a+6)):(t.fromArray(this.vertices,a+3),e.fromArray(this.vertices,a),r.fromArray(this.vertices,a+6)),s=!s,i.subVectors(r,e),o.subVectors(t,e),i.cross(o),i.normalize(),this.normals[a]+=i.x,this.normals[a+1]+=i.y,this.normals[a+2]+=i.z,this.normals[a+3]+=i.x,this.normals[a+4]+=i.y,this.normals[a+5]+=i.z,this.normals[a+6]+=i.x,this.normals[a+7]+=i.y,this.normals[a+8]+=i.z;for(a=6,n=this.idx-6;a<n;a++)this.normals[a]=this.normals[a]/3;this.normals[3]=this.normals[3]/2,this.normals[4]=this.normals[4]/2,this.normals[5]=this.normals[5]/2,this.normals[this.idx-6]=this.normals[this.idx-6]/2,this.normals[this.idx-6+1]=this.normals[this.idx-6+1]/2,this.normals[this.idx-6+2]=this.normals[this.idx-6+2]/2,this.geometry.normalizeNormals()}})},function(t,e){AFRAME.registerSystem("motion-capture-replayer",{init:function(){var t,e,r,i=this.sceneEl;e=i.systems["tracked-controls"],r=AFRAME.components["tracked-controls"].Component.prototype.tick,this.gamepads=[],this.updateControllerListOriginal=e.updateControllerList.bind(e),e.updateControllerList=this.updateControllerList.bind(this),t=AFRAME.components["tracked-controls"].Component.prototype,t.tick=this.trackedControlsTickWrapper,t.trackedControlsTick=r},trackedControlsTickWrapper:function(t,e){this.el.components["motion-capture-replayer"]||this.trackedControlsTick(t,e)},updateControllerList:function(){var t,e=this.sceneEl,r=e.systems["tracked-controls"];for(this.updateControllerListOriginal(),this.gamepads.forEach(function(t){r.controllers[t.index]||(r.controllers[t.index]=t)}),t=0;t<r.controllers.length;t++)r.controllers[t]||(r.controllers[t]={id:"___",index:-1,hand:"finger"});e.emit("controllersupdated",void 0,!1)}})},function(t,e,r){var i=(r(1),"motionCaptureRecordings"),o="recordings",a=1;AFRAME.registerSystem("recordingdb",{init:function(){var t,e=this;this.db=null,this.hasLoaded=!1,t=indexedDB.open(i,a),t.onerror=function(){console.error("Error opening IndexedDB for motion capture.",t.error)},t.onupgradeneeded=function(t){var r,i=e.db=t.target.result;r=i.createObjectStore("recordings",{autoIncrement:!1}),r.createIndex("recordingName","recordingName",{unique:!0}),e.objectStore=r},t.onsuccess=function(t){e.db=t.target.result,e.hasLoaded=!0,e.sceneEl.emit("recordingdbinitialized")}},getTransaction:function(){var t=this.db.transaction([o],"readwrite");return t.objectStore(o)},getRecordingNames:function(){var t=this;return new Promise(function(e){var r=[];t.waitForDb(function(){t.getTransaction().openCursor().onsuccess=function(t){var i=t.target.result;return i?(r.push(i.key),void i.continue()):void e(r.sort())}})})},getRecordings:function(t){var e=this;return new Promise(function(t){e.waitForDb(function(){e.getTransaction().openCursor().onsuccess=function(e){for(var r=e.target.result,i=[r.value];r.ontinue();)i.push(r.value);t(i)}})})},getRecording:function(t){var e=this;return new Promise(function(r){e.waitForDb(function(){e.getTransaction().get(t).onsuccess=function(t){r(t.target.result)}})})},addRecording:function(t,e){this.getTransaction().add(e,t)},deleteRecording:function(t){this.getTransaction().delete(t)},waitForDb:function(t){return this.hasLoaded?void t():void this.sceneEl.addEventListener("recordingdbinitialized",t)}})}]);