Chain vdb_view to vdb_render
I was interested when using vdb_view to render a color image using vdb_render. The changes in this PR cause vdb_view to print the camera transformation matrix when the user hits the 'p' key. This allows the user the option of connecting the two programs together.
Previous discussion on this subject: https://github.com/AcademySoftwareFoundation/openvdb/discussions/1715
@danrbailey I had talked to you a few months ago about chaining vdb_view and vdb_print. Here is a proposed PR for the discussion here, what do you think?
https://github.com/AcademySoftwareFoundation/openvdb/discussions/1715
I am chaining vdb_view to vdb_render using the following script:
import subprocess
import numpy as onp
import pathlib
from scipy.spatial.transform import Rotation
vdb_path = pathlib.Path.home() / 'model.vdb'
# Run vdb_view process
vdb_view_command = f'vdb_view {str(vdb_path)}'
vdb_view_stream = subprocess.Popen(vdb_view_command.split(' '), stdout=subprocess.PIPE)
# When user presses the 'p' key show a rendered image
lines = []
for line in vdb_view_stream.stdout:
lines.append(line[:-1].decode('utf-8'))
if len(lines) >= 4:
matrix = onp.array(eval(''.join(lines)))
lines = []
rotation = Rotation.from_matrix(matrix[:3, :3])
translation = rotation.apply(-matrix[3, :3])
rph_degrees = rotation.as_euler('xyz', degrees=True)
exr_path = vdb_path.with_suffix('.exr')
command = (
f'vdb_render {str(vdb_path)} {str(exr_path)} '
f'-res 1920x1080 '
f'-color color '
f'-rotate {rph_degrees[0]},{rph_degrees[1]},{rph_degrees[2]} '
f'-translate {translation[0]},{translation[1]},{translation[2]} '
)[:-1]
subprocess.run(command.split(' '))
command = f'exrdisplay {str(exr_path)}'
subprocess.run(command.split(' '))