Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BufferGeometryUtils.mergeVertices: Shift the hash bin to avoid missing neighbors #26746

Merged
merged 1 commit into from Sep 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 5 additions & 3 deletions examples/jsm/utils/BufferGeometryUtils.js
Expand Up @@ -631,8 +631,10 @@ function mergeVertices( geometry, tolerance = 1e-4 ) {
}

// 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 ++ ) {

const index = indices ? indices.getX( i ) : i;
Expand All @@ -648,7 +650,7 @@ function mergeVertices( geometry, tolerance = 1e-4 ) {
for ( let k = 0; k < itemSize; k ++ ) {

// double tilde truncates the decimal value
hash += `${ ~ ~ ( attribute[ getters[ k ] ]( index ) * shiftMultiplier ) },`;
hash += `${ ~ ~ ( attribute[ getters[ k ] ]( index ) * hashMultiplier + hashAdditive ) },`;

}

Expand Down