Skip to main content

Geometry

How the geometry of solids is shown, and the bounds of a model. The three.js geometry itself, made from the graphic ClassCAD sends, is for apps that work with faces and edges directly.

Types​

GeometryConfig​

type GeometryConfig = {
disabled?: boolean;
edges?: ElementConfig;
meshes?: ElementConfig & {
depthWrite?: boolean;
wireframe?: boolean;
};
points?: ElementConfig;
};

How the geometry of solids is shown in the 3D view of @buerli.io/react.

It is set for all solids (config.geometry in the options of init of @buerli.io/classcad), and for a product or a solid with setConfig of a drawing's api.geometry; the solid's goes over the product's, which goes over the one for all.

Example​

import { init, WASMClient } from '@buerli.io/classcad'
import { getDrawing } from '@buerli.io/core'

// For all solids: dark edges, no points
init(drawingId => new WASMClient(drawingId, { token: 'ccpk_…' }), {
config: { geometry: { edges: { color: '#333333' }, points: { hidden: true } } },
})

// For one solid: a faded wireframe that the pointer does not pick
getDrawing(drawingId).api.geometry.setConfig(solidId, { disabled: true, meshes: { wireframe: true } })
// … and back to how all others are shown
getDrawing(drawingId).api.geometry.setConfig(solidId, null)

Properties​

PropertyTypeDescription
disabled?booleanShows the faces faded (opacity 0.1), and lets the pointer pass through the geometry.
edges?ElementConfigHow the edges are shown: hidden, color and opacity (for edges without their own). Hidden edges are still picked by the pointer.
meshes?ElementConfig & { depthWrite?: boolean; wireframe?: boolean; }How the faces are shown: hidden, color, opacity (0 to 1, for faces without their own), wireframe to draw them as lines, and depthWrite: false to let what is behind them show.
points?ElementConfigHow the points are shown: hidden, color and opacity.

GeometryBounds​

type GeometryBounds = {
center: THREE.Vector3;
max: THREE.Vector3;
min: THREE.Vector3;
radius: number;
};

The bounds of a model, in world coordinates: a box (min, max) and the sphere around it (center, radius).

geometry.bounds of a drawing holds the bounds of all its products, for example to fit the camera; it changes when graphic comes in or products are added or removed. Before there is any, it is a box from -100 to 100.

Example​

import { getDrawing } from '@buerli.io/core'
import * as THREE from 'three'

// Look at the whole model from the front
const { center, radius } = getDrawing(drawingId).geometry.bounds
camera.position.copy(center).add(new THREE.Vector3(0, 0, radius * 3))
camera.lookAt(center)

Properties​

PropertyTypeDescription
centerTHREE.Vector3The center of the box and of the sphere.
maxTHREE.Vector3The box's largest corner.
minTHREE.Vector3The box's smallest corner.
radiusnumberThe radius of the sphere around the box.

Advanced​

Most apps do not need these directly: types they meet through the exports above, and what is there for special cases or for building on buerli itself.

ArcGeometry​

An arc or a circle of a solid (or of a sketch), as three.js line segments, with its center, radius and plane.

Example​

import { ScgGraphicType } from '@buerli.io/classcad'
import { getDrawing } from '@buerli.io/core'

// The holes of a solid, by the circles of their edges: center and diameter
const arcs = getDrawing(drawingId).geometry.cache[solidId]?.arcs ?? []
for (const circle of arcs.filter(arc => arc.type === ScgGraphicType.CIRCLE)) {
console.log(circle.center.toArray(), circle.radius * 2)
}

Properties​

PropertyTypeDescription
anglenumberThe angle the arc spans, in radians.
centerVector3The center.
colorColor | undefinedThe color ClassCAD gave it (its material), if any.
container{ id: number; ownerId: number; type: NONE | BREP | POLYBREP | CURVEARRAY; }The container (solid) it is in.
container.idnumberThe container's id, the solid's CAD entity, as in geometry.cache.
container.ownerIdnumberThe solid object it belongs to, in the structure tree.
container.typeNONE | BREP | POLYBREP | CURVEARRAYWhat kind of container: brep, polyBrep or curveArray.
endVector3Where it ends; where it starts for a circle.
geometryBufferGeometry<NormalBufferAttributes, BufferGeometryEventMap>The arc, as line segments.
graphicIdnumberThe edge's id in its container.
layeranyThe layer ClassCAD put it on.
normalVector3The normal of the arc's plane, of length 1.
opacitynumberThe opacity ClassCAD gave it, from 0 to 1; 0 when it has none.
operationIdanyThe operation (feature) that made a face.
radiusnumberThe radius.
rawGraphicScgGraphicElement | nullThe element as ClassCAD sent it (ScgGraphicElement).
startVector3Where the arc starts.
typeScgGraphicTypearc or circle, or curveArc or curveCircle in a sketch's curves.

CircleGeometry​

type CircleGeometry = ArcGeometry;

A circle of a solid: an ArcGeometry whose type is circle (or curveCircle).


ConeGeometry​

A conical face of a solid: a MeshGeometry with its cone.

Properties​

PropertyTypeDescription
axisVector3The cone's axis, of length 1.
colorColor | undefinedThe color ClassCAD gave it (its material), if any.
container{ id: number; ownerId: number; type: NONE | BREP | POLYBREP | CURVEARRAY; }The container (solid) it is in.
container.idnumberThe container's id, the solid's CAD entity, as in geometry.cache.
container.ownerIdnumberThe solid object it belongs to, in the structure tree.
container.typeNONE | BREP | POLYBREP | CURVEARRAYWhat kind of container: brep, polyBrep or curveArray.
geometryBufferGeometry<NormalBufferAttributes, BufferGeometryEventMap>The face's triangles, with normals.
graphicIdnumberThe face's id in its container.
heightnumberIts height along the axis.
isValidbooleanWhether the face has vertices; faces without are left out.
layeranyThe layer ClassCAD put it on.
loopsnumber[][]The loops of edges around the face, each a list of edge ids.
opacitynumberThe opacity ClassCAD gave it, from 0 to 1; 0 when it has none.
operationIdanyThe operation (feature) that made a face.
originVector3The center of the cone's base.
radiusBottomnumberThe radius at the base.
radiusTopnumberThe radius at the top.
rawGraphicScgGraphicElement | nullThe element as ClassCAD sent it (ScgGraphicElement).
typeScgGraphicTypecone.

ContainerGeometryT​

The three.js geometry of a container, a solid: its faces, edges and points, made from the graphic ClassCAD sent.

geometry.cache of a drawing holds it by container id, the ids in solids of a part. Its coordinates are those of the part; the product's transformation (api.structure.calculateGlobalTransformation) places it in the world.

Example​

import { getDrawing } from '@buerli.io/core'

const { geometry, structure } = getDrawing(drawingId)
const part = structure.currentProduct ? structure.tree[structure.currentProduct] : undefined
// All faces of the part's solids, as three.js geometries
const faces = (part?.solids ?? []).flatMap(id => geometry.cache[id]?.meshes.map(mesh => mesh.geometry) ?? [])

Properties​

PropertyTypeDescription
arcsArcGeometry[]The arcs and circles.
box{ max: Vector3; min: Vector3; }The bounding box, in the coordinates of the part.
box.maxVector3Its largest corner.
box.minVector3Its smallest corner.
colorColor | undefinedThe color ClassCAD gave it (its material), if any.
container{ id: number; ownerId: number; type: NONE | BREP | POLYBREP | CURVEARRAY; }The container (solid) it is in.
container.idnumberThe container's id, the solid's CAD entity, as in geometry.cache.
container.ownerIdnumberThe solid object it belongs to, in the structure tree.
container.typeNONE | BREP | POLYBREP | CURVEARRAYWhat kind of container: brep, polyBrep or curveArray.
edgesEdgeGeometry[]The other curved edges.
graphicIdnumberThe container's id, the solid's CAD entity.
layeranyThe layer ClassCAD put it on.
linesLineGeometry[]The straight edges.
mapRecord<GraphicID, GeometryElement>The faces and edges by id.
meshesMeshGeometry[]The faces.
opacitynumberThe opacity ClassCAD gave it, from 0 to 1; 0 when it has none.
operationIdanyThe operation (feature) that made a face.
pointsPointGeometry[]The points, the ends of the edges.
rawGraphicScgGraphicElement | nullThe element as ClassCAD sent it (ScgGraphicElement).
typeScgGraphicTypeThe kind of container: brep for a solid, polyBrep for a mesh solid, curveArray for a sketch's curves.

