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

Fix degenerate lines in final result #193

Merged
merged 4 commits into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions src/core/TriangleSplitter.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,7 @@ export class TriangleSplitter {

if ( Math.abs( 1.0 - Math.abs( _triangleNormal.dot( normal ) ) ) < PARALLEL_EPSILON ) {

if ( this.coplanarTriangleUsed === false ) {

this.coplanarTriangleUsed = true;

}
this.coplanarTriangleUsed = true;

for ( let i = 0, l = triangles.length; i < l; i ++ ) {

Expand Down
18 changes: 13 additions & 5 deletions src/core/operations/operations.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
} from './operationsUtils.js';
import { getTriCount } from '../utils/geometryUtils.js';
import { HOLLOW_INTERSECTION, HOLLOW_SUBTRACTION } from '../constants.js';
import { isTriDegenerate } from '../utils/triangleUtils.js';

const _matrix = new Matrix4();
const _normalMatrix = new Matrix3();
Expand Down Expand Up @@ -296,12 +297,19 @@ function performWholeTriangleOperations(
const i2 = aIndex.getX( i3 + 2 );
const groupIndex = groupOffset === - 1 ? 0 : groupIndices[ currId ] + groupOffset;

for ( let k = 0, lk = _attr.length; k < lk; k ++ ) {
_tri.a.fromBufferAttribute( aPosition, i0 );
_tri.b.fromBufferAttribute( aPosition, i1 );
_tri.c.fromBufferAttribute( aPosition, i2 );
if ( ! isTriDegenerate( _tri ) ) {

const action = _actions[ k ];
const attrSet = _attr[ k ].getGroupAttrSet( groupIndex );
const invertTri = action === INVERT_TRI;
appendAttributesFromIndices( i0, i1, i2, aAttributes, a.matrixWorld, _normalMatrix, attrSet, invertTri !== invertedGeometry );
for ( let k = 0, lk = _attr.length; k < lk; k ++ ) {

const action = _actions[ k ];
const attrSet = _attr[ k ].getGroupAttrSet( groupIndex );
const invertTri = action === INVERT_TRI;
appendAttributesFromIndices( i0, i1, i2, aAttributes, a.matrixWorld, _normalMatrix, attrSet, invertTri !== invertedGeometry );

}

}

Expand Down
4 changes: 2 additions & 2 deletions src/core/utils/triangleUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ export function isTriDegenerate( tri, eps = EPSILON ) {
// compute angles to determine whether they're degenerate
_AB.subVectors( tri.b, tri.a );
_AC.subVectors( tri.c, tri.a );
_CB.subVectors( tri.c, tri.b );
_CB.subVectors( tri.b, tri.c );

const angle1 = _AB.angleTo( _AC ); // AB v AC
const angle2 = _AB.angleTo( _CB ) - Math.PI; // AB v BC - 180deg
const angle2 = _AB.angleTo( _CB ); // AB v BC
const angle3 = Math.PI - angle1 - angle2; // 180deg - angle1 - angle2

return Math.abs( angle1 ) < eps ||
Expand Down