Skip to content

Query: Brep ​

BREP queries — read the topology and geometry of a boundary-representation mesh as plain values / child handles. A BrepHandle is a session-ephemeral resource handle obtained from design.query.geometry.getBrep; it goes stale on undo/redo/re-topologize. Enumerations mint fresh child topology handles (FaceHandle, EdgeHandle, VertexHandle, HalfEdgeHandle); the registry dedupes by identity, so re-enumeration returns the same handles. Position reads return Vec3Components. No query mutates its inputs. Accessed via snaptrude.core.geom.query.brep.

Types ​

Vec3Components ​

Plain-value vector record returned by position reads.

PropertyTypeDescription
xnumberX component
ynumberY component
znumberZ component

BBoxComponents ​

Plain-value axis-aligned bounding box record.

PropertyTypeDescription
minVec3ComponentsMinimum corner
maxVec3ComponentsMaximum corner

Functions ​

listFaces(brep) ​

List the faces of a brep.

  • Parameters:
    • brep: BrepHandle — The brep to query
  • Returns: FaceHandle[] — The faces
ts
const brep = await snaptrude.design.query.geometry.getBrep(component);
const faces = await snaptrude.core.geom.query.brep.listFaces(brep);

listEdges(brep) ​

List the edges of a brep.

  • Parameters:
    • brep: BrepHandle — The brep to query
  • Returns: EdgeHandle[] — The edges

listVertices(brep) ​

List the vertices of a brep.

  • Parameters:
    • brep: BrepHandle — The brep to query
  • Returns: VertexHandle[] — The vertices

listHalfEdges(brep) ​

List the half-edges of a brep.

  • Parameters:
    • brep: BrepHandle — The brep to query
  • Returns: HalfEdgeHandle[] — The half-edges

getEdge(brep, vertexIndexA, vertexIndexB) ​

Get the edge connecting two vertices (by their brep vertex indices).

  • Parameters:
    • brep: BrepHandle — The brep to query
    • vertexIndexA: number — First vertex index
    • vertexIndexB: number — Second vertex index
  • Returns: EdgeHandle | null — The edge, or null if no such edge exists

hasEdge(brep, vertexIndexA, vertexIndexB) ​

Test whether an edge connects two vertices (by their brep vertex indices).

  • Parameters:
    • brep: BrepHandle — The brep to query
    • vertexIndexA: number — First vertex index
    • vertexIndexB: number — Second vertex index
  • Returns: boolean — true if such an edge exists, otherwise false

listEdgesBetween(brep, vertexIndexA, vertexIndexB) ​

List every edge connecting two vertices (by their brep vertex indices) — the multi-edge form of getEdge, for the case where two vertices are joined by more than one edge (the two half-arcs of a cylinder rim, say).

Vertex indices, not face indices

This is not a face-pair lookup — it will not find "the edge between the cylinder and the cap". To pick edges by the faces they lie between, walk listEdges and read each edge's two faces with edge.listFaces + face.getSurfaceKind (the rim recipe on brepFromFillet).

  • Parameters:
    • brep: BrepHandle — The brep to query
    • vertexIndexA: number — First vertex index
    • vertexIndexB: number — Second vertex index
  • Returns: EdgeHandle[] — The edges

getEdgeCurve(brep, edge) ​

Read the exact curve of a brep edge as plain values — a discriminated union on type. Pure read: no geometry kernel is loaded. Points and directions are Vec3Components (like getVertexPosition); axis is a unit vector; lengths and radii are raw Babylon units. Unlike query.edge.getCurve — which mints a curve handle and returns null for full-circle edges — this read returns plain values for every exact curve, circles included.

typeFields
"line"startPoint, endPoint, length
"arc"startPoint, endPoint, centre, axis, radius, length
"circle"centre, axis, radius, length — a full-circle edge (e.g. a cylinder cap rim)
"spline"startPoint, endPoint, degree, controlPoints, knots, length — a free-form NURBS edge

For a "spline" edge, knots is the expanded knot vector — each knot repeated by its multiplicity, the textbook NURBS form — so knots.length === controlPoints.length + degree + 1. This is also the exact read-back the query.curve spline table points at: everything query.curve will not answer for a spline can be computed from these poles and knots.

  • Parameters:
    • brep: BrepHandle — The brep the edge belongs to
    • edge: EdgeHandle — The edge whose curve to read
  • Returns: The curve data as a discriminated union on type (see table above)
  • Throws: VALIDATION if the edge is not on brep (enumerate edges of the same brep via listEdges/getEdge); PRECONDITION_FAILED if the edge is a rational (weighted) spline — the wire form carries no weights, so it is refused rather than reported as a different curve; OPERATION_FAILED if the edge carries no exact curve geometry (never the case for breps authored via core.geom.create)
ts
// Read the radius of a cylinder's curved rim edges
const cylinder = await snaptrude.core.geom.create.brepFromExtrusion(
  circleContour, // a circle authored as two semicircular arcs
  { x: 0, y: 1, z: 0 },
  5
);
const edges = await snaptrude.core.geom.query.brep.listEdges(cylinder);
for (const edge of edges) {
  const curve = await snaptrude.core.geom.query.brep.getEdgeCurve(cylinder, edge);
  if (curve.type === "arc") console.log("rim radius:", curve.radius);
}

getVertexPosition(brep, vertex) ​

Get the position of a vertex within a brep.

  • Parameters:
    • brep: BrepHandle — The brep to query
    • vertex: VertexHandle — The vertex whose position to read
  • Returns: Vec3Components — The position, as { x, y, z }
