UNPKG

@speckle/viewer

Version:

A 3d viewer for Speckle, based on threejs.

51 lines (50 loc) 2.04 kB
/** * Set of functions to triangulate n-gon faces (i.e. polygon faces with an arbitrary (n) number of vertices). * This class is a JavaScript port of https://github.com/specklesystems/speckle-sharp/blob/main/Objects/Objects/Utils/MeshTriangulationHelper.cs */ export default class MeshTriangulationHelper { /** * Calculates the triangulation of the face at given faceIndex. * @remarks This implementation is based the ear clipping method proposed by "Christer Ericson (2005) <i>Real-Time Collision Detection</i>. * @param {Number} faceIndex The index of the face's cardinality indicator `n` * @param {Number[]} faces The list of faces in the mesh * @param {Number[]} vertices The list of vertices in the mesh * @return {Number[]} flat list of triangle faces (without cardinality indicators) */ static triangulateFace(faceIndex: number, faces: number[], vertices: number[]): number[]; /** * Tests if point v is within the triangle *abc*. * @param {Vector3} v * @param {Vector3} a * @param {Vector3} b * @param {Vector3} c * @returns {boolean} true if v is within triangle. */ static testPointTriangle(v: Vector3, a: Vector3, b: Vector3, c: Vector3): boolean; /** * Checks that triangle abc is clockwise with reference to referenceNormal. * @param {Vector3} referenceNormal The normal direction of the face. * @param {Vector3} a * @param {Vector3} b * @param {Vector3} c * @returns {boolean} true if triangle is ccw */ static triangleIsCCW(referenceNormal: Vector3, a: Vector3, b: Vector3, c: Vector3): boolean; } /** * Encapsulates vector maths operations required for polygon triangulation */ declare class Vector3 { constructor(x: any, y: any, z: any); x: any; y: any; z: any; add(v: any): Vector3; sub(v: any): Vector3; mul(n: any): Vector3; dot(v: any): number; cross(v: any): Vector3; squareSum(): number; normalize(): void; } export {};