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},userHeight:{default:1.6},linearDamping:{default:.05},enableSlopes:{default:!0}},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.getAttribute("position"));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-e.height,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.body;n.velocity.copy(i.getAttribute("velocity")),n.position.copy(i.getAttribute("position")),n.position.y+=this.data.userHeight}},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=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)}if(e.copy(t).normalize(),c&&e.y<.5?(a.enableSlopes?n.y<1-1e-6&&n.copy(this.raycastToGround(c,n)):n.set(0,1,0),t=t.projectOnPlane(n)):this.system.driver.world&&t.add(this.system.driver.world.gravity.scale(4*o/1e3)),c&&c.el&&c.el.components.velocity){var m=c.el.getAttribute("velocity");r.position.copy({x:r.position.x+m.x*o/1e3,y:r.position.y+m.y*o/1e3,z:r.position.z+m.z*o/1e3})}r.velocity.copy(t),r.position.y-=a.userHeight,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 o.y-=this.data.height,(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 Map;return function(){var s=this.el,o=this.data,r=[],a=void 0;s.getObject3D("mesh")&&(n.clear(),t.copy(s.object3D.getWorldPosition()),s.object3D.getWorldScale(i),a=o.radius*function(t){return Math.max.apply(null,t.toArray())}(i),this.els.forEach(function(i){var s=void 0,o=void 0,l=void 0,h=void 0,c=void 0,d=void 0;i.isEntity&&(o=i.getObject3D("mesh"))&&(d=(h=(new THREE.Box3).setFromObject(o)).getSize(),c=Math.max(d.x,d.y,d.z)/2,s=Math.sqrt(2*c*c),h.getCenter(e),s&&(l=t.distanceTo(e))<s+a&&(r.push(i),n.set(i,l)))}),r.sort(function(t,e){return n.get(t)>n.get(e)?1:-1}).forEach(this.handleHit),0===r.length&&s.emit("hit",{el:null}),this.collisions.filter(function(t){return!n.has(t)}).forEach(this.handleHitEnd),this.collisions=r)}}(),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]);
|