Open Source tiny 3D engine for tkinter
Project description
Tiny 3D Engine
This package is a python 3D engine based on the Tkinter Canvas. It uses Numpy for math handling.
It is available on pipy, documentation is on readtthedocs, sources are mirrored on gitlab.com
Install this using
pip install tiny_3d_engine
It create simle 3D rendering for bars
, tri
and quad
elements and store the scenes in Ensight's ASCII .geo
format.
A trivial square would look like:
example
In the following example, two squares are appended to an initially void Scene3D object.
- The first, in blue, is made of edges (2 vertices connectivity)
- The second, in red, is made od squares (4 vertices connectivity)
This scene is passed to the Engine3D object, triggering a window.
from tiny_3d_engine import (Scene3D, Engine3D)
scene = Scene3D()
SIZE = 2
LENGTH= 200.
points = list()
conn = list()
dx = LENGTH/
for i in range(SIZE):
for j in range(SIZE):
index = len(points)
points.append([i*dx, j*dx, 0])
points.append([(i+1)*dx, j*dx, 0])
points.append([i*dx, (j+1)*dx, 0])
points.append([(i+1)*dx, (j+1)*dx, 0])
#conn.append([index, index+1, index+2])
#conn.append([index+3, index+1, index+2])
conn.append([index, index+1])
conn.append([index+3, index+1])
scene.add_or_update_part("square1", points, conn, color="#0000ff")
points = list()
conn = list()
for i in range(SIZE):
for j in range(SIZE):
index = len(points)
points.append([i*dx, j*dx, LENGTH])
points.append([(i+1)*dx, j*dx, LENGTH])
points.append([i*dx, (j+1)*dx, LENGTH])
points.append([(i+1)*dx, (j+1)*dx, LENGTH])
conn.append([index, index+1, index+3, index+2])
scene.add_or_update_part("square2", points, conn, color="#ff0000")
test = Engine3D(scene)
test.rotate("x", 45)
test.rotate("y", 45)
test.render()
#test.bench_speed()
test.mainloop()
requirements
The present library require Numpy and Tkinter. The Tk aspects are limited to the screen object. In the future I might write extensions for PyQT4 Canvas or Matplotlib... or not.
origin
It is a mix between a Pure Tcl/Tk Engine of mine pureTK 3d engine and the the pyEngine3D-master of henryHaefligerpyEngine3D , because I really liked the API.
The present one allow several parts to be loaded, and uses numpy. Scenes can be dumped or read from the Ensight .case/.geo files.
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
Built Distribution
Hashes for tiny_3d_engine-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2a185ed59891512cbb52100a95738c7af972abf919b6ccc954fbc0b0835500a9 |
|
MD5 | 957c4ccf7488211c0ed424533e14e5b4 |
|
BLAKE2b-256 | 4d3c85b56472487b5b515a8c2dd1fc78af4c258a5c5932102e12bead52d5f4ad |