Skip to content
Shapemetry

@huukhanhnguyen/geometry / namespaces/TriangleMesh

namespaces/TriangleMesh

boundingBox

const boundingBox: (positions, indices) => Float64Array = wasm.triangle_mesh_bounding_box

TriangleMesh.boundingBox — [minX, minY, minZ, maxX, maxY, maxZ].

Parameters

positions

Float64Array

indices

Uint32Array

Returns

Float64Array


chainCutLoops

const chainCutLoops: (segments) => string = wasm.triangle_mesh_chain_cut_loops

TriangleMesh.chainCutLoops — stitch plane-crossing segments into closed 3D loops by shared endpoints, dropping any chain that does not close.

Static in the TS and stateless here. segments is flat, six numbers per segment (ax, ay, az, bx, by, bz) — the same layout [triangle_mesh_clip_to_plane] reports its cut segments in. The result is JSON [[x, y, z, …], …], one flat point run per loop: the loops are RAGGED and small, and a header per loop would buy nothing a string does not.

Parameters

segments

Float64Array

Returns

string


clipToPlane

const clipToPlane: (positions, indices, plane) => Float64Array = wasm.triangle_mesh_clip_to_plane

TriangleMesh.clipToPlane — the kept half plus the raw cut segments:

[0] = length of the kept half's packed soup
[1] = cut-segment value count (6 per segment: ax, ay, az, bx, by, bz)
then: the packed soup, then the segments.

Parameters

positions

Float64Array

indices

Uint32Array

plane

Float64Array

Returns

Float64Array


containsPoint

const containsPoint: (positions, indices, x, y, z) => boolean = wasm.triangle_mesh_contains

TriangleMesh.containsPoint.

Parameters

positions

Float64Array

indices

Uint32Array

x

number

y

number

z

number

Returns

boolean


deform

const deform: (positions, indices, tags, extras, origin_x, origin_y, origin_z, direction_x, direction_y, direction_z, kind, parameter, detail) => Float64Array = wasm.triangle_mesh_deform

Packed Barr deform: [posCount, indexCount, tagCount, extraCount, ...positions, ...indices, ...tags, ...extras].

Parameters

positions

Float64Array

indices

Uint32Array

tags

Uint32Array

extras

Float64Array

origin_x

number

origin_y

number

origin_z

number

direction_x

number

direction_y

number

direction_z

number

kind

string

parameter

number

detail

number

Returns

Float64Array


displace

const displace: (positions, indices, field_width, field_height, field_channels, field_data, amount, tile, detail) => Float64Array = wasm.triangle_mesh_displace

Triplanar displace. field_data is the ImageBuffer channel-0-leading float buffer (width * height * channels). Returns a packed soup.

Parameters

positions

Float64Array

indices

Uint32Array

field_width

number

field_height

number

field_channels

number

field_data

Float32Array

amount

number

tile

number

detail

number

Returns

Float64Array


faceNormal

const faceNormal: (positions, indices, face_index) => Float64Array = wasm.triangle_mesh_face_normal

TriangleMesh.faceNormal — unit normal of triangle face_index.

Parameters

positions

Float64Array

indices

Uint32Array

face_index

number

Returns

Float64Array


flatten

const flatten: (positions, indices) => Float64Array = wasm.triangle_mesh_flatten

TriangleMesh.flatten — LSCM conformal flattening. Positions and indices carry over unchanged, so what the flattening PRODUCES is the UV run, and that run alone is what comes back: two numbers per vertex.

Parameters

positions

Float64Array

indices

Uint32Array

Returns

Float64Array


fromPoints

const fromPoints: (points) => Float64Array = wasm.triangle_mesh_from_points

TriangleMesh.fromPoints — Delaunay over a scattered 2.5D point set. points is flat [x, y, z, ...]; the result is a packed soup.

Parameters

points

Float64Array

Returns

Float64Array


intersect

const intersect: (positions_a, indices_a, uvs_a, positions_b, indices_b, uvs_b) => Float64Array = wasm.triangle_mesh_intersect

TriangleMesh.intersect — a packed soup.

Parameters

positions_a

Float64Array

indices_a

Uint32Array

uvs_a

Float64Array

positions_b

Float64Array

indices_b

Uint32Array

uvs_b

Float64Array

Returns

Float64Array


isSolid

const isSolid: (positions, indices) => boolean = wasm.triangle_mesh_is_solid

TriangleMesh.isSolid.

Parameters

positions

Float64Array

indices

Uint32Array

Returns

boolean


loopSubdivide

const loopSubdivide: (positions, indices, iterations) => Float64Array = wasm.triangle_mesh_loop_subdivide

TriangleMesh.loopSubdivide — a packed soup.

Parameters

positions

Float64Array

indices

Uint32Array

iterations

number

Returns

Float64Array


planarize

const planarize: (pool, faces_json, pinned) => Float64Array = wasm.triangle_mesh_planarize

