Skip to main content

Flet 3D & 2D (flet-3d)

A vectorized 3D and 2D software rendering & physics engine for Flet 1.0+ powered by NumPy and flet.canvas.Canvas.

Run real-time interactive 3D scenes, .obj/.mtl models, vector .svg artwork, and 2D rigid-body physics across Windows, macOS, Linux, Web, Android, and iOS—with zero external C/OpenGL native dependencies.


Features

3D Engine (VectorizedEngine3D & Viewport3D)

  • Vectorized NumPy Matrix Pipeline: Fast 4x4 homogeneous Model-View-Projection math, back-face culling, and flat directional lighting.
  • True Sutherland-Hodgman Near-Plane Clipping: Cleanly slices triangles straddling z = near_plane without coordinate explosion or pop-out.
  • 2D Screen-Bounds Frustum Culling: Drops off-screen and sub-pixel triangles before depth sorting (np.argsort).
  • Run-Length Draw-Call Batching: Groups consecutive depth-sorted triangles of matching quantized RGB colors into single cv.Path objects, cutting Flet IPC serialization overhead by 70–90%.
  • 6-DOF Camera (Camera6DOF): Full WASD + Q/E + Shift flight movement and mouse/touch drag look.
  • Wavefront .obj + .mtl Loader (load_obj_with_progress): Multi-material diffuse color parsing, polygon fan-triangulation, byte-level progress tracking, and automatic triangle-budget decimation for massive meshes.
  • Möller–Trumbore Ray-Triangle Picking (engine.pick): Instant 3D object selection and world-space hit inspection on click/tap.
  • Live Debug Overlays: Toggleable wireframe, solid fill, and surface normal vectors.

2D Engine (VectorizedEngine2D, Viewport2D, PhysicsWorld2D, load_svg)

  • 3x3 Affine Camera (Camera2D): Smooth drag panning, scroll-wheel zoom-to-cursor, rotation (Q/E), and WASD movement.
  • Z-Layer Painter's Sorting & Batching: Renders thousands of triangles at 60 FPS with an infinite adaptive world grid.
  • Nested .svg Vector Importer (load_svg): Parses <path>, <rect>, <circle>, <ellipse>, and <polygon> tags—including nested <g transform="translate(...) rotate(...) scale(...) matrix(...)"> hierarchies, Bézier curve flattening, and ear-clipping triangulation.
  • 2D Rigid-Body Physics (PhysicsWorld2D): Gravity, angular velocity/torque, wall/floor bounces, elastic body-to-body collisions, and interactive impulse kicks.
  • Barycentric Shape Picking: Accurate point-in-polygon selection respecting Z-layer stacking.

Installation

git clone https://github.com/osamalzabidi/flet-3d.git
cd flet-3d
uv sync

Using pip

pip install git+https://github.com/osamalzabidi/flet-3d.git

Repository Structure

flet-3d/
├── src/
│   ├── __init__.py       # Public exports for 2D & 3D engines
│   ├── camera.py         # Camera6DOF (3D) & Camera2D (2D)
│   ├── engine.py         # VectorizedEngine & RenderStats (2D and 3D)
│   ├── loaders.py        # Wavefront .obj/.mtl loader & SceneBuilder2D
│   ├── physics.py        # PhysicsWorld2D & RigidBody2D rigid-body simulator
│   ├── svg_loader.py     # Nested <g transform> SVG parser & ear-clipping triangulator
│   └── viewport.py       # Drop-in Flet Viewport3D & Viewport2D gesture controls
├── examples/
│   ├── 2d/
│   │   ├── 01_minimal_2d.py
│   │   ├── 02_physics_sandbox.py
│   │   ├── 03_particle_fountain.py
│   │   ├── 04_tilemap_editor.py
│   │   └── 05_nested_svg_transforms.py
│   └── 3d/
│       ├── 01_minimal_viewer.py
│       ├── 02_procedural_terrain.py
│       ├── 03_solar_system_animation.py
│       ├── 04_cad_inspector_ui.py
│       └── 05_voxel_minecraft_builder.py
├── pyproject.toml
├── LICENSE
└── README.md

Quickstart Examples

1. 3D Viewport Quickstart

import asyncio
import flet as ft
import numpy as np
from flet_3d import Camera6DOF, VectorizedEngine3D, Viewport3D

