FluidCAD

repository·main·Indexed 19 days ago

https://github.com/fluid-cad/fluidcad

A code-driven 3D parametric modeling engine and JavaScript library (v0.0.41) that leverages the OpenCascade B-Rep kernel. It provides real-time visual feedback via a web-based viewport and includes official extensions for VS Code and Neovim, as well as an MCP server for LLM agent integration.

Tokens
162.4K
Snippets
680
Records
859
Agent score
64%

What's inside fluidcad

  1. Overview of FluidCAD API Features

    main

    The FluidCAD API provides a programmatic interface for 3D modeling through several functional categories:

    • 2D Sketching: Create foundational geometry such as lines, circles, arcs, and rectangles.
    • 3D Operations: Transform 2D sketches into 3D volumes using operations like extrude(), revolve(), loft(), sweep(), and boolean operations.
    • Transforms: Manipulate existing geometry using translate(), rotate(), mirror(), copy(), and repeat().
    • Utilities: Manage the scene using functions for selection, coloring, removal, and loading.
  2. Core 3D operations in FluidCAD

    main

    FluidCAD transforms 2D sketches into 3D geometry using several core operations. These operations are categorized by their function:

    OperationDescription
    extrudePulls a sketch into a solid along the plane's normal
    cutRemoves material from a solid using a sketch profile
    revolveRotates a sketch around an axis
    loftCreates a smooth transition between two or more profiles
    sweepMoves a profile along a path
    filletRounds edges
    chamferBevels edges
    shellHollows out a solid
  3. Understand the FluidCAD User Interface

    main

    The FluidCAD viewport provides several controls for managing your code-driven 3D model. Key elements include:

    • History Panel: Lists every feature (operation) in your model in order.
      • Rollback: Click a feature name to rollback the model to that point in history.
      • Breakpoints: Double-click a feature name to insert a breakpoint() at that feature.
      • Feature Status: A checkmark indicates the feature was served from cache; a refresh icon indicates it was re-computed.
    • Shapes Panel: Lists all solid shapes produced by the model and provides shape properties (e.g., center of mass).
    • Camera Controls: Toggle between Perspective camera (objects farther away appear smaller) and Orthographic camera (no perspective distortion), or use Fit model into view to reset the camera.
    • Grid: Toggle the background grid on or off.
  4. Emboss, deboss, or create standalone wrapped pads with wrap()

    main

    The wrap() function returns a Wrap object that allows you to control how the wrapped geometry interacts with the target face via method chaining:

    1. Emboss (Default): Calling wrap(thickness, sketch, face) raises the sketch from the surface.
    2. Deboss: Chain .remove() to sink the sketch into the surface: wrap(thickness, sketch, face).remove().
    3. Standalone Pad: Chain .new() to prevent the wrapped geometry from merging with the target face: wrap(thickness, sketch, face).new().
    // Example of embossing (default behavior)
    wrap(2, mySketch, myCylindricalFace);
    
    // Example of debossing (sinking into the surface)
    wrap(2, mySketch, myCylindricalFace).remove();
    
    // Example of creating a standalone wrapped pad
    wrap(2, mySketch, myCylindricalFace).new();
  5. How reusable objects work in FluidCAD

    main

    By default, most FluidCAD features (like extrude(), shell(), cut(), and sweep()) consume their inputs. When a feature consumes an object, that geometry is removed from the scene to prevent accidental reuse in subsequent operations.

    To prevent an object from being consumed, call .reusable() on it. This tells FluidCAD to keep the object alive in the scene so it can be used by multiple features.

    .reusable() can be applied to:

    • Sketch geometries: Individual shapes defined inside a sketch() block.
    • Whole sketches: The object returned by the sketch(...) function.
    • Selections: The object returned by select(...) (e.g., when using the same selection for both a sketch plane and a project() source).
  6. When to use fillet vs chamfer

    main

    While both modify edges, they serve different purposes:

    • Use chamfer for manufacturing edge breaks. It is computationally faster and easier to specify from technical drawings.
    • Use fillet when the part is being visually styled or when the round is structurally significant (e.g., for stress relief).
  7. Difference between repeat() and copy()

    main

    Choosing between repeat() and copy() depends on whether you want to re-execute a modeling operation or simply duplicate an existing shape.

    GoalMethod
    Re-run a feature so it cuts/extrudes into the same solid at each positionrepeat()
    Create one solid with multiple pockets or bossesrepeat() with the cut/extrude result
    Clone a finished shape at new positions (each copy is independent)copy()
    Create many separate solids of the same shapecopy() with .new() on the original
    Mirror a feature across a planerepeat("mirror", plane, feature)

    Key Intuition: copy() duplicates a finished shape; repeat() re-executes a feature. Because repeat() re-runs the feature, it respects auto-fusion semantics (overlapping copies merge).

  8. Understand the cut() direction convention

    main

    The cut() function operates in the opposite direction of extrude. While extrude adds material, cut removes it by moving into the solid.

    • Positive distance: Cuts in the opposite direction of the sketch normal (moving into the solid the sketch sits on). This is the standard way to create a pocket.
    • Negative distance: Cuts along the sketch normal (moving out of the side the sketch faces).
    • No-argument cut(): Performs a through-all cut, which moves in the opposite direction of the sketch normal until it passes through the entire solid.
  9. Use Vertex as a 2D point reference

    main
    A Vertex is a lazy-evaluated representation of a point on geometry. While it is a specific type, it can be passed to any function expecting a Point2DLike type. This allows you to reference specific points on existing geometry (such as those returned by start(), end(), or tangent() on Geometry objects) without manually calculating coordinates.
  10. Use constrained geometry primitives

    main

    FluidCAD provides three primary constrained primitives to create geometry that is automatically tangent to existing sketch elements. Instead of manual calculations, you describe the relationship (tangency) and the solver computes the positions and angles.

    • tLine(): Creates a line tangent to one or two objects.
    • tArc(): Creates an arc tangent to objects, points, or the previous element.
    • tCircle(): Creates a circle tangent to two objects.
    import { tLine, tArc, tCircle } from 'fluidcad/constraints';
  11. Disambiguate constrained primitives with constraint qualifiers

    main

    When using constrained primitives like tLine, tArc, or tCircle, multiple valid geometric solutions may exist (for example, multiple tangent lines between two circles). Constraint qualifiers wrap a geometry object to specify which solution should be selected based on its spatial relationship to the object.

    Import these from fluidcad/constraints:

    • outside(obj): The resulting geometry must be external to obj (sharing no interior).
    • enclosing(obj): The resulting geometry must wrap around obj.
    • enclosed(obj): The resulting geometry must sit entirely inside obj.
    • unqualified(obj): Removes any previously applied qualification on obj.
    import { outside } from "fluidcad/constraints";
    
    sketch("xy", () => {
      const c1 = circle([0, 0], 40).reusable();
      const c2 = circle([100, 0], 40).reusable();
      // Selects the external tangent between c1 and c2
      tLine(outside(c1), outside(c2));
    });
    extrude(2);