Skip to content

nyr-github/ai-3d-learning

Repository files navigation

AI 3D Learning Platform

An interactive 3D educational platform for exploring biological entities, chemical molecules, and physical structures. Built with Next.js, Three.js, and React Three Fiber.

🌟 Features

Interactive 3D Viewing

  • Real-time 3D Rendering: Explore scientific models with full rotation, zoom, and pan controls
  • Optimized Model Loading: Intelligent caching and preloading system for instant access
  • DRACO Compression: Supports compressed GLB models for faster loading
  • Responsive Design: Adapts seamlessly from desktop to mobile devices

Educational Content

  • Rich Metadata: Each entity includes detailed descriptions, fun facts, and teaching focus points
  • Key Structures: Highlight important anatomical or molecular features with test point markers
  • Microscope Visibility: Information about visibility under light and electron microscopes
  • Size Ranges: Interactive sliders showing realistic scale with units

Multi-Discipline Architecture

  • Extensible Data Model: Generic entity system supports biology, chemistry, physics, and more
  • Project-based Organization: Group related models into educational projects
  • Categorization System: Main categories and sub-categories for easy navigation
  • Attribute System: Flexible key-value attributes for domain-specific data

Modern UI/UX

  • Resizable Panels: Desktop layout with adjustable sidebar, viewer, and info panel
  • Mobile-First Design: Touch-optimized controls with slide-out drawers
  • Academic Theme: Clean, modern laboratory-inspired design system
  • Accessibility: Proper ARIA labels and keyboard navigation support

πŸ—οΈ Architecture

Technology Stack

Core Framework:

  • Next.js 16 - React framework with App Router and static export
  • React 19 - Latest React with concurrent features
  • TypeScript - Full type safety across the codebase

3D Rendering:

  • Three.js - Core 3D graphics library
  • React Three Fiber - React renderer for Three.js
  • Drei - Useful helpers for React Three Fiber (Environment, OrbitControls, etc.)
  • DRACO - 3D model compression for optimized loading

Styling & UI:

  • Tailwind CSS v4 - Utility-first CSS framework
  • Radix UI - Accessible component primitives
  • Lucide React - Modern icon library
  • CSS Variables - Theme system with custom properties

Development Tools:

  • Sharp - Image processing for WebP conversion
  • glTF Transform - 3D model optimization
  • ESLint - Code quality and consistency

Project Structure

ai-3d-learning/
β”œβ”€β”€ app/                          # Next.js App Router
β”‚   β”œβ”€β”€ page.tsx                  # Homepage with project overview
β”‚   β”œβ”€β”€ layout.tsx                # Root layout with metadata
β”‚   β”œβ”€β”€ globals.css               # Global styles and CSS variables
β”‚   └── project/[slug]/           # Dynamic route for each project
β”‚       β”œβ”€β”€ page.tsx              # Server component with static params
β”‚       └── ProjectClient.tsx     # Client component with interactive UI
β”œβ”€β”€ components/                   # React components
β”‚   β”œβ”€β”€ EntityViewer.tsx          # 3D canvas viewer with controls
β”‚   β”œβ”€β”€ EntityInfoPanel.tsx       # Entity details and attributes
β”‚   β”œβ”€β”€ EntitySidebar.tsx         # Model selection sidebar
β”‚   β”œβ”€β”€ ModelScene.tsx            # Three.js scene wrapper
β”‚   β”œβ”€β”€ Layout.tsx                # Header and Footer
β”‚   └── ui/                       # Reusable UI primitives
β”œβ”€β”€ data/                         # Content and data models
β”‚   β”œβ”€β”€ types.ts                  # TypeScript interfaces
β”‚   β”œβ”€β”€ index.ts                  # Data utilities and exports
β”‚   └── projects/                 # Project-specific data
β”‚       └── bio.ts                # Biology project entities
β”œβ”€β”€ hooks/                        # Custom React hooks
β”‚   └── useModel.ts               # Model loading state management
β”œβ”€β”€ lib/                          # Core utilities
β”‚   β”œβ”€β”€ modelLoader.ts            # Advanced model loading system
β”‚   └── utils.ts                  # Helper functions
β”œβ”€β”€ public/                       # Static assets
β”‚   β”œβ”€β”€ models/                   # 3D GLB model files
β”‚   β”œβ”€β”€ images/                   # Entity preview images (WebP)
β”‚   └── draco/                    # DRACO decoder files
└── scripts/                      # Build and optimization scripts
    β”œβ”€β”€ optimize-glb.ts           # GLB model optimization
    β”œβ”€β”€ convert-images-to-webp.ts # Image conversion to WebP
    └── update-model-sizes.ts     # Sync model file sizes

