aframe-extras
Version:
Add-ons and examples for A-Frame VR.
2 lines • 7.05 kB
JavaScript
!function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var i=e();for(var s in i)("object"==typeof exports?exports:t)[s]=i[s]}}(self,(()=>(()=>{var t={95:t=>{t.exports=AFRAME.registerComponent("checkpoint",{schema:{offset:{default:{x:0,y:0,z:0},type:"vec3"}},init:function(){this.active=!1,this.targetEl=null,this.fire=this.fire.bind(this),this.offset=new THREE.Vector3},update:function(){this.offset.copy(this.data.offset)},play:function(){this.el.addEventListener("click",this.fire)},pause:function(){this.el.removeEventListener("click",this.fire)},remove:function(){this.pause()},fire:function(){const t=this.el.sceneEl.querySelector("[checkpoint-controls]");if(!t)throw new Error("No `checkpoint-controls` component found.");t.components["checkpoint-controls"].setCheckpoint(this.el)},getOffset:function(){return this.offset.copy(this.data.offset)}})},889:t=>{function e(t,e,i,s){t&&(e=e||[],t.traverse((t=>{var n;t.isMesh&&((n=t.material)?Array.isArray(n)?n:n.materials?n.materials:[n]:[]).forEach((t=>{t&&!("envMap"in t)||e.length&&-1===e.indexOf(t.name)||(t.envMap=i,t.reflectivity=s,t.needsUpdate=!0)}))})))}t.exports=AFRAME.registerComponent("cube-env-map",{multiple:!0,schema:{path:{default:""},extension:{default:"jpg",oneOf:["jpg","png"]},enableBackground:{default:!1},reflectivity:{default:1,min:0,max:1},materials:{default:[]}},init:function(){const t=this.data;this.texture=(new THREE.CubeTextureLoader).load([t.path+"posx."+t.extension,t.path+"negx."+t.extension,t.path+"posy."+t.extension,t.path+"negy."+t.extension,t.path+"posz."+t.extension,t.path+"negz."+t.extension]),this.texture.format=THREE.RGBAFormat,this.object3dsetHandler=()=>{const t=this.el.getObject3D("mesh"),i=this.data;e(t,i.materials,this.texture,i.reflectivity)},this.object3dsetHandler(),this.el.addEventListener("object3dset",this.object3dsetHandler)},update:function(t){const i=this.data,s=this.el.getObject3D("mesh");let n=[],r=[];if(i.materials.length&&(t.materials?(n=i.materials.filter((e=>!t.materials.includes(e))),r=t.materials.filter((t=>!i.materials.includes(t)))):n=i.materials),n.length&&e(s,n,this.texture,i.reflectivity),r.length&&e(s,r,null,1),t.materials&&i.reflectivity!==t.reflectivity){const n=i.materials.filter((e=>t.materials.includes(e)));n.length&&e(s,n,this.texture,i.reflectivity)}this.data.enableBackground&&!t.enableBackground?this.setBackground(this.texture):!this.data.enableBackground&&t.enableBackground&&this.setBackground(null)},remove:function(){this.el.removeEventListener("object3dset",this.object3dsetHandler);const t=this.el.getObject3D("mesh"),i=this.data;e(t,i.materials,null,1),i.enableBackground&&this.setBackground(null)},setBackground:function(t){this.el.sceneEl.object3D.background=t}})},771:t=>{t.exports=AFRAME.registerComponent("grab",{init:function(){this.system=this.el.sceneEl.systems.physics,this.GRABBED_STATE="grabbed",this.grabbing=!1,this.hitEl=null,this.physics=this.el.sceneEl.systems.physics,this.constraint=null,this.onHit=this.onHit.bind(this),this.onGripOpen=this.onGripOpen.bind(this),this.onGripClose=this.onGripClose.bind(this)},play:function(){const t=this.el;t.addEventListener("hit",this.onHit),t.addEventListener("gripdown",this.onGripClose),t.addEventListener("gripup",this.onGripOpen),t.addEventListener("trackpaddown",this.onGripClose),t.addEventListener("trackpadup",this.onGripOpen),t.addEventListener("triggerdown",this.onGripClose),t.addEventListener("triggerup",this.onGripOpen)},pause:function(){const t=this.el;t.removeEventListener("hit",this.onHit),t.removeEventListener("gripdown",this.onGripClose),t.removeEventListener("gripup",this.onGripOpen),t.removeEventListener("trackpaddown",this.onGripClose),t.removeEventListener("trackpadup",this.onGripOpen),t.removeEventListener("triggerdown",this.onGripClose),t.removeEventListener("triggerup",this.onGripOpen)},onGripClose:function(){this.grabbing=!0},onGripOpen:function(){const t=this.hitEl;this.grabbing=!1,t&&(t.removeState(this.GRABBED_STATE),this.hitEl=void 0,this.system.removeConstraint(this.constraint),this.constraint=null)},onHit:function(t){const e=t.detail.el;e.is(this.GRABBED_STATE)||!this.grabbing||this.hitEl||(e.addState(this.GRABBED_STATE),this.hitEl=e,this.constraint=new CANNON.LockConstraint(this.el.body,e.body),this.system.addConstraint(this.constraint))}})},778:t=>{t.exports=AFRAME.registerComponent("normal-material",{init:function(){this.material=new THREE.MeshNormalMaterial({flatShading:!0}),this.applyMaterial=this.applyMaterial.bind(this),this.el.addEventListener("object3dset",this.applyMaterial),this.applyMaterial()},remove:function(){this.el.removeEventListener("object3dset",this.applyMaterial)},applyMaterial:function(){this.el.object3D.traverse((t=>{t.isMesh&&(t.material=this.material)}))}})},109:t=>{t.exports=AFRAME.registerComponent("sphere-collider",{schema:{enabled:{default:!0},interval:{default:80},objects:{default:""},state:{default:"collided"},radius:{default:.05},watch:{default:!0}},init:function(){this.observer=null,this.els=[],this.collisions=[],this.prevCheckTime=void 0,this.eventDetail={},this.handleHit=this.handleHit.bind(this),this.handleHitEnd=this.handleHitEnd.bind(this)},play:function(){const t=this.el.sceneEl;this.data.watch&&(this.observer=new MutationObserver(this.update.bind(this,null)),this.observer.observe(t,{childList:!0,subtree:!0}))},pause:function(){this.observer&&(this.observer.disconnect(),this.observer=null)},update:function(){const t=this.data;let e;e=t.objects?this.el.sceneEl.querySelectorAll(t.objects):this.el.sceneEl.children,this.els=Array.prototype.slice.call(e)},tick:function(){const t=new THREE.Vector3,e=new THREE.Vector3,i=new THREE.Vector3,s=new THREE.Vector3,n=new THREE.Box3,r=[],o=new Map;return function(a){if(!this.data.enabled)return;const h=this.prevCheckTime;if(h&&a-h<this.data.interval)return;this.prevCheckTime=a;const l=this.el,c=this.data;let d;var p;l.getObject3D("mesh")&&(r.length=0,o.clear(),l.object3D.getWorldPosition(t),l.object3D.getWorldScale(i),d=c.radius*(p=i,Math.max(p.x,p.y,p.z)),this.els.forEach((function(i){let a,h,l,c;i.isEntity&&(h=i.getObject3D("mesh"),h&&(n.setFromObject(h).getSize(s),c=Math.max(s.x,s.y,s.z)/2,a=Math.sqrt(2*c*c),n.getCenter(e),a&&(l=t.distanceTo(e),l<a+d&&(r.push(i),o.set(i,l)))))})),r.sort(((t,e)=>o.get(t)>o.get(e)?1:-1)).forEach(this.handleHit),this.collisions.filter((t=>!o.has(t))).forEach(this.handleHitEnd),function(t,e){t.length=0;for(let i=0;i<e.length;i++)t[i]=e[i]}(this.collisions,r))}}(),handleHit:function(t){t.emit("hit"),t.addState(this.data.state),this.eventDetail.el=t,this.el.emit("hit",this.eventDetail)},handleHitEnd:function(t){t.emit("hitend"),t.removeState(this.data.state),this.eventDetail.el=t,this.el.emit("hitend",this.eventDetail)}})}},e={};function i(s){var n=e[s];if(void 0!==n)return n.exports;var r=e[s]={exports:{}};return t[s](r,r.exports,i),r.exports}return i(95),i(889),i(771),i(778),i(109),{}})()));
//# sourceMappingURL=aframe-extras.misc.min.js.map