Shapemetry API / Mesh
Class: Mesh
Defined in: mesh/Mesh.ts:38
Mesh - half-edge editing kernel for n-gon faces (single outer loop, no holes).
Owns element arrays. Topology lives on elements themselves via circular linked lists (disk / radial / corner cycles); the mesh just keeps insertion-order arrays for iteration and free-list management.
Faces with holes are not supported at runtime - use Mesh.fromPolygonMesh which triangulates hole loops on import.
Implements
Shell
Constructors
Constructor
new Mesh():
Mesh
Returns
Mesh
Properties
vertices
vertices:
MeshVertex[] =[]
Defined in: mesh/Mesh.ts:39
edges
edges:
MeshEdge[] =[]
Defined in: mesh/Mesh.ts:40
corners
corners:
MeshCorner[] =[]
Defined in: mesh/Mesh.ts:41
faces
faces:
MeshFace[] =[]
Defined in: mesh/Mesh.ts:42
Accessors
vertexCount
Get Signature
get vertexCount():
number
Defined in: mesh/Mesh.ts:44
Returns
number
edgeCount
Get Signature
get edgeCount():
number
Defined in: mesh/Mesh.ts:45
Returns
number
cornerCount
Get Signature
get cornerCount():
number
Defined in: mesh/Mesh.ts:46
Returns
number
faceCount
Get Signature
get faceCount():
number
Defined in: mesh/Mesh.ts:47
Returns
number
isSolid
Get Signature
get isSolid():
boolean
Defined in: mesh/Mesh.ts:921
Returns
boolean
Implementation of
Shell.isSolid
Methods
fromPolygonMesh()
staticfromPolygonMesh(json):Mesh
Defined in: mesh/Mesh.ts:377
Import PolygonMeshJSON (wire format). Materializes one MeshVertex per unique positions slot (1e-6 spatial dedup absorbs ULP noise from the producer's quantize-key dedup), resolves face loops to vertex arrays, runs a T-junction stitch pass (any vertex strictly inside another face's edge is injected into that edge - Clipper-driven coplanar merges drop such vertices, breaking manifoldness if not re-inserted), then builds half-edge. Faces with holes triangulate via triangulateLoops since the runtime stores single-loop n-gon faces only. Per-face uvMatrix decodes to PlanarProjection.
Parameters
json
Returns
Mesh
fromTriangleMesh()
staticfromTriangleMesh(triangleMesh):Mesh
Defined in: mesh/Mesh.ts:548
Parameters
triangleMesh
Returns
Mesh
box()
staticbox(width,depth,height):Mesh
Defined in: mesh/Mesh.ts:592
Axis-aligned box at origin with size (width=X, depth=Y, height=Z). UV per face in world units.
Parameters
width
number
depth
number
height
number
Returns
Mesh
cone()
staticcone(radiusBottom,radiusTop,height,sides):Mesh
Defined in: mesh/Mesh.ts:641
Cone / cylinder / pyramid by varying radii. UV per face - isometric unroll (Blender / SketchUp / Modo convention, world units):
- Caps: PlanarProjection in the cap plane.
- Lateral (cone, R_bot != R_top): unroll to an annular sector centered at the virtual apex. Slant
L = sqrt(R^2 + h^2), sector angle =2pi.R_bot/L_bot == 2pi.R_top/L_top(similar triangles). Adjacent side faces share UV exactly at common edges (isometry -> affine-exact under per-face PlanarProjection). Pointed cone: apex collapses to a single UV point(0, 0)- no texture smear. - Lateral (cylinder, R_bot = R_top): rectangular unroll (sector degenerates).
Rationale: a truncated cone's side face is a trapezoid in 3D. Mapping it to a UV rectangle (Three.js / Unity convention) is NOT affine-consistent
- per-face PlanarProjection would leave UV seams between adjacent faces. The annular-sector unroll IS an isometry, so the per-face affine fit reproduces all 4 corners exactly and adjacent faces stay continuous. Same shape every major DCC tool produces (Blender, SketchUp, Modo, Rhino).
Parameters
radiusBottom
number
radiusTop
number
height
number
sides
number
Returns
Mesh
sweep()
staticsweep(path,profile,options?):Mesh
Defined in: mesh/Mesh.ts:788
Sweep a 2D profile along a 2D path (both polylines).
Path lies in XY (z=0). At each path step a local frame is built from the path tangent: u-axis = right side of path (tangent rotated -90 deg in XY), v-axis = world +Z. Each profile point (u, v) maps to pathPoint + u*right + v*up.
path[0] === path[end] => path closed (loop); same for profile (tube cross-section). When profile is closed and path is open, end caps are added by default (controlled by options.caps).
Parameters
path
[number, number][]
profile
[number, number][]
options?
caps?
boolean
Returns
Mesh
fromJSON()
staticfromJSON(data):Mesh
Defined in: mesh/Mesh.ts:1043
Rebuild a Mesh from MeshJSON. Positions are taken verbatim - the producer is expected to share indices for coincident vertices. Each face becomes a single n-gon loop. Use fromPolygonMesh instead if the input has hole loops or unmerged duplicate vertices.
Parameters
data
Returns
Mesh
ensureIndices()
ensureIndices():
void
Defined in: mesh/Mesh.ts:50
Refresh element.index to its position in the array.
Returns
void
toTriangleMesh()
toTriangleMesh():
TriangleMesh
Defined in: mesh/Mesh.ts:59
Returns
Implementation of
Shell.toTriangleMesh
toPolygonMesh()
toPolygonMesh():
PolygonMeshJSON
Defined in: mesh/Mesh.ts:203
Export as PolygonMeshJSON (wire format). Coplanar-adjacent faces are merged into face-with-holes via Clipper (concentric loops produce hole loops); the merged geometry is then serialized into a shared positions pool (1e-9 tolerance bucket) with per-face uvMatrix (Planar projections only - non-Planar projections are dropped, matrix encoding can't carry them).
Returns
boundingBox()
boundingBox():
BoundingBox
Defined in: mesh/Mesh.ts:913
Returns
Implementation of
Shell.boundingBox
surfaceArea()
surfaceArea():
number
Defined in: mesh/Mesh.ts:918
Returns
number
Implementation of
Shell.surfaceArea
volume()
volume():
number
Defined in: mesh/Mesh.ts:919
Returns
number
Implementation of
Shell.volume
contains()
contains(
p):boolean
Defined in: mesh/Mesh.ts:920
Parameters
p
Returns
boolean
Implementation of
Shell.contains
transform()
transform(
m):Mesh
Defined in: mesh/Mesh.ts:925
Parameters
m
Returns
Mesh
Implementation of
Shell.transform
clone()
clone():
Mesh
Defined in: mesh/Mesh.ts:929
Returns
Mesh
Implementation of
Shell.clone
reverse()
reverse():
Mesh
Defined in: mesh/Mesh.ts:933
Returns
Mesh
Implementation of
Shell.reverse
_rebuild()
_rebuild(
transformPoint,reverseLoops,projectionTransform?):Mesh
Defined in: mesh/Mesh.ts:941
Walk faces and rebuild a new Mesh with optional point transform + loop reversal. projectionTransform (optional) is applied to each face's uvProjection so UV stays glued to the geometry under a world-space transform. Caller passes the same Transformation it used for transformPoint; omit for identity ops (clone/reverse).
Parameters
transformPoint
(p) => Point
reverseLoops
boolean
projectionTransform?
Returns
Mesh
splitByPlane()
splitByPlane(
plane):SplitByPlaneResult<Mesh>
Defined in: mesh/Mesh.ts:983
Parameters
plane
Returns
SplitByPlaneResult<Mesh>
Implementation of
Shell.splitByPlane
union()
union(
other):Mesh
Defined in: mesh/Mesh.ts:992
Parameters
other
Shell
Returns
Mesh
Implementation of
Shell.union
intersect()
intersect(
other):Mesh
Defined in: mesh/Mesh.ts:995
Parameters
other
Shell
Returns
Mesh
Implementation of
Shell.intersect
subtract()
subtract(
other):Mesh
Defined in: mesh/Mesh.ts:998
Parameters
other
Shell
Returns
Mesh
Implementation of
Shell.subtract
xor()
xor(
other):Mesh
Defined in: mesh/Mesh.ts:1001
Parameters
other
Shell
Returns
Mesh
Implementation of
Shell.xor
toJSON()
toJSON():
MeshJSON
Defined in: mesh/Mesh.ts:1012
Serialize half-edge state as MeshJSON - preserves n-gon faces and per-face material. UV projections are not serialized; reapply them on the consumer side if needed.
Returns
Implementation of
Shell.toJSON
bevel()
bevel(
edges,radius,segments?):void
Defined in: mesh/Mesh.ts:1075
Parameters
edges
Iterable<MeshEdge>
radius
number
segments?
number = 1
Returns
void
extrude()
extrude(
faces,thickness):void
Defined in: mesh/Mesh.ts:1079
Parameters
faces
Iterable<MeshFace>
thickness
number
Returns
void
extrudeEdges()
extrudeEdges(
edges,direction,distance):void
Defined in: mesh/Mesh.ts:1083
Parameters
edges
Iterable<MeshEdge>
direction
distance
number
Returns
void
thicken()
thicken(
thickness,options?):void
Defined in: mesh/Mesh.ts:1087
Parameters
thickness
number
options?
ThickenOptions = {}
Returns
void
lattice()
lattice(
options):void
Defined in: mesh/Mesh.ts:1091
Parameters
options
Returns
void
subdivide()
subdivide(
options?):void
Defined in: mesh/Mesh.ts:1095
Parameters
options?
SubdivideOptions = {}
Returns
void