@bitbybit-dev/manifold-worker
Version:
Bit By Bit Developers Manifold Based CAD Library to Program Geometry Via WebWorker
89 lines (88 loc) • 3.41 kB
JavaScript
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());
});
};
/**
* Contains various functions for Solid meshes from Manifold library https://github.com/elalish/manifold
* Thanks Manifold community for developing this kernel
*/
export class ManifoldShapes {
constructor(manifoldWorkerManager) {
this.manifoldWorkerManager = manifoldWorkerManager;
}
/**
* Convert a Mesh into a Manifold, retaining its properties and merging only
* the positions according to the merge vectors. Will throw an error if the
* result is not an oriented 2-manifold. Will collapse degenerate triangles
* and unnecessary vertices.
*
* All fields are read, making this structure suitable for a lossless
* round-trip of data from manifoldToMesh(). For multi-material input, use
* reserveIDs() to set a unique originalID for each material, and sort the
* materials into triangle runs.
* @param inputs mesh definition
* @returns manifold
* @group create
* @shortname manifold from mesh
* @drawable true
*/
manifoldFromMesh(inputs) {
return this.manifoldWorkerManager.genericCallToWorkerPromise("manifold.shapes.manifoldFromMesh", inputs);
}
/**
* Create a 3D cube shape
* @param inputs Cube parameters
* @returns Cube solid
* @group primitives
* @shortname cube
* @drawable true
*/
cube(inputs) {
return __awaiter(this, void 0, void 0, function* () {
return this.manifoldWorkerManager.genericCallToWorkerPromise("manifold.shapes.cube", inputs);
});
}
/**
* Create a 3D sphere shape
* @param inputs Sphere parameters
* @returns Sphere solid
* @group primitives
* @shortname sphere
* @drawable true
*/
sphere(inputs) {
return __awaiter(this, void 0, void 0, function* () {
return this.manifoldWorkerManager.genericCallToWorkerPromise("manifold.shapes.sphere", inputs);
});
}
/**
* Create a 3D tetrahedron shape
* @returns Tetrahedron solid
* @group primitives
* @shortname tetrahedron
* @drawable true
*/
tetrahedron() {
return __awaiter(this, void 0, void 0, function* () {
return this.manifoldWorkerManager.genericCallToWorkerPromise("manifold.shapes.tetrahedron", {});
});
}
/**
* Create a 3D cylinder shape
* @param inputs Cylinder parameters
* @returns Cylinder solid
* @group primitives
* @shortname cylinder
* @drawable true
*/
cylinder(inputs) {
return __awaiter(this, void 0, void 0, function* () {
return this.manifoldWorkerManager.genericCallToWorkerPromise("manifold.shapes.cylinder", inputs);
});
}
}