Skip to content

Commit

Permalink
filtered out first recur of outer triangles.
Browse files Browse the repository at this point in the history
  • Loading branch information
gonnavis committed Mar 15, 2022
1 parent fbf8dbe commit 42d0df8
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 40 deletions.
85 changes: 47 additions & 38 deletions mesh-cut/MeshCutter.js
Original file line number Diff line number Diff line change
Expand Up @@ -516,50 +516,59 @@ class MeshCutter {
const y2 = coords2D[delaunay.triangles[i * 3 + 2] * 2 + 1]

// filter out outer triangles: if has any edge not overlap with original model's edges, delete the triangle.
let isOverlap0 = false
for(let il = 0; il < linesInner.length; il += 2) {
const p0 = linesInner[il]
const p1 = linesInner[il + 1]
if(
(x0 === p0.x && y0 === p0.y && x1 === p1.x && y1 === p1.y) ||
(x0 === p1.x && y0 === p1.y && x1 === p0.x && y1 === p0.y)
) {
isOverlap0 = true;
break;
if(true) { // todo: need recur filter out.
if(delaunay.halfedges[i * 3 + 0] === -1) {
let isOverlap0 = false
for(let il = 0; il < linesInner.length; il += 2) {
const p0 = linesInner[il]
const p1 = linesInner[il + 1]
if(
(x0 === p0.x && y0 === p0.y && x1 === p1.x && y1 === p1.y) ||
(x0 === p1.x && y0 === p1.y && x1 === p0.x && y1 === p0.y)
) {
isOverlap0 = true;
break;
}
}
if(!isOverlap0) continue;
}
}
if(!isOverlap0) continue;

let isOverlap1 = false
for(let il = 0; il < linesInner.length; il += 2) {
const p0 = linesInner[il]
const p1 = linesInner[il + 1]
if(
(x1 === p0.x && y1 === p0.y && x2 === p1.x && y2 === p1.y) ||
(x1 === p1.x && y1 === p1.y && x2 === p0.x && y2 === p0.y)
) {
isOverlap1 = true;
break;

if(delaunay.halfedges[i * 3 + 1] === -1) {
let isOverlap1 = false
for(let il = 0; il < linesInner.length; il += 2) {
const p0 = linesInner[il]
const p1 = linesInner[il + 1]
if(
(x1 === p0.x && y1 === p0.y && x2 === p1.x && y2 === p1.y) ||
(x1 === p1.x && y1 === p1.y && x2 === p0.x && y2 === p0.y)
) {
isOverlap1 = true;
break;
}
}
if(!isOverlap1) continue;
}
}
if(!isOverlap1) continue;

let isOverlap2 = false
for(let il = 0; il < linesInner.length; il += 2) {
const p0 = linesInner[il]
const p1 = linesInner[il + 1]
if(
(x2 === p0.x && y2 === p0.y && x0 === p1.x && y0 === p1.y) ||
(x2 === p1.x && y2 === p1.y && x0 === p0.x && y0 === p0.y)
) {
isOverlap2 = true;
break;

if(delaunay.halfedges[i * 3 + 2] === -1) {
let isOverlap2 = false
for(let il = 0; il < linesInner.length; il += 2) {
const p0 = linesInner[il]
const p1 = linesInner[il + 1]
if(
(x2 === p0.x && y2 === p0.y && x0 === p1.x && y0 === p1.y) ||
(x2 === p1.x && y2 === p1.y && x0 === p0.x && y0 === p0.y)
) {
isOverlap2 = true;
break;
}
}
if(!isOverlap2) continue;
}
}
if(!isOverlap2) continue;

// end filter out outer triangles

console.log('remained triangle')

points1.push(
new THREE.Vector3(x0, y0, 0),
new THREE.Vector3(x2, y2, 0),
Expand Down
4 changes: 2 additions & 2 deletions mesh-cut/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ const extrudeSettings = {
bevelEnabled: false,
};
const geometry = new THREE.ExtrudeGeometry( shape, extrudeSettings );
// geometry.translate(0, 0, -.5)
geometry.translate(0, 0, -.5)

// const positions = [

Expand All @@ -132,7 +132,7 @@ const geometry = new THREE.ExtrudeGeometry( shape, extrudeSettings );

const material = new THREE.MeshStandardMaterial({
// const material = new THREE.MeshBasicMaterial({
// color: 'red',
color: 'black',
wireframe: true,
side: THREE.DoubleSide,
map: new THREE.TextureLoader().load('./image/uv_grid_opengl.jpg'),
Expand Down

0 comments on commit 42d0df8

Please sign in to comment.