1 |
- !function t(e,i,n){function s(r,a){if(!i[r]){if(!e[r]){var l="function"==typeof require&&require;if(!a&&l)return l(r,!0);if(o)return o(r,!0);var h=new Error("Cannot find module '"+r+"'");throw h.code="MODULE_NOT_FOUND",h}var c=i[r]={exports:{}};e[r][0].call(c.exports,function(t){var i=e[r][1][t];return s(i||t)},c,c.exports,t,e,i,n)}return i[r].exports}for(var o="function"==typeof require&&require,r=0;r<n.length;r++)s(n[r]);return s}({1:[function(t,e,i){"use strict";t("./src/misc")},{"./src/misc":5}],2:[function(t,e,i){"use strict";e.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(){var 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)}})},{}],3:[function(t,e,i){"use strict";function n(t,e,i,n){t&&(e=e||[],t.traverse(function(t){if(t.isMesh){(function(t){return t?Array.isArray(t)?t:t.materials?t.materials:[t]:[]})(t.material).forEach(function(t){(!t||"envMap"in t)&&(e.length&&-1===e.indexOf(t.name)||(t.envMap=i,t.reflectivity=n,t.needsUpdate=!0))})}}))}e.exports=AFRAME.registerComponent("cube-env-map",{multiple:!0,schema:{path:{default:""},extension:{default:"jpg",oneOf:["jpg","png"]},format:{default:"RGBFormat",oneOf:["RGBFormat","RGBAFormat"]},enableBackground:{default:!1},reflectivity:{default:1,min:0,max:1},materials:{default:[]}},init:function(){var t=this,e=this.data;this.texture=(new THREE.CubeTextureLoader).load([e.path+"posx."+e.extension,e.path+"negx."+e.extension,e.path+"posy."+e.extension,e.path+"negy."+e.extension,e.path+"posz."+e.extension,e.path+"negz."+e.extension]),this.texture.format=THREE[e.format],this.object3dsetHandler=function(){var e=t.el.getObject3D("mesh"),i=t.data;n(e,i.materials,t.texture,i.reflectivity)},this.el.addEventListener("object3dset",this.object3dsetHandler)},update:function(t){var e=this.data,i=this.el.getObject3D("mesh"),s=[],o=[];if(e.materials.length&&(t.materials?(s=e.materials.filter(function(e){return!t.materials.includes(e)}),o=t.materials.filter(function(t){return!e.materials.includes(t)})):s=e.materials),s.length&&n(i,s,this.texture,e.reflectivity),o.length&&n(i,o,null,1),t.materials&&e.reflectivity!==t.reflectivity){var r=e.materials.filter(function(e){return t.materials.includes(e)});r.length&&n(i,r,this.texture,e.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);var t=this.el.getObject3D("mesh"),e=this.data;n(t,e.materials,null,1),e.enableBackground&&this.setBackground(null)},setBackground:function(t){this.el.sceneEl.object3D.background=t}})},{}],4:[function(t,e,i){"use strict";e.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(){var 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(){var 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(){var 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){var e=t.detail.el;e&&!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))}})},{}],5:[function(t,e,i){"use strict";t("./checkpoint"),t("./cube-env-map"),t("./grab"),t("./jump-ability"),t("./kinematic-body"),t("./mesh-smooth"),t("./normal-material"),t("./sphere-collider")},{"./checkpoint":2,"./cube-env-map":3,"./grab":4,"./jump-ability":6,"./kinematic-body":7,"./mesh-smooth":8,"./normal-material":9,"./sphere-collider":10}],6:[function(t,e,i){"use strict";e.exports=AFRAME.registerComponent("jump-ability",{dependencies:["velocity"],schema:{on:{default:"keydown:Space gamepadbuttondown:0"},playerHeight:{default:1.764},maxJumps:{default:1},distance:{default:5},debug:{default:!1}},init:function(){this.velocity=0,this.numJumps=0;var t=this.beginJump.bind(this),e=this.data.on.split(" ");this.bindings={};for(var i=0;i<e.length;i++)this.bindings[e[i]]=t,this.el.addEventListener(e[i],t);this.bindings.collide=this.onCollide.bind(this),this.el.addEventListener("collide",this.bindings.collide)},remove:function(){for(var t in this.bindings)this.bindings.hasOwnProperty(t)&&(this.el.removeEventListener(t,this.bindings[t]),delete this.bindings[t]);this.el.removeEventListener("collide",this.bindings.collide),delete this.bindings.collide},beginJump:function(){if(this.numJumps<this.data.maxJumps){var t=this.data,e=Math.sqrt(-2*t.distance*-24.8),i=this.el.getAttribute("velocity");this.el.setAttribute("velocity",{x:i.x,y:e,z:i.z}),this.numJumps++,this.el.emit("jumpstart")}},onCollide:function(){this.numJumps>0&&this.el.emit("jumpend"),this.numJumps=0}})},{}],7:[function(t,e,i){"use strict";e.exports=AFRAME.registerComponent("kinematic-body",{dependencies:["velocity"],schema:{mass:{default:5},radius:{default:1.3},linearDamping:{default:.05},enableSlopes:{default:!0},enableJumps:{default:!1}},init:function(){this.system=this.el.sceneEl.systems.physics,this.system.addComponent(this);var t=this.el,e=this.data,i=(new CANNON.Vec3).copy(t.object3D.getWorldPosition(new THREE.Vector3));this.body=new CANNON.Body({material:this.system.getMaterial("staticMaterial"),position:i,mass:e.mass,linearDamping:e.linearDamping,fixedRotation:!0}),this.body.addShape(new CANNON.Sphere(e.radius),new CANNON.Vec3(0,e.radius,0)),this.body.el=this.el,this.el.body=this.body,this.system.addBody(this.body),t.hasAttribute("wasd-controls")&&console.warn("[kinematic-body] Not compatible with wasd-controls, use movement-controls.")},remove:function(){this.system.removeBody(this.body),this.system.removeComponent(this),delete this.el.body},beforeStep:function(t,e){if(e){var i=this.el,n=this.data,s=this.body;n.enableJumps||s.velocity.set(0,0,0),s.position.copy(i.getAttribute("position"))}},step:function(){var t=new THREE.Vector3,e=new THREE.Vector3,i=new THREE.Vector3,n=new THREE.Vector3;return function(s,o){if(o){var r=this.body,a=this.data,l=void 0,h=-1/0,c=void 0,d=this.system.getContacts();o=Math.min(o,1e3*this.system.data.maxInterval),n.set(0,0,0),t.copy(this.el.getAttribute("velocity")),r.velocity.copy(t);for(var u,p=0;u=d[p];p++)if(u.enabled){if(r.id===u.bi.id)u.ni.negate(i);else{if(r.id!==u.bj.id)continue;i.copy(u.ni)}r.velocity.dot(i)<-1e-6&&i.y<=.5?t.projectOnPlane(i):i.y>.5&&(l=r.id===u.bi.id?Math.abs(u.rj.y+u.bj.position.y):Math.abs(u.ri.y+u.bi.position.y))>h&&(h=l,n.copy(i),c=r.id===u.bi.id?u.bj:u.bi)}e.copy(t).normalize(),c&&(!a.enableJumps||e.y<.5)?(a.enableSlopes?n.y<1-1e-6&&n.copy(this.raycastToGround(c,n)):n.set(0,1,0),t.projectOnPlane(n)):this.system.driver.world&&t.add(this.system.driver.world.gravity.scale(4*o/1e3)),r.velocity.copy(t),this.el.setAttribute("velocity",r.velocity),this.el.setAttribute("position",r.position)}}}(),raycastToGround:function(t,e){var i=void 0,n=void 0,s=this.body.position,o=this.body.position.clone();return(i=new CANNON.Ray(s,o))._updateDirection(),i.intersectBody(t),i.hasHit?(n=i.result.hitNormalWorld,Math.abs(n.y)>Math.abs(e.y)?n:e):e}})},{}],8:[function(t,e,i){"use strict";e.exports=AFRAME.registerComponent("mesh-smooth",{init:function(){this.el.addEventListener("model-loaded",function(t){t.detail.model.traverse(function(t){t.isMesh&&t.geometry.computeVertexNormals()})})}})},{}],9:[function(t,e,i){"use strict";e.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)},remove:function(){this.el.removeEventListener("object3dset",this.applyMaterial)},applyMaterial:function(){var t=this;this.el.object3D.traverse(function(e){e.isMesh&&(e.material=t.material)})}})},{}],10:[function(t,e,i){"use strict";e.exports=AFRAME.registerComponent("sphere-collider",{schema:{objects:{default:""},state:{default:"collided"},radius:{default:.05},watch:{default:!0}},init:function(){this.observer=null,this.els=[],this.collisions=[],this.handleHit=this.handleHit.bind(this),this.handleHitEnd=this.handleHitEnd.bind(this)},remove:function(){this.pause()},play:function(){var 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(){var t=this.data,e=void 0;e=t.objects?this.el.sceneEl.querySelectorAll(t.objects):this.el.sceneEl.children,this.els=Array.prototype.slice.call(e)},tick:function(){var t=new THREE.Vector3,e=new THREE.Vector3,i=new THREE.Vector3,n=new THREE.Vector3,s=new THREE.Box3,o=new Map;return function(){var r=this.el,a=this.data,l=[],h=void 0;r.getObject3D("mesh")&&(o.clear(),r.object3D.getWorldPosition(t),r.object3D.getWorldScale(i),h=a.radius*function(t){return Math.max.apply(null,t.toArray())}(i),this.els.forEach(function(i){var r=void 0,a=void 0,c=void 0,d=void 0;i.isEntity&&(a=i.getObject3D("mesh"))&&(s.setFromObject(a).getSize(n),d=Math.max(n.x,n.y,n.z)/2,r=Math.sqrt(2*d*d),s.getCenter(e),r&&(c=t.distanceTo(e))<r+h&&(l.push(i),o.set(i,c)))}),l.sort(function(t,e){return o.get(t)>o.get(e)?1:-1}).forEach(this.handleHit),0===l.length&&r.emit("hit",{el:null}),this.collisions.filter(function(t){return!o.has(t)}).forEach(this.handleHitEnd),this.collisions=l)}}(),handleHit:function(t){t.emit("hit"),t.addState(this.data.state),this.el.emit("hit",{el:t})},handleHitEnd:function(t){t.emit("hitend"),t.removeState(this.data.state),this.el.emit("hitend",{el:t})}})},{}]},{},[1]);
|