CylinderGeometry​

A cylindrical face of a solid: a MeshGeometry with its cylinder.

Properties​

PropertyTypeDescription
axisVector3The cylinder's axis, of length 1.
colorColor | undefinedThe color ClassCAD gave it (its material), if any.
container{ id: number; ownerId: number; type: NONE | BREP | POLYBREP | CURVEARRAY; }The container (solid) it is in.
container.idnumberThe container's id, the solid's CAD entity, as in geometry.cache.
container.ownerIdnumberThe solid object it belongs to, in the structure tree.
container.typeNONE | BREP | POLYBREP | CURVEARRAYWhat kind of container: brep, polyBrep or curveArray.
geometryBufferGeometry<NormalBufferAttributes, BufferGeometryEventMap>The face's triangles, with normals.
graphicIdnumberThe face's id in its container.
heightnumberIts height along the axis.
isValidbooleanWhether the face has vertices; faces without are left out.
layeranyThe layer ClassCAD put it on.
loopsnumber[][]The loops of edges around the face, each a list of edge ids.
opacitynumberThe opacity ClassCAD gave it, from 0 to 1; 0 when it has none.
operationIdanyThe operation (feature) that made a face.
originVector3The center of the cylinder's base.
radiusnumberIts radius.
rawGraphicScgGraphicElement | nullThe element as ClassCAD sent it (ScgGraphicElement).
typeScgGraphicTypecylinder.

EdgeGeometry​

A curved edge of a solid that is not an arc (or a spline of a sketch), as three.js line segments, with its ends.

Properties​

PropertyTypeDescription
colorColor | undefinedThe color ClassCAD gave it (its material), if any.
container{ id: number; ownerId: number; type: NONE | BREP | POLYBREP | CURVEARRAY; }The container (solid) it is in.
container.idnumberThe container's id, the solid's CAD entity, as in geometry.cache.
container.ownerIdnumberThe solid object it belongs to, in the structure tree.
container.typeNONE | BREP | POLYBREP | CURVEARRAYWhat kind of container: brep, polyBrep or curveArray.
endVector3Where it ends.
geometryBufferGeometry<NormalBufferAttributes, BufferGeometryEventMap>The curve, as line segments.
graphicIdnumberThe edge's id in its container.
layeranyThe layer ClassCAD put it on.
opacitynumberThe opacity ClassCAD gave it, from 0 to 1; 0 when it has none.
operationIdanyThe operation (feature) that made a face.
rawGraphicScgGraphicElement | nullThe element as ClassCAD sent it (ScgGraphicElement).
startVector3Where the curve starts.
typeScgGraphicTypenurbsCurve, or curveSpline in a sketch's curves.

GeometryElement​

type GeometryElement =
| MeshGeometry
| PlaneGeometry
| CylinderGeometry
| ConeGeometry
| SphereGeometry
| LineGeometry
| EdgeGeometry
| ArcGeometry
| CircleGeometry
| PointGeometry;

An element of the geometry of a solid: a face, an edge or a point.

Its type (a GraphicType) tells which: plane, cylinder, cone, sphere and nurbsSurface are faces (MeshGeometry), line, arc, circle and nurbsCurve edges, point a point.

Example​

import { ScgGraphicType } from '@buerli.io/classcad'
import { CylinderGeometry, getDrawing } from '@buerli.io/core'

// The cylindrical faces of the model, with their radius
const { api } = getDrawing(drawingId)
const cylinders = api.geometry.filter(elem => elem.type === ScgGraphicType.CYLINDER) as CylinderGeometry[]
cylinders.forEach(cylinder => console.log(cylinder.graphicId, cylinder.radius))

isEqualGeometry()​

