Browse Source

prevent unexpected vertex weighting

Garrett Johnson 6 years ago
parent
commit
0c08f4f001
1 changed files with 22 additions and 4 deletions
  1. 22 4
      examples/js/loaders/LDrawLoader.js

+ 22 - 4
examples/js/loaders/LDrawLoader.js

@@ -66,6 +66,13 @@ THREE.LDrawLoader = ( function () {
 
 		}
 
+		// NOTE: Some of the normals wind up being skewed in an unexpected way because
+		// quads provide more "influence" to some vertex normals than a triangle due to
+		// the fact that a quad is made up of two triangles and all triangles are weighted
+		// equally. To fix this quads could be tracked separately so their vertex normals
+		// are weighted appropriately or we could try only adding a normal direction
+		// once per normal.
+
 		// Iterate until we've tried to connect all triangles to share normals
 		while ( true ) {
 
@@ -150,11 +157,22 @@ THREE.LDrawLoader = ( function () {
 							var otherHash = hashEdge( otherV0, otherV1 );
 							if ( otherHash === reverseHash ) {
 
-								otherTri[ `n${ otherIndex }` ] = tri[ `n${ next }` ];
-								otherTri[ `n${ otherNext }` ] = tri[ `n${ index }` ];
+								if ( otherTri[ `n${ otherIndex }` ] === null ) {
+
+									var norm = tri[ `n${ next }` ];
+									otherTri[ `n${ otherIndex }` ] = norm;
+									norm.add( otherTri.faceNormal );
+
+								}
+
+								if ( otherTri[ `n${ otherNext }` ] === null ) {
+
+									var norm = tri[ `n${ index }` ];
+									otherTri[ `n${ otherNext }` ] = norm;
+									norm.add( otherTri.faceNormal );
+
+								}
 
-								tri[ `n${ next }` ].add( otherTri.faceNormal );
-								tri[ `n${ index }` ].add( otherTri.faceNormal );
 								break;
 
 							}