0
$\begingroup$

I have a 3-dimensional volume array of size (64, 64, 64) which has an extension of ".npy". I wanted to visualize in Blender so that I can do post-processing work from the software.

  1. I tried loading through script as np.load('data.npy') after importing numpy library. It did not show me any error, but I am unable to visualize it.

  2. Is there a way I could load ".npy" file extension in Blender and visualize it. Or, is there a way I can convert the possible format for blender.

$\endgroup$
2
$\begingroup$

Numpy point cloud

Test script.

  • Get the verts of context object
  • Save as test.npy
  • Load saved file
  • Create mesh with saved verts
  • Add mesh to new object and link to scene

Test script

import bpy
import numpy as np

context = bpy.context
ob = context.object
me = ob.data
# get the coords of context object
coords = np.empty(len(me.vertices) * 3)
me.vertices.foreach_get("co", coords)
print(coords.reshape(-1, 3))
# save to .npy file
np.save('test.npy', coords.reshape(-1, 3))
#load it into another array
verts = np.load('test.npy')
print(verts)
# new mesh
me = bpy.data.meshes.new("Verts")
# load in verts
me.from_pydata(verts, [], [])
# create object and link to scene
vob = bpy.data.objects.new("Verts", me)
context.collection.objects.link(vob)
# give same global transform
#vob.matrix_world = ob.matrix_world
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.