Metadata-Version: 2.5
Name: worldlock
Version: 0.1.0
Summary: 3D-consistent video generation with persistent world geometry, dual-pass conditioning, and low-VRAM support.
Author: Worldlock Contributors
License: MIT
License-File: LICENSE
Keywords: 3d-consistency,animatediff,controlnet,diffusers,pyrender,video-generation
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Multimedia :: Video
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Requires-Python: >=3.10
Requires-Dist: accelerate>=0.27.0
Requires-Dist: diffusers>=0.27.0
Requires-Dist: imageio-ffmpeg>=0.4.9
Requires-Dist: imageio>=2.31.0
Requires-Dist: numpy>=1.24.0
Requires-Dist: opencv-python>=4.8.0
Requires-Dist: peft>=0.9.0
Requires-Dist: pillow>=10.0.0
Requires-Dist: pyrender>=0.1.45
Requires-Dist: torch>=2.1.0
Requires-Dist: transformers>=4.38.0
Requires-Dist: trimesh>=4.0.0
Provides-Extra: dev
Requires-Dist: mypy>=1.9.0; extra == 'dev'
Requires-Dist: pytest>=8.0.0; extra == 'dev'
Requires-Dist: ruff>=0.4.0; extra == 'dev'
Description-Content-Type: text/markdown

# Worldlock

**3D-consistent video generation with persistent world geometry, dual-pass conditioning, and low-VRAM support.**

Worldlock decouples **3D spatial structure** from **AI video synthesis**. Instead of relying solely on text prompts—where objects warp, drift, or change proportions mid-spin—Worldlock renders a lightweight 3D world (`trimesh` + `pyrender`) to extract **gamma-normalized depth maps** and **multi-channel color-ID edge maps**, guiding `AnimateDiff` + `ControlNet` to render photorealistic, geometrically locked video clips even on **4 GB dedicated VRAM** GPUs.

---

## Key Features

* **Persistent 3D World State (`WorldScene` & `SceneObject`):** Build scenes from primitives (`add_box`, `add_ground_grid`, `add_slatted_crate`) or import custom `.glb`, `.gltf`, and `.obj` models (`load_mesh`), animating individual objects independently of the background.
* **Dual-Pass Conditioning (`ConditioningExtractor`):** Automatically switches between natural RGB lighting and high-contrast segmentation IDs to extract crisp, isoluminant-safe Canny wireframes alongside depth maps—eliminating double-edge artifacts on complex geometry.
* **Flexible Camera Trajectories (`CameraPath`):** Supports stationary turntable cameras (`CameraPath.static`), circular camera orbits (`CameraPath.orbit`), and linear push-in moves (`CameraPath.dolly`).
* **4 GB VRAM-First Rendering (`WorldRenderer`):** Built-in sequential CPU offloading, VAE slicing, and FreeNoise sliding context windows (`low_vram=True` by default) prevent Windows shared-RAM bottlenecks and out-of-memory errors.

---

## Installation

Install directly from PyPI (or in editable mode from source):

```bash
pip install worldlock
```

### From Source (Development)

```bash
git clone https://github.com
cd worldlock
pip install -e ".[dev]"
```

> **Linux Headless Tip:** If rendering on a headless Linux server without a display, install `pyglet` / OSMesa or EGL (`sudo apt-get install libosmesa6-dev` or set `PYOPENGL_PLATFORM=egl`).

---

## Quickstart: Turntable Crate Spin

```python
from worldlock import CameraPath, WorldRenderer, WorldScene

# 1. Build a persistent 3D world and animate the hero crate
scene = WorldScene()
scene.add_directional_light()
scene.add_ground_grid()

crate = scene.add_slatted_crate("hero_crate")
crate.animate_rotation(axis="y", degrees=180.0, num_frames=16)

# 2. Set up a fixed 3/4 camera looking at the center of the scene
camera = CameraPath.static(
    position=(1.8, 3.8, 4.1),
    target=(0.0, 0.0, 0.0),
    num_frames=16,
)

# 3. Render a 3D-consistent video (tuned for 4 GB+ dedicated VRAM)
renderer = WorldRenderer(low_vram=True)
video = renderer.render(
    scene=scene,
    camera_path=camera,
    prompt=(
        "RAW photo, an oak wooden slatted crate sitting in the center on granite tiles, "
        "bright daylight, crisp shadows, 8k uhd"
    ),
    negative_prompt="3d render, cgi, cartoon, blurry, distorted, morphing, flickering, warped",
)
video.save("worldlock_demo.mp4", fps=16)
```

---

## Custom 3D Models & Orbiting Cameras

You can import any `.glb` or `.obj` asset and orbit the camera around it while keeping the background stationary:

```python
from worldlock import CameraPath, ConditioningExtractor, WorldRenderer, WorldScene

scene = WorldScene()
scene.add_directional_light()
scene.add_ground_grid()

# Load your own 3D mesh
asset = scene.create_object("custom_asset").load_mesh("model.glb", scale=1.0)

# Orbit the camera 180 degrees around the object
camera = CameraPath.orbit(
    center=(0.0, 0.0, 0.0),
    radius=4.5,
    height=2.8,
    degrees=180.0,
    num_frames=16,
)

# Optional: Inspect or save Depth & Canny conditioning maps before running diffusion
extractor = ConditioningExtractor(width=512, height=512)
conditioning = extractor.extract(scene, camera, save_dir="scene_frames")

renderer = WorldRenderer(low_vram=True)
video = renderer.render_from_conditioning(
    conditioning=conditioning,
    prompt="RAW photo, weathered bronze sculpture in a sunlit stone courtyard, 8k uhd",
)
video.save("orbit_demo.mp4", fps=16)
```

---

## Architecture Overview

| Module | Class | Responsibility |
| :--- | :--- | :--- |
| `worldlock.scene` | `WorldScene`, `SceneObject` | Manages 3D geometry, directional lights, per-object transforms, and dual-pass materials. |
| `worldlock.camera` | `CameraPath` | Computes orthonormal OpenGL camera poses for static, orbit, and dolly trajectories. |
| `worldlock.conditioning` | `ConditioningExtractor` | Renders offscreen depth maps, multi-channel ID Canny edges, and base RGB sequences. |
| `worldlock.renderer` | `WorldRenderer` | Runs `AnimateDiff` + dual `ControlNet` (`Depth` + `Canny`) with low-VRAM memory optimizations. |

---

## License

MIT License. See [LICENSE](LICENSE) for details.