|
| 1 | +# Blender scripting example |
| 2 | + |
| 3 | +Blender for 3D graphics creation<br> |
| 4 | +https://www.blender.org/ |
| 5 | + |
| 6 | + |
| 7 | +## Installation |
| 8 | + |
| 9 | +The python script `blender_sphere.py` uses Blender's python module. To use the script, we also need some interpolation routines from matplotlib/scipy which are not provided in the default python version that blender internally uses. One possibility to use the systems python frameworks is to set an environment variable `BLENDER_SYSTEM_PATH`. For example, on Mac having python installed through [MacPorts](https://www.macports.org), one can set |
| 10 | +``` |
| 11 | +export BLENDER_SYSTEM_PYTHON='/opt/local/Library/Frameworks/Python.framework/Versions/3.10/' |
| 12 | +``` |
| 13 | +For this to work, the python version must match the internal python version from Blender. In this example, Blender version 3.4.1 uses a python version 3.10. |
| 14 | + |
| 15 | + |
| 16 | +## Simulation setup |
| 17 | + |
| 18 | +First, run a (global) simulation example, e.g., in `EXAMPLES/global_small/`, turn on the surface movie flag in the `DATA/Par_file` and set the output type to velocities: |
| 19 | + ``` |
| 20 | + MOVIE_SURFACE = .true. |
| 21 | + .. |
| 22 | + MOVIE_VOLUME_TYPE = 6 |
| 23 | + ``` |
| 24 | + |
| 25 | + This will create a series of `moviedata***` files in the example `OUTPUT_FILES/` folder. |
| 26 | + Create a (symbolic) link to `OUTPUT_FILES` into this rendering working directory, e.g., |
| 27 | + ``` |
| 28 | + ln -s ../../../../EXAMPLES/global_small/OUTPUT_FILES/ |
| 29 | + ``` |
| 30 | + |
| 31 | + |
| 32 | +## Visualization |
| 33 | + |
| 34 | +To plot an image with python's matplotlib module of such a `moviedata***` file, you can type: |
| 35 | +``` |
| 36 | +./plot_moviedata.py --moviedata=OUTPUT_FILES/moviedata002800 --show |
| 37 | +``` |
| 38 | +This script just uses the default python framework with matplotlib/scipy to interpolate and plot an image, without any need of blender's functionality. For more options on this script type `./plot_moviedata.py --help` . It is meant to check and quickly visualize the moviedata files. |
| 39 | + |
| 40 | + |
| 41 | +### Blender textures |
| 42 | + |
| 43 | +For the example here to work, the blender script `plot_blender_sphere.py` will need a few texture images for the rendering of the sphere (earth image, topography, clouds, night). These can be created and put into the `resources/` folder. These textures are not provided here, as the file sizes can become quite large for high-res images and would bloat up the github repository. |
| 44 | + |
| 45 | +The `shakemovie` repository uses textures as well, you can use the script `convert_tga_to_jpg.sh` in the `resources/` folder to convert those `*.ppm` and `*.tga` files to high-res JPEG and PNG files, which are formats readable by blender. |
| 46 | + |
| 47 | +You could run the script also with no textures by setting the texture paths to empty strings in the user parameter section in file `plot_blender_sphere.py`. |
| 48 | + |
| 49 | + |
| 50 | +### Blender rendering |
| 51 | + |
| 52 | +Once the texture files are created, you can set the corresponding file names as user parameters in the python script `plot_blender_sphere.py`, then type: |
| 53 | + ``` |
| 54 | + ./plot_blender_sphere.py --moviedata=OUTPUT_FILES/moviedata002800 |
| 55 | + ``` |
| 56 | + |
| 57 | + This will create an image `out.moviedata002800.jpg`. For more script options, you can type `./plot_blender_sphere.py --help` . |
| 58 | + |
| 59 | + |
| 60 | +Finally, to create an animation, you would call the script with multiple moviedata files as input. It will render all data and rotate the sphere to create a movie: |
| 61 | + ``` |
| 62 | + ./plot_blender_sphere.py --moviedata=OUTPUT_FILES/moviedata00** |
| 63 | + ``` |
| 64 | + |
| 65 | +Please be patient, the rendering for many moviedata files can take a while. The movie file is stored as `out.anim.mp4`. |
| 66 | + |
| 67 | + |
| 68 | +Feel free to modify and contribute any improvements to these python scripts - and have fun with blender for scientific visualization! |
0 commit comments