An open API service indexing awesome lists of open source software.

https://github.com/nbschultz97/polygen-ai

AI-powered 3D modeling assistant. Generate, edit, and export 3D models using natural language.
https://github.com/nbschultz97/polygen-ai

3d-modeling ai openscad react saas typescript

Last synced: 23 days ago
JSON representation

AI-powered 3D modeling assistant. Generate, edit, and export 3D models using natural language.

Awesome Lists containing this project

README

          

# PolyGen AI

**v3.9.1** | [Changelog](CHANGELOG.md) | [Roadmap](ROADMAP.md) | [Deployment Guide](DEPLOYMENT.md)

A text-to-3D model generator powered by a multi-agent AI pipeline. Converts natural language descriptions into printable OpenSCAD code using Google Gemini (Planner) and Anthropic Claude (Coder).

**Now available as a SaaS** with user authentication, subscription tiers, and usage tracking.

## Live Demo

πŸš€ Live at [polygen.ceradonsystems.com](https://polygen.ceradonsystems.com/) β€” try 2 free generations without signing up!

## Quick Start (Local Dev)

```bash
# 1. Clone and install
git clone https://github.com/nbschultz97/polygen-ai.git
cd polygen-ai && pnpm install

# 2. Configure API keys (minimum: Gemini + Anthropic)
cp .env.example .env.local
# Edit .env.local β€” set GEMINI_API_KEY and ANTHROPIC_API_KEY

# 3. Start dev server
pnpm dev

# 4. Open http://localhost:5173 β€” use "Try Demo" for anonymous mode
# (Supabase/Stripe are optional β€” auth features gracefully degrade)
```

> **No API keys?** The app loads but generation requires at least Gemini + Anthropic keys. See `.env.example` for details.

## Features

### Core 3D Generation

- **Natural Language Input** - Describe what you want to create in plain English
- **Image-to-3D** - Upload a photo and recreate it as a printable model
- **STL Remix** - Upload an existing STL and generate parametric modifications around it
- **OpenSCAD Code Generation** - Outputs parametric, printable-ready pure OpenSCAD code
- **Preview/Render Split** - Fast preview for iteration, full Manifold render for verified export
- **In-App 3D Preview** - View your model in the browser with Three.js
- **Visual Critic** - Auto-triggers AI vision analysis on renders to catch structural issues
- **Parametric GST Templates** - Pre-built tactical templates for complex assemblies (Picatinny, MOLLE)
- **STL Export** - Download STL files after verified render

### v2.2 Reliable Code Generation

- **Closed-Loop Validation** - 3-attempt retry system with escalating guidance
- **Error Categorization** - Parses errors into 7 categories with suggested fixes
- **Pitfall Database** - 12 common OpenSCAD mistakes with bad/good examples
- **Auto-Preprocessing** - Injects epsilon and $fn if missing
- **Manifold Checking** - Detects open edges and non-manifold geometry
- **Teaching Mode** - Educational comments explain OpenSCAD concepts

### Multi-Agent Pipeline (v2.0+)

- **Planner Agent (Gemini 3 Pro)** - Generates Geometric Structure Tree (GST) from natural language
- **Coder Agent (Claude Sonnet)** - Converts GST to pure OpenSCAD code
- **Browser Validation** - WASM-based OpenSCAD compilation (fully serverless)
- **Smart Quick Fixes** - Context-aware refinement suggestions based on GST component types
- **Symbolic Correction** - Edit requests preserve component relationships

### SaaS Platform (v3.0+)

- **User Authentication** - Email/password and Google OAuth via Supabase
- **Subscription Tiers** - Free, Pro ($19/mo), Enterprise ($99/mo)
- **Usage Tracking** - Generation limits enforced per tier
- **Stripe Payments** - Secure checkout and subscription management
- **Analytics Dashboard** - Track your usage, manage subscription
- **Referral System** - Earn bonus generations by referring friends

### UX

- **Design Templates** - 9 quick-start templates for common objects
- **Clarification Questions** - AI asks follow-up questions with clickable suggested answers
- **User Preferences** - Save your printer settings, tolerances, and material preferences
- **Onboarding Tour** - Guided introduction for new users
- **Export Options** - Copy code, download `.scad` files, or open directly in OpenSCAD

## Pricing

| Plan | Price | Generations | Features |
| -------------- | --------- | ----------- | ------------------------------------------------------- |
| **Free** | $0 | 5/month | Basic templates, OpenSCAD export |
| **Pro** | $19/month | 100/month | All templates, STL export, 3D preview, priority support |
| **Enterprise** | $99/month | Unlimited | + API access, team features |

## Architecture

```
User Prompt β†’ [Planner/Gemini] β†’ GST JSON β†’ [Coder/Claude] β†’ OpenSCAD β†’ [Validator/WASM] β†’ 3D Model
↑ ↑
Clarification Retry with errors
Questions (max 3 attempts)
```

**Geometric Structure Tree (GST)**: An intermediate JSON representation that captures the semantic structure of the model (components, parameters, anchors, boolean operations) before code generation.

## Run Locally

**Prerequisites:** Node.js 20+

1. Clone the repository:

```bash
git clone https://github.com/nbschultz97/polygen-ai.git
cd polygen-ai
```

2. Install dependencies:

```bash
npm install
```

3. Copy the environment template:

```bash
cp .env.example .env.local
```

4. Fill in your API keys in `.env.local`:

```bash
# AI APIs (Required)
GEMINI_API_KEY=your_gemini_key
ANTHROPIC_API_KEY=your_claude_key
USE_MULTI_AGENT=true

# Supabase (Required for auth)
VITE_SUPABASE_URL=https://your-project.supabase.co
VITE_SUPABASE_ANON_KEY=your_anon_key

# Stripe (Required for payments)
STRIPE_SECRET_KEY=sk_live_xxx
VITE_STRIPE_PRO_MONTHLY_PRICE_ID=price_xxx
```

5. Run the app:

```bash
npm run dev
```

6. Open http://localhost:5173 in your browser

## Deployment

See [DEPLOYMENT.md](DEPLOYMENT.md) for complete deployment instructions including:

- Supabase setup and database schema
- Stripe configuration and webhook setup
- Vercel deployment with environment variables
- Custom domain configuration

## Configuration

### AI Configuration

| Variable | Default | Description |
| ------------------- | ---------------------- | ---------------------------------------- |
| `GEMINI_API_KEY` | (required) | Google AI API key for Planner agent |
| `GEMINI_MODEL` | `gemini-3-pro-preview` | Gemini model variant |
| `THINKING_LEVEL` | `high` | Reasoning depth: `low`, `medium`, `high` |
| `ANTHROPIC_API_KEY` | (optional) | Claude API key for Coder agent |
| `USE_MULTI_AGENT` | `false` | Enable Planner→Coder→Validator pipeline |

### SaaS Configuration

| Variable | Description |
| --------------------------- | --------------------------------------- |
| `VITE_SUPABASE_URL` | Supabase project URL |
| `VITE_SUPABASE_ANON_KEY` | Supabase anonymous key |
| `SUPABASE_SERVICE_ROLE_KEY` | Supabase service role key (server-side) |
| `STRIPE_SECRET_KEY` | Stripe secret key |
| `STRIPE_WEBHOOK_SECRET` | Stripe webhook signing secret |
| `VITE_STRIPE_*_PRICE_ID` | Stripe price IDs for each plan |
| `VITE_GA_MEASUREMENT_ID` | Google Analytics 4 ID (optional) |

## Tech Stack

- **Frontend**: React 19 + TypeScript + Vite 7 + Tailwind CSS
- **3D Rendering**: Three.js + OpenSCAD WASM
- **AI**: Google Gemini API (Planner) + Anthropic Claude API (Coder)
- **Auth**: Supabase Auth with Google OAuth
- **Payments**: Stripe Subscriptions
- **Hosting**: Vercel (recommended)
- **Analytics**: Google Analytics 4

## Project Structure

```
polygen-ai/
β”œβ”€β”€ components/ # React components
β”‚ β”œβ”€β”€ AuthContext.tsx # Authentication state
β”‚ β”œβ”€β”€ LandingPage.tsx # Marketing homepage
β”‚ β”œβ”€β”€ MainApp.tsx # Authenticated app wrapper
β”‚ β”œβ”€β”€ PricingPage.tsx # Subscription plans
β”‚ └── ...
β”œβ”€β”€ services/ # Business logic
β”‚ β”œβ”€β”€ authService.ts # Supabase auth
β”‚ β”œβ”€β”€ stripeService.ts # Stripe integration
β”‚ β”œβ”€β”€ geminiService.ts # Gemini API
β”‚ β”œβ”€β”€ coderService.ts # Claude API
β”‚ β”œβ”€β”€ errorCategorizer.ts # Error analysis
β”‚ └── ...
β”œβ”€β”€ api/ # Vercel Edge Functions
β”‚ └── stripe/ # Payment endpoints
β”œβ”€β”€ supabase/ # Database schemas
β”œβ”€β”€ marketing/ # Launch materials
β”œβ”€β”€ seo/ # SEO assets
└── public/ # Static files
```

## Contributing

See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.

## License

MIT

---

Built by [Noah Schultz](https://github.com/nbschultz97) | Powered by Gemini + Claude