Browse Source

Generalize Reflector geometry

WestLangley 7 years ago
parent
commit
0c37de10c0
2 changed files with 17 additions and 15 deletions
  1. 11 11
      examples/js/objects/Reflector.js
  2. 6 4
      examples/webgl_mirror.html

+ 11 - 11
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 );

+ 6 - 4
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 );