Skip to main content

Third-party assets

Python model code in cad/ remains the source of truth. Some workflows still need committed reference files that are not generated from build123d — raster masks for emboss sampling, imported STEP shells, SVG profiles, or mesh inputs for boolean or visualization helpers.

Those files live under cad/assets/, separate from:

  • Generated exports (STEP/STL/PNG from @artifact functions) — never commit these except golden fixtures under tests/fixtures/.
  • External part libraries — catalog geometry from bd_warehouse and similar packages, installed via pyproject.toml, not checked into the repo.

Directory layout​

cad/assets/
├── images/ # Raster inputs (PNG, JPEG, alpha masks, height maps)
├── meshes/ # Triangle meshes (STL, OBJ, PLY) used as reference or cutters
├── svg/ # 2D vector profiles and logos for sketch import
├── step/ # B-rep reference solids (vendor STEP, legacy CAD imports)
└── manifests/ # One YAML file per asset — license, source, and usage notes

Each subdirectory contains an empty .gitignore so Git keeps the folder in the tree even before you add files. Drop new assets in the matching type folder and add a manifest alongside them.

FolderTypical formatsUse in models
images/.png, .jpg, .jpegTexture sampling, bump maps, alpha masks
meshes/.stl, .obj, .plyReference geometry, mesh-to-BRep workflows
svg/.svgImported sketches, logos, 2D cut profiles
step/.step, .stpVendor parts, legacy imports, fixed reference solids
manifests/.yamlProvenance and license for every committed asset

Manifest format​

Every file under images/, meshes/, svg/, or step/ should have a sibling manifest in manifests/ named after the asset (without extension):

# cad/assets/manifests/circle_alpha.yaml
id: circle_alpha
path: images/circle_alpha.jpg
type: image
format: jpeg
used_by:
- cad.parts.sphere_texture_emboss
description: Tileable alpha mask for seigaiha-style radial bump embossing on the demo sphere
license: CC0-1.0
source_url: https://example.com/original
notes: Dark pixels become surface bumps; white pixels are skipped
FieldRequiredPurpose
idyesStable identifier (matches filename stem)
pathyesRelative path from cad/assets/
typeyesimage, mesh, svg, or step
formatyesFile extension or MIME hint
used_byyesPython modules that load the asset
descriptionyesShort human-readable summary
licenseyesSPDX identifier or plain-text license name
source_urlrecommendedWhere the file was obtained
notesoptionalSampling rules, units, or caveats

Loading assets from model code​

Resolve paths relative to the cad/ package so tests and CI find files regardless of working directory:

from pathlib import Path

ASSETS = Path(__file__).resolve().parents[1] / "assets"
TEXTURE_PATH = ASSETS / "images" / "circle_alpha.jpg"

Pass texture_path as an optional parameter when tests need overrides; assert the default file exists in unit tests.

Live example: texture emboss on the demo sphere​

The demo sphere applies a seigaiha-style surface pattern by sampling an alpha JPEG and fusing radial bumps onto the sphere shell before the NE quadrant cut and hardware pockets.

PieceLocation
Assetcad/assets/images/circle_alpha.jpg
Manifestcad/assets/manifests/circle_alpha.yaml
Buildercad/parts/sphere_texture_emboss.py
Integrationcad/parts/sphere.py (make_textured_sphere_solid)
Teststests/test_sphere_texture_emboss.py

Dark pixels in the texture (luminance below a threshold) become outward radial bumps; white pixels are skipped. The emboss depth is half the depth of the embossed label text so both features read clearly in the viewer and release PNG.

Agent and contributor rules​

Do:

  • Place third-party or reference files only under cad/assets/<type>/.
  • Add a manifest in manifests/ with license and used_by before merging.
  • Load assets via Path(__file__).resolve().parents[1] / "assets" / ....
  • Add a unit test that the default asset path exists when the builder depends on it.

Do not:

  • Commit generated STEP/STL exports from @artifact functions (except tests/fixtures/ golden files).
  • Scatter assets under cad/parts/ or the repo root.
  • Reference assets by hard-coded absolute paths or paths relative to the repo root without anchoring to cad/.

Agents: summary in AGENTS.md — Third-party assets.