πŸ”¬ How It Works

1. Data Model System

The platform uses a generic entity-based data model that can represent any 3D educational content:

interface Entity3D {
  id: string;                    // Unique identifier
  name: string;                  // Display name
  mainCategory: string;          // Primary classification
  subCategory: string;           // Secondary classification
  description: string;           // Detailed description
  funFact: string;               // Engaging trivia
  teachingFocus: string;         // Educational objectives
  attributes: Attribute[];       // Flexible key-value data
  features: Feature[];           // Key structures/test points
  model3D: Model3DMetadata;      // 3D model configuration
}

This design allows:

  • Extensibility: Add new disciplines without code changes
  • Consistency: Uniform data structure across all entities
  • Rich Metadata: Support for domain-specific attributes

2. Model Loading Pipeline

The custom model loader implements an optimized loading strategy:

1. Request Initiation
   ↓
2. Check Cache (in-memory Map)
   ↓ (cache miss)
3. Download with Progress Tracking
   ↓
4. Parse GLB with DRACO Decoder
   ↓
5. Store in Cache
   ↓
6. Resolve Promise to Component

Key Features:

  • State-driven: Tracks phases (idle β†’ downloading β†’ parsing β†’ completed)
  • Promise-based: Components await model readiness
  • Intelligent Caching: Prevents redundant downloads
  • Preloading: Anticipates next model user might view

3. 3D Rendering Architecture

EntityViewer (React Component)
└── Canvas (React Three Fiber)
    β”œβ”€β”€ Lighting Setup
    β”‚   β”œβ”€β”€ Ambient Light
    β”‚   └── Directional Lights (with shadows)
    β”œβ”€β”€ Environment (Studio preset)
    β”œβ”€β”€ ModelScene (GLTF content)
    β”œβ”€β”€ ContactShadows (Ground reflection)
    └── OrbitControls (User interaction)

Optimization Strategies:

  • Adaptive DPR: [1, 2] for retina displays
  • Shadow Maps: 1024x1024 for balance of quality/performance
  • Environment Maps: Studio lighting for realistic materials
  • Lazy Loading: Suspense boundaries for async content

4. Responsive Layout System

Desktop (>640px):

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚              Header                      β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ Sidebar  β”‚   3D Viewer  β”‚  Info Panel   β”‚
β”‚  (20%)   β”‚   (55%)      β”‚    (25%)      β”‚
β”‚Resizable β”‚  Resizable   β”‚  Resizable    β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚              Footer                      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Mobile (<640px):

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚    Header            β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ [Menu] [Info]        β”‚ ← Control buttons
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                      β”‚
β”‚   3D Viewer (Full)   β”‚
β”‚                      β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚    Footer            β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
     ↓ Swipe/Tap
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Sidebar     β”‚ ← Slide-out drawer
β”‚  (Overlay)   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

5. Static Site Generation

The platform uses Next.js static export for GitHub Pages deployment:

// Generate all project routes at build time
export function generateStaticParams() {
  return projects.map((project) => ({
    slug: project.slug,
  }));
}

Benefits:

  • Zero Server Required: Pure static HTML/CSS/JS
  • Fast Loading: Pre-rendered pages
  • CDN Ready: Deploy anywhere (GitHub Pages, Vercel, Netlify)
  • SEO Friendly: Server-rendered metadata

πŸš€ Getting Started

Prerequisites

  • Node.js 20+
  • pnpm 10+ (or npm/yarn)

Installation

# Clone the repository
git clone <repository-url>
cd ai-3d-learning

# Install dependencies
pnpm install

# Start development server
pnpm dev

The application will be available at http://localhost:3000

Build for Production

# Build static site
pnpm build

# Preview production build
pnpm start

Static files are generated in the out/ directory.

πŸ› οΈ Development Scripts

Model Optimization

# Optimize all GLB models
pnpm optimize:glb ./public/models

# Optimize with custom output directory
pnpm optimize:glb ./public/models ./public/models-optimized

Uses glTF Transform to:

  • Compress textures to WebP
  • Apply DRACO mesh compression
  • Reduce file sizes by 50-80%

Image Conversion

# Convert images to WebP
pnpm convert:webp ./public/images

Converts PNG/JPG to optimized WebP format with:

  • Max width: 400px
  • Quality: 80%
  • Maintains aspect ratio

Update Model Metadata

