7

What are good libraries for creating a python program for (visually appealing) 3D physics simulations/visualizations?

I've looked at Vpython but the simulations I have seen look ugly, I want them to be visually appealing. It also looks like an old library. For 3D programming I've seen suggestions of using Panda3D and python-ogre but I'm not sure if it is really suited for exact simulations. Also, I would prefer a library that combines well with other libraries (E.g. pygame does not combine so well with other libraries).

Bentley4
  • 10,678
  • 25
  • 83
  • 134
  • What are good libraries for creating a python program for (visually appealing) 3D physics simulations/visualizations? (e.g. for simulating a projectile on a 3D cartesian grid or visualizing em-fields of a moving charged particle) – Bentley4 May 07 '12 at 21:39
  • http://pyopengl.sourceforge.net/ – John Riselvato May 07 '12 at 21:47

4 Answers4

4

3D support for python is fairly weak compared to other languages, but with the way that most of them are built, the appearance of the program is far more mutable than you might think. For instance, you talked about Vpython, while many of their examples are not visually appealing, most of them are also from previous releases, the most recent release includes both extrusions, materials, and skins, which allow you to customize your appearance much moreso than before.

It is probably worth noting also, that it is simply not possible to make render-quality images in real time (cycles is a huge step in that direction, but it's still not quite there). I believe that most of your issue here is you are looking for something that technology is simply not capable of now, however if you are willing to take on the burden for making your simulation look visually appealing, Vpython (which is a gussied up version of PyOpenGL) is probably your best bet. Below is a run down of different technologies though, in case you are looking for anything more general:

Blender: The most powerful python graphics program available, however it is made for graphic design and special effects, though it has very complex physics running underneath it, Blender is not made for physics simulations. Self contained.

Panda3D: A program very often compared to Blender, however mostly useful for games. The game engine is nicer to work with than Blender's, but the render quality is far lower, as is the feature-richness. Self contained

Ogre: A library that was very popular for game development back in the day, with a lot of powerful functionality, especially for creating game environments. Event handling is also very well implemented. Can be made to integrate with other libraries, but with difficulty.

VPython: A library intended for physics simulations that removes a lot of the texture mapping and rendering power compared to the other methods, however this capability is still there, as VPython is largely built from OpenGL, which is one of the most versatile graphics libraries around. As such, VPython also is very easy to integrate with other libraries.

PyOpenGL: OpenGL for Python. OpenGL is one of the most widely use graphics libraries, and is without a doubt capable of producing some of the nicest visuals on this list (Except for Blender, which is a class of its own), however it will not be easy to do so. PyOpenGL is very bare bones, and while the functionality is there, it will be harder to implement than anything else. Plays very will with other libraries, but only if you know what you're doing.

Slater Victoroff
  • 21,376
  • 21
  • 85
  • 144
  • Thnx! Reading what you wrote I figure if I wanted to start now the best way is to begin with VPython, develop the program as far as I can with that and modify it with PyOpenGl when necessary. When do you think the average computer will be fast enough for python to produce runtime physics simulations smoothly(rough estimate)? – Bentley4 Jun 02 '12 at 10:41
  • 1
    Your computer is currently totally capable of running a smooth runtime physics simulation, but you probably have to change your definition of smooth slightly. If you run your simulation in a simple while loop python will try to update as fast as possible which gives rise to a host of problems, however you can limit the rate of your while loop by simply saying something like: while True: rate(100) where the number in parens is the number of refreshes per second, I have found that 20 refreshes a second is about as low as the rate can go without loss in quality, and is light on your processor. – Slater Victoroff Jun 03 '12 at 20:21
  • How would you implement that rate function? Using time.sleep(n)? Thank you great tip! – Bentley4 Jun 06 '12 at 11:56
  • 1
    I believe the rate function is actually built in – Slater Victoroff Jun 06 '13 at 21:57
2

Try PyOpenGL. It is a library that provides Python bindings to OpenGL through the Python ctypes library.

Heres a demo of this:

PyOpenGL baseball demo

Community
  • 1
  • 1
C0deH4cker
  • 3,959
  • 1
  • 24
  • 35
2

If I needed a visualization package for python, I would start with Processing.py: https://github.com/jdf/processing.py

This is a python binding for the java-based Processing.org codes. A quick comparison can be found here: http://wiki.processing.org/w/Python_Comparison

Of course, if you are not constrained to python, then Processing itself would also be a good starting point: http://processing.org

There are also python bindings out there for Visualization Toolkit (VTK), but most of their examples are either C++ or Tk.

If all you're looking for is scene graph to move geometries around, not native vis, then I have seen some python binding for Open Scene Graph out there, eg: http://code.google.com/p/osgswig/

Good Luck!

Ruan Caiman
  • 881
  • 5
  • 5
0

From your question, it is not clear what you want to achieve. Do you want to create a standalone application that can be used to control the simulation at runtime, or, create a simulation using Python that can then be viewed offline?

For the latter, you could look at Blender, an open source 3D content creation suite which includes a python scripting interface giving access to most (if not all) of the internals of the application. Blender comes with some physics and particle libraries which might be of use and as an application is indicative of the type of software used to make visual effects for films etc.

If you want to make a standalone application to control the simulation at runtime, this is most likely not a suitable option. However if you want to produce a series of viewable images it might be worth a look.

Mark Streatfield
  • 3,189
  • 1
  • 22
  • 19
  • I want to make a standalone application that can be used to control the simulation at runtime. The graphics can be minimal if that is what is needed to make it run decently. E.g. only using lines, arrows and points to recreate a reference frame and mathematical points. If possible also simple but clean models for rigid bodies. – Bentley4 May 08 '12 at 00:32