{"id":31811266,"url":"https://github.com/adam0brien/nl-cad","last_synced_at":"2026-07-08T16:31:08.875Z","repository":{"id":309722464,"uuid":"1036759335","full_name":"Adam0Brien/nl-cad","owner":"Adam0Brien","description":"Natural language to OpenSCAD code generation","archived":false,"fork":false,"pushed_at":"2025-08-13T11:58:16.000Z","size":55,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-08-13T13:32:26.855Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Adam0Brien.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-08-12T14:40:29.000Z","updated_at":"2025-08-13T11:58:19.000Z","dependencies_parsed_at":"2025-08-13T13:32:31.263Z","dependency_job_id":"78d5e00b-9bba-44fa-9cff-4d008a65c83a","html_url":"https://github.com/Adam0Brien/nl-cad","commit_stats":null,"previous_names":["adam0brien/nl-cad"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/Adam0Brien/nl-cad","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Adam0Brien%2Fnl-cad","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Adam0Brien%2Fnl-cad/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Adam0Brien%2Fnl-cad/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Adam0Brien%2Fnl-cad/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Adam0Brien","download_url":"https://codeload.github.com/Adam0Brien/nl-cad/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Adam0Brien%2Fnl-cad/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279006444,"owners_count":26084107,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-11T02:00:06.511Z","response_time":55,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-10-11T06:41:27.518Z","updated_at":"2025-10-11T06:41:28.539Z","avatar_url":"https://github.com/Adam0Brien.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# NL-CAD: Natural Language CAD Generator\n\nA multi-mode OpenSCAD code generator that converts natural language descriptions into 3D models. Supports multiple generation modes including mechanical parts, voxel-style objects, and mazes.\n\n## 🎯 Features\n\n### Generator Modes\n\n1. **🔧 BOSL Generator** - Mechanical parts using BOSL2 library\n   - Bolts, nuts, washers, screws\n   - Mechanical components with precise dimensions\n   - Threading and standard hardware\n\n2. **🧊 Cube Generator** - Voxel-style objects using only cubes\n   - Minecraft-like blocky creations\n   - Buildings, characters, objects made from cubes\n   - Pixel art in 3D\n\n3. **🌀 Maze Generator** - Generate various types of mazes\n   - Rectangular and circular mazes\n   - Configurable difficulty levels\n   - Multi-level mazes with decorative elements\n   - Algorithmic generation with recursive backtracking\n\n4. **🎭 Two-Stage Generator** - Advanced AI-powered generation\n   - Design stage: Creative conceptualization using optimized model\n   - Code stage: Technical implementation with specialized model\n   - Improved code quality and variable validation\n\n5. **💬 Conversational Generator** - Interactive design sessions\n   - Ask clarifying questions about your design needs\n   - Iterative refinement through conversation\n   - Progressive design development with feedback\n   - Handles timeouts gracefully with intelligent fallbacks\n\n### Interfaces\n\n- **Command Line Interface** - Simple CLI with speech recognition and conversational mode\n- **Web Interface** - Browser-based UI with STL generation and interactive conversations\n- **Direct API** - Python module for integration\n\n## 🚀 Quick Start\n\n### Installation\n\n```bash\ngit clone \u003crepository\u003e\ncd nl-cad\npip install -r requirements.txt\n```\n\n### Basic Usage\n\n#### Command Line\n\n```bash\n# BOSL mode (default) - mechanical parts\npython main.py -d \"M8 x 25 bolt\"\n\n# Generate using speech input 🎤\npython3 main.py --speech\n\n# Quick speech input (no confirmation)\npython3 main.py --quick-speech\n\n# Using make commands\nmake speech                    # Speech with confirmation\nmake quick-speech              # Quick speech mode\nmake run DESCRIPTION=\"M6 bolt\" # Text input\n\n# Run test cases to see examples\npython3 main.py --test\n```\n\n**What You Can Generate:**\n- **Fasteners:** \"M8 x 25 bolt\", \"M10 nut\", \"3/8 inch washer\"\n- **Shapes:** \"cuboid 20mm 30mm 40mm\", \"cyl length 40mm diameter 25mm\"\n- **🎤 Speech Input:** Just speak naturally: \"Create an M8 bolt 25 millimeters long\"\n\n**How It Works:**\n1. You type: \"M8 x 25 bolt\"\n2. AI figures out: size=8, length=25, coarse=true  \n3. Output: Minimal OpenSCAD code with BOSL includes\n\n**Examples:**\n| What you want | Type this | Gets this |\n|---------------|-----------|-----------|\n| M6 bolt, 20mm long | `\"M6 x 20 bolt\"` | `metric_bolt(size=6, l=20, coarse=true)` |\n| 3/8 inch washer | `\"3/8 inch washer\"` | `metric_washer(size=9.525)` |\n| 20x30x40 cube | `\"cuboid 20mm 30mm 40mm\"` | `cuboid(size=[20,30,40])` |\n\n**Abstract Examples (AI-Powered):**\n- `\"i need a bolt the width of a king-sized bed and is 200 long\"` → AI interprets as ~152mm diameter and 200mm length\n- `\"box roughly the size of a smartphone\"` → AI interprets as ~70x140mm\n\n**Advanced Features:**\n- **🎤 Speech Recognition**: Speak your CAD requests naturally\n- **AI Integration**: Uses Ollama for complex, abstract descriptions\n- **Dual Input Modes**: Type or speak - your choice!\n\n**Limits:**\n- Simple shapes (no complex assemblies)\n\n**Troubleshooting:**\n- **\"No component found\"** → Try simpler words: \"bolt\" instead of \"hex head fastener\"\n- **Missing length** → Include it: \"M6 x 25 bolt\" not just \"M6 bolt\"\n- **AI not working** → Check if Ollama is running: `ollama list`\n- **🎤 Speech not working** → Install audio dependencies: `pip install SpeechRecognition pyaudio`\n- **Microphone issues** → Test with: `python3 speech/speech_recognizer.py`\n\n**Project Structure:**\n```\nHackathon/\n├── main.py                    # Main program (just run this)\n├── generation/\n│   └── bosl_generator.py     # The AI logic and parameter extraction\n├── speech/                    # 🎤 Speech recognition module\n│   ├── __init__.py\n│   └── speech_recognizer.py  # Speech-to-text functionality\n├── data/\n│   ├── bosl_catalog.json     # BOSL component definitions\n│   └── openscad_catalog.json # Basic OpenSCAD primitives\n├── config/\n│   ├── creative/             # Creative AI generation prompts\n│   │   ├── system_prompt.txt # Spatial reasoning \u0026 OpenSCAD rules\n│   │   └── user_prompt.txt   # Creative generation instructions\n│   ├── catalog/              # Catalog-based generation prompts\n│   │   ├── system_prompt.txt # Parameter extraction rules\n│   │   └── user_prompt.txt   # Catalog matching instructions\n│   ├── system_prompt.txt     # BOSL generation instructions\n│   └── user_prompt.txt       # BOSL user prompts\n├── output/                   # Generated .scad files\n```\n\n**Testing:**\n\n# Test basic functionality\npython3 main.py --test\n```\n\n**For Developers:**\n- **Adding Components**: Edit `data/bosl_catalog.json`\n- **Adjusting AI Behavior**: \n  - Creative generation: Modify `config/creative/system_prompt.txt` and `config/creative/user_prompt.txt`\n  - Catalog generation: Modify `config/catalog/system_prompt.txt` and `config/catalog/user_prompt.txt`\n  - BOSL generation: Modify `config/system_prompt.txt` and `config/user_prompt.txt`\n- **Extending Logic**: Modify `generation/bosl_generator.py`\n# Cube mode - voxel objects  \npython main.py -m cube -d \"simple house\"\n\n# Maze mode - generate mazes\npython main.py -m maze -d \"10x10 maze with dead ends\"\n\n# Two-stage mode - enhanced AI generation  \npython main.py -m two-stage -d \"modern coffee mug with handle\"\n\n# Conversational mode - interactive design\npython main.py -m conversation -d \"I want to create something special\"\n\n# Save to file\npython main.py -m maze -d \"circular maze\" -o output/my_maze.scad\n\n# Voice input\npython main.py --speech -m cube\n```\n\n#### Web Interface\n\n```bash\npython web_app.py\n# Open http://localhost:5000\n```\n\n### Testing\n\n```bash\n# Test all generators\npython main.py --test\n\n# Test maze generation specifically\npython simple_maze_test.py\n```\n\n## 📝 Usage Examples\n\n### BOSL Generator Examples\n\n```bash\npython main.py -d \"M8 x 25 bolt\"\npython main.py -d \"cuboid 20mm 30mm 40mm\"  \npython main.py -d \"cylinder diameter 25mm height 40mm\"\npython main.py -d \"M10 nut\"\npython main.py -d \"3/8 inch washer\"\n```\n\n### Cube Generator Examples\n\n```bash\npython main.py -m cube -d \"simple house\"\npython main.py -m cube -d \"castle tower\"\npython main.py -m cube -d \"robot figure\"\npython main.py -m cube -d \"tree\"\npython main.py -m cube -d \"car\"\n```\n\n### Maze Generator Examples\n\n```bash\npython main.py -m maze -d \"simple 5x5 maze\"\npython main.py -m maze -d \"complex 10x10 maze with dead ends\"\npython main.py -m maze -d \"beginner maze with base platform\"\npython main.py -m maze -d \"advanced maze with pillars and roof\"\npython main.py -m maze -d \"circular maze\"\npython main.py -m maze -d \"multi-level maze\"\n```\n\n### Two-Stage Generator Examples\n\n```bash\npython main.py -m two-stage -d \"modern coffee mug with handle\"\npython main.py -m two-stage -d \"decorative vase with Greek patterns\"\npython main.py -m two-stage -d \"desk organizer with compartments\"\npython main.py -m two-stage -d \"phone charging stand\"\npython main.py -m two-stage -d \"storage box with hinged lid\"\n```\n\n### Conversational Mode Examples\n\n```bash\n# Start interactive design session\npython main.py -m conversation -d \"I want to design a treasure chest\"\npython main.py -m conversation -d \"help me create a custom container\"\npython main.py -m conversation -d \"I need something decorative\"\n\n# The system will ask clarifying questions like:\n# - What dimensions do you need?\n# - What style preferences do you have?\n# - Any specific functional requirements?\n# - Materials and appearance preferences?\n```\n\n## 🔧 Technical Details\n\n### Architecture\n\nThe system uses a base class architecture:\n\n- `BaseGenerator` - Abstract base class for all generators\n- `BOSLGenerator` - Inherits from BaseGenerator, handles mechanical parts\n- `CubeGenerator` - Inherits from BaseGenerator, cube-only objects\n- `MazeGenerator` - Inherits from BaseGenerator, maze generation\n\n### Maze Generation Features\n\n#### Algorithmic Generation\n- **Recursive Backtracking Algorithm** - Creates perfect mazes with single solution paths\n- **Configurable Difficulty** - Beginner, intermediate, and advanced modes\n- **Multiple Maze Types** - Rectangular, circular, and multi-level mazes\n\n#### Maze Parameters\n- **Size**: Grid dimensions (e.g., 5x5, 10x10, 15x8)\n- **Wall Properties**: Height (20 units), thickness (2 units), path width (10 units)\n- **Features**: Base platforms, decorative pillars, roofs, rooms\n\n#### Maze Types\n1. **Rectangular Mazes** - Standard grid-based mazes\n2. **Circular Mazes** - Radial maze layouts (planned)\n3. **Multi-level Mazes** - Stacked maze levels with connections\n\n### Output Files\n\nGenerated files are saved to the `output/` directory:\n- `.scad` files - OpenSCAD source code\n- `.stl` files - 3D printable models (via web interface)\n\n## 🎛️ Configuration\n\n### Environment Variables\n\n```bash\n# Ollama Configuration (for LLM-based generation)\nexport OLLAMA_MODEL=\"deepseek-coder:6.7b\"\nexport OLLAMA_BASE_URL=\"http://localhost:11434\"\nexport OLLAMA_NUM_PREDICT=\"2500\"\nexport OLLAMA_CONNECT_TIMEOUT=\"10\"\nexport OLLAMA_READ_TIMEOUT=\"600\"\n```\n\n### Prompt Customization\n\nEach generator uses customizable prompt files in the `config/` directory:\n\n- `system_prompt.txt` / `user_prompt.txt` - BOSL generator\n- `cube_system_prompt.txt` / `cube_user_prompt.txt` - Cube generator  \n- `maze_system_prompt.txt` / `maze_user_prompt.txt` - Maze generator\n\n## 🔬 Testing\n\n### Automated Tests\n\n```bash\n# Run all generator tests\npython main.py --test\n\n# Test specific maze generation\npython simple_maze_test.py\n```\n\n### Manual Testing\n\n1. Generate a maze: `python main.py -m maze -d \"5x5 simple maze\" -o test.scad`\n2. Open `test.scad` in OpenSCAD\n3. Press F5 to preview or F6 to render\n4. You should see a 3D maze with walls and paths\n\n### Expected Output\n\nA successful maze generation will create:\n- Boundary walls forming the maze perimeter\n- Internal walls creating the maze paths\n- Entrance and exit openings\n- Optional features (base, pillars, roof) if requested\n\n## 🛠️ Development\n\n### Adding New Generators\n\n1. Create a new generator class inheriting from `BaseGenerator`\n2. Implement required abstract methods:\n   - `_get_default_prompt()`\n   - `generate()`\n   - `_validate_and_clean_code()`\n3. Add the generator to `main.py` and `web_app.py`\n4. Create prompt files in `config/`\n\n### Maze Algorithm Improvements\n\nThe maze generator supports multiple algorithms:\n- ✅ Recursive Backtracking (implemented)\n- 🔄 Binary Tree (planned)\n- 🔄 Eller's Algorithm (planned)\n- 🔄 Wilson's Algorithm (planned)\n\n## 🐛 Troubleshooting\n\n### Common Issues\n\n1. **\"Module not found\" errors** - Install requirements: `pip install -r requirements.txt`\n2. **Empty maze output** - Check that the algorithmic fallback is working\n3. **OpenSCAD errors** - Verify the generated code syntax in OpenSCAD\n4. **Speech recognition fails** - Install additional dependencies: `pip install SpeechRecognition pyaudio`\n\n### Debugging\n\nEnable verbose output by running with Python's `-v` flag:\n```bash\npython -v main.py -m maze -d \"test maze\"\n```\n\n## 📊 Example Output\n\nA typical 5x5 maze generates approximately:\n- 45 lines of OpenSCAD code  \n- 1500+ characters\n- Boundary walls (4 pieces)\n- Internal walls (15-25 pieces depending on maze complexity)\n- Entrance and exit openings\n\n## 🤝 Contributing\n\n1. Fork the repository\n2. Create a feature branch\n3. Add tests for new generators\n4. Submit a pull request\n\n## 📄 License\n\n[License information here]\n\n## 🔗 Related Projects\n\n- [BOSL2](https://github.com/revarbat/BOSL2) - Advanced OpenSCAD library\n- [OpenSCAD](https://openscad.org/) - The OpenSCAD application\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadam0brien%2Fnl-cad","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fadam0brien%2Fnl-cad","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadam0brien%2Fnl-cad/lists"}