# Sync file sizes in data models
pnpm update:model-sizes

Automatically updates fileSize fields in model definitions based on actual GLB file sizes.

πŸ“¦ Adding New Content

1. Create Entity Data

Add new entities in data/projects/<project>.ts:

{
  id: "my-entity",
  name: "My Entity",
  subtitle: "Description",
  mainCategory: "Category",
  subCategory: "Subcategory",
  accent: "#hexcolor",
  description: "Detailed explanation...",
  funFact: "Interesting fact!",
  teachingFocus: "Learning objective...",
  attributes: [
    { name: "Size Range", value: "10-100", unit: "ΞΌm" },
    // ... more attributes
  ],
  features: [
    { name: "Feature 1", detail: "Description", isHighFreqTestPoint: true },
    // ... more features
  ],
  whereItOccurs: {
    text: "Where to find it...",
    habitat: "Habitat info..."
  },
  model3D: {
    modelUrl: asset("models/my-entity.glb"),
    imageUrl: asset("images/my-entity.webp"),
    fileSize: 1234567,
    defaultRotationY: -Math.PI / 4,
    displayScale: 1.4,
  }
}

2. Add 3D Model

Place your GLB file in public/models/:

cp my-entity.glb public/models/

Optimization recommended:

pnpm optimize:glb ./public/models

3. Add Preview Image

Place WebP image in public/images/:

cp my-entity.webp public/images/

Or convert from PNG/JPG:

pnpm convert:webp ./public/images

4. Update File Sizes

pnpm update:model-sizes

5. Test Locally

pnpm dev

Navigate to http://localhost:3000/project/<project-slug> to see your new entity.

🌐 Deployment

GitHub Pages

The project includes a complete GitHub Actions workflow:

# .github/workflows/deploy.yml
# Automatically deploys on push to main branch

Setup:

  1. Push to main branch
  2. GitHub Actions builds and deploys
  3. Site available at https://<username>.github.io/<repo>

Other Platforms

Since it's a static site, you can deploy to:

  • Vercel: vercel --prod
  • Netlify: Drag & drop out/ folder
  • AWS S3: Upload out/ to S3 bucket
  • Any CDN: Serve static files

πŸŽ“ Educational Use Cases

For Teachers

  • Visual Demonstrations: Show complex 3D structures in class
  • Self-Study Resource: Students can explore at their own pace
  • Test Preparation: High-frequency test points highlighted
  • Comparative Learning: Side-by-side model comparisons

For Students

  • Interactive Exploration: Rotate, zoom, and examine every detail
  • Contextual Learning: Fun facts and real-world applications
  • Microscope Prep: Know what to expect before lab sessions
  • Scale Understanding: Size ranges with visual sliders

For Content Creators

  • Extensible Platform: Add your own 3D models and data
  • Multi-Discipline: Support any scientific field
  • AI-Generated Models: Includes prompts for AI 3D generation
  • Open Architecture: Modify and customize freely

πŸ“Š Current Content

Biology Project (/project/bio)

Cells:

  • Plant Cell (Eukaryotic, Autotrophic)
  • Animal Cell (Eukaryotic, Heterotrophic)
  • Bacterial Cell (Prokaryotic)
  • White Blood Cell (Immune System)
  • Neuron (Nervous System)

Organelles:

  • Mitochondrion (Powerhouse)
  • Chloroplast (Photosynthesis)
  • Cell Membrane (Fluid Mosaic Model)

Biomolecules:

  • DNA Double Helix (Genetic Code)

Viruses:

  • T4 Bacteriophage (Bacterial Virus)

πŸ”§ Troubleshooting

Models Not Loading

  • Check GLB files exist in public/models/
  • Verify file sizes match in data definitions
  • Run pnpm update:model-sizes to sync

Build Fails

  • Ensure all TypeScript types are correct
  • Check that generateStaticParams returns valid slugs
  • Clear .next/ cache: rm -rf .next

Performance Issues

  • Optimize GLB files: pnpm optimize:glb
  • Convert images to WebP: pnpm convert:webp
  • Check browser console for Three.js warnings

🀝 Contributing

Contributions are welcome! Please:

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Test thoroughly
  5. Submit a pull request

πŸ“ License

This project is open source and available under the MIT License.

πŸ™ Acknowledgments

  • Three.js community for amazing 3D web tools
  • React Three Fiber for seamless React integration
  • Next.js team for the excellent framework
  • Educators who inspired this platform

Built with ❀️ for science education

Explore. Learn. Discover.

About

show 3D created by image

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors