@huukhanhnguyen/geometry / brepJson
brepJson
InvalidBrepJsonError
A value that does not have BrepData's four tables.
Extends
Error
Constructors
Constructor
new InvalidBrepJsonError(
reason):InvalidBrepJsonError
Parameters
reason
string
Returns
Overrides
Error.constructor
cause?
optionalcause?:unknown
Inherited from
Error.cause
message
message:
string
Inherited from
Error.message
name
name:
string
Inherited from
Error.name
stack?
optionalstack?:string
Inherited from
Error.stack
analyticFromRevolve()
analyticFromRevolve(
surface):AnalyticSurface|null
The named analytic form of a revolve surface — the INVERSE of the kernel's revolve_form in crates/geometry/src/brep/topo/serialize.rs, which is the side that BUILDS a revolve from named analytic parameters.
It exists because a document that stores a profile has to be RECOGNISED by anything that wants named parameters — an exact-B-Rep writer emits CYLINDRICAL_SURFACE with an axis and a radius, not a swept profile. Keeping the recognition in ONE function is the point — before this, seventeen call sites read row.radius directly off the document, and after the fold each of them would otherwise have grown its own recognition.
null when the profile is not one of the four analytic shapes; a general revolve has no named form, and that is the case the fold made expressible.
The SHAPE it returns, AnalyticSurface, is declared in @huukhanhnguyen/types; the recognition below is the runtime half.
Parameters
surface
Returns
AnalyticSurface | null
extractShellTables()
extractShellTables(
vertices,edges,loops,faces,faceIndices):BrepData
Extract one connected face-set into its own four-table BrepData, remapping every index so the result is self-contained.
The default kernel doors no longer use this: fromKernelDocument keeps the document tables as one body. Reserved for deliberate identity-minting splits (islands become objects).
Parameters
vertices
edges
BrepEdge[]
loops
BrepLoop[]
faces
BrepFace[]
faceIndices
number[]
Returns
fromKernelDocument()
fromKernelDocument(
document):BrepData
Kernel JSON (parsed) → one scene BrepData holding the document's tables as-is. The shells partition is ignored — connectivity derives it when a consumer asks. Multi-shell documents do not trigger extractShellTables.
Face material comes back OUT of attributes onto its own field (materialFromWire) — the inverse of what toKernelDocument folded in.
Parameters
document
unknown
Returns
parseBrepJson()
parseBrepJson(
value):BrepData
unknown → BrepData, or throw InvalidBrepJsonError. The door every JSON.parse(<kernel document>) should cross.
Parameters
value
unknown
Returns
splitBrepComponents()
splitBrepComponents(
brep):BrepData[]
Split one body document into one BrepData per CONNECTED face set — the deliberate identity-minting split (islands become objects), the inverse of the merge every kernel door now performs. A body already in one piece comes back as itself, uncopied.
Parameters
brep
Returns
BrepData[]
surfaceForm()
surfaceForm(
surface):AnalyticSurface|null
The named analytic form of ANY document surface: a plane is already one, a revolve is recognised, a nurbs has none. This is the shape BrepData.faceFormsJson hands back, so a writer can take its form from either source and switch once.
Parameters
surface
Returns
AnalyticSurface | null
toKernelDocument()
toKernelDocument(
brep):string
Scene BrepData → kernel JSON string. Derives the shells partition from face-edge connectivity before emit: one shells row per connected component. A one-component body (the common case) still emits a single row spanning every face. The extra field is wire-only — not a public sibling type.
A face's material folds into its attributes on the way out (materialToWire): the crate's face row carries attributes as one opaque blob and knows no other field, so a top-level material would be dropped on load and never come back from a boolean.
Parameters
brep
Returns
string