UNPKG

1.69 kBJavaScriptView Raw
1!function(e){function t(r){if(i[r])return i[r].exports;var a=i[r]={exports:{},id:r,loaded:!1};return e[r].call(a.exports,a,a.exports,t),a.loaded=!0,a.exports}var i={};return t.m=e,t.c=i,t.p="",t(0)}([function(e,t){if("undefined"==typeof AFRAME)throw new Error("Component attempted to register before AFRAME was available.");AFRAME.registerComponent("mirror",{schema:{resolution:{type:"number",default:128},refraction:{type:"number",default:.95},color:{type:"color",default:16777215},distance:{type:"number",default:3e3},interval:{type:"number",default:1e3},repeat:{type:"boolean",default:!1}},multiple:!1,init:function(){this.counter=this.data.interval,this.cam=new THREE.CubeCamera(.5,this.data.distance,this.data.resolution),this.el.object3D.add(this.cam),this.mirrorMaterial=new THREE.MeshBasicMaterial({color:this.data.color,refractionRatio:this.data.refraction,envMap:this.cam.renderTarget.texture}),this.done=!1;var e=this.mirrorMaterial;this.mesh=this.el.getObject3D("mesh"),this.mesh&&this.mesh.traverse(function(t){t instanceof THREE.Mesh&&(t.material=e)})},tick:function(e,t){if(!this.done)if(this.counter>0)this.counter-=t;else if(this.mesh=this.el.getObject3D("mesh"),this.mesh){this.mesh.visible=!1,AFRAME.scenes[0].renderer.autoClear=!0,this.cam.position.copy(this.el.object3D.worldToLocal(this.el.object3D.getWorldPosition())),this.cam.updateCubeMap(AFRAME.scenes[0].renderer,this.el.sceneEl.object3D);var i=this.mirrorMaterial;this.mesh.traverse(function(e){e instanceof THREE.Mesh&&(e.material=i)}),this.mesh.visible=!0,this.data.repeat||(this.done=!0,this.counter=this.data.interval)}},update:function(e){},remove:function(){},pause:function(){},play:function(){}})}]);
\No newline at end of file