Quellcode durchsuchen

Playing around with UVs

zz85 vor 14 Jahren
Ursprung
Commit
c2e0d05ec6
2 geänderte Dateien mit 24 neuen und 9 gelöschten Zeilen
  1. 10 3
      examples/canvas_geometry_subdivison.html
  2. 14 6
      src/core/Geometry.js

+ 10 - 3
examples/canvas_geometry_subdivison.html

@@ -87,7 +87,7 @@
 
 				for ( var i = 0; i < 6; i ++ ) {
 
-					materials.push( [ new THREE.MeshBasicMaterial( { color: Math.random() * 0xffffff, wireframe: true } ) ] );
+					materials.push( [ new THREE.MeshBasicMaterial( { color: Math.random() * 0xffffff, wireframe: false } ) ] );
 
 				}
 				
@@ -106,7 +106,9 @@
 				//PlaneGeometry not supported
 				
 				// quick fix for duplicated vertices
-				geometry.checkDupVertices();
+				// /geometry.checkDupVertices( true );
+				
+				console.log(geometry);
 				
 				smooth = createSubdivision(geometry, 2);
 				
@@ -163,7 +165,12 @@
 				// }
 				
 
-				cube = new THREE.Mesh( smooth, new THREE.MeshBasicMaterial( { color: 0x405040, wireframe:true,  opacity:0.8 } ) ); //new THREE.MeshFaceMaterial()
+				// cube = new THREE.Mesh( smooth, new THREE.MeshBasicMaterial( { color: 0x405040, wireframe:false,  opacity:0.8 } ) ); 
+				cube = new THREE.Mesh( smooth, new THREE.MeshFaceMaterial() ); 
+				// material =  new THREE.MeshPhongMaterial( { color: 0xffffff, shading: THREE.FlatShading } );
+				// 	 new THREE.MeshPhongMaterial( { color: 0xffffff, shading: THREE.SmoothShading } );
+				
+				//
 				cube.doubleSided = true;
 				cube.position.y = 150;
 				cube.overdraw = true;

+ 14 - 6
src/core/Geometry.js

@@ -547,29 +547,36 @@ THREE.Geometry.prototype = {
 
 	}, 
 	
-	checkDupVertices: function() {
+	checkDupVertices: function(toPatch) {
+		
 		var uniqueVertices = {}, patch = {};
 		var v, key;
-		var precision = 1;
+		var precision = 1000;
 		var i,il, face;
 		
 		for (i=0,il=this.vertices.length;i<il;i++) {
 			
 			v = this.vertices[i].position;
-			//key = [v.x.toFixed(precision), v.y.toFixed(precision), v.z.toFixed(precision)].join('_');
-			key = [Math.round(v.x * 1000), Math.round(v.y* 1000), Math.round(v.z* 1000)].join('_');
+			key = [Math.round(v.x * precision), Math.round(v.y* precision), Math.round(v.z* precision)].join('_');
 			
 			if (uniqueVertices[key]===undefined) {
 				uniqueVertices[key] = i;
 			} else {
-				//console.log('HEY ', i, 'should be using ', uniqueVertices[key]);
+				console.log('Duplicate vertex found. ', i, ' could be using ', uniqueVertices[key]);
 				patch[i] = uniqueVertices[key];
 			}
 			
 		};
 		
+		
+		
+		if (!toPatch) return;
+		
 		// Start to patch.
-		//console.log(patch);
+		console.log('Start' , patch, toPatch);
+		
+		
+		//TODO: Clear delete vertices?
 		
 		var runPatch = function(i) {
 			if (patch[i] !== undefined) {
@@ -578,6 +585,7 @@ THREE.Geometry.prototype = {
 			}
 			return i;
 		};
+		
 		for( i = 0, il = this.faces.length; i < il; i ++ ) {
 
 			face = this.faces[ i ];