Package: tiny-3d-engine
Tiny 3D EngineThis package is a python 3D engine based on the Tkinter Canvas.
It uses Numpy for math handling.It is available onpipy,
documentation is onreadtthedocs, sources are mirrored ongitlab.comInstall this usingpipinstalltiny_3d_engineIt create simle 3D rendering forbars,triandquadelements and store the scenes in Ensight's ASCII.geoformat.
A trivial grid would look like:Loading a modelIn this simple example, a .geo file is loadedload_file_as_sceneinto a 3D scene. This scene is given to a new engine objectEngine3D. We apply a rotation.rotate()before rendering.render()the scene on the screen, then leave the interaction to the user.mainloop().scene=load_file_as_scene("myfile.geo")test=Engine3D(scene)test.rotate('y',45)test.render()test.mainloop()The SCENE and the ENGINETheSCENEis an object storing the 3D model.
A void scene is simplyNone. You can update a scene with the method.update(). Each scene handle several parts identified by a name, a string looking either as-tag-(e.g."ceiling") or as-family-.-tag-(e.g."house.ceiling").TheENGINEis used to project the scene on the 2D screen.
Once started, the view point can be contrlled by methods such as.translate()or.rotate(), then refreshed with.render(). The scen cane be update with.update(). If you want user interaction with the result, finish with the typical TK.mainloop().What if I already have my vertices and polygons?In the following example, two squares are appended to an initially voidScene3Dobject, using the methodscene.add_or_update_part.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 theEngine3Dobject, triggering a window.fromtiny_3d_engineimport(Scene3D,Engine3D)scene=Scene3D()SIZE=2LENGTH=200.points=list()conn=list()dx=LENGTH/foriinrange(SIZE):forjinrange(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])conn.append([index+3,index+1])scene.update("square1",points,conn,color="#0000ff")points=list()conn=list()foriinrange(SIZE):forjinrange(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.update("square2",points,conn,color="#ff0000")test=Engine3D(scene)test.rotate("x",45)test.rotate("y",45)test.render()test.mainloop()(It would have been easier in numpy, but I wanted to keep this readable for non-numpy programmers)Command lineA small command line interface is available:Usage:tiny_3d_engine[OPTIONS]COMMAND[ARGS]...---------------TINY_3D_ENGINE--------------------YouarenowusingtheCommandlineinterfaceofTiny3Dengine,aPython3Tkinterlightweight3Dengine,createdatCERFACS(https://cerfacs.fr).Thispackageislikelyasadependencyofotherpackages,toprovidealight3Dfeedbackforsmall3Dscenes<100000polygons.ThisCLIisgivenherefordevelopersperusalanddemonstrations.Findthescriptofthesesmalltoolsinthe/examplesfolderofthepackage.Thisisapythonpackagecurrentlyinstalledinyourpythonenvironement.Seethefulldocumentationat:https://tiny-3d-engine.readthedocs.io/en/latest/.DISCLAIMER:Tiny3Dengineisabruteforceflatrenderer.AsitisNOTusingyourgraphicalcard,donotexcpectanythingfancierthana1980videogame.

Options:--helpShowthismessageandexit.

Commands:benchRunashortbenchmarkonyourmachine.loadLoada3DscenefromFILENAME.rabbitRunademowiththeStanfordRabbit.PerformancesDo not expect more than an early 90s videogame. During mouse interations, the frames per second is roughly 30 000 / nb. of polygons (i.e. 15 fps for 2000 polygons).The engine is by default limited 100 000 polygons in a static view and 2 000 during mouse interactions. If the model goes beyond these limits, the engine ramdomly remove polygons at the loading time, to keep the window responsive.RequirementsThe present library require Numpy and Tkinter.
The Tk aspects are limited to thescreenobject.
In the future I might write extensions for PyQT4 Canvas or Matplotlib... or not.OriginsThis work stems from a mix between a Pure Tcl/Tk Engine of minepure TK 3d engineand the the pyEngine3D-master ofhenry HaefligerpyEngine3D, 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.