Browse Source

fixed a very rare case situation when a duplicated vertex in a face4
allows a reduction to a face3 in Geometry's .mergeVertices(). so finally the
LatheGeometry example in subdivision surfaces is finally working as
intended!

zz85 13 years ago
parent
commit
4becf192df
2 changed files with 19 additions and 6 deletions
  1. 5 6
      examples/webgl_geometry_subdivison.html
  2. 14 0
      src/core/Geometry.js

+ 5 - 6
examples/webgl_geometry_subdivison.html

@@ -224,13 +224,12 @@
 				smooth = THREE.GeometryUtils.clone( geometry );
 
 				// mergeVertices(); is run in case of duplicated vertices
-				if (! (geometry instanceof THREE.LatheGeometry) ) {
-					smooth.mergeVertices();
-				}
+				smooth.mergeVertices();
+				
+				smooth.computeCentroids();
+				smooth.computeFaceNormals();
+				smooth.computeVertexNormals();
 				
-				// smooth.computeCentroids();
-				// smooth.computeFaceNormals();
-				// smooth.computeVertexNormals();
 				modifier.modify( smooth );
 
 				updateInfo();

+ 14 - 0
src/core/Geometry.js

@@ -574,6 +574,7 @@ THREE.Geometry.prototype = {
 		var precisionPoints = 4; // number of decimal points, eg. 4 for epsilon of 0.0001
 		var precision = Math.pow( 10, precisionPoints );
 		var i,il, face;
+		var abcd = 'abcd', o, k;
 
 		for ( i = 0, il = this.vertices.length; i < il; i ++ ) {
 
@@ -615,6 +616,19 @@ THREE.Geometry.prototype = {
 				face.c = changes[ face.c ];
 				face.d = changes[ face.d ];
 
+				// check dups in (a, b, c, d) and convert to -> face3
+				o = [face.a, face.b, face.c, face.d];
+				for (k=3;k>0;k--) {
+					if ( o.indexOf(face[abcd[k]]) != k ) {
+						// console.log('faces', face.a, face.b, face.c, face.d, 'dup at', k);
+						o.splice(k, 1);
+						this.faces[ i ] = new THREE.Face3(o[0], o[1], o[2]);
+						this.faceVertexUvs[0][i].splice(k, 1);
+						
+					}
+				}
+
+
 			}
 
 		}