diff --git a/dist/aframe-mirror-component.js b/dist/aframe-mirror-component.js index 3b337db..74484d4 100644 --- a/dist/aframe-mirror-component.js +++ b/dist/aframe-mirror-component.js @@ -58,6 +58,7 @@ resolution: { type:'number', default: 128}, refraction: { type:'number', default: 0.95}, color: {type:'color', default: 0xffffff}, + near: {type: 'number', default: 0.05}, distance: {type:'number', default: 3000}, interval: { type:'number', default: 1000}, repeat: { type:'boolean', default: false} @@ -74,7 +75,7 @@ init: function(){ this.counter = this.data.interval; const cubeRenderTarget = new THREE.WebGLCubeRenderTarget( this.data.resolution, { format: THREE.RGBFormat, generateMipmaps: true, minFilter: THREE.LinearMipmapLinearFilter } ); - this.cam = new THREE.CubeCamera( 0.5, this.data.distance, cubeRenderTarget); + this.cam = new THREE.CubeCamera( this.data.near, this.data.distance, cubeRenderTarget); 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 = false; @@ -97,8 +98,10 @@ if(this.mesh){ this.mesh.visible = false; AFRAME.scenes[0].renderer.autoClear = true; - this.cam.position.copy(this.el.object3D.worldToLocal(this.el.object3D.getWorldPosition())); - this.cam.updateCubeMap( AFRAME.scenes[0].renderer, this.el.sceneEl.object3D ); + var camVector = new THREE.Vector3(); + this.el.object3D.getWorldPosition(camVector); + this.cam.position.copy(this.el.object3D.worldToLocal(camVector)); + this.cam.update( AFRAME.scenes[0].renderer, this.el.sceneEl.object3D ); var mirrormat = this.mirrorMaterial; this.mesh.traverse( function( child ) { diff --git a/dist/aframe-mirror-component.min.js b/dist/aframe-mirror-component.min.js index 0099670..e9206d0 100644 --- a/dist/aframe-mirror-component.min.js +++ b/dist/aframe-mirror-component.min.js @@ -1 +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 +!function(b){var c={};function a(d){if(c[d])return c[d].exports;var e=c[d]={exports:{},id:d,loaded:!1};return b[d].call(e.exports,e,e.exports,a),e.loaded=!0,e.exports}a.m=b,a.c=c,a.p="",a(0)}([function(a,b){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;let a=new THREE.WebGLCubeRenderTarget(this.data.resolution,{format:THREE.RGBFormat,generateMipmaps:!0,minFilter:THREE.LinearMipmapLinearFilter});this.cam=new THREE.CubeCamera(.001,this.data.distance,a),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 b=this.mirrorMaterial;this.mesh=this.el.getObject3D("mesh"),this.mesh&&this.mesh.traverse(function(a){a instanceof THREE.Mesh&&(a.material=b)})},tick:function(c,b){if(!this.done){if(this.counter>0)this.counter-=b;else if(this.mesh=this.el.getObject3D("mesh"),this.mesh){this.mesh.visible=!1,AFRAME.scenes[0].renderer.autoClear=!0;var a=new THREE.Vector3;this.el.object3D.getWorldPosition(a),this.cam.position.copy(this.el.object3D.worldToLocal(a)),this.cam.update(AFRAME.scenes[0].renderer,this.el.sceneEl.object3D);var d=this.mirrorMaterial;this.mesh.traverse(function(a){a instanceof THREE.Mesh&&(a.material=d)}),this.mesh.visible=!0,this.data.repeat||(this.done=!0,this.counter=this.data.interval)}}},update:function(a){},remove:function(){},pause:function(){},play:function(){}})}]) diff --git a/index.js b/index.js index f0df8df..39cac15 100644 --- a/index.js +++ b/index.js @@ -28,7 +28,8 @@ AFRAME.registerComponent('mirror', { init: function(){ this.counter = this.data.interval; - this.cam = new THREE.CubeCamera( 0.5, this.data.distance, this.data.resolution); + const cubeRenderTarget = new THREE.WebGLCubeRenderTarget( this.data.resolution, { format: THREE.RGBFormat, generateMipmaps: true, minFilter: THREE.LinearMipmapLinearFilter } ); + this.cam = new THREE.CubeCamera( 0.5, this.data.distance, cubeRenderTarget); 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 = false; @@ -51,7 +52,9 @@ AFRAME.registerComponent('mirror', { if(this.mesh){ this.mesh.visible = false; AFRAME.scenes[0].renderer.autoClear = true; - this.cam.position.copy(this.el.object3D.worldToLocal(this.el.object3D.getWorldPosition())); + var camVector = new THREE.Vector3(); + this.el.object3D.getWorldPosition(camVector); + this.cam.position.copy(this.el.object3D.worldToLocal(camVector)); this.cam.updateCubeMap( AFRAME.scenes[0].renderer, this.el.sceneEl.object3D ); var mirrormat = this.mirrorMaterial;