ClassCAD
npm install @buerli.io/classcad
This library connects Buerli with ClassCAD, the CAD backend. Buerli/classcad in particular functions as a bridge between the Javascript client and ClassCAD, allowing you to pick specific interfaces (SocketIO, WASM, ...).
Note: In order to observe Javascript conventions the ClassCAD API is unwrapped in Buerli. Where normally each function would return an object with a
resultproperty, and amessagesproperty for errors, all ClassCAD API functions in Buerli return the result directly and throw errors as exceptions that can be caught with try/catch.
init
Initializes Buerli with the given factory and options. This function is typically called once at the start of your application to set up the Buerli environment. It tells Buerli where ClassCAD is running and how to connect to it.
Declaration
(source: function, options?: PARTIAL<{
theme: {
primary: string,
secondary: string,
dark: string,
highlightedGeom: string,
hoveredGeom: string,
},
config: {
geometry: {
disabled?: boolean,
meshes?: ElementConfig & {
wireframe?: boolean,
depthWrite?: boolean,
},
edges?: ElementConfig,
points?: ElementConfig,
},
},
}>): null
type ElementConfig = {
hidden?: boolean,
color?: any,
opacity?: number,
};
Params
| Name | Type | Default | Description |
|---|---|---|---|
| source | function | Factory function (WASM, SOCKETIO) | |
| options | object | Optional configuration options for Buerli |
Returns null
Example
import { init, WASMClient } from '@buerli.io/classcad'
// Get your key from the user area on classcad.ch
const classcadKey = '...'
init((drawingID) => new WASMClient(drawingID, { classcadKey }))
WASMClient
Initializes ClassCAD WASM, meaning ClassCAD will run in the browser using WebAssembly.
Declaration
(drawingID: number, options: object): object
Params
| Name | Type | Default | Description |
|---|---|---|---|
| drawingID | number | The drawingID you receive from init() | |
| options | object | Configuration |
Returns object
Example
import { init, WASMClient } from '@buerli.io/classcad'
// Get your key from the user area on classcad.ch
const classcadKey = '...'
init((drawingID) => new WASMClient(drawingID, { classcadKey }))
SocketIOClient
Initializes the ClassCAD SocketIO, meaning ClassCAD will run on a server and communicate with your application via Socket.IO.
Declaration
(url: string, drawingID: number): object
Params
| Name | Type | Default | Description |
|---|---|---|---|
| url | string | URL | |
| drawingID | number | The drawingID you receive from init() |
Returns object
Example
import { init, SocketIOClient } from '@buerli.io/classcad'
// Run your ClassCAD via Docker, or natively
init((drawingID) => new SocketIOClient('https://localhost:9091', drawingID))
BuerliCadFacade
This class mediates between ClassCAD and buerli and provides direct Threejs integrations. It allows you to connect to a live drawing and carry out operations on it. You can use this class to create, modify, and query geometries in buerli/ClassCAD.
Example
import { BuerliCadFacade } from '@buerli.io/classcad'
const facade = new BuerliCadFacade()
await facade.connect()
const api = facade.api.v1
// Create a part
const part = await api.part.create({ name: 'Flange' })
// Create a parametric box in it
const box = await api.part.box({ id: part })
Properties
.api
The API object that provides methods to interact with the ClassCAD API.
Note: The ClassCAD API fundamentally is based on server round-trips and must function the same between REST, SocketIO, WASM, and other interfaces and languages. This means that the API is asynchronous. All functions typically return a promise that yields an object with a
resultproperty, and amessagesproperty, which contains errors and warnings. The raw javascript ClassCAD API would be something like this:
const { result: part, messages } = await api.part.create({ name: 'Flange' })
if (messages.length > 0) {
throw new Error(messages)
}
const { result: box, messages } = await api.part.box({ id: part })
if (messages.length > 0) {
throw new Error(messages)
}
Note: With the
.apiproperty of this class the API has been unwrapped for a more conventional usage in Javascript. This means that all API functions yield the result directly and throw errors as exceptions that can be caught with try/catch. Warnings will be logged to the console.
try {
const part = await api.part.create({ name: 'Flange' })
const box = await api.part.box({ id: part })
} catch (error) {
console.error('An error occured:', error)
}
.drawingId
The unique identifier (UUID) for the session.
Functions
.connect(drawingName?: string)
Creates a new buerli drawing and connects it to ClassCAD. It will use the connection type provided in the init function that has to be called beforehand.
Returns Promise<DrawingID | null>
.disconnect()
Disconnects the drawing from ClassCAD and resets the drawing.
Returns void
.undo(state?: string)
Undo the last operation or if state isn't empty, load the state with name = state.
Returns void
This is experimental and should not be used by production applications!
Is not available in ClassCAD WASM
.redo(state?: string)
Redo the last undo or if state isn't empty, load the state with name = state.
Returns void
This is experimental and should not be used by production applications!
Is not available in ClassCAD WASM
.createBufferGeometry(objectId?: ObjectID|ObjectID[])
Creates a THREEJS buffer geometry of any product (part or assembly).
Returns Promise<BufferGeometry[] | undefined>
.createScene(objectId?: ObjectID|ObjectID[], options?: { meshPerGeometry?: boolean; structureOnly?: boolean })
Creates a THREEJS scene of any product (part or assembly).
Returns Promise<{ scene: Scene; nodes: { [key: string]: Object3D }; materials: { [key: string]: Material } }>
.createThreeShape(owner: ObjectID, shape: THREE.Shape)
Creates a curve from THREEJS shapes.
Returns Promise<object>
.createPolyline(owner: ObjectID, fPts: { point: THREE.Vector3; radius: number }[], close = true)
Creates a Polyline2D.
Returns Promise<object>
.selectGeometry(types: GrT[], count?: number)
Halts execution until a specific geometry is selected by the user.
Returns Promise<InteractionInfo[]>