Browse Source

Another minecraft demo optimization: creating only one material per unique texture.

This also reduces number of VBOs. There aren't many of them anyways, but it's always nice to have less ;)
alteredq 14 years ago
parent
commit
9e5017a2ed
1 changed files with 21 additions and 6 deletions
  1. 21 6
      examples/geometry_minecraft.html

+ 21 - 6
examples/geometry_minecraft.html

@@ -75,14 +75,18 @@
 
 				scene = new THREE.Scene();
 
+				var grass_dirt = loadTexture( 'textures/minecraft/grass_dirt.png' ),
+					grass 	   = loadTexture( 'textures/minecraft/grass.png' ),
+					dirt	   = loadTexture( 'textures/minecraft/dirt.png' );
+					
 				var materials = [
 
-					loadTexture( 'textures/minecraft/grass_dirt.png' ), // right
-					loadTexture( 'textures/minecraft/grass_dirt.png' ), // left
-					loadTexture( 'textures/minecraft/grass.png' ), 		// top
-					loadTexture( 'textures/minecraft/dirt.png' ), 		// bottom
-					loadTexture( 'textures/minecraft/grass_dirt.png' ), // back
-					loadTexture( 'textures/minecraft/grass_dirt.png' ) 	// front
+					grass_dirt, // right
+					grass_dirt, // left
+					grass, 		// top
+					dirt, 		// bottom
+					grass_dirt, // back
+					grass_dirt 	// front
 
 				];
 
@@ -166,6 +170,17 @@
 
 			}
 
+			function generateAO( image, sides ) {
+			
+				var c = document.createElement('canvas');
+				c.width = image.width;
+				c.height = image.height;
+				c.getContext( "2d" ).drawImage( image, 0, 0 );
+				
+				return c;
+				
+			}
+			
 			function loadTexture( path ) {
 
 				var image = new Image();