PBD planarize of a welded vertex pool. faces_json is number[][][] (face → loops → pool indices). pinned is 0/1 per pool vertex. Returns the mutated pool as a flat [x,y,z,…].

Parameters

pool

Float64Array

faces_json

string

pinned

Uint8Array

Returns

Float64Array


reverse

const reverse: (positions, indices, uvs, normals) => Float64Array = wasm.triangle_mesh_reverse

TriangleMesh.reverse — flips winding and negates the normals.

Parameters

positions

Float64Array

indices

Uint32Array

uvs

Float64Array

normals

Float64Array

Returns

Float64Array


simplify

const simplify: (positions, indices, options_json) => Float64Array = wasm.triangle_mesh_simplify

TriangleMesh.simplify — quadric decimation, a packed soup. options_json mirrors SimplifyOptions; "" or "{}" means all defaults.

Parameters

positions

Float64Array

indices

Uint32Array

options_json

string

Returns

Float64Array


solidify

const solidify: (positions, indices, thickness) => Float64Array = wasm.triangle_mesh_solidify

Simple solidify (vertex-normal offset + rim). Returns a packed soup.

Parameters

positions

Float64Array

indices

Uint32Array

thickness

number

Returns

Float64Array


splitByPlane

const splitByPlane: (positions, indices, uvs, normals, plane) => Float64Array = wasm.triangle_mesh_split_by_plane

TriangleMesh.splitByPlane — TWO soups plus the cut boundary, packed the same way one soup is:

[0] = length of the `above` packed soup   (0 when that half is ABSENT)
[1] = length of the `below` packed soup   (0 when that half is ABSENT)
[2] = ring count
[3 .. 3 + ringCount] = each ring's value count (2 * its point count)
then, in order: the `above` soup, the `below` soup, the rings as flat
[x, y, ...] pairs, and the 16-number boundary transformation.

A present-but-empty half still carries pack_triangle_mesh's four-count header, so its length is 4 and never 0 — which is what lets 0 mean "no such half" rather than "an empty one".

Parameters

positions

Float64Array

indices

Uint32Array

uvs

Float64Array

normals

Float64Array

plane

Float64Array

Returns

Float64Array


subtract

const subtract: (positions_a, indices_a, uvs_a, positions_b, indices_b, uvs_b) => Float64Array = wasm.triangle_mesh_subtract

TriangleMesh.subtract — a packed soup.

Parameters

positions_a

Float64Array

indices_a

Uint32Array

uvs_a

Float64Array

positions_b

Float64Array

indices_b

Uint32Array

uvs_b

Float64Array

Returns

Float64Array


surfaceArea

const surfaceArea: (positions, indices) => number = wasm.triangle_mesh_surface_area

TriangleMesh.surfaceArea.

Parameters

positions

Float64Array

indices

Uint32Array

Returns

number


transform

const transform: (positions, indices, uvs, normals, matrix) => Float64Array = wasm.triangle_mesh_transform

TriangleMesh.transform — a packed soup. UVs ride along untouched and normals go through the cofactor matrix, so both are taken as operands.

Parameters

positions

Float64Array

indices

Uint32Array

uvs

Float64Array

normals

Float64Array

matrix

Float64Array

Returns

Float64Array


union

const union: (positions_a, indices_a, uvs_a, positions_b, indices_b, uvs_b) => Float64Array = wasm.triangle_mesh_union

TriangleMesh.union — a packed soup. Pass empty uvs_* when an operand has no UV channel; a vertex born on a UV-bearing triangle gets the barycentric blend of that triangle's corners.

Parameters

positions_a

Float64Array

indices_a

Uint32Array

uvs_a

Float64Array

positions_b

Float64Array

indices_b

Uint32Array

uvs_b

Float64Array

Returns

Float64Array


uvMatrixAt

const uvMatrixAt: (positions, indices, uvs, face_index, normal) => Float64Array<ArrayBufferLike> | undefined = wasm.triangle_mesh_uv_matrix_at

TriangleMesh.uvMatrixAt — the 16-number world-to-UV matrix of a triangle, or undefined when the soup carries no UVs (or the reference normal is degenerate). Pass an EMPTY normal for the TS undefined argument, which makes it use the face's own normal.

Parameters

positions

Float64Array

indices

Uint32Array

uvs

Float64Array

face_index

number

normal

Float64Array

Returns

Float64Array<ArrayBufferLike> | undefined


volume

const volume: (positions, indices) => number = wasm.triangle_mesh_volume

TriangleMesh.volume.

Parameters

positions

Float64Array

indices

Uint32Array

Returns

number


weld

const weld: (positions, indices, tolerance?) => Float64Array = wasm.triangle_mesh_weld

TriangleMesh.weld — merge vertices that share a quantized position and drop the triangles that collapse, as a packed Form-2 mesh. tolerance is undefined for the kernel default (1e-4).

Parameters

positions

Float64Array

indices

Uint32Array

tolerance?

number | null

Returns

Float64Array

Last updated: 📖 7 min readEdit on GitHub