0

I would like to use blender to visualize a scatter plot animation with data from a large 2D array, such as

a = np.array([[0, 0, 0],
              [1, 2, 1],
              [4, 0, 1]]).

Here a[i] describes the position of the i-th mesh/object. I wish to create these objects in the blender scene. The following code does that with cubes, but is too slow when a contains thousands of vectors.

import bpy
import numpy as np

a = np.array([[0, 0, 0],
              [1, 2, 1],
              [4, 0, 1]])
for pos_vec in a:
    bpy.ops.mesh.primitive_cube_add(location=pos_vec)

How can I do this without looping in python or make it as fast as possible?

1 Answer 1

1

It looks like your "3D" array is a more like point Cloud data.

And Blender can import .ply point cloud data

bpy.ops.import_mesh.ply(filepath="PATH_TO_PLY.ply")

And Before that you just need to convert your 3-D array to .ply, there are plenty of ways. Each below will work.

  • Supposed you have your 3-D array in numpy.array. You can try python2plyfile

  • matlab

array3D =[1,0,0
          2,0,0
          3,0,0]
pc = pointCloud(array3D) 
pcwirte(pc, "PLY_FILE.ply")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.