ts
const { brep: brepQuery } = snaptrude.core.geom.query;

const brep = await snaptrude.design.query.geometry.getBrep(component);
const vertices = await brepQuery.listVertices(brep);
const position = await brepQuery.getVertexPosition(brep, vertices[0]);
// position = { x, y, z } in Snaptrude units

listVertexPositions(brep) ​

List the positions of all vertices in a brep (ordered as listVertices).

  • Parameters:
    • brep: BrepHandle — The brep to query
  • Returns: Vec3Components[] — The positions

getCentroid(brep) ​

Get the centroid of a brep: the mean of its vertex positions for planar and cylinder-sided solids; for a solid with sphere, cone, torus or spline geometry, its exact centre of mass (integrated over the surfaces; the vertex mean again if the kernel cannot integrate it, e.g. an open brep).

  • Parameters:
    • brep: BrepHandle — The brep to query
  • Returns: Vec3Components — The centroid

getFaceCount(brep) ​

Get the number of faces in a brep.

  • Parameters:
    • brep: BrepHandle — The brep to query
  • Returns: number — The face count

getEdgeCount(brep) ​

Get the number of edges in a brep.

  • Parameters:
    • brep: BrepHandle — The brep to query
  • Returns: number — The edge count

getVertexCount(brep) ​

Get the number of vertices in a brep.

  • Parameters:
    • brep: BrepHandle — The brep to query
  • Returns: number — The vertex count

getHalfEdgeCount(brep) ​

Get the number of half-edges in a brep.

  • Parameters:
    • brep: BrepHandle — The brep to query
  • Returns: number — The half-edge count

getBoundingBox(brep) ​

Get the axis-aligned bounding box of a brep. Curved geometry is bounded by the surface, not just the topological vertices: a sphere reports centre ± radius and a torus centre ± (R + r) in plane, even though neither has a vertex anywhere near those extremes. Arc and spline edges are sampled and curved faces measured, so this agrees with the entity-level design.query.measure box for a committed mass.

  • Parameters:
    • brep: BrepHandle — The brep to query
  • Returns: BBoxComponents — The bounding box, as { min, max }

getVolume(brep) ​

Get the enclosed volume of a closed solid, integrated from its exact surfaces. Curved faces are measured analytically, not from their tessellation — a real sphere of radius 5 reports 523.6, whatever its triangle count. That makes this the reliable way to confirm a solid is the shape you intended: a torus should measure 2·π²·R·r².

Volume is in cubic raw Babylon units — when converting units, cube the factor.

Runs on the OpenCascade kernel (the first kernel call loads a wasm of tens of MB — expect a pause of seconds).

  • Parameters:
    • brep: BrepHandle — The solid to measure
  • Returns: number — The enclosed volume in cubic raw Babylon units
  • Throws: OPERATION_FAILED if the kernel cannot compute the volume (the brep is not a closed solid)
ts
const [mass] = await snaptrude.design.query.listMasses();
const brep = await snaptrude.design.query.geometry.getBrep(mass);
if (brep) {
  const volume = await snaptrude.core.geom.query.brep.getVolume(brep);
  console.log("volume:", volume);
}

isEqual(brepA, brepB) ​

Test whether two breps are geometrically equal.

  • Parameters:
    • brepA: BrepHandle — First brep
    • brepB: BrepHandle — Second brep
  • Returns: boolean — true if the breps are equal, otherwise false

getDistance(brepA, brepB) ​

Measures the minimum distance between two solids, with the closest witness point on each. Touching or overlapping solids report a distance of 0 with contact points.

  • Parameters:
    • brepA: BrepHandle — First solid
    • brepB: BrepHandle — Second solid
  • Returns: { distance, pointA, pointB } — The minimum distance and the closest points on brepA and brepB as Vec3Components
  • Throws: OPERATION_FAILED if the kernel cannot compute the distance
ts
const [a, b] = await snaptrude.design.query.listMasses();
const brepA = await snaptrude.design.query.geometry.getBrep(a);
const brepB = await snaptrude.design.query.geometry.getBrep(b);
if (brepA && brepB) {
  const { distance, pointA, pointB } = await snaptrude.core.geom.query.brep.getDistance(
    brepA,
    brepB
  );
  console.log("clearance:", distance);
}

Errors ​

Failed calls reject with a typed PluginError — see Error Handling. Conditions specific to this namespace:

CodeThrown byWhendetails
HANDLE_INVALIDall methodsThe brep (or child topology) handle is invalid, foreign, or stale — brep handles go stale on undo/redo/re-topologize—
VALIDATIONgetEdgeCurveThe edge does not belong to the given brep—
PRECONDITION_FAILEDgetEdgeCurveThe edge is a rational (weighted) spline — the "spline" wire form carries no weights, so reporting it would describe a different curve. hint: sample the edge's shape instead—
OPERATION_FAILEDgetEdgeCurveThe edge carries no exact line/arc/circle/spline curve geometry (never the case for breps authored via core.geom.create)—
OPERATION_FAILEDgetVolumeThe geometry kernel could not compute the volume — the brep is not a closed solid—
OPERATION_FAILEDgetDistanceThe geometry kernel could not compute the distance between the two solids—

Beyond handle resolution these reads are total — degenerate topology comes back as []/null results, not errors. The exceptions: getDistance and getVolume run on the geometry kernel and can throw OPERATION_FAILED, and getEdgeCurve throws VALIDATION when the edge is not on the given brep (PRECONDITION_FAILED for a rational spline edge).