async def main(page: ft.Page):
    page.title = "Flet 3D Quickstart"
    page.bgcolor = "#020617"
    page.padding = 0

    vertices = np.array([
        [-1, -1, -1], [1, -1, -1], [1, 1, -1], [-1, 1, -1],
        [-1, -1,  1], [1, -1,  1], [1, 1,  1], [-1, 1,  1],
    ], dtype=np.float32)

    faces = np.array([, [0, 3, 2], [1, 6, 5], [1, 2, 6],
, [5, 6, 7], [4, 3, 0], [4, 7, 3],
, [3, 7, 6], [4, 1, 5], [4, 0, 1],
    ], dtype=np.int32)

    colors = np.tile(np.array([56, 189, 248], dtype=np.float32), (len(faces), 1))

    viewport = Viewport3D(
        vertices, faces, colors,
        camera=Camera6DOF(pos=(0.0, 1.5, -5.0), pitch=-0.25),
        engine=VectorizedEngine3D(),
    )
    page.add(viewport)

    while True:
        viewport.engine.width = page.width or 800
        viewport.engine.height = page.height or 600
        viewport.render_frame()
        page.update()
        await asyncio.sleep(1 / 60)

if __name__ == "__main__":
    ft.run(main)

2. 2D Vector Scene & Rigid-Body Physics Quickstart

import asyncio
import flet as ft
from flet_3d import SceneBuilder2D, Viewport2D
from flet_3d.physics import PhysicsWorld2D

async def main(page: ft.Page):
    page.title = "Flet 2D Physics Quickstart"
    page.bgcolor = "#020617"
    page.padding = 0

    builder = SceneBuilder2D()
    builder.add_rect(0.0, -240.0, 600.0, 24.0, (51, 65, 85), z_layer=0, obj_id=0)   # Static floor
    builder.add_polygon(-60.0, 140.0, 42.0, sides=6, color=(56, 189, 248), z_layer=1, obj_id=1)
    builder.add_polygon(60.0, 210.0, 38.0, sides=5, color=(244, 114, 182), z_layer=2, obj_id=2)

    vertices, faces, colors, z_layers, object_ids = builder.build()
    physics = PhysicsWorld2D.from_buffers(vertices, faces, object_ids, static_ids={0})

    viewport = Viewport2D(vertices, faces, colors, z_layers)
    page.add(viewport)

    while True:
        viewport.engine.width = page.width or 800
        viewport.engine.height = page.height or 600
        physics.step(1 / 60, vertices)
        viewport.render_frame()
        page.update()
        await asyncio.sleep(1 / 60)

if __name__ == "__main__":
    ft.run(main)

Controls & Shortcuts

Mode Action Input
3D Camera Move / Strafe / Elevate W A S D + Q / E (Shift to sprint)
3D Camera Look / Orbit Click & Drag (or Touch Drag / ft.Accelerometer Tilt on Mobile)
3D / 2D Select / Pick Object Single Click / Tap
2D Camera Pan / Zoom-to-Cursor Drag Empty Space / Mouse Wheel
2D Camera Move / Rotate View W A S D / Q / E
Debug Toggle Wireframe / Solid / Normals 1 / 2 / 3

License

Licensed under the Apache License 2.0. See LICENSE for details.

Metadata

Release files for flet-3d 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for flet-3d 0.1.0
File Size Uploaded Provenance Actions
flet_3d-0.1.0.tar.gz 18.6 kB With provenance Details for flet_3d-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for flet-3d 0.1.0
File Interpreter ABI Platform Actions
flet_3d-0.1.0-py3-none-any.whl Python 3 none any Details for flet_3d-0.1.0-py3-none-any.whl

Total release size: 39.5 kB

Release files / flet_3d-0.1.0.tar.gz

Download URL flet_3d-0.1.0.tar.gz
Size 18.6 kB
Tags Source
SHA-256 checksum
How to use checksums
75d6331ac7c4163acbeb05b0c6622888d80540ba28f61ba30088856321b1eeed
BLAKE2b-256 checksum
How to use checksums
3abd8be60d33ea9947f4d9796072c004230ff6c491da1c554677d4dae48025ff
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 2, 2026.

Transparency log

Release files / flet_3d-0.1.0-py3-none-any.whl

Download URL flet_3d-0.1.0-py3-none-any.whl
Size 20.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9c3c51e3eab60086dbbde4e25674f38ebff2505267ebdb5211d26079635ccf4d
BLAKE2b-256 checksum
How to use checksums
8c3e288d64f24213c870244cae8a8bad6efb90672cf2fc10893758a68ed5de6c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 2, 2026.

Transparency log

Security for flet-3d 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for flet_3d-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 2, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page