Parts
When you build models with multiple components, auto-fusion can work against you — you don't want a bolt to merge into a bracket. part() creates isolation boundaries so components stay separate.
Defining a part
Wrap modeling operations in a part() call:
import { part, sketch, extrude } from 'fluidcad/core';
import { rect, circle } from 'fluidcad/core';
part("base", () => {
sketch("xy", () => {
rect(120, 80).center()
})
extrude(10)
})
part("pillar", () => {
sketch("xy", () => {
circle(30)
})
extrude(60)
})
Shapes inside "base" fuse with each other, and shapes inside "pillar" fuse with each other, but the two parts stay separate — even though the pillar sits on top of the base.
Passing options
The part() callback receives an options object. You pass options when you instantiate the part with use():
import { part, use, cylinder, select, color } from 'fluidcad/core';
import { face } from 'fluidcad/filters';
const peg = part("peg", (options) => {
cylinder(options?.radius || 10, options?.height || 40)
select(face())
color("orange")
})
use(peg, { radius: 15, height: 60 }) // custom size
use(peg) // default size
Use options?.property || defaultValue to provide defaults when an option isn't passed.
Importing parts from other files
Parts are regular ES module exports. Define a part in one file and import it in another:
// peg.fluid.js
import { part, cylinder, select, color } from 'fluidcad/core';
import { face } from 'fluidcad/filters';
export const peg = part("peg", (options) => {
cylinder(options?.radius || 10, options?.height || 40)
select(face())
color("orange")
})
// assembly.fluid.js
import { peg } from './peg.fluid.js';
import { use, sketch, extrude, translate } from 'fluidcad/core';
import { rect } from 'fluidcad/core';
// Base plate
sketch("xy", () => {
rect(100, 60).center()
})
extrude(5)
// Place pegs with different sizes
const p1 = use(peg, { radius: 8, height: 30 })
translate(30, 15, 5)
const p2 = use(peg, { radius: 12, height: 50 })
translate(-30, -15, 5)
This pattern lets you build libraries of reusable parametric components.