GLTF and Blender integration

O2sclpy

O2graph has experimental support for writing 3D objects to GLTF files and using Blender to perform some simple renderings of those 3D objects. O2graph needs a working directory to store the relevant textures and files, so typically one begins by setting the working directory for the 3D-objects using -set td_wdir.

One can create simple materials using -td-mat, a surface from a table3d slice using -td-den-plot, a scatter plot from a table using -td-scatter, an axis using -td-axis, axis labels set on rectangular prisms using -td-axis-label, an icosphere using -td-icos, an arrow using -td-arrow, and a parallelogram using -td-pgram.

Sets of 3D objects can be written to a GLTF file using -gltf. GLTF files, in turn, can be viewed in Blender using -bl-import.

The command -bl-yaw-mp4 creates a MP4 file from a Blender rendering of a set of 3D objects by rotating the camera around the vertical axis. The command -bl-yaw-six is similar, but moves the camera differently: it rotates in such a way as to show the faces of all six sides of the cube aligned with the coordinate axes.

Internally, the scales of the 3D objects are set with the variables xlo, xhi, ylo, yhi, zlo, and zhi. These can be set manually or if not, they are set automatically by the first yt-related command. All commands work on the user coordinate system by default, and then transform their arguments to \([0,1]\) when necessary.

3D Scatter plot example

o2graph -set td_wdir gltf \
-create table x grid:0,1,0.01 -function "x+0.1*sin(1.0e6*x)" y \
-function "x+y+0.1*sin(1.0e6*y)" z \
-index -select-rows "N<10" -function "x*20" x2 \
-td-scatter x y z x2 y z -td-axis "$ R~(\mathrm{km}) $" \
"$ M~(\mathrm{M}_{\odot}) $" "Probability" scatter_col_ \
-gltf scatter_col.gltf
_images/scatter_col.png

3D Density plot example

o2graph -create table3d x grid:0,1,0.1 y grid:0,1,0.1 \
z "exp(-3*(x-0.3)^2-3*(y-0.7)^2)" -set td_wdir gltf \
-td-den-plot z "cmap=viridis" -td-axis "$ R~(\mathrm{km}) $" \
"$ M~(\mathrm{M}_{\odot}) $" "Probability" den_plot_col_ \
-gltf den_plot_col.gltf
_images/den_plot_col.png

The GLTF can be viewed in any GLTF reader, for example at http://3dviewer.net/#model=https://github.com/awsteiner/o2sclpy/blob/dev/doc/static/gltf/den_plot_col.zip .

Density plot movie

o2graph -set td_wdir gltf -create table3d x grid:0,1,0.01 y grid:0,1,0.1 \
z "exp(-(x-0.3)^2-(y-0.7)^2)" \
-td-den-plot z "cmap=viridis" -td-axis "$ R~(\mathrm{km}) $" \
"$ M~(\mathrm{M}_{\odot}) $" "Probability" bl_den_plot_yaw_ \
-bl-yaw-mp4 40 gltf/bl_den_plot_yaw.mp4