kernelQuery(mesh) is the kernel's read side: what a host asks of a model
by entity id, with plain values back. Callers get ids, numbers and
[x, y, z] tuples, never the mesh's own objects, so nothing a read
returns can change the model or go stale under an edit. The verbs are how
a model changes; this is how it is read.
import { kernelQuery } from '@commonplace-technologies/kernel';
const q = kernelQuery(mesh); // given a value that may not be a mesh, it returns null for a non-mesh
A query reads the model live: make one per read or keep one for the
model's life, it never needs refreshing. Reads never throw. An unknown id,
or a question the geometry cannot answer, comes back as null (or
'unknown' for a classification).
Ids are the kernel's own strings. They survive save and load
and undo, and name the same entity until an edit splits or erases it;
each verb's result lists the ids it removed and created. An edge is a
pair of half-edges and is named by the smaller of their two ids (its
canonical id); every method that takes an edge id accepts either half's,
and q.edgeIdOf(id) gives the canonical one.
| Call | Returns |
|---|---|
q.counts() |
{ faces, edges, vertices } |
q.faceIds(), q.edgeIds(), q.vertexIds() |
Every id of that kind |
q.kindOf(id) |
'face', 'edge', 'vertex' or null |
q.edgeIdOf(id) |
The canonical id of the edge either half names |
q.face(id) returns a FaceRecord:
| Field | Meaning |
|---|---|
surface |
The surface kind the face lies on (below) |
flat |
The face is flat, whatever its kind (a ruled quad on straight, coplanar rails is flat) |
normal |
The outline's unit normal, or null when degenerate |
area |
The area of a flat face, holes taken out; null for a curved one (use massProperties) |
outline |
The outline's vertex ids, in loop order (counter-clockwise seen from the front) |
holes |
Each hole's vertex ids, in loop order |
edgeIds |
Every edge on the boundary, holes included |
color, tags |
When it has them |
The surface kinds are the paper vocabulary and what is imported for
context: planar; the ruled family (ruled, ruled-chain,
trimmed-rail); the developable family (developable-bezier,
tangent-developable); patches (trimmed-patch, host-patch,
rational-bezier-bicubic-patch); and NURBS (nurbs-surface,
nurbs-surface-bicubic), carried for imported parts. Branch on flat
before branching on the kind: most flat faces a verb makes are planar,
but a quad is carried on its rails.
q.neighborsOfFace(id) gives the faces that share an edge with it.
q.edge(id) returns an EdgeRecord:
| Field | Meaning |
|---|---|
start, end |
Vertex ids (start is null for a dangling half) |
curve |
The curve kind: line, arc, ellipse, bezier-cubic, rational-bezier-cubic, a trim on a surface, … |
faceIds |
The faces on the edge: none for a wire, one on a sheet's border, two inside a closed shell, one more for each further use (a fin or an inner wall on the edge) |
wire |
No face on either side |
soft |
A seam drawn smooth: its two faces read as one surface |
crease, foldSteps, tags |
A crease mark, its fold angles, its tags, when it has them |
Evaluating an edge, from its start (t = 0) to its end (t = 1):
q.edgePointAt(edgeId, 0.5); // the point halfway along the curve
q.edgeLength(edgeId); // along the curve, not the chord
q.edgePolyline(edgeId); // points within the edge's own drawing deviation
q.vertex(id) gives its position and the edges and faces that meet
there; q.position(id) the position alone, cheaply. q.vertexRing(id)
lists the edges around the vertex in order, each with the faces on its two
sides, so a host can walk a fan without asking for each face.
A face is evaluated over its domain: its plane's frame for a flat face,
the surface's own (u, v) for a curved one.
const d = q.faceDomain(faceId); // { space: 'plane' | 'uv', u: [u0, u1], v: [v0, v1] }
q.facePointAt(faceId, u, v); // a point of the surface
q.faceNormalAt(faceId, u, v); // the unit normal there, on the face's front side
q.projectToFace(faceId, [x, y, z]); // { u, v, point, distance }: the nearest point of the surface
q.classifyPointOnFace(faceId, [x, y, z]); // 'inside' | 'outside' | 'unknown' against the trim
q.faceTriangles(faceId); // the face's fill, 9 numbers a triangle
projectToFace projects onto the untrimmed surface; follow it with
classifyPointOnFace to know whether the point is on the face itself.
A host that snaps to a circle's center or an ellipse's foci, shows an arc's radius, or snaps where an edge pierces a wall reads the exact geometry here, as plain definitions. The intersections are the kernel's own solvers, so a host snaps where the kernel would cut.
q.edgeCurve(edgeId); // CurveDef: line | arc | ellipse | bezier | on-surface
q.faceSurface(faceId); // SurfaceDef: plane | cylinder | cone | sphere | torus | ruled | nurbs | other
q.intersectEdges(edgeA, edgeB); // { crossings: [{ point, tA, tB, tangent }], overlaps: [{ tA, tB }] }
q.intersectEdgeFace(edgeId, faceId); // { points: [{ point, t, tangent, inside }], overlaps: [{ t, inside }] }
q.tangentPlane(faceId, [x, y, z]); // { point, normal, u, v, distance }
edgeCurve runs the way the edge's record does: parameter 0 at start,
1 at end, the parameter edgePointAt takes. The kernel stores one curve
for both halves of an edge and walks it either way; the definition is
already turned to the record's direction.
kind |
Fields | The point at t |
|---|---|---|
line |
start, end |
start + t·(end − start) |
arc |
center, normal, radius, refAxis, startAngle, sweepAngle |
center + radius·(cos θ·refAxis + sin θ·(normal × refAxis)), θ = startAngle + t·sweepAngle |
ellipse |
center, axisU, axisV, startAngle, sweepAngle; normal, major, minor, phase |
center + cos θ·axisU + sin θ·axisV; equally center + cos(θ − phase)·major + sin(θ − phase)·minor |
bezier |
controls, weights when rational |
The Bézier of degree controls.length − 1 |
on-surface |
curve (the kind) |
No closed form: a trim, a surface–surface intersection; use edgePointAt |
An ellipse's axisU and axisV are the conjugate semi-diameters it is
stored with and need not be perpendicular; major and minor are its
principal semi-axes, so its foci are center ± √(|major|² − |minor|²)·major/|major|.
A full circle or ellipse has |sweepAngle| = 2π.
faceSurface is the untrimmed surface the face lies on. A face that is a
plane, a right circular cylinder or cone, a sphere or a torus is reported
as one whatever the kernel stores it as (a cylinder's wall is stored on
two circular rails), recognized to rounding and never approximated.
kind |
Fields |
|---|---|
plane |
origin, normal (front side), uAxis, vAxis: a flat face's (u, v) frame |
cylinder |
origin (a point on the axis), axis (unit), radius |
cone |
apex, axis (unit, opening away from the apex), halfAngle (radians) |
sphere |
center, radius |
torus |
center, axis, majorRadius, minorRadius |
ruled |
railA, railB (curve definitions): S(u, v) = (1 − v)·A(u) + v·B(u), the face's own (u, v) |
nurbs |
degreeU, degreeV, countU, countV, controls (row-major, i along u), weights, knotsU, knotsV |
other |
surface (the kind): exact but no definition to hand out (a tangent developable, an offset); use facePointAt |
intersectEdges and intersectEdgeFace solve on the curves' and
surfaces' own definitions, within the kernel's tolerance, never on a
tessellation. Each parameter is the one edgePointAt takes. A contact
with parallel tangents is reported with tangent: true, not dropped;
an edge lying along another (or in a surface) is an overlap. A pierce
point is flagged inside when it lies on the face itself, within its
trim. Both return null when the solver has no answer: its module still
loading (loadKernel() loads it), or an edge that is a curve on a
surface that is gone. intersectEdgeFace reads only edges with a
definition of their own (not on-surface ones).
tangentPlane is the plane at the point of the untrimmed surface nearest
the one given; follow it with classifyPointOnFace to know whether that
point is on the face.
q.bodies(): the connected pieces of the model (faces, edges and
vertices joined by edges), each with closed when its faces bound a
volume. q.bodyOf(id) is the piece that holds an entity.q.classifyPointInBody([x, y, z], faceIds?): 'in', 'out', 'on' or
'unknown' against the solid the faces bound.q.massProperties(options?): area, volume, centroid and inertia, per
shell and in total, on the faces' own surfaces. null until its module
has loaded; loadKernel() loads it.q.pickFace(origin, direction); // { faceId, point, distance } | null
q.pickEdge(origin, direction, maxGap); // { edgeId, point, distance, gap } | null
Both take a ray in the model's frame. pickFace returns the first face
the ray meets on its own surface and inside its trim (a ray through a hole
goes on), passing over hidden faces. pickEdge returns the edge that
passes nearest the ray if within maxGap of it, nearest the ray first and
then nearest the origin. Both scan the model; see
Build your own modeler for how a host uses
them.
q.develop(faceId, options?): one face laid flat: exactly where its
surface develops, or flattened with its strain stated unless
exactOnly; a typed refusal when it cannot be.q.unfold(faceIds?, options?): faces unfolded into nets, hinged along
shared straight edges, every edge reported as a fold (with its signed
angle) or a cut, and the faces left off with their reasons.Both are null until the unfold module has loaded; loadKernel() loads
it. The unfold, layOutNet and paperModel functions build on them for
cutting sheets.