From 0c37de10c09937193fec289d29eaea4edb33c81a Mon Sep 17 00:00:00 2001 From: WestLangley Date: Fri, 10 Nov 2017 16:52:00 -0500 Subject: [PATCH 1/2] Generalize Reflector geometry --- examples/js/objects/Reflector.js | 22 +++++++++++----------- examples/webgl_mirror.html | 10 ++++++---- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/examples/js/objects/Reflector.js b/examples/js/objects/Reflector.js index 5fdc137417403e..d8b4cbaa6ab17a 100644 --- a/examples/js/objects/Reflector.js +++ b/examples/js/objects/Reflector.js @@ -2,9 +2,9 @@ * @author Slayvin / http://slayvin.net */ -THREE.Reflector = function ( width, height, options ) { +THREE.Reflector = function ( geometry, options ) { - THREE.Mesh.call( this, new THREE.PlaneBufferGeometry( width, height ) ); + THREE.Mesh.call( this, geometry ); this.type = 'Reflector'; @@ -65,15 +65,15 @@ THREE.Reflector = function ( width, height, options ) { this.material = material; - this.onBeforeRender = function ( renderer, scene, camera ) { - - if ( 'recursion' in camera.userData ) { - - if ( camera.userData.recursion === recursion ) return; - - camera.userData.recursion ++; - - } + this.onBeforeRender = function ( renderer, scene, camera ) { + + if ( 'recursion' in camera.userData ) { + + if ( camera.userData.recursion === recursion ) return; + + camera.userData.recursion ++; + + } reflectorWorldPosition.setFromMatrixPosition( scope.matrixWorld ); cameraWorldPosition.setFromMatrixPosition( camera.matrixWorld ); diff --git a/examples/webgl_mirror.html b/examples/webgl_mirror.html index cd39de06211f74..57a2d33a73541f 100644 --- a/examples/webgl_mirror.html +++ b/examples/webgl_mirror.html @@ -86,9 +86,10 @@ var planeGeo = new THREE.PlaneBufferGeometry( 100.1, 100.1 ); - // reflector/mirror planes + // reflectors/mirrors - var groundMirror = new THREE.Reflector( 100, 100, { + var geometry = new THREE.PlaneBufferGeometry( 100, 100 ); + var groundMirror = new THREE.Reflector( geometry, { clipBias: 0.003, textureWidth: WIDTH * window.devicePixelRatio, textureHeight: HEIGHT * window.devicePixelRatio, @@ -98,14 +99,15 @@ groundMirror.rotateX( - Math.PI / 2 ); scene.add( groundMirror ); - var verticalMirror = new THREE.Reflector( 60, 60, { + var geometry = new THREE.CircleBufferGeometry( 40, 6 ); + var verticalMirror = new THREE.Reflector( geometry, { clipBias: 0.003, textureWidth: WIDTH * window.devicePixelRatio, textureHeight: HEIGHT * window.devicePixelRatio, color: 0x889999, recursion: 1 } ); - verticalMirror.position.y = 35; + verticalMirror.position.y = 50; verticalMirror.position.z = -45; scene.add( verticalMirror ); From 1663e818b64da383640ab10818f36ac950d2d4b0 Mon Sep 17 00:00:00 2001 From: WestLangley Date: Sat, 11 Nov 2017 18:10:51 -0500 Subject: [PATCH 2/2] Generalize Reflector/Refractor geometry --- examples/js/objects/ReflectorRTT.js | 4 ++-- examples/js/objects/Refractor.js | 4 ++-- examples/webgl_mirror_nodes.html | 3 ++- examples/webvr_sandbox.html | 3 ++- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/examples/js/objects/ReflectorRTT.js b/examples/js/objects/ReflectorRTT.js index 0383f2a755cbdb..28bdfc8da30e30 100644 --- a/examples/js/objects/ReflectorRTT.js +++ b/examples/js/objects/ReflectorRTT.js @@ -1,6 +1,6 @@ -THREE.ReflectorRTT = function ( width, height, options ) { +THREE.ReflectorRTT = function ( geometry, options ) { - THREE.Reflector.call( this, width, height, options ); + THREE.Reflector.call( this, geometry, options ); this.geometry.setDrawRange( 0, 0 ); // avoid rendering geometry diff --git a/examples/js/objects/Refractor.js b/examples/js/objects/Refractor.js index 1fda41b3067f6b..66684ee8a8aac0 100644 --- a/examples/js/objects/Refractor.js +++ b/examples/js/objects/Refractor.js @@ -3,9 +3,9 @@ * */ -THREE.Refractor = function ( width, height, options ) { +THREE.Refractor = function ( geometry, options ) { - THREE.Mesh.call( this, new THREE.PlaneBufferGeometry( width, height ) ); + THREE.Mesh.call( this, geometry ); this.type = 'Refractor'; diff --git a/examples/webgl_mirror_nodes.html b/examples/webgl_mirror_nodes.html index 71f08bb999de8c..d67a257217462c 100644 --- a/examples/webgl_mirror_nodes.html +++ b/examples/webgl_mirror_nodes.html @@ -153,7 +153,8 @@ var planeGeo = new THREE.PlaneBufferGeometry( 100.1, 100.1 ); // reflector/mirror plane - var groundMirror = new THREE.ReflectorRTT( 100, 100, { clipBias: 0.003, textureWidth: WIDTH, textureHeight: HEIGHT } ); + var geometry = new THREE.PlaneBufferGeometry( 100, 100 ); + var groundMirror = new THREE.ReflectorRTT( geometry, { clipBias: 0.003, textureWidth: WIDTH, textureHeight: HEIGHT } ); var mask = new THREE.SwitchNode( new THREE.TextureNode( decalDiffuse ), 'w' ); var maskFlip = new THREE.Math1Node( mask, THREE.Math1Node.INVERT ); diff --git a/examples/webvr_sandbox.html b/examples/webvr_sandbox.html index 69920b7911c285..46a8cfd62ad8b3 100644 --- a/examples/webvr_sandbox.html +++ b/examples/webvr_sandbox.html @@ -85,7 +85,8 @@ // - reflector = new THREE.Reflector( 1.4, 1.4, { + var geometry = new THREE.PlaneBufferGeometry( 1.4, 1.4 ); + reflector = new THREE.Reflector( geometry, { textureWidth: window.innerWidth * window.devicePixelRatio, textureHeight: window.innerHeight * window.devicePixelRatio } );