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.
- Persistent 3D World State (
WorldScene&SceneObject): Build scenes from primitives (add_box,add_ground_grid,add_slatted_crate) or import custom.glb,.gltf, and.objmodels (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=Trueby default) prevent Windows shared-RAM bottlenecks and out-of-memory errors.
Install directly from PyPI (or in editable mode from source):
pip install worldlockgit 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-devor setPYOPENGL_PLATFORM=egl).
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)You can import any .glb or .obj asset and orbit the camera around it while keeping the background stationary:
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)| 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. |
MIT License. See LICENSE for details.