Browse Source

Fixed bad vertex magic number

zz85 14 years ago
parent
commit
7fa0d7b887
2 changed files with 57 additions and 48 deletions
  1. 56 43
      examples/canvas_geometry_subdivison.html
  2. 1 5
      src/extras/modifiers/SubdivisionModifier.js

+ 56 - 43
examples/canvas_geometry_subdivison.html

@@ -152,10 +152,10 @@
 				
 				info.innerHTML = 'Drag to spin the geometry THREE.' + params.type
 				 	+ ' with ' + modifier.subdivisions + ' subdivisions'  + 
-					'<br/>Subdivision <a href="#" onclick="nextSubdivision(1); return false;">+</a>/<a href="#" onclick="nextSubdivision(-1); return false;">-</a>' + 
+					'<br/>Subdivisions: <a href="#" onclick="nextSubdivision(1); return false;">more</a> / <a href="#" onclick="nextSubdivision(-1); return false;">less</a>' + 
 					'<br/>Geometry: <a href="#" onclick="nextGeometry();return false;">next</a>' +
-					'<br/>vertices count: before ' + geometry.vertices.length + ' after ' + smooth.vertices.length +
-					'<br/>face count: before ' + geometry.faces.length + ' after ' + smooth.faces.length
+					'<br/>Vertices count: before ' + geometry.vertices.length + ' after ' + smooth.vertices.length +
+					'<br/>Face count: before ' + geometry.faces.length + ' after ' + smooth.faces.length
 				; //+ params.args;
 				
 				var faceABCD = "abcd";
@@ -190,49 +190,62 @@
 				group.position.y = 150;
 				scene.add( group );
 
+
+				var debugNewPoints = false;
+				var debugOldPoints = false;
+				
 				// Debug new Points
-				// var PI2 = Math.PI * 2;
-				// var program = function ( context ) {
-				// 
-				// 	context.beginPath();
-				// 	context.arc( 0, 0, 1, 0, PI2, true );
-				// 	context.closePath();
-				// 	context.fill();
-				// 
-				// }
-				// 
-				// for ( var i = 0; i < smooth.vertices.length; i++ ) {
-				// 
-				// 	particle = new THREE.Particle( new THREE.ParticleCanvasMaterial( { color: Math.random() * 0x808008 + 0x808080, program: program } ) );
-				// 	particle.position = smooth.vertices[i].position;
-				// 	var pos = smooth.vertices.position
-				// 	particle.scale.x = particle.scale.y = 5;
-				// 	group.add( particle );
-				// }
+				
+				if (debugNewPoints) {
+					var PI2 = Math.PI * 2;
+					var program = function ( context ) {
+			
+						context.beginPath();
+						context.arc( 0, 0, 1, 0, PI2, true );
+						context.closePath();
+						context.fill();
+			
+					}
+			
+					for ( var i = 0; i < smooth.vertices.length; i++ ) {
+			
+						particle = new THREE.Particle( new THREE.ParticleCanvasMaterial( { color: Math.random() * 0x808008 + 0x808080, program: program } ) );
+						particle.position = smooth.vertices[i].position;
+						var pos = smooth.vertices.position
+						particle.scale.x = particle.scale.y = 5;
+						group.add( particle );
+					}
+				
+				}
+				
 				
 				//Debug original points
 				
-				// var drawText = function(i) {
-				// 	
-				// 	return function ( context ) {
-				// 
-				// 		context.beginPath();
-				// 		context.scale(0.1,-0.1);
-				// 
-				// 		context.fillText(i, 0,0);
-				// 		
-				// 	};
-				// 						
-				// }
-				// for ( var i = 0; i < geometry.vertices.length; i++ ) {
-				// 
-				// 	particle = new THREE.Particle( new THREE.ParticleCanvasMaterial( { color: Math.random() * 0x808008 + 0x808080, program: drawText(i) } ) );
-				// 	particle.position = smooth.vertices[i].position;
-				// 	var pos = geometry.vertices.position
-				// 	particle.scale.x = particle.scale.y = 30;
-				// 	group.add( particle );
-				// }
-				// 
+				if (debugOldPoints) {
+					
+					var drawText = function(i) {
+					
+						return function ( context ) {
+				
+							context.beginPath();
+							context.scale(0.1,-0.1);
+				
+							context.fillText(i, 0,0);
+						
+						};
+										
+					}
+					
+					for ( var i = 0; i < geometry.vertices.length; i++ ) {
+				
+						particle = new THREE.Particle( new THREE.ParticleCanvasMaterial( { color: Math.random() * 0x808008 + 0x808080, program: drawText(i) } ) );
+						particle.position = smooth.vertices[i].position;
+						var pos = geometry.vertices.position
+						particle.scale.x = particle.scale.y = 30;
+						group.add( particle );
+					}
+				}
+				
 
 				var meshmaterials = [
 				 	// new THREE.MeshBasicMaterial( { color: 0x000000, shading: THREE.FlatShading, wireframe: true } )
@@ -246,7 +259,7 @@
 				// new THREE.MeshPhongMaterial( { color: 0xffffff, shading: THREE.FlatShading } );
 				// new THREE.MeshPhongMaterial( { color: 0xffffff, shading: THREE.SmoothShading } );
 
-				 cube = new THREE.Mesh( smooth, meshmaterials ); 
+				cube = new THREE.Mesh( smooth, meshmaterials ); 
 	
 				var toscale =  params.scale ? params.scale : 1;
 				cube.scale.x = toscale;

+ 1 - 5
src/extras/modifiers/SubdivisionModifier.js

@@ -331,14 +331,10 @@ THREE.SubdivisionModifier.prototype.smooth = function ( oldGeometry ) {
 			hashAB = edge_hash( face.a, face.b );
 			hashBC = edge_hash( face.b, face.c );
 			hashCA = edge_hash( face.c, face.a );
-
 			
 			f4( currentVerticeIndex, edgePoints[hashAB], face.b, edgePoints[hashBC], face, ['123', '12', '2', '23'] );
 			f4( currentVerticeIndex, edgePoints[hashBC], face.c, edgePoints[hashCA], face, ['123', '23', '3', '31'] );
 			f4( currentVerticeIndex, edgePoints[hashCA], face.a, edgePoints[hashAB], face, ['123', '31', '1', '12'] );
-			// face subdivide color and materials too? 
-			
-			
 			
 		} else if ( face instanceof THREE.Face4 ) {
 			// create 4 face4s
@@ -349,7 +345,7 @@ THREE.SubdivisionModifier.prototype.smooth = function ( oldGeometry ) {
 			hashDA = edge_hash( face.d, face.a );
 			
 			f4( currentVerticeIndex, edgePoints[hashAB], face.b, edgePoints[hashBC], face, ['1234', '12', '2', '23']  );
-			f4( currentVerticeIndex, edgePoints[hashBC], face.c, edgePoints[hashCD], face, ['1234', '13', '3', '34']  );
+			f4( currentVerticeIndex, edgePoints[hashBC], face.c, edgePoints[hashCD], face, ['1234', '23', '3', '34']  );
 			f4( currentVerticeIndex, edgePoints[hashCD], face.d, edgePoints[hashDA], face, ['1234', '34', '4', '41']  );
 			f4( currentVerticeIndex, edgePoints[hashDA], face.a, edgePoints[hashAB], face, ['1234', '41', '1', '12']  );