UNPKG

@achirita/blox

Version:

A CAD library for building 3D models in the browser.

137 lines (136 loc) 5.57 kB
import { Face, Edge, Vertex } from './index'; import { Vector, Axis, Plane } from '../math'; export class Solid { /** * Creates a new solid from a set of faces. * @param {...Face} faces - One or more `Face` objects to create the solid from. * @returns {Solid} A new `Solid` object representing the created solid. */ static fromFaces(...faces: Face[]): Solid; constructor(wrapped: any); /** * Returns the wrapped OpenCascade object. * @private */ private get wrapped(); /** * Retrieves all faces of the solid. * @returns {Face[]} An array of `Face` objects representing the solid's faces. */ get faces(): Face[]; /** * Retrieves all edges of the solid. * @returns {Edge[]} An array of `Edge` objects representing the solid's edges. */ get edges(): Edge[]; /** * Retrieves all vertices of the solid. * @returns {Vertex[]} An array of `Vertex` objects representing the solid's vertices. */ get vertices(): Vertex[]; /** * Computes the center of mass of the solid. * @returns {Vector} A `Vector` object representing the center of mass of the solid. */ get centerOfMass(): Vector; /** * Computes the volume of the solid. * @returns {number} The volume of the solid. */ get volume(): number; /** * Translates the solid by a specified offset. * @param {Vector} offset - The translation offset. * @returns {Solid} A new `Solid` object representing the translated solid. */ translate(offset: Vector): Solid; /** * Rotates the solid around a specified axis by a given angle. * @param {Object} parameters - Rotation parameters. * @param {Axis} parameters.axis - The axis to rotate around. * @param {number} parameters.angle - The rotation angle in radians. * @returns {Solid} A new `Solid` object representing the rotated solid. */ rotate({ axis, angle }: { axis: Axis; angle: number; }): Solid; /** * Mirrors the solid across a specified plane. * @param {Plane} plane - The plane to mirror across. * @returns {Solid} A new `Solid` object representing the mirrored solid. */ mirror(plane: Plane): Solid; /** * Scales the solid by a specified factor. * @param {number} factor - The scaling factor. * @returns {Solid} A new `Solid` object representing the scaled solid. */ scale(factor: number): Solid; /** * Splits the solid into multiple parts using a specified tool. * @param {Plane} tool - The tool used to split the solid. * @returns {Solid[]} An array of `Solid` objects representing the split parts. */ split(tool: Plane): Solid[]; /** * Cuts the solid using one or more tools (other solids). * @param {...Solid} tools - One or more `Solid` objects to use as cutting tools. * @returns {Solid[]} An array of `Solid` objects representing the result. */ cut(...tools: Solid[]): Solid[]; /** * Intersects the solid with one or more tools (other solids). * @param {...Solid} tools - One or more `Solid` objects to intersect with. * @returns {Solid[]} An array of `Solid` objects representing the result. */ intersect(...tools: Solid[]): Solid[]; /** * Joins the solid with one or more tools (other solids). * @param {...Solid} tools - One or more `Solid` objects to join with. * @returns {Solid[]} An array of `Solid` objects representing the result. */ join(...tools: Solid[]): Solid[]; /** * Applies a fillet (rounded edge) to selected edges of the solid. * @param {Object} parameters - Fillet parameters. * @param {function(Edge): boolean} parameters.selector - A function to select edges for the fillet. * @param {number} parameters.radius - The radius of the fillet. * @returns {Solid} A new `Solid` object with the fillet applied. */ fillet({ selector, radius }: { selector: (arg0: Edge) => boolean; radius: number; }): Solid; /** * Applies a chamfer (beveled edge) to selected edges of the solid. * @param {Object} parameters - Chamfer parameters. * @param {function(Edge): boolean} parameters.selector - A function to select edges for the chamfer. * @param {number} parameters.distance - The distance of the chamfer. * @returns {Solid} A new `Solid` object with the chamfer applied. */ chamfer({ selector, distance }: { selector: (arg0: Edge) => boolean; distance: number; }): Solid; /** * Creates a hollow version of the solid by offsetting its faces by a specified thickness. * @param {Object} parameters - Shell parameters. * @param {function(Face): boolean} parameters.selector - A function to select faces for the shell. * @param {number} parameters.thickness - The thickness of the shell. Positive value shells outwards, negative value shells inwards. * @param {('arc'|'tangent'|'intersection')} [parameters.joinType="intersection"] - The join type for the shell. * @returns {Solid} A new `Solid` object representing the shelled solid. */ shell({ selector, thickness, joinType }: { selector: (arg0: Face) => boolean; thickness: number; joinType?: ("arc" | "tangent" | "intersection"); }): Solid; /** * Computes the hash code for the solid. * @returns {number} The hash code. * @private */ private hashCode; #private; }