replicad Documentation

website·Indexed 33 days ago

https://replicad.xyz

A CAD library for creating 2D and 3D shapes programmatically. The documentation includes a comprehensive API reference for sketching, extrusion, and geometric operations, as well as tutorials and recipes for designing complex objects like watering cans and Gridfinity components.

Tokens
86.7K
Snippets
896
Records
1K
Agent score
67%

What's inside replicad

  1. Overview of GenericSketcher

    Sketchers are used to draw two-dimensional shapes using curve segments. The process begins by defining the starting point using movePointerTo. Each subsequent sketching method draws a curve (line, arc, elliptic arc, or bezier curve) from the current pointer position to a new end point. The end point of one segment becomes the start point of the next. Once the sketching process is complete, a Sketch object is returned, which can then be used to add three-dimensionality.
  2. Overview of the replicad CAD API

    replicad is a JavaScript library for 3D modeling that allows developers to sketch, shape, and modify geometry using a streamlined API inspired by cadquery and Cascade Studio. It is powered by the OpenCascade kernel, providing professional CAD features such as STEP export, fillets, and chamfers. Because it is written in JavaScript, it runs in all modern browsers and integrates with the standard JS ecosystem of libraries and tooling.
  3. Overview of the replicad library

    replicad is a library used to build browser-based 3D models using code. It serves as an abstraction over OpenCascade, allowing developers to integrate 3D modeling capabilities directly into their own web applications, such as custom editors or generative 3D design tools.
  4. Use DrawingPen for 2D drawing operations

    DrawingPen is a helper class used to create 2D drawings by exposing a builder interface. It is not a drawing object itself, but a tool to construct one. It extends BaseSketcher2d and implements GenericSketcher<Drawing>.
    const pen = new DrawingPen(origin);
  5. Shape3DLike Interface Overview

    The Shape3DLike interface defines the standard set of properties and methods available for 3D shapes in Replicad. It uses several type parameters to maintain type safety across different shape and mesh implementations: ShapeT for the shape type, MeshT for the resulting mesh type, OtherT (aliased to ShapeT), and MeshOptionsT (aliased to any).
  6. Access Face geometric properties

    The Face class provides several getters to retrieve geometric and topological information about the face:
    // Get the center point of the face
    const center = face.center; // returns Vector
    
    // Get the surface associated with the face
    const surface = face.surface; // returns Surface
    
    // Get the orientation of the face
    const orientation = face.orientation; // returns "forward" | "backward"
    
    // Get the geometry type of the surface
    const type = face.geomType; // returns SurfaceType
    
    // Get the UV bounds of the face
    const uvBounds = face.UVBounds; // returns FaceUVBounds
  7. Fuse multiple shapes into one body

    Use the .fuse() method to merge two or more shapes into a single combined body. This is a fundamental operation for combining separate geometric components into a single part.
    const body = profile.sketchOnPlane("XZ").revolve([0, 0, 1]);
    const filler = topCircle.loftWith([middleCircle, bottomCircle], { ruled: false });
    
    // Merge the body and the filler
    const fused = body.fuse(filler);
  8. Use the FilterFcn type for custom finders

    The FilterFcn<Type> type alias is used to define filter functions within Replicad finders. It is a generic object that provides context about the element being filtered and its associated normal vector.
    type FilterFcn<Type> = {
      element: Type;
      normal: Vector | null;
    };
  9. Use WrappingObj to wrap deletable objects

    The WrappingObj<Type> class is a generic wrapper for objects that implement the Deletable interface. It extends Disposable and is used as a base class for many core Replicad entities such as Vector, Transformation, BoundingBox, Shape, and MeshShape. It provides a way to manage the lifecycle and access the underlying wrapped object.
  10. Use FaceSketcher to sketch on non-planar faces

    The FaceSketcher class enables sketching on non-planar faces (e.g., the sides of a cylinder). It uses normalized coordinates between 0 and 1 for both directions. For closed surfaces like revolution surfaces or cylinders, the first parameter represents the angle and may be less than 0 or greater than 1.
    // Initialize a FaceSketcher for a specific face
    const sketcher = new FaceSketcher(face, origin);
  11. Access MeshShape properties and data

    MeshShape provides getters to retrieve spatial and structural information about the mesh:
    // Get the bounding box of the shape
    const box = shape.boundingBox;
    
    // Check if the shape is empty
    const empty = shape.isEmpty;
    
    // Export the shape as a MeshShapeMesh
    const meshData = shape.mesh();
  12. Get BoundingBox2d dimensions and position

    The BoundingBox2d class provides several accessors to retrieve spatial information about the bounding box:
    const width = bbox.width;   // returns number
    const height = bbox.height; // returns number
    const center = bbox.center; // returns Point2D
    const bounds = bbox.bounds; // returns [Point2D, Point2D]
    const repr = bbox.repr;     // returns string representation