Browse Source

Using "best practices" in minecraft examples as discussed in #2780.

Mr.doob 12 years ago
parent
commit
bdf658231e
2 changed files with 24 additions and 29 deletions
  1. 12 15
      examples/webgl_geometry_minecraft.html
  2. 12 14
      examples/webgl_geometry_minecraft_ao.html

+ 12 - 15
examples/webgl_geometry_minecraft.html

@@ -90,35 +90,32 @@
 
 				// sides
 
+				var matrix = new THREE.Matrix4();
+				var vector = new THREE.Vector3();
+
 				var pxGeometry = new THREE.PlaneGeometry( 100, 100 );
 				pxGeometry.faces[ 0 ].materialIndex = 1;
-				pxGeometry.applyMatrix( new THREE.Matrix4().makeRotationY( Math.PI / 2 ) );
-				pxGeometry.applyMatrix( new THREE.Matrix4().makeTranslation( 
-					new THREE.Vector3( 50, 0, 0 ) ) );
+				pxGeometry.applyMatrix( matrix.makeRotationY( Math.PI / 2 ) );
+				pxGeometry.applyMatrix( matrix.makeTranslation( vector.set( 50, 0, 0 ) ) );
 
 				var nxGeometry = new THREE.PlaneGeometry( 100, 100 );
 				nxGeometry.faces[ 0 ].materialIndex = 1;
-				nxGeometry.applyMatrix( new THREE.Matrix4().makeRotationY( - Math.PI / 2 ) );
-				nxGeometry.applyMatrix( new THREE.Matrix4().makeTranslation( 
-					new THREE.Vector3( - 50, 0, 0 ) ) );
+				nxGeometry.applyMatrix( matrix.makeRotationY( - Math.PI / 2 ) );
+				nxGeometry.applyMatrix( matrix.makeTranslation( vector.set( - 50, 0, 0 ) ) );
 
 				var pyGeometry = new THREE.PlaneGeometry( 100, 100 );
 				pyGeometry.faces[ 0 ].materialIndex = 0;
-				pyGeometry.applyMatrix( new THREE.Matrix4().makeRotationX( - Math.PI / 2 ) );
-				pyGeometry.applyMatrix( new THREE.Matrix4().makeTranslation( 
-					new THREE.Vector3( 0, 50, 0 ) ) );
+				pyGeometry.applyMatrix( matrix.makeRotationX( - Math.PI / 2 ) );
+				pyGeometry.applyMatrix( matrix.makeTranslation( vector.set( 0, 50, 0 ) ) );
 
 				var pzGeometry = new THREE.PlaneGeometry( 100, 100 );
 				pzGeometry.faces[ 0 ].materialIndex = 1;
-				pzGeometry.applyMatrix( new THREE.Matrix4().makeTranslation( 
-					new THREE.Vector3( 0, 0, 50 ) ) );
+				pzGeometry.applyMatrix( matrix.makeTranslation( vector.set( 0, 0, 50 ) ) );
 
 				var nzGeometry = new THREE.PlaneGeometry( 100, 100 );
 				nzGeometry.faces[ 0 ].materialIndex = 1;
-				nzGeometry.applyMatrix( new THREE.Matrix4().makeRotationY( Math.PI ) );
-				nzGeometry.applyMatrix( new THREE.Matrix4().makeTranslation( 
-					new THREE.Vector3( 0, 0, -50 ) ) );
-
+				nzGeometry.applyMatrix( matrix.makeRotationY( Math.PI ) );
+				nzGeometry.applyMatrix( matrix.makeTranslation( vector.set( 0, 0, -50 ) ) );
 				//
 
 				var geometry = new THREE.Geometry();

+ 12 - 14
examples/webgl_geometry_minecraft_ao.html

@@ -100,39 +100,37 @@
 				var light = new THREE.Color( 0xffffff );
 				var shadow = new THREE.Color( 0x505050 );
 
+				var matrix = new THREE.Matrix4();
+				var vector = new THREE.Vector3();
+
 				var pxGeometry = new THREE.PlaneGeometry( 100, 100 );
 				pxGeometry.faces[ 0 ].materialIndex = 1;
 				pxGeometry.faces[ 0 ].vertexColors = [ light, shadow, shadow, light ];
-				pxGeometry.applyMatrix( new THREE.Matrix4().makeRotationY( Math.PI / 2 ) );
-				pxGeometry.applyMatrix( new THREE.Matrix4().makeTranslation( 
-					new THREE.Vector3( 50, 0, 0 ) ) );
+				pxGeometry.applyMatrix( matrix.makeRotationY( Math.PI / 2 ) );
+				pxGeometry.applyMatrix( matrix.makeTranslation( vector.set( 50, 0, 0 ) ) );
 
 				var nxGeometry = new THREE.PlaneGeometry( 100, 100 );
 				nxGeometry.faces[ 0 ].materialIndex = 1;
 				nxGeometry.faces[ 0 ].vertexColors = [ light, shadow, shadow, light ];
-				nxGeometry.applyMatrix( new THREE.Matrix4().makeRotationY( - Math.PI / 2 ) );
-				nxGeometry.applyMatrix( new THREE.Matrix4().makeTranslation( 
-					new THREE.Vector3( - 50, 0, 0 ) ) );
+				nxGeometry.applyMatrix( matrix.makeRotationY( - Math.PI / 2 ) );
+				nxGeometry.applyMatrix( matrix.makeTranslation( vector.set( - 50, 0, 0 ) ) );
 
 				var pyGeometry = new THREE.PlaneGeometry( 100, 100 );
 				pyGeometry.faces[ 0 ].materialIndex = 0;
 				pyGeometry.faces[ 0 ].vertexColors = [ light, light, light, light ];
-				pyGeometry.applyMatrix( new THREE.Matrix4().makeRotationX( - Math.PI / 2 ) );
-				pyGeometry.applyMatrix( new THREE.Matrix4().makeTranslation( 
-					new THREE.Vector3( 0, 50, 0 ) ) );
+				pyGeometry.applyMatrix( matrix.makeRotationX( - Math.PI / 2 ) );
+				pyGeometry.applyMatrix( matrix.makeTranslation( vector.set( 0, 50, 0 ) ) );
 
 				var pzGeometry = new THREE.PlaneGeometry( 100, 100 );
 				pzGeometry.faces[ 0 ].materialIndex = 1;
 				pzGeometry.faces[ 0 ].vertexColors = [ light, shadow, shadow, light ];
-				pzGeometry.applyMatrix( new THREE.Matrix4().makeTranslation( 
-					new THREE.Vector3( 0, 0, 50 ) ) );
+				pzGeometry.applyMatrix( matrix.makeTranslation( vector.set( 0, 0, 50 ) ) );
 
 				var nzGeometry = new THREE.PlaneGeometry( 100, 100 );
 				nzGeometry.faces[ 0 ].materialIndex = 1;
 				nzGeometry.faces[ 0 ].vertexColors = [ light, shadow, shadow, light ];
-				nzGeometry.applyMatrix( new THREE.Matrix4().makeRotationY( Math.PI ) );
-				nzGeometry.applyMatrix( new THREE.Matrix4().makeTranslation( 
-					new THREE.Vector3( 0, 0, -50 ) ) );
+				nzGeometry.applyMatrix( matrix.makeRotationY( Math.PI ) );
+				nzGeometry.applyMatrix( matrix.makeTranslation( vector.set( 0, 0, -50 ) ) );
 
 				//