o
odinpkg.dev
packages / library / ohcad

ohcad

9d19bfflibrary

A focused Part-Design style CAD kernel and 2D technical drawing system implemented in Odin.

No license ยท updated 8 months ago

OhCAD - Odin CAD System

A focused Part-Design style CAD kernel and 2D technical drawing system implemented in Odin.

Project Status

๐ŸŽ‰ Week 12.2 Complete - Constraint Editing with Inline Text Widget! ๐ŸŽ‰

Full parametric CAD workflow with editable constraints and live solver updates!

Current Features:

  • โœ… 2D parametric sketching (lines, circles, arcs)
  • โœ… Constraint solver (12 constraint types with visual feedback)
  • โœ… Constraint editing - Double-click dimensions to edit values inline
  • โœ… 3D extrusion and revolution with parametric updates
  • โœ… Boolean operations (cut/pocket with OCCT - OpenCascade Technology)
  • โœ… Face selection and sketch-on-face workflow
  • โœ… SDL3 GPU rendering (Metal on macOS)
  • โœ… Multi-touch gestures (trackpad support)
  • โœ… Feature tree with dependency tracking
  • โœ… Undo/redo system (50 command history)
  • โœ… Professional UI with toolbar, properties panel, feature tree, and status bar
  • โœ… Text rendering with fontstash (BigShoulders font)
  • โœ… Shaded rendering with Phong lighting
  • โœ… STL export for 3D printing
  • โœ… Hover highlights and closed shape visualization

See Development Plan for complete roadmap and SDL3 GPU Migration Summary for technical details.


Features (Target MVP)

  • 2D Parametric Sketcher with constraint solving
  • 3D Features: Extrude (pad), pocket (cut), revolve, basic fillet/chamfer
  • Parametric Feature Tree with replay/regeneration
  • B-rep Topology for robust solid modeling
  • Technical Drawing: Orthographic views, hidden line removal, dimensions
  • File Export: STL, SVG, PDF

Why Odin?

  • Explicit memory layout, no GC pauses
  • Easy C interop for reusing libraries
  • Simple syntax for systems programming
  • Excellent built-in packages (math, graphics, testing, etc.)

Project Structure

mix_OhCAD/
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ main.odin              # Main entry point
โ”‚   โ”œโ”€โ”€ core/
โ”‚   โ”‚   โ”œโ”€โ”€ math/              # CAD-specific math utilities
โ”‚   โ”‚   โ”œโ”€โ”€ geometry/          # 2D/3D geometric primitives
โ”‚   โ”‚   โ”œโ”€โ”€ topology/          # B-rep data structures
โ”‚   โ”‚   โ””โ”€โ”€ kernel/            # CSG/B-rep operations (future)
โ”‚   โ”œโ”€โ”€ features/
โ”‚   โ”‚   โ”œโ”€โ”€ sketch/            # 2D sketching system
โ”‚   โ”‚   โ”œโ”€โ”€ extrude/           # Extrude feature (future)
โ”‚   โ”‚   โ”œโ”€โ”€ revolve/           # Revolve feature (future)
โ”‚   โ”‚   โ””โ”€โ”€ constraints/       # Constraint solver (future)
โ”‚   โ”œโ”€โ”€ io/
โ”‚   โ”‚   โ”œโ”€โ”€ stl/               # STL import/export
โ”‚   โ”‚   โ”œโ”€โ”€ svg/               # SVG export (future)
โ”‚   โ”‚   โ””โ”€โ”€ step/              # STEP I/O (future)
โ”‚   โ””โ”€โ”€ ui/
โ”‚       โ”œโ”€โ”€ viewer/            # 3D OpenGL viewer (future)
โ”‚       โ””โ”€โ”€ drawing/           # Technical drawing (future)
โ”œโ”€โ”€ tests/                     # Unit and integration tests
โ”œโ”€โ”€ docs/                      # Documentation
โ”œโ”€โ”€ examples/                  # Example models (future)
โ””โ”€โ”€ Makefile                   # Build system

Building

Prerequisites

  • Odin Compiler (latest version)
  • SDL3 (for GPU-accelerated rendering)
  • Metal-capable macOS system (for Metal backend)
  • OpenGL 3.3+ (for legacy GLFW version)

Quick Start

# Build SDL3 GPU version (recommended)
make gpu

# Run SDL3 GPU application
make run-gpu

# Build GLFW version (legacy backup)
make

# Run GLFW application
make run

# Run tests
make test

# Clean build artifacts
make clean

Manual Build

# SDL3 GPU version (recommended)
odin build src/main_gpu.odin -file -out:bin/ohcad_gpu -debug

# GLFW version (legacy)
odin build src/main.odin -file -out:bin/ohcad -debug

# Run tests
odin test tests -all-packages

Shader Compilation (SDL3 GPU)

cd src/ui/viewer/shaders
./build_shaders.sh
# Generates line_shader.metallib (~15KB)

Development

Week-by-Week Plan

See the Development Plan for the complete 16-week MVP roadmap.

Current Week: Week 1 - Project Setup & Core Math

Architecture

See the High-Level Design for detailed architecture and design decisions.

Built-in Packages Reference

See Odin Built-in Packages for a catalog of Odin packages we're leveraging.


Contributing

This is an educational project focused on learning CAD system architecture and Odin programming.

Code Style

  • Follow Odin naming conventions (snake_case for functions, PascalCase for types)
  • Use f64 for all geometric calculations (CAD precision)
  • Document complex algorithms and geometric predicates
  • Write unit tests for all math and geometry functions

Testing

# Run all tests
make test

# Run specific test package
odin test tests/math -all-packages

License

MIT License - See LICENSE file for details.


Roadmap

Phase 1: Foundation (Weeks 1-4) โœ… COMPLETE

  • Project setup
  • Core math library (57/57 tests passing)
  • Geometry primitives (2D/3D)
  • B-rep topology (handle-based system)
  • Basic 3D viewer (GLFW + OpenGL)

Phase 2: 2D Sketcher (Weeks 5-8) โœ… COMPLETE

  • Sketch data model with coordinate transforms
  • Interactive sketch tools (line, circle, select)
  • Constraint system (16 constraint types)
  • Levenberg-Marquardt constraint solver
  • Visual constraint feedback (icons + dimensions)
  • Profile detection for extrusion

Phase 3: 3D Features (Weeks 9-12) ๐Ÿ”„ IN PROGRESS

  • Week 9: Extrude/pad feature with parametric updates โœ…
  • Week 9.5: SDL3 GPU migration + multi-touch gestures โœ…
  • Week 9.6: UI framework & toolbar integration โœ…
  • Week 10.5: Boolean operations (cut/pocket)
  • Week 11: Revolve feature
  • Week 12: STL export & basic fillet

Phase 4: Technical Drawing (Weeks 13-16) - MVP Target

  • Orthographic projection
  • Hidden line removal
  • Dimensioning
  • SVG/PDF export

Phase 5: Polish (Weeks 17+)

  • Boolean robustness
  • Advanced fillets
  • STEP I/O
  • NURBS surfaces

References

  • SolveSpace - Constraint solver reference
  • BRL-CAD - CSG concepts
  • Open CASCADE - B-rep algorithms
  • Odin Documentation - https://odin-lang.org/docs/

Built with โค๏ธ and Odin