Flet 3D & 2D (flet-3d)
A vectorized 3D and 2D software rendering, UI widget, and physics engine for Flet 1.0+ powered by NumPy and flet.canvas.Canvas.
Build interactive 3D product cards, spinning geometric badges, .obj/.mtl model viewers, vector .svg artwork, and 2D rigid-body physics across Windows, macOS, Linux, Web, Android, and iOS—with zero external C/OpenGL native dependencies.
🎬 Video Demos
Interactive 3D Product Store & UI Flow
Real-time Physics & Rendering Engine
Interactive 3D Mathematical Surface & Raycast Telemetry Explorer
interactive 3D Rubik's Cube simulator
2D + 3D Hybrid Dashboard
interactive 3D Articulated Robotic Arm
✨ Features
Declarative UI Widgets (Shape3DWidget, Shape2DWidget, ObjModelWidget, SvgWidget)
- Drop-In Flet Controls: Embed interactive 3D and 2D shapes directly inside
Row,Column,Card, andContainerlayouts with zero matrix math or manualwhile Trueloops. - Built-In Primitive Library (
Mesh3D&SceneBuilder2D): Createbox,pyramid,octahedron,icosphere,torus,cylinder,star,diamond,hexagon, andcirclemeshes using standard hex colors ("#38bdf8"). - Micro-Interactions Out of the Box: Automatic 60 FPS lifecycle management, touch/mouse swipe inertia, radial studio glow backdrops, hover highlights, and spring-pulse click animations.
3D Engine (VectorizedEngine3D & Viewport3D)
- Vectorized NumPy Matrix Pipeline: Fast
4x4homogeneous Model-View-Projection math, back-face culling, and Blinn-Phong diffuse + specular shading. - True Sutherland-Hodgman Near-Plane Clipping: Cleanly slices triangles straddling
z = near_planewithout 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 & IPC Optimization: Groups depth-sorted triangles by quantized RGB color with cached
ft.Paintpools,0.1pxcoordinate rounding, and single-callcv.Points(PointMode.LINES)wireframes—cutting Flet IPC serialization overhead by 70–90%. - 6-DOF Camera (
Camera6DOF): FullWASD+Q/E+Shiftflight movement, mouse/touch drag look with momentum coasting, andft.Accelerometertilt support on mobile. - Wavefront
.obj+.mtlLoader (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.
2D Engine (VectorizedEngine2D, Viewport2D, PhysicsWorld2D, load_svg)
- 3x3 Affine Camera (
Camera2D): Smooth drag panning, scroll-wheel zoom-to-cursor, rotation (Q/E), andWASDmovement. - Z-Layer Painter's Sorting & Batching: Renders thousands of triangles at 60 FPS with a vectorized infinite world grid.
- Nested
.svgVector 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
Using pip
pip install flet-3d
Using uv (or from Source)
git clone https://github.com/osamalzabidi/flet-3d.git
cd flet-3d
uv sync
📁 Repository Structure
flet-3d/
├── src/
│ ├── __init__.py # Unified public exports for 2D, 3D, Physics & Widgets
│ ├── camera.py # Camera6DOF (3D with inertia) & Camera2D (2D)
│ ├── engine.py # VectorizedEngine3D, VectorizedEngine2D & RenderStats
│ ├── loaders.py # Wavefront .obj/.mtl loader, SceneBuilder3D & SceneBuilder2D
│ ├── physics.py # PhysicsWorld2D & RigidBody2D rigid-body simulator
│ ├── primitives.py # Mesh3D primitives (box, icosphere, torus, etc.) & hex_to_rgb
│ ├── svg_loader.py # Nested <g transform> SVG parser & ear-clipping triangulator
│ ├── viewport.py # Auto-resizing Viewport3D & Viewport2D gesture controls
│ └── widgets.py # Self-contained Shape3DWidget, Shape2DWidget, ObjModelWidget, SvgWidget
├── 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
├── tests/
├── pyproject.toml
├── LICENSE
└── README.md
🚀 Quickstart Examples
1. Declarative 3D & 2D UI Widgets (Zero Boilerplate)
Embed interactive 3D and 2D shapes directly into any Flet layout—no manual render loop required:
import flet as ft
from flet_3d import Mesh3D, Shape2DWidget, Shape3DWidget
def main(page: ft.Page):
page.title = "Flet 3D & 2D Widgets"
page.bgcolor = "#020617"
page.padding = 24
page.add(
ft.Row(
spacing=16,
wrap=True,
controls=[
Shape3DWidget(
mesh=Mesh3D.torus(color="#38bdf8"),
width=180,
height=180,
bgcolor="#0f172a",
on_click=lambda _: print("Torus clicked!"),
),
Shape3DWidget(
mesh=Mesh3D.icosphere(subdivisions=2, color="#f472b6"),
width=180,
height=180,
bgcolor="#0f172a",
hover_highlight="#4ade80",
),
Shape2DWidget(
shape="star",
size=180,
color="#facc15",
bgcolor="#0f172a",
border_radius=16,
),
],
)
)
if __name__ == "__main__":
ft.run(main)
2. Full-Screen 3D Viewport (Viewport3D)
Viewport3D handles resizing, camera inertia, and auto-rendering out of the box:
import flet as ft
from flet_3d import Camera6DOF, Mesh3D, Viewport3D
def main(page: ft.Page):
page.title = "Flet 3D Viewport"
page.bgcolor = "#020617"
page.padding = 0
cube = Mesh3D.box(width=2.0, height=2.0, depth=2.0, color="#38bdf8")
viewport = Viewport3D(
cube.vertices,
cube.faces,
cube.colors,
camera=Camera6DOF(pos=(0.0, 1.5, -5.0), pitch=-0.25),
on_pick=lambda hit: print("Hit triangle:", hit),
)
page.add(viewport)
if __name__ == "__main__":
ft.run(main)
3. 2D Vector Scene & Rigid-Body Physics (PhysicsWorld2D)
Pass auto_render=False when driving your own synchronized physics and animation loop:
import asyncio
import flet as ft
from flet_3d import PhysicsWorld2D, SceneBuilder2D, Viewport2D
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, auto_render=False)
page.add(viewport)
while True:
physics.step(1 / 60, vertices)
viewport.render_frame()
viewport.canvas.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 (with Inertia) | 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.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| flet_3d-0.2.0.tar.gz | 37.0 kB | With provenance | Details for flet_3d-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| flet_3d-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for flet_3d-0.2.0-py3-none-any.whl |
Total release size: 70.6 kB
Release files / flet_3d-0.2.0.tar.gz
| Download URL | flet_3d-0.2.0.tar.gz |
|---|---|
| Size | 37.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
22081c1368a061071aa6b9fc3c00be9fb7a07c3ce18fa37b57c45026028cdf0a
|
|
BLAKE2b-256 checksum How to use checksums |
e3ddfaf9303003eebe540dd088a75569b9bbd71e1e398241fd182b1e9e39094e
|
| 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 3, 2026.
Transparency logRelease files / flet_3d-0.2.0-py3-none-any.whl
| Download URL | flet_3d-0.2.0-py3-none-any.whl |
|---|---|
| Size | 33.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5610aef0b5f133ca3ad6609100219b02568fff39646d9650b701211f521f2eaa
|
|
BLAKE2b-256 checksum How to use checksums |
7eea854890c677f2df84a14707d235f40d421cd9ef81092c9ca6bbdb5c4da70c
|
| 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 3, 2026.
Transparency logSecurity for flet-3d 0.2.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.
Attestation for flet_3d-0.2.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 3, 2026.
Transparency logA 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.