3
$\begingroup$

I have a voxel representation of a model of the human body in numpy and would like to render it directly in Blender. Is there a file format for this? Most of the ones I've seen use polygonal meshes (ie. .obj files). In other words, could one render Minecraft directly in Blender? (or if not, in Unity3D, Maya, UnrealEngine, or any other popular modeling 3-D software?)

enter image description here

$\endgroup$
1
  • $\begingroup$ I don't know if there are any voxel based interchange file formats or standards, never heard of any myself, but if there are any, there might not be an imported or exporter for Blender so you would probably have to write your own $\endgroup$ – Duarte Farrajota Ramos Aug 5 '18 at 22:55
5
$\begingroup$

While there are several file formats used for voxel data, they are used for volumetric data, such as smoke and fluid, which I doubt will help you.

As you have the data in numpy, I would suggest letting numpy save the data to file using numpy.save, but if you are using numpy to generate the data you can use numpy in blender and not use a file format at all.

By creating your selection of block types, you can then use a script to duplicate a block into each position.

import bpy
import numpy as np

objs = bpy.data.objects
scn = bpy.context.scene

scene_objs = [
        objs['sand'],
        objs['grass'],
        objs['water'],
        ]

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

for x in range(voxel_data.shape[0]):
    for y in range(voxel_data.shape[1]):
        obj = scene_objs[voxel_data[x,y]].copy()
        scn.objects.link(obj)
        obj.location = (x*2.1, y*2.1, 0)
$\endgroup$
3
  • $\begingroup$ Great! Is there a way to smooth the edges and have Blender intelligently understand where to smooth? I'm trying to model the human body in Blender. $\endgroup$ – Nathan Aug 6 '18 at 22:47
  • $\begingroup$ Also, I appreciate you reading between the lines and solving my actual problem, rather than the one that was literally stated. Perhaps I should edit the original question $\endgroup$ – Nathan Aug 6 '18 at 23:01
  • 1
    $\begingroup$ @frank I would think if you can detect the spots to smooth, use a different block that has a beveled edge, or you could have modifiers in place and adjust settings for each object. obj.modifiers['Subsurf].levels = 2 $\endgroup$ – sambler Aug 7 '18 at 3:06
-2
$\begingroup$
import bpy
import numpy as np

objs = bpy.data.objects
scn = bpy.context.scene

scene_objs = [
        objs['sand'],
        objs['grass'],
        objs['water'],
        ]

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

for x in range(voxel_data.shape[0]):
    for y in range(voxel_data.shape[1]):
        obj = scene_objs[voxel_data[x,y]].copy()
        scn.objects.link(obj)
        obj.location = (x*2.1, y*2.1, 0)
$\endgroup$
2
  • 1
    $\begingroup$ an explanation of how this works would help this answer a lot $\endgroup$ – Sazerac Oct 23 '19 at 4:56
  • $\begingroup$ This code is verbatim copied (line for line) from the above answer $\endgroup$ – Nathan Mar 5 at 17:53

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.