From 6c747e9a9fd70c60f36cb0fee5f6cd65c89428e4 Mon Sep 17 00:00:00 2001 From: dandykong <37414102+dandykong@users.noreply.github.com> Date: Sun, 5 Jun 2022 10:47:20 -0500 Subject: [PATCH 1/9] Update index.js --- index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index f0df8df..8cc880c 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; From 4e6eb81fbfb20b723c6428c72e05784f09ccc4d0 Mon Sep 17 00:00:00 2001 From: dandykong <37414102+dandykong@users.noreply.github.com> Date: Sun, 5 Jun 2022 10:49:02 -0500 Subject: [PATCH 2/9] Remove unintended whitespace from the last commit --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 8cc880c..782d882 100644 --- a/index.js +++ b/index.js @@ -29,7 +29,7 @@ AFRAME.registerComponent('mirror', { 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( 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; From 5382781744b203c1f7b1a6bc824660ddb2306dbe Mon Sep 17 00:00:00 2001 From: dandykong <37414102+dandykong@users.noreply.github.com> Date: Sun, 5 Jun 2022 11:48:58 -0500 Subject: [PATCH 3/9] Update aframe-mirror-component.js Fix bug caused by a Three.JS update that modified getWorldPosition to use a mandatory target argument instead of returning its output. --- dist/aframe-mirror-component.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/dist/aframe-mirror-component.js b/dist/aframe-mirror-component.js index 3b337db..d969cc1 100644 --- a/dist/aframe-mirror-component.js +++ b/dist/aframe-mirror-component.js @@ -79,6 +79,7 @@ this.mirrorMaterial = new THREE.MeshBasicMaterial( { color: this.data.color, refractionRatio: this.data.refraction, envMap: this.cam.renderTarget.texture } ); this.done = false; var mirrormat = this.mirrorMaterial; + var camVector = new THREE.Vector3(); this.mesh = this.el.getObject3D('mesh'); if(this.mesh){ this.mesh.traverse( function( child ) { @@ -97,7 +98,8 @@ 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.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; From f10296fd1705844faa00df6cd8daa563de15dbe8 Mon Sep 17 00:00:00 2001 From: dandykong <37414102+dandykong@users.noreply.github.com> Date: Sun, 5 Jun 2022 11:55:12 -0500 Subject: [PATCH 4/9] Update aframe-mirror-component.js --- dist/aframe-mirror-component.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dist/aframe-mirror-component.js b/dist/aframe-mirror-component.js index d969cc1..71f22e9 100644 --- a/dist/aframe-mirror-component.js +++ b/dist/aframe-mirror-component.js @@ -79,7 +79,6 @@ this.mirrorMaterial = new THREE.MeshBasicMaterial( { color: this.data.color, refractionRatio: this.data.refraction, envMap: this.cam.renderTarget.texture } ); this.done = false; var mirrormat = this.mirrorMaterial; - var camVector = new THREE.Vector3(); this.mesh = this.el.getObject3D('mesh'); if(this.mesh){ this.mesh.traverse( function( child ) { @@ -98,6 +97,7 @@ if(this.mesh){ this.mesh.visible = false; AFRAME.scenes[0].renderer.autoClear = true; + 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 ); From beca60ba65035f2705615287d4d3cbc0ae7e9507 Mon Sep 17 00:00:00 2001 From: dandykong <37414102+dandykong@users.noreply.github.com> Date: Sun, 5 Jun 2022 12:55:56 -0500 Subject: [PATCH 5/9] Update index.js --- index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 782d882..39cac15 100644 --- a/index.js +++ b/index.js @@ -52,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; From 33f9e9c1fd87eb8d3477f5a07ffe70ab474fea4d Mon Sep 17 00:00:00 2001 From: dandykong <37414102+dandykong@users.noreply.github.com> Date: Sun, 5 Jun 2022 13:00:38 -0500 Subject: [PATCH 6/9] Update aframe-mirror-component.min.js --- dist/aframe-mirror-component.min.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dist/aframe-mirror-component.min.js b/dist/aframe-mirror-component.min.js index 0099670..8a3c38d 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(.5,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.updateCubeMap(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(){}})}]) From e59f4588ec0d9969bb1456d3855b9c1de4ad1752 Mon Sep 17 00:00:00 2001 From: dandykong <37414102+dandykong@users.noreply.github.com> Date: Sun, 26 Jun 2022 22:07:26 -0500 Subject: [PATCH 7/9] Update aframe-mirror-component.min.js --- dist/aframe-mirror-component.min.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dist/aframe-mirror-component.min.js b/dist/aframe-mirror-component.min.js index 8a3c38d..e9206d0 100644 --- a/dist/aframe-mirror-component.min.js +++ b/dist/aframe-mirror-component.min.js @@ -1 +1 @@ -!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(.5,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.updateCubeMap(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(){}})}]) +!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(){}})}]) From 5bc67f536fd0cda9e14a0c2a0bd53bc4b4fafb2a Mon Sep 17 00:00:00 2001 From: dandykong <37414102+dandykong@users.noreply.github.com> Date: Sun, 26 Jun 2022 22:07:56 -0500 Subject: [PATCH 8/9] Update aframe-mirror-component.js --- dist/aframe-mirror-component.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dist/aframe-mirror-component.js b/dist/aframe-mirror-component.js index 71f22e9..6e0d346 100644 --- a/dist/aframe-mirror-component.js +++ b/dist/aframe-mirror-component.js @@ -74,7 +74,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( 0.001, 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; @@ -100,7 +100,7 @@ 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 ); + this.cam.update( AFRAME.scenes[0].renderer, this.el.sceneEl.object3D ); var mirrormat = this.mirrorMaterial; this.mesh.traverse( function( child ) { From bd989d2245aae4843d5a53083495cad05a0e1a6b Mon Sep 17 00:00:00 2001 From: dandykong <37414102+dandykong@users.noreply.github.com> Date: Sun, 26 Jun 2022 22:27:56 -0500 Subject: [PATCH 9/9] Update aframe-mirror-component.js --- dist/aframe-mirror-component.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dist/aframe-mirror-component.js b/dist/aframe-mirror-component.js index 6e0d346..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.001, 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;