vcad.
Back to Rust API
Rust API

Primitives

Basic 3D shapes: cube, cylinder, sphere, cone

Primitives are the building blocks of vcad models. Every part starts with one or more primitives combined with boolean operations.

Cube

Creates a box with one corner at the origin.

Part::cube(name: &str, x: f64, y: f64, z: f64) -> Part
name&strrequired

Part name for identification in scenes and debugging.

xf64required

Width (size along X axis) in millimeters.

yf64required

Depth (size along Y axis) in millimeters.

zf64required

Height (size along Z axis, vertical) in millimeters.

Origin: Corner at (0, 0, 0), extends to (x, y, z).

// 30mm cube
let cube = Part::cube("box", 30.0, 30.0, 30.0);

Centered Cube

Creates a box centered at the origin.

centered_cube(name: &str, x: f64, y: f64, z: f64) -> Part

Origin: Center at (0, 0, 0), extends from (-x/2, -y/2, -z/2) to (x/2, y/2, z/2).

// 30mm cube centered at origin
let cube = centered_cube("box", 30.0, 30.0, 30.0);

Use centered_cube when combining shapes at the origin. Use Part::cube when positioning relative to a corner.

Cylinder

Creates a cylinder along the Z axis (vertical in Z-up convention).

Part::cylinder(name: &str, radius: f64, height: f64, segments: i32) -> Part
name&strrequired

Part name.

radiusf64required

Radius in millimeters.

heightf64required

Height along Z axis in millimeters (already vertical).

segmentsi32required

Number of facets around circumference. Higher = smoother.

Origin: Base center at (0, 0, 0), extends to (0, 0, height).

// Cylinder: 10mm radius, 25mm tall, 32 segments
let cyl = Part::cylinder("shaft", 10.0, 25.0, 32);

Centered Cylinder

Creates a cylinder centered on all axes.

centered_cylinder(name: &str, radius: f64, height: f64, segments: i32) -> Part

Origin: Center at (0, 0, 0), extends from (0, 0, -height/2) to (0, 0, height/2).

// Centered cylinder
let cyl = centered_cylinder("shaft", 10.0, 25.0, 32);

Segment Count Guidelines

SegmentsUse case
16Tiny holes, prototyping
24Small features, internal holes
32General purpose (default)
64Visible curves
128High-quality renders

Sphere

Creates a sphere at the origin.

Part::sphere(name: &str, radius: f64, segments: i32) -> Part
name&strrequired

Part name.

radiusf64required

Radius in millimeters.

segmentsi32required

Subdivision level (both latitude and longitude).

Origin: Center at (0, 0, 0).

// 15mm radius sphere
let ball = Part::sphere("ball", 15.0, 32);

Cone

Creates a cone or truncated cone along the Z axis (vertical in Z-up convention).

Part::cone(name: &str, r_bottom: f64, r_top: f64, height: f64, segments: i32) -> Part
name&strrequired

Part name.

r_bottomf64required

Bottom radius in millimeters.

r_topf64required

Top radius in millimeters. Use 0 for a pointed cone.

heightf64required

Height along Z axis in millimeters.

segmentsi32required

Number of facets around circumference.

Origin: Base center at (0, 0, 0), extends to (0, 0, height).

// Pointed cone
let cone = Part::cone("point", 10.0, 0.0, 20.0, 32);

// Truncated cone (frustum)
let frustum = Part::cone("frustum", 15.0, 8.0, 25.0, 32);

Empty Part

Creates a part with no geometry. Useful as an identity for union operations.

Part::empty(name: &str) -> Part
// Accumulate parts
let mut result = Part::empty("combined");
for part in parts {
    result = result + part;
}

Helper Functions

Counterbore Hole

Creates a hole with counterbore for socket head cap screws.

counterbore_hole(
    hole_dia: f64,
    cb_dia: f64,
    cb_depth: f64,
    total_depth: f64,
    segments: i32,
) -> Part
// M5 SHCS counterbore
let hole = counterbore_hole(5.5, 10.0, 5.0, 20.0, 32);
let result = plate - hole;

Bolt Pattern

Creates a circular pattern of holes (bolt circle).

bolt_pattern(
    count: usize,
    bcd: f64,        // Bolt Circle Diameter
    hole_dia: f64,
    depth: f64,
    segments: i32,
) -> Part
// 6 holes on a 60mm BCD
let holes = bolt_pattern(6, 60.0, 5.5, 10.0, 32);
let flange = flange - holes;

Units

vcad is unit-agnostic—all dimensions are f64. By convention:

  • Length: millimeters
  • Angles: degrees (in transforms)
  • Segments: integer count

This matches STL/DXF conventions used in manufacturing.