Skip to content

Commit

Permalink
Reuse functions
Browse files Browse the repository at this point in the history
  • Loading branch information
gkjohnson committed Sep 27, 2023
1 parent 2700f2f commit 00a0bf5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/SilhouetteGenerator.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { Path64, Clipper, FillRule } from 'clipper2-js';
import { ShapeGeometry, Vector3, Shape, Vector2, Triangle, ShapeUtils, Line3, BufferGeometry } from 'three';
import { ShapeGeometry, Vector3, Shape, Vector2, Triangle, ShapeUtils, BufferGeometry } from 'three';
import { compressPoints } from './utils/compressPoints.js';
import { triangleIsInsidePaths } from './utils/triangleIsInsidePaths.js';
import { getSizeSortedTriList } from './utils/getSizeSortedTriList.js';
import { getTriCount } from './utils/geometryUtils.js';

const AREA_EPSILON = 1e-8;
const UP_VECTOR = /* @__PURE__ */ new Vector3( 0, 1, 0 );
Expand Down Expand Up @@ -122,7 +123,7 @@ export class SilhouetteGenerator {

const index = geometry.index;
const posAttr = geometry.attributes.position;
const triCount = index ? index.count / 3 : posAttr.count / 3;
const triCount = getTriCount( geometry );
let overallPath = null;

const triList = getSizeSortedTriList( geometry );
Expand Down
7 changes: 7 additions & 0 deletions src/utils/geometryUtils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export function getTriCount( geometry ) {

const { index } = geometry;
const posAttr = geometry.attributes.position;
return index ? index.count / 3 : posAttr.count / 3;

}
3 changes: 2 additions & 1 deletion src/utils/getSizeSortedTriList.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { Triangle } from 'three';
import { getTriCount } from './geometryUtils.js';

const _tri = new Triangle();
export function getSizeSortedTriList( geometry ) {

const index = geometry.index;
const posAttr = geometry.attributes.position;
const triCount = index ? index.count / 3 : posAttr.count / 3;
const triCount = getTriCount( geometry );

return new Array( triCount )
.fill()
Expand Down

0 comments on commit 00a0bf5

Please sign in to comment.