UNPKG

@bitbybit-dev/jscad-worker

Version:

Bit By Bit Developers JSCAD Based CAD Library to Program Geometry Via WebWorker

133 lines (132 loc) 5.45 kB
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; import { JSCADBooleans } from "./booleans"; import { JSCADExpansions } from "./expansions"; import { JSCADExtrusions } from "./extrusions"; import { JSCADHulls } from "./hulls"; import { JSCADPath } from "./path"; import { JSCADPolygon } from "./polygon"; import { JSCADShapes } from "./shapes"; import { JSCADText } from "./text"; import { JSCADColors } from "./colors"; /** * Contains various functions for Solid meshes from JSCAD library https://github.com/jscad/OpenJSCAD.org * Thanks JSCAD community for developing this kernel */ export class JSCAD { constructor(jscadWorkerManager) { this.jscadWorkerManager = jscadWorkerManager; this.booleans = new JSCADBooleans(jscadWorkerManager); this.expansions = new JSCADExpansions(jscadWorkerManager); this.extrusions = new JSCADExtrusions(jscadWorkerManager); this.hulls = new JSCADHulls(jscadWorkerManager); this.path = new JSCADPath(jscadWorkerManager); this.polygon = new JSCADPolygon(jscadWorkerManager); this.shapes = new JSCADShapes(jscadWorkerManager); this.text = new JSCADText(jscadWorkerManager); this.colors = new JSCADColors(jscadWorkerManager); } /** * Converts the Jscad mesh to polygon points representing triangles of the mesh. * @param inputs Jscad mesh * @returns polygon points * @group conversions * @shortname to polygon points * @drawable false */ toPolygonPoints(inputs) { return __awaiter(this, void 0, void 0, function* () { return this.jscadWorkerManager.genericCallToWorkerPromise("toPolygonPoints", inputs); }); } /** * Transforms the Jscad solid meshes with a given list of transformations. * @param inputs Solids with the transformation matrixes * @returns Solids with a transformation * @group transforms * @shortname transform solids * @drawable true */ transformSolids(inputs) { return __awaiter(this, void 0, void 0, function* () { return this.jscadWorkerManager.genericCallToWorkerPromise("transformSolids", inputs); }); } /** * Transforms the Jscad solid mesh with a given list of transformations. * @param inputs Solid with the transformation matrixes * @returns Solid with a transformation * @group transforms * @shortname transform solid * @drawable true */ transformSolid(inputs) { return __awaiter(this, void 0, void 0, function* () { return this.jscadWorkerManager.genericCallToWorkerPromise("transformSolid", inputs); }); } /** * Downloads the binary STL file from a 3D solid * @param inputs 3D Solid * @group io * @shortname solid to stl */ downloadSolidSTL(inputs) { return __awaiter(this, void 0, void 0, function* () { const res = yield this.jscadWorkerManager.genericCallToWorkerPromise("downloadSolidSTL", inputs); this.downloadFile(res.blob, inputs.fileName, "stl"); }); } /** * Downloads the binary STL file from a 3D solids * @param inputs 3D Solid * @group io * @shortname solids to stl */ downloadSolidsSTL(inputs) { return __awaiter(this, void 0, void 0, function* () { const res = yield this.jscadWorkerManager.genericCallToWorkerPromise("downloadSolidsSTL", inputs); this.downloadFile(res.blob, inputs.fileName, "stl"); }); } /** * Downloads the dxf file from jscad geometry. Supports paths and meshes in array. * @param inputs 3D geometry * @group io * @shortname geometry to dxf */ downloadGeometryDxf(inputs) { return __awaiter(this, void 0, void 0, function* () { const res = yield this.jscadWorkerManager.genericCallToWorkerPromise("downloadGeometryDxf", inputs); this.downloadFile(res.blob, inputs.fileName, "dxf"); }); } /** * Downloads the 3MF file from jscad geometry. * @param inputs 3D geometry * @group io * @shortname geometry to 3mf */ downloadGeometry3MF(inputs) { return __awaiter(this, void 0, void 0, function* () { const res = yield this.jscadWorkerManager.genericCallToWorkerPromise("downloadGeometry3MF", inputs); this.downloadFile(res.blob, inputs.fileName, "3mf"); }); } downloadFile(blob, fileName, extension) { const blobUrl = URL.createObjectURL(blob); const fileLink = document.createElement("a"); fileLink.href = blobUrl; fileLink.target = "_self"; fileLink.download = fileName + "." + extension; fileLink.click(); fileLink.remove(); } }