I have a 3d numpy array containing results from a simulation which I want to render using Blender. When visualized using napari I get the expected result:
Using pyopenvdb’s copyFromArray function, I’ve attempted to import the same array within blender.
import bpy, os
import pyopenvdb as vdb
import numpy as np
# --- Scenario 3 -> .npy import of the actual array ---
actual_vol_path = '/Users/tomaubier/actual_volume.npy'
volume = np.load(actual_vol_path)
# numpy array to openvdb object
vecgrid = vdb.DoubleGrid()
vecgrid.name = 'density'
vecgrid.copyFromArray(volume)
# Saving the openvdb object
vdb_file_path = f'/Users/tomaubier/openvdb_volume.vdb'
vdb.write(vdb_file_path, grids=[vecgrid])
# Importing the volume within blender
bpy.ops.object.volume_import(filepath=vdb_file_path, files=[])
However this code gives me what looks like a array of shuffled values.
I then made up an arbitrary array defined as
# Making up a MWE volume
x = np.linspace(0, 5*np.pi, x_shape)
y = np.linspace(0, np.pi, y_shape)
z = np.linspace(0, .2*np.pi, z_shape)
X, Y, Z = np.meshgrid(x, y, z)
mwe_volume_presave = np.cos(X*Y*Z)
and got the expected result:
To check whether or not saving and loading the values in a .npy file could be at the root of this issue, I rendered the same dummy array after saving and loading it in a numpy file. As expected this test led to the same rendered output.
I currently don’t have any clues as to whats going on.. Do you guys have any ideas?
If anyone wants to perform tests with the data I used, I've created a repo with the blender file and .npy array.
Best.
printmethod to print values to the system command line. If I were you, I would try to look at a few coordinates where you know the values and see how they are loaded into Blender. This will give you good clues. I can also strongly recommend using VS Code as an external editor (and debugger!) to set breakpoints and check variables. I found this YouTube Video helpful:https://www.youtube.com/watch?v=YUytEtaVrrc$\endgroup$matplotlib imshow()that the volume forwarded to thecopyFromArrayfunction contained the expected values. The hypothesis stating that the issue arises from the numpy array to openvdb object conversion is still holding. I if you have any idea as to how I could debug this conversion process I would happily take your suggestions. Cheers $\endgroup$Geometry Nodesetup with aPoints to VolumeNode. Then you would have full control over your volume. I once did something similar to parse a 3D lookup table from a file. $\endgroup$