Skip to main content

Differentiable 3D computer vision on Apple Silicon, built on MLX

Project description

MLX3D

Differentiable 3D computer vision on Apple Silicon, built on MLX.

MLX3D brings the PyTorch3D workflow to Macs: batched 3D data structures, cameras, differentiable rendering, and modern view synthesis — NeRF and 3D Gaussian Splatting with custom Metal kernels — running natively on the Apple GPU.

📖 Documentation & tutorials

Features

  • Structures — batched Meshes / Pointclouds with list, packed and padded views; differentiable normals, areas, edges.
  • Cameras & transforms — OpenCV/COLMAP-convention pinhole cameras (ray generation, projection, look-at) and batched rotation conversions (quaternion, axis-angle, Euler, 6D).
  • Ops & losses — GPU brute-force k-NN, chamfer distance, area-weighted surface sampling, Laplacian/edge/normal-consistency mesh losses, PSNR and differentiable SSIM.
  • NeRF — positional encoding, the NeRF MLP, stratified + hierarchical sampling, volume rendering, Blender-synthetic dataset loader.
  • Mesh rendering — differentiable soft triangle rasterization, UV texture sampling for OBJ/MTL assets, and scalar-field mesh extraction.
  • Gaussian Splatting — a Metal translation of the reference CUDA rasterizer (tile-based forward & backward kernels wrapped in mx.custom_function), EWA projection, spherical harmonics, adaptive density control, COLMAP loading, and standard 3DGS .ply checkpoints. ~30 FPS forward at 720p with 100k Gaussians on an M-series GPU.
  • Interactive viewermlx3d-view point_cloud.ply opens a browser viewer with orbit/pan/zoom; frames are rendered on the Apple GPU by the Metal rasterizer and streamed live. Works for NeRFs too.
  • IO — OBJ and PLY (ascii + binary, including Gaussian Splatting checkpoint layouts), plus one-line image save_image / load_image for any renderer output.
  • Composable & extensible — every image renderer is a plain callable (camera, scene) -> {"image", "alpha", "depth"} (the Renderer protocol), so you can drop in your own rasterizer, shader, or ray tracer and reuse the rest of the pipeline — no base classes to subclass.

Installation

pip install mlx3d

Requires an Apple Silicon Mac and Python ≥ 3.10.

Quick example

import mlx.core as mx
from mlx3d.cameras import Camera
from mlx3d.splatting import GaussianModel

model = GaussianModel.from_points(
    points=mx.random.normal((10_000, 3)) * 0.5,
    colors=mx.random.uniform(shape=(10_000, 3)),
)
camera = Camera.look_at(eye=(0, 0, -4), at=(0, 0, 0), width=1280, height=720)
out = model.render(camera)            # differentiable end to end
print(out["image"].shape)             # (720, 1280, 3)

Train Gaussian Splatting on any COLMAP scene (same inputs as the original 3DGS):

python examples/train_gaussian_splatting.py --data /path/to/scene --iters 7000
mlx3d-view outputs/gs/point_cloud.ply   # inspect the result interactively

More in the docs: mesh optimization, point cloud fitting, NeRF, Gaussian Splatting.

Examples

The examples/ folder has runnable scripts for every core feature. The self-contained ones generate their own synthetic data — no downloads — and finish in seconds:

uv run python examples/render_mesh.py        # soft mesh rasterization
uv run python examples/raytrace_volume.py    # ray casting + volume rendering
uv run python examples/extract_mesh.py       # marching cubes from an SDF
uv run python examples/fit_pointcloud.py     # point-cloud optimization
uv run python examples/fit_mesh.py           # mesh fitting (chamfer + regularizers)
uv run python examples/fit_nerf.py           # train a small NeRF
uv run python examples/fit_gaussians.py      # fit 3D Gaussians
uv run python examples/extend_renderer.py    # plug in a custom renderer

See examples/README.md for the full list, including the COLMAP/Blender training scripts.

Development

Development uses uv:

git clone https://github.com/amirhossein-razlighi/mlx3D
cd mlx3D
uv sync               # creates .venv with all dev dependencies
uv run pytest tests/
uv run mkdocs serve   # docs at http://127.0.0.1:8000

Contributions are welcome — file an issue to get started.

Roadmap

  • Meshes / Pointclouds structures, cameras, transforms
  • OBJ / PLY IO
  • knn, chamfer, surface sampling, mesh losses, SSIM/PSNR
  • NeRF (hierarchical sampling, volume rendering)
  • Differentiable point splatting renderer
  • 3D Gaussian Splatting with Metal forward/backward kernels
  • COLMAP / Blender dataset loaders
  • Differentiable mesh rasterizer (soft rasterization)
  • Textured mesh rendering (.mtl, UV textures)
  • Optimizer-state-preserving densification for 3DGS
  • Configurable 3DGS training method with vanilla default and MCMC-style fixed-budget relocation
  • 2DGS / surfel-style Gaussian mode with local-normal thickness constraints
  • 2DGS geometry losses and surface extraction refinements
  • Additional well-known splatting recipes (anti-aliasing, compression, 3DGUT-style variants)
  • Viewer depth-map mode for Gaussian checkpoints
  • Viewer mesh-style inspection with GPU-efficient depth contours
  • Marching cubes / mesh extraction
  • More acceleration structures (hash-grid encodings for NeRF)

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mlx3d-0.1.1.tar.gz (1.8 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mlx3d-0.1.1-py3-none-any.whl (129.5 kB view details)

Uploaded Python 3

File details

Details for the file mlx3d-0.1.1.tar.gz.

File metadata

  • Download URL: mlx3d-0.1.1.tar.gz
  • Upload date:
  • Size: 1.8 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for mlx3d-0.1.1.tar.gz
Algorithm Hash digest
SHA256 1be09bd81007d563fb7f6873c28b4d5c31fe1142a8dab16dfa5c2d4f212a4cc7
MD5 a508a3ab94e4820048cb62301741acae
BLAKE2b-256 d1f3bb92fc369e491b31a35e5f6e2e9208e8f6b6f34cacb7e71605c0e2494de1

See more details on using hashes here.

Provenance

The following attestation bundles were made for mlx3d-0.1.1.tar.gz:

Publisher: publish.yml on amirhossein-razlighi/mlx3D

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mlx3d-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: mlx3d-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 129.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for mlx3d-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 cb745f46cf155a3a8c66025f72cdada9ad58c3659c49b2414c927a3dc942dcf4
MD5 5d519bf700b96625a9198545f2700109
BLAKE2b-256 44d601c21e1dc30d48d3aab54b9c3394ca0feada585d274ead64da9cc8da7d57

See more details on using hashes here.

Provenance

The following attestation bundles were made for mlx3d-0.1.1-py3-none-any.whl:

Publisher: publish.yml on amirhossein-razlighi/mlx3D

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page