function isEqualGeometry(a, b): boolean;

Returns whether two elements of the geometry are the same: the same graphicId and type.

Parameters​

ParameterType
aGeometryElement
bGeometryElement

Returns​

boolean


LineGeometry​

A straight edge of a solid (or a line of a sketch), as three.js geometry, with its ends.

Properties​

PropertyTypeDescription
colorColor | undefinedThe color ClassCAD gave it (its material), if any.
container{ id: number; ownerId: number; type: NONE | BREP | POLYBREP | CURVEARRAY; }The container (solid) it is in.
container.idnumberThe container's id, the solid's CAD entity, as in geometry.cache.
container.ownerIdnumberThe solid object it belongs to, in the structure tree.
container.typeNONE | BREP | POLYBREP | CURVEARRAYWhat kind of container: brep, polyBrep or curveArray.
endVector3Where it ends.
geometryBufferGeometry<NormalBufferAttributes, BufferGeometryEventMap>The line, as a line segment.
graphicIdnumberThe edge's id in its container.
layeranyThe layer ClassCAD put it on.
opacitynumberThe opacity ClassCAD gave it, from 0 to 1; 0 when it has none.
operationIdanyThe operation (feature) that made a face.
rawGraphicScgGraphicElement | nullThe element as ClassCAD sent it (ScgGraphicElement).
startVector3Where the line starts.
typeScgGraphicTypeline, or curveLine in a sketch's curves.

MeshGeometry​

A face of a solid, as three.js geometry: its triangles, its kind, and the loops of edges around it.

A planar, cylindrical, conical or spherical face is a PlaneGeometry, CylinderGeometry, ConeGeometry or SphereGeometry, with what describes its surface. Its coordinates are those of its part; the product's transformation (api.structure.calculateGlobalTransformation) places it in the world.

Example​

import { getDrawing, MeshGeometry } from '@buerli.io/core'
import * as THREE from 'three'

// A face of a solid as a mesh of its own, placed in the world
const { api, geometry } = getDrawing(drawingId)
const face = geometry.cache[solidId]?.map[faceId] as MeshGeometry | undefined
if (face) {
const mesh = new THREE.Mesh(face.geometry, new THREE.MeshStandardMaterial({ color: 'orange' }))
mesh.applyMatrix4(api.structure.calculateGlobalTransformation(productId))
scene.add(mesh)
}

Properties​

PropertyTypeDescription
colorColor | undefinedThe color ClassCAD gave it (its material), if any.
container{ id: number; ownerId: number; type: NONE | BREP | POLYBREP | CURVEARRAY; }The container (solid) it is in.
container.idnumberThe container's id, the solid's CAD entity, as in geometry.cache.
container.ownerIdnumberThe solid object it belongs to, in the structure tree.
container.typeNONE | BREP | POLYBREP | CURVEARRAYWhat kind of container: brep, polyBrep or curveArray.
geometryBufferGeometry<NormalBufferAttributes, BufferGeometryEventMap>The face's triangles, with normals.
graphicIdnumberThe face's id in its container.
isValidbooleanWhether the face has vertices; faces without are left out.
layeranyThe layer ClassCAD put it on.
loopsnumber[][]The loops of edges around the face, each a list of edge ids.
opacitynumberThe opacity ClassCAD gave it, from 0 to 1; 0 when it has none.
operationIdanyThe operation (feature) that made a face.
rawGraphicScgGraphicElement | nullThe element as ClassCAD sent it (ScgGraphicElement).
typeScgGraphicTypeThe kind of face: plane, cylinder, cone, sphere or nurbsSurface.

PlaneGeometry​

A planar face of a solid: a MeshGeometry with its plane.

Properties​

PropertyTypeDescription
colorColor | undefinedThe color ClassCAD gave it (its material), if any.
container{ id: number; ownerId: number; type: NONE | BREP | POLYBREP | CURVEARRAY; }The container (solid) it is in.
container.idnumberThe container's id, the solid's CAD entity, as in geometry.cache.
container.ownerIdnumberThe solid object it belongs to, in the structure tree.
container.typeNONE | BREP | POLYBREP | CURVEARRAYWhat kind of container: brep, polyBrep or curveArray.
geometryBufferGeometry<NormalBufferAttributes, BufferGeometryEventMap>The face's triangles, with normals.
graphicIdnumberThe face's id in its container.
isValidbooleanWhether the face has vertices; faces without are left out.
layeranyThe layer ClassCAD put it on.
loopsnumber[][]The loops of edges around the face, each a list of edge ids.
normalVector3The plane's normal, of length 1.
opacitynumberThe opacity ClassCAD gave it, from 0 to 1; 0 when it has none.
operationIdanyThe operation (feature) that made a face.
pointOnPlaneVector3A point of the plane.
rawGraphicScgGraphicElement | nullThe element as ClassCAD sent it (ScgGraphicElement).
typeScgGraphicTypeplane.

PointGeometry​

A point of a solid (or of a sketch): an end of edges, with the edges it is an end of.

Properties​

PropertyTypeDescription
colorColor | undefinedThe color ClassCAD gave it (its material), if any.
container{ id: number; ownerId: number; type: NONE | BREP | POLYBREP | CURVEARRAY; }The container (solid) it is in.
container.idnumberThe container's id, the solid's CAD entity, as in geometry.cache.
container.ownerIdnumberThe solid object it belongs to, in the structure tree.
container.typeNONE | BREP | POLYBREP | CURVEARRAYWhat kind of container: brep, polyBrep or curveArray.
geometryVector3Where the point is, as for position.
graphicIdnumberThe point's id in its container.
keystringThe point's key in its container, <graphicId>|point.
layeranyThe layer ClassCAD put it on.
opacitynumberThe opacity ClassCAD gave it, from 0 to 1; 0 when it has none.
operationIdanyThe operation (feature) that made a face.
owners{ ownerId: number; type: PointType; }[] & { ownerId: number; type: PointType; }[]The edges the point is an end of: each edge's id (ownerId) and which end it is (type).
positionVector3Where the point is.
rawGraphicScgGraphicElement | nullThe element as ClassCAD sent it (ScgGraphicElement).
typeScgGraphicTypepoint, or curvePoint in a sketch's curves.

ProductElement​

type ProductElement = GeometryElement & {
productId: ObjectID;
};

An element of the geometry with the product it is in: the data of a SelectedItem in BuerliScope.

The product places the element in the world (see Measure.transform).

Type Declaration​

NameTypeDescription
productIdObjectIDThe product (part or assembly instance) the element belongs to.

Example​

import { BuerliScope, getDrawing, ProductElement } from '@buerli.io/core'

// The faces and edges the active selector holds, each with the product it is in
const { selection } = getDrawing(drawingId)
const items = selection.active ? selection.refs[selection.active].items : []
const elements = items.filter(item => item.scope === BuerliScope).map(item => item.data as ProductElement)

SphereGeometry​

A spherical face of a solid: a MeshGeometry with its radius.

Properties​

PropertyTypeDescription
colorColor | undefinedThe color ClassCAD gave it (its material), if any.
container{ id: number; ownerId: number; type: NONE | BREP | POLYBREP | CURVEARRAY; }The container (solid) it is in.
container.idnumberThe container's id, the solid's CAD entity, as in geometry.cache.
container.ownerIdnumberThe solid object it belongs to, in the structure tree.
container.typeNONE | BREP | POLYBREP | CURVEARRAYWhat kind of container: brep, polyBrep or curveArray.
geometryBufferGeometry<NormalBufferAttributes, BufferGeometryEventMap>The face's triangles, with normals.
graphicIdnumberThe face's id in its container.
isValidbooleanWhether the face has vertices; faces without are left out.
layeranyThe layer ClassCAD put it on.
loopsnumber[][]The loops of edges around the face, each a list of edge ids.
opacitynumberThe opacity ClassCAD gave it, from 0 to 1; 0 when it has none.
operationIdanyThe operation (feature) that made a face.
radiusnumberThe sphere's radius.
rawGraphicScgGraphicElement | nullThe element as ClassCAD sent it (ScgGraphicElement).
typeScgGraphicTypesphere.