Skip to content

varomix/ohcad

Repository files navigation

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

About

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

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors