Browse Source

mergeVertices: Shift the hash bin to move boundary away from round threshold (#26746)

Garrett Johnson 1 year ago
parent
commit
e58a74e190
1 changed files with 5 additions and 3 deletions
  1. 5 3
      examples/jsm/utils/BufferGeometryUtils.js

+ 5 - 3
examples/jsm/utils/BufferGeometryUtils.js

@@ -631,8 +631,10 @@ function mergeVertices( geometry, tolerance = 1e-4 ) {
 	}
 	}
 
 
 	// convert the error tolerance to an amount of decimal places to truncate to
 	// convert the error tolerance to an amount of decimal places to truncate to
-	const decimalShift = Math.log10( 1 / tolerance );
-	const shiftMultiplier = Math.pow( 10, decimalShift );
+	const halfTolerance = tolerance * 0.5;
+	const exponent = Math.log10( 1 / tolerance );
+	const hashMultiplier = Math.pow( 10, exponent );
+	const hashAdditive = halfTolerance * hashMultiplier;
 	for ( let i = 0; i < vertexCount; i ++ ) {
 	for ( let i = 0; i < vertexCount; i ++ ) {
 
 
 		const index = indices ? indices.getX( i ) : i;
 		const index = indices ? indices.getX( i ) : i;
@@ -648,7 +650,7 @@ function mergeVertices( geometry, tolerance = 1e-4 ) {
 			for ( let k = 0; k < itemSize; k ++ ) {
 			for ( let k = 0; k < itemSize; k ++ ) {
 
 
 				// double tilde truncates the decimal value
 				// double tilde truncates the decimal value
-				hash += `${ ~ ~ ( attribute[ getters[ k ] ]( index ) * shiftMultiplier ) },`;
+				hash += `${ ~ ~ ( attribute[ getters[ k ] ]( index ) * hashMultiplier + hashAdditive ) },`;
 
 
 			}
 			}