Skip to content

KAIST-VML/KOCCA-SceneGeneration

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

27 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

KOCCA 3D Scene Generation API

A powerful REST API that generates 3D scenes from text descriptions using advanced AI algorithms. This project combines layout synthesis, object retrieval, and scene composition to create realistic 3D environments in GLB format.

๐Ÿ—๏ธ Architecture

The system uses a multi-stage pipeline:

  1. Text Analysis - OpenAI GPT processes natural language descriptions
  2. Layout Synthesis - Generates spatial arrangements and room layouts
  3. Object Retrieval - Finds and selects appropriate 3D models from dataset
  4. Scene Composition - Assembles final 3D scene with proper positioning and lighting

๐Ÿ“‹ Requirements

  • Python: 3.8+
  • OS: Linux (Ubuntu 18.04+ recommended)
  • GPU: CUDA-compatible GPU with 8GB+ VRAM (optional but recommended)
  • RAM: 16GB minimum, 32GB recommended
  • Storage: 50GB+ for full 3D-FUTURE dataset

๐Ÿš€ Quick Start

Installation

# Clone the repository
git clone https://github.com/KAIST-VML/KOCCA-SceneGeneration.git
cd KOCCA-SceneGeneration

# Install Python dependencies
pip install -r requirements.txt

# Set up environment variables
set -a                
source config.env     # modify it before you use
set +a

Dataset Setup

This project requires the 3D-FUTURE dataset for 3D object models:

# Create dataset directory
mkdir -p dataset

# Download 3D-FUTURE dataset (registration required)
# Visit: https://tianchi.aliyun.com/specials/promotion/alibaba-3d-future
# Download all parts and extract to dataset/ directory

# Expected structure after extraction:
# dataset/
# โ”œโ”€โ”€ 3D-FUTURE-model-part1/
# โ”œโ”€โ”€ 3D-FUTURE-model-part2/
# โ”œโ”€โ”€ 3D-FUTURE-model-part3/
# โ””โ”€โ”€ 3D-FUTURE-model-part4/

3D-FUTURE Dataset Information

Configuration

Edit config.env:

# Required: OpenAI API key for text processing
export OPENAI_API_KEY="sk-your-openai-api-key"

# Optional: Custom paths
export SCENE_BASE_PATH="./space-generator"
export SCENE_OUTPUT_DIR="./outputs"
export SCENE_WORK_DIR="."
export export DATASET_BASE_PATH = "your dataset path"

Running the Server

# Method 1: Using the provided script
bash run.sh

# Method 2: Manual execution
source config.env
python main.py
# ex. 
# python client.py "a cozy living room with a sofa and a coffee table" ./downloads --iterations 200


# Method 3: Production deployment
uvicorn main:app --host 0.0.0.0 --port 8000 --workers 4

Server will start at http://localhost:8000

๐Ÿ“– Usage

Python Client

import requests
from client import SceneGenerationClient

# Initialize client
client = SceneGenerationClient("http://localhost:8000")

# Generate scene
result = client.generate_scene(
    prompt="A modern 4x4 living room with minimalist furniture",
    output_path="./living_room.glb",
    iterations=300
)

Command Line

# Basic usage
python client.py "A cozy bedroom with wooden furniture" "./bedroom.glb"

# Advanced options
python client.py "A modern kitchen" "./kitchen.glb" \
    --iterations 500 \
    --server-url http://localhost:8000 \
    --check-interval 5

REST API

Generate Scene

curl -X POST http://localhost:8000/api/generate-scene \
  -H "Content-Type: application/json" \
  -d '{
    "scene_descriptor": "A 5x5 modern office space",
    "iterations": 300,
    "openai_api_key": "sk-your-key"
  }'

Check Status

curl http://localhost:8000/api/status/{task_id}

Download Result

curl http://localhost:8000/download/{task_id} -o scene.glb

๐Ÿ”ง API Reference

Endpoints

Method Endpoint Description
GET /health Server health check
POST /api/set-api-key Configure OpenAI API key
POST /api/generate-scene Start scene generation
GET /api/status/{task_id} Check generation progress
GET /download/{task_id} Download generated GLB file

Request/Response Schemas

Scene Generation Request

{
  "scene_descriptor": "string",
  "iterations": 300,
  "openai_api_key": "string"
}

Status Response

{
  "task_id": "string",
  "status": "processing|completed|failed",
  "stage": "scene_synthesis|text_retrieval|clip_retrieval|scene_composition",
  "progress": 0.75,
  "message": "string",
  "output_file": "string"
}

๐Ÿ“ Project Structure

KOCCA-SceneGeneration/
โ”œโ”€โ”€ main.py                     # FastAPI server implementation
โ”œโ”€โ”€ client.py                   # Python client library
โ”œโ”€โ”€ config.env                  # Environment configuration
โ”œโ”€โ”€ requirements.txt            # Python dependencies
โ”œโ”€โ”€ run.sh                      # Server startup script
โ”œโ”€โ”€ layout_scene_api.sh         # Scene generation pipeline
โ”œโ”€โ”€ space-generator/            # Core generation algorithms
โ”‚   โ”œโ”€โ”€ Scene_Synthesis/        # Layout generation module
โ”‚   โ”‚   โ”œโ”€โ”€ models/            # Pre-trained models
โ”‚   โ”‚   โ””โ”€โ”€ utils/             # Utility functions
โ”‚   โ””โ”€โ”€ retrieval/             # Object retrieval system
โ”‚       โ”œโ”€โ”€ clip_retrieval.py  # CLIP-based object matching
โ”‚       โ””โ”€โ”€ text_retrieval.py  # Text-based object search
โ”œโ”€โ”€ dataset/                    # 3D object dataset (download required)
โ”‚   โ”œโ”€โ”€ 3D-FUTURE-model-part1/ # Download from Alibaba Tianchi
โ”‚   โ”œโ”€โ”€ 3D-FUTURE-model-part2/ # Registration required
โ”‚   โ”œโ”€โ”€ 3D-FUTURE-model-part3/ # ~40GB total size
โ”‚   โ””โ”€โ”€ 3D-FUTURE-model-part4/ # 10,000+ 3D models
โ””โ”€โ”€ outputs/                    # Generated scene files

๐ŸŽฏ Features

  • Multi-modal Input: Support for natural language scene descriptions
  • Scalable Architecture: Async processing with task queue management
  • Rich Object Database: Integration with 3D-FUTURE dataset (10,000+ models)
  • Format Support: Outputs industry-standard GLB files
  • Progress Tracking: Real-time generation progress monitoring
  • RESTful API: Easy integration with web applications
  • Error Handling: Comprehensive error reporting and recovery

๐Ÿ”ง Development

Setup Development Environment

# Install development dependencies
pip install -r requirements-dev.txt

# Run tests
pytest tests/

# Code formatting
black .
isort .

# Type checking
mypy .

Environment Variables

Variable Description Default
OPENAI_API_KEY OpenAI API key (required) -
SCENE_BASE_PATH Space generator directory ./space-generator
SCENE_OUTPUT_DIR Output directory ./outputs
SCENE_WORK_DIR Working directory .
LOG_LEVEL Logging level INFO

About

3D Scene generation project

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors