Skip to content

editorGlobalsPlateRenderSurfaceTriangulator

Class: PlateRenderSurfaceTriangulator

Hierarchy

  • PlateRenderSurfaceTriangulator

Index

Methods

Methods

Static Private _cdt2dTriangulation

_cdt2dTriangulation(surface: PlateRenderSurface): void

Defined in src/util/PlateRenderSurfaceTriangulator.ts:101

Generates a surfaceTriangulation using the cdt2d module. Self touching outlines are supported by cdt2d, but they may not have the same vertex on the same point, but need to reuse the same vertex. The touching can then be expressed by using vertices multiple times in the edges.

Parameters:

Name Type Description
surface PlateRenderSurface -

Returns: void


Static Private _createPointArrayFromVertexIndices

_createPointArrayFromVertexIndices(vertexIndices: number[], vertices: PlateRenderSurfaceVertex[]): number[]

Defined in src/util/PlateRenderSurfaceTriangulator.ts:234

Converts an array of vertex indices to a flattened representation of the vertex positions [x1, y1, x2, y2, …]

Parameters:

Name Type
vertexIndices number[]
vertices PlateRenderSurfaceVertex[]

Returns: number[]


Static Private _earcutTriangulation

_earcutTriangulation(surface: PlateRenderSurface, subdivisions: ArrayLine2[]): void

Defined in src/util/PlateRenderSurfaceTriangulator.ts:64

Parameters:

Name Type
surface PlateRenderSurface
subdivisions ArrayLine2[]

Returns: void


Static Private _generateEdgesForCdt2d

_generateEdgesForCdt2d(surface: PlateRenderSurface, duplicatedToNonDuplicatedIndices: Map‹number, number›): any[]

Defined in src/util/PlateRenderSurfaceTriangulator.ts:156

Parameters:

Name Type
surface PlateRenderSurface
duplicatedToNonDuplicatedIndices Map‹number, number›

Returns: any[]


Static Private _generatePointsAndEdgesForCdt2d

_generatePointsAndEdgesForCdt2d(surface: PlateRenderSurface): object

Defined in src/util/PlateRenderSurfaceTriangulator.ts:139

Removes points close together, to generate two-manifold geometry when triangulating. For triangulation, outlines/holes are not allowed to touch, but it is okay that points are used multiple times (by multiple edges). For example the donut with one missing boxel. +---------+ | | | +--+ | | | | | | +--O--+ | | +------+ At the O position, there exist two points in the outline, that have the same coordinates. These should now be deduplicated, and the edges should use the ~same~ point. That's why we need some logic to convert between duplicated points, and deduplicated points with edges, which is then used by cdt2d. The triangulation will only use one vertex per position, and not "reconvert" to the original vertexes that were deduplicated.

Parameters:

Name Type
surface PlateRenderSurface

Returns: object

{deduplicatedPointPositions: An array of [x, y] coordinates, that contains all point positions edges: the indices into the deduplicatedPointPositions Array to mark which edges are used nonDuplicatedToDuplicatedIndices: Map, which maps the index of a point from deduplicatedPointPositions into the original, duplicated points}

  • deduplicatedPointPositions: number[][]

  • edges: Array‹[number, number]›

  • nonDuplicatedToDuplicatedIndices: Map‹number, number›


Static Private _generatePointsForCdt2d

_generatePointsForCdt2d(surface: PlateRenderSurface): object

Defined in src/util/PlateRenderSurfaceTriangulator.ts:190

Note that one nonDuplicated point can have many duplicated ones, that are all at the same position. For rendering and sending to csg this does not matter, because they are all at the same position. (For the triangulation, cdt2d actually requires it to not have points at the same position)

Parameters:

Name Type Description
surface PlateRenderSurface -

Returns: object

  • deduplicatedPointPositions: number[][]

  • duplicatedToNonDuplicatedIndices: Map‹number, number›

  • nonDuplicatedToDuplicatedIndices: Map‹number, number›


Static Private _getLocationRelativeToLine

_getLocationRelativeToLine(point: IArrayPoint, line: Line3, onLineDelta: number): number

Defined in src/util/PlateRenderSurfaceTriangulator.ts:378

Parameters:

Name Type Default
point IArrayPoint -
line Line3 -
onLineDelta number 0.0001

Returns: number


Static Private _isDegenerate

_isDegenerate(triangle: IArrayFace, surface: PlateRenderSurface): boolean

Defined in src/util/PlateRenderSurfaceTriangulator.ts:403

Parameters:

Name Type
triangle IArrayFace
surface PlateRenderSurface

Returns: boolean


Static Private _roundNumbers

_roundNumbers(numbers: number[]): number[]

Defined in src/util/PlateRenderSurfaceTriangulator.ts:395

Rounds all elements of the supplied array to 1/1000th precision.

Parameters:

Name Type Description
numbers number[] the numbers to round, will be modified

Returns: number[]

the modified array with rounded numbers


Static Private _segmentizeHoles

_segmentizeHoles(surface: PlateRenderSurface, subdivisions: ArrayLine2[], segments: ISegment[]): void

Defined in src/util/PlateRenderSurfaceTriangulator.ts:330

Similar to {@see _segmentizeOutline}. Push all vertex positions belonging to holes into their segment and fill the holeStartIndices array.

Parameters:

Name Type Description
surface PlateRenderSurface -
subdivisions ArrayLine2[] -
segments ISegment[] -

Returns: void


Static Private _segmentizeOutline

_segmentizeOutline(surface: PlateRenderSurface, subdivisions: ArrayLine2[], segments: ISegment[]): void

Defined in src/util/PlateRenderSurfaceTriangulator.ts:287

Push references of the vertex positions of the vertices in the surface into the segments array.

Parameters:

Name Type Description
surface PlateRenderSurface -
subdivisions ArrayLine2[] -
segments ISegment[] -

Returns: void


Static Private _segmentizeSurfacePoints

_segmentizeSurfacePoints(surface: PlateRenderSurface, subdivisions: ArrayLine2[]): ISegment[]

Defined in src/util/PlateRenderSurfaceTriangulator.ts:259

Given an array of subdivisions (regular 2D lines), this will group the surface points. The assumptions made are: - There are extra, collinear points at subdivisions - The subdivisions are all parallel and in the same direction This is required so that the triangulation does not span triangles across segment borders.

Parameters:

Name Type Default Description
surface PlateRenderSurface - -
subdivisions ArrayLine2[] [] -

Returns: ISegment[]


Static triangulate

triangulate(surface: PlateRenderSurface, subdivisions: ArrayLine2[], method: PlateRenderTriangulationMethod): void

Defined in src/util/PlateRenderSurfaceTriangulator.ts:39

Triangulates the surface taking into account the subdivisions. This will fill the faces in the surface.

Parameters:

Name Type Default
surface PlateRenderSurface -
subdivisions ArrayLine2[] -
method PlateRenderTriangulationMethod PlateRenderTriangulationMethod.EARCUT

Returns: void

an array of triangles, each storing the indices of the points in the this.points array.