A kernel model saves as plain JSON and loads back with every entity under the id it had. A host stores the JSON however it likes: a file, a database row, a request body.
import { loadMesh, saveMesh } from '@commonplace-technologies/kernel';
const text = JSON.stringify(saveMesh(mesh));
const loaded = loadMesh(JSON.parse(text));
if (loaded.ok) use(loaded.mesh);
else console.log(loaded.error.code, loaded.error.message);
saveMesh(mesh) returns a MeshDocument:
{
"format": "commonplace-kernel-mesh",
"formatVersion": "2026-05-06",
"mesh": { "vertices": [ ... ], "halfEdges": [ ... ], "faces": [ ... ] }
}
| Field | Meaning |
|---|---|
format |
Always "commonplace-kernel-mesh" (MESH_DOCUMENT_FORMAT). |
formatVersion |
The shape of mesh, an ISO date (MESH_FORMAT_VERSION). |
mesh |
HalfEdgeMesh.toJSON(): every vertex, half-edge and face, with the curve each edge lies on and the surface each face lies on. |
The mesh payload is the one the host application stores under each
definition's geometry in its own documents, so a host document's
geometry and a kernel document's mesh are interchangeable. Its records
are records of
vertices with positions, half-edges with their twin, loop and ring links,
faces with their outline and holes, and the exact curve and surface
records (arcs, Béziers, rails, developable and NURBS surfaces). Positions
are Z up and unitless; the host says what a unit is.
formatVersion versions the mesh records. A host application stores
the same records, so the two move together. It changes only when the shape of the records needs a forward
migration; a new optional key (a new curve kind, a tag) is added without
a bump, and an older kernel reading it ignores the key.
loadMesh reads:
toJSON() payload with no wrapper, as found in a host
document's geometry.A document from a newer kernel is refused (newer-format) rather than
read in part.
loadMesh never throws. It returns { ok: true, mesh } or
{ ok: false, error: { code, message } }:
code |
When |
|---|---|
not-a-mesh |
Not a mesh document (another format, no formatVersion) and not a bare payload with vertices, halfEdges and faces arrays. |
newer-format |
Saved by a newer kernel, in a shape this one does not know. |
unreadable |
The records do not join up: a half-edge names a vertex the document does not hold, or rebuilding the links fails. |
A load checks that the records make a mesh, not that the mesh is a valid
model. For a document from outside your own program, follow the load with
validate(loaded.mesh) and decide what to do with its problems.
kernelQuery names it) is stable for the same reason.saveMesh(loadMesh(doc).mesh) writes the same JSON
again.meshVerbContext(loaded.